Games-Lacuna-Task

 view release on metacpan or  search on metacpan

lib/Games/Lacuna/Task/Action/Defence.pm  view on Meta::CPAN

        unless $spaceport;
    my $spaceport_object = $self->build_object($spaceport);
    
    # Get all available ships
    my $ships_data = $self->request(
        object  => $spaceport_object,
        method  => 'view_all_ships',
        params  => [ { no_paging => 1 }, { tag => [ 'War' ] } ],
    );
    
    my @relocate_ship;
    my $dispatch_ship = 0;
    
    # Loop all war ships
    LOCAL_SHIPS:
    foreach my $ship (@{$ships_data->{ships}}) {
        next LOCAL_SHIPS
            unless $ship->{type} eq 'fighter'
            || $ship->{type} eq 'sweeper';
        
        next LOCAL_SHIPS

lib/Games/Lacuna/Task/Action/Defence.pm  view on Meta::CPAN

        # Dispatch fighter directly
        if ($ship->{type} eq 'fighter') {
            $dispatch_ship++;
            $self->request(
                object  => $spaceport_object,
                method  => 'send_ship',
                params  => [ $ship->{id}, { body_id => $to_body_id } ],
            );
        # Add sweeper to list of dispatchable units
        } elsif ($ship->{type} eq 'sweeper') {
            push(@relocate_ship,$ship->{id});
        }
        
        # Check if we have enough defenders
        return $dispatch_ship
            if $dispatch_ship >= $count;
    }
    
    # Relocate sweepers via push
    my $relocateable_ships = min( ($count-$dispatch_ship) , scalar(@relocate_ship), $self->_planet_attack->{$to_body_id}{free_slots} );
    if ($relocateable_ships > 0) {
        my @relocate_ships_final = @relocate_ship[0..($relocateable_ships-1)];
        $dispatch_ship += $self->push_ships($from_body_id,$to_body_id,\@relocate_ships_final);
    }
    
    return $dispatch_ship;
}

sub recall_defender {
    my ($self,$body_id,$first_attacker_arrive) = @_;
    
    my $spaceport = $self->find_building($body_id,'SpacePort');
    return 0



( run in 1.659 second using v1.01-cache-2.11-cpan-71847e10f99 )