Skip to content

Commit

Permalink
Finish Bugout, Sabotage Defenses, and fetching issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemming552 committed Nov 30, 2014
1 parent b0b2855 commit 4c33f1b
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/Lacuna/DB/Result/Ships/SpyPod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ with "Lacuna::Role::Ship::Send::NotIsolationist";
with "Lacuna::Role::Ship::Send::LoadWithSpies";
with "Lacuna::Role::Ship::Send::IsHostile";
with "Lacuna::Role::Ship::Arrive::CaptureWithSpies";
with "Lacuna::Role::Ship::Arrive::PickUpSpies";
with "Lacuna::Role::Ship::Arrive::CargoExchange";
with "Lacuna::Role::Ship::Arrive::Scuttle";

Expand Down
1 change: 1 addition & 0 deletions lib/Lacuna/DB/Result/Ships/SpyShuttle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ with "Lacuna::Role::Ship::Send::LoadWithSpies";
with "Lacuna::Role::Ship::Send::IsHostile";
with "Lacuna::Role::Ship::Arrive::CaptureWithSpies";
with "Lacuna::Role::Ship::Arrive::Orbit";
with "Lacuna::Role::Ship::Arrive::PickUpSpies";
with "Lacuna::Role::Ship::Arrive::CargoExchange";

no Moose;
Expand Down
203 changes: 202 additions & 1 deletion lib/Lacuna/DB/Result/Spies.pm
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ sub offensive_assignments {
recovery => $self->recovery_time(60 * 60 * 8),
skill => 'mayhem',
},
{
task =>'Sabotage Defenses',
recovery => $self->recovery_time(60 * 60 * 10),
skill => 'mayhem',
},
{
task =>'Sabotage BHG',
recovery => 0,
Expand Down Expand Up @@ -262,13 +267,23 @@ sub defensive_assignments {

sub neutral_assignments {
my $self = shift;
return (
my @assignments = (
{
task => 'Idle',
recovery => 0,
skill => 'none',
},
);
if ($self->on_body->id ne $self->from_body_id) {
push @assignments, (
{
task =>'Bugout',
recovery => 0,
skill => '*',
},
);
}
return @assignments;
}

sub get_possible_assignments {
Expand Down Expand Up @@ -531,6 +546,7 @@ use constant assignments => (
'Rescue Comrades',
'Sabotage Resources',
'Appropriate Resources',
'Sabotage Defenses',
'Sabotage Infrastructure',
'Sabotage BHG',
'Assassinate Operatives',
Expand All @@ -539,6 +555,7 @@ use constant assignments => (
'Incite Rebellion',
'Appropriate Technology',
'Incite Insurrection',
'Bugout',
'Intel Training',
'Mayhem Training',
'Politics Training',
Expand Down Expand Up @@ -620,6 +637,9 @@ sub assign {
elsif ($assignment eq 'Security Sweep') {
return $self->run_security_sweep($mission);
}
elsif ($assignment eq 'Bugout') {
return $self->bugout($mission);
}
else {
return $self->run_mission($mission);
}
Expand Down Expand Up @@ -684,6 +704,7 @@ my %outcomes = (
'Appropriate Technology' => 'appropriate_tech',
'Sabotage Probes' => 'sabotage_probes',
'Rescue Comrades' => 'rescue_comrades',
'Sabotage Defenses' => 'sabotage_defenses',
'Sabotage Resources' => 'sabotage_resources',
'Appropriate Resources' => 'appropriate_resources',
'Assassinate Operatives' => 'assassinate_operatives',
Expand Down Expand Up @@ -943,6 +964,88 @@ sub run_security_sweep {
return $out;
}

sub bugout {
my ($self, $mission) = @_;

if (!$self->empire->alliance_id || $self->empire->alliance_id != $self->on_body->empire->alliance_id ) {
my $power = $self->offense + $self->intel_xp;
my $toughness = 0;
my $defender = $self->get_defender;
my $hfa = 0;
if (defined $defender) {
$toughness = $defender->defense + $defender->intel_xp;
$hfa = $defender->home_field_advantage;
}
my $breakthru = ($power - $toughness - $hfa) + $self->luck;

$breakthru = ( randint(0,99) < 5) ? $breakthru * -1 : $breakthru;
if ($breakthru < -2000) {
$self->on_body->add_news(50,
'An enemy agent narrowly got away from the security forces of %s.',
$self->on_body->name);
$self->on_body->empire->send_predefined_message(
tags => ['Spies','Alert'],
filename => 'unauthorized_launch_tracked.txt',
params => [$self->on_body->id, $self->on_body->name,
$self->from_body->x, $self->from_body->y, $self->from_body->name],
);
#Narrow escape home
}
elsif ($breakthru > 500) {
#Clean escape
$self->on_body->add_news(10,
'An unauthorized ship launching happened on %s.',
$self->on_body->name);
}
else {
$self->on_body->add_news(50,
'An unauthorized ship launching happened on %s.',
$self->on_body->name);
$self->on_body->empire->send_predefined_message(
tags => ['Spies','Alert'],
filename => 'unauthorized_launch.txt',
params => [$self->on_body->id, $self->on_body->name],
);
}
$self->empire->send_predefined_message(
tags => ['Intelligence'],
filename => 'on_way_home.txt',
params => [
$self->on_body->empire->id,
$self->on_body->empire->name,
$self->on_body->x,
$self->on_body->y,
$self->on_body->name,
$self->name,
$self->from_body->id,
$self->from_body->name],
);
}
my $spy_pod = Lacuna->db->resultset('Ships')->new({
body_id => $self->from_body_id,
type => 'spy_pod',
name => "Bugout",
})->insert;
$spy_pod->date_available(DateTime->now);
$spy_pod->speed(1000+ ($self->level*100));
$spy_pod->send(
target => $self->on_body,
direction => 'in',
payload => { spies => [ $self->id ] }
);
$self->available_on($spy_pod->date_available);
$self->on_body_id($self->from_body_id);
$self->task('Travelling');
$self->started_assignment(DateTime->now);
$self->update;
my $out = { result => 'Success',
# message_id => $message_id,
reason => random_element(['Mom would have been proud.',
'Done.',
'That is why you pay me the big bucks.']) };
return $out;
}

sub get_defender {
my ($self, $mission) = @_;

Expand Down Expand Up @@ -1546,6 +1649,26 @@ sub abduct_operatives_loss {
}
}

sub sabotage_defenses {
my $self = shift;
given (randint(1,4)) {
when (1) { return $self->knock_defender_unconscious(@_) }
when (2) { return $self->shut_down_defenses(@_) }
when (3) { return $self->shut_down_defenses(@_) }
when (4) { return $self->destroy_defense_ship(@_) }
# when (5) { return $self->destroy_incoming_supply(@_) }
}
}

sub sabotage_defenses_loss {
my $self = shift;
given (randint(1,3)) {
when (1) { return $self->capture_saboteur(@_) }
when (2) { return $self->thwart_saboteur(@_) }
when (3) { return $self->knock_attacker_unconscious(@_) }
}
}

sub sabotage_resources {
my $self = shift;
given (randint(1,9)) {
Expand Down Expand Up @@ -2269,6 +2392,44 @@ sub destroy_infrastructure {
)->id;
}

sub destroy_defense_ship {
my ($self, $defender) = @_;
my $ship = $self->on_body->ships->search(
{task => 'Docked',
type => {'in' => ['sweeper',
'fighter',
'drone',
]},
},
{rows => 1, order_by => 'rand()' }
)->single;

return $self->ship_not_found->id unless (defined $ship);
$self->things_destroyed( $self->things_destroyed + 1 );
$self->on_body->empire->send_predefined_message(
tags => ['Spies','Alert'],
filename => 'ship_blew_up_at_port.txt',
params => [$ship->type_formatted, $self->on_body->id, $self->on_body->name],
);
my $message = $self->empire->send_predefined_message(
tags => ['Intelligence'],
filename => 'sabotage_report.txt',
params => [$ship->type_formatted,
$self->on_body->x,
$self->on_body->y,
$self->on_body->name,
$self->name,
$self->from_body->id,
$self->from_body->name],
);
$self->on_body->add_news(90,
'Today officials on %s are investigating the explosion of a %s at the Space Port.',
$self->on_body->name,
$ship->type_formatted);
$ship->delete;
return $message->id;
}

sub destroy_ship {
my ($self, $defender) = @_;
my $ship = $self->on_body->ships->search(
Expand Down Expand Up @@ -2788,6 +2949,46 @@ sub thwart_thief {
return $defender->thwart_a_spy($self)->id;
}

sub shut_down_defenses {
my ($self, $defender) = @_;

my ($building) = sort {
rand() <=> rand()
}
grep {
($_->efficiency > 0) and (
$_->class eq 'Lacuna::DB::Result::Building::SAW' or
$_->class eq 'Lacuna::DB::Result::Building::Shipyard' or
$_->class eq 'Lacuna::DB::Result::Building::Intelligence' or
$_->class eq 'Lacuna::DB::Result::Building::Security' or
$_->class eq 'Lacuna::DB::Result::Building::Module::PoliceStation' or
$_->class eq 'Lacuna::DB::Result::Building::Permanent::GratchsGauntlet' or
$_->class eq 'Lacuna::DB::Result::Building::Permanent::CitadelOfKnope' )
}
@{$self->on_body->building_cache};

return $self->building_not_found->id unless defined $building;
$self->on_body->empire->send_predefined_message(
tags => ['Spies','Alert'],
filename => 'building_loss_of_power.txt',
params => [$building->name, $self->on_body->id, $self->on_body->name],
);
$building->spend_efficiency(2 * $self->level)->update;
$self->on_body->add_news(25,
'Employees at the %s on %s were left in the dark today during a power outage.',
$building->name,
$self->on_body->name);
return $self->empire->send_predefined_message(
tags => ['Intelligence'],
filename => 'we_disabled_a_building.txt',
params => [$building->name,
$self->on_body->x,
$self->on_body->y,
$self->on_body->name,
$self->format_from],
)->id;
}

sub shut_down_building {
my ($self, $defender) = @_;

Expand Down
1 change: 1 addition & 0 deletions lib/Lacuna/Role/Ship/Arrive/Orbit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ after handle_arrival_procedures => sub {
# only orbit on arrival to the foreign body
return if $self->direction eq 'in';

return if ( $self->payload->{fetch_spies} ); # Don't orbit if we're fetching
$self->orbit->update;

confess [-1];
Expand Down
1 change: 1 addition & 0 deletions lib/Lacuna/Role/Ship/Send/LoadWithSpies.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ after send => sub {
return if ( $self->direction eq 'in' && $self->type ne 'spy_shuttle' ); # load outbound ships and inbound spy shuttles
return if ( $self->payload->{mercenary} ); # Mercenary already loaded
return if ( $self->payload->{spies} ); # Spies already loaded
return if ( $self->payload->{fetch_spies} ); # Don't send spies if we are fetching
my $arrives = DateTime->now->add(seconds=>$self->calculate_travel_time($self->foreign_body));
my @spies;
my $to_body = $self->direction eq 'out' ? $self->foreign_body : $self->body;
Expand Down
7 changes: 7 additions & 0 deletions var/messages/on_way_home.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
On Way Home
~~~
I managed to give {Empire %s %s}'s goons the slip and am heading away from {Starmap %s %s %s}. I'll be home soon.

Regards,

%s of {Planet %s %s}
8 changes: 8 additions & 0 deletions var/messages/unauthorized_launch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Unauthorized Launch
~~~
A launch was seen leaving the atmosphere just now from {Planet %s %s}.

Regards,

Your Humble Assistant

9 changes: 9 additions & 0 deletions var/messages/unauthorized_launch_tracked.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Launch Tracked
~~~
A launch was seen leaving the atmosphere just now from {Planet %s %s}.
We managed to track it long enough to see that it is headed for {Starmap %s %s %s}.

Regards,

Your Humble Assistant

3 changes: 3 additions & 0 deletions var/www/public/changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
3.0907:
- Add: Timer added to colony object preventing passage into Neutral Zone.
- Add: colonies and stations added to empire stat. planets kept to maintain backwards compatibility
- Fix: Fetching Spies no longer will send more spies.
- Add: Sabotage Defenses task added for spies.
- Add: Bugout task for spies added to get spies home.

3.0906:
- Fix: Some fixes to the send_ship_types API call.
Expand Down

0 comments on commit 4c33f1b

Please sign in to comment.