diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index db2b2942..ed6ec076 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -30,17 +30,26 @@ after handle_arrival_procedures => sub { $self->saw_combat($body_attacked) if $is_planet; my $alliance_id; - if ( $is_planet && $body_attacked->empire ) { + if ( $is_planet && $body_attacked->empire ) { $alliance_id = $body_attacked->empire->alliance_id; } - my $bodies = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search({ id => { '!=' => $body_attacked->id}, star_id => $body_attacked->star_id}); + my $bodies = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search( + { id => { '!=' => $body_attacked->id}, star_id => $body_attacked->star_id} + ); while (my $body = $bodies->next) { - next unless ( $body->empire_id || $is_asteroid ); - if ( $is_asteroid || $body->empire->alliance_id == $alliance_id ) { - $self->saw_combat($body) if $body->isa('Lacuna::DB::Result::Map::Body::Planet'); + # asteroids don't have SAWs + next unless $body->isa('Lacuna::DB::Result::Map::Body::Planet'); + + if ( $is_asteroid ) { + # all planets defend the asteroids in their system + $self->saw_combat($body); + } + else { + next unless ( $body->empire && $body->empire_id && $body->empire->alliance_id == $alliance_id ); + # alliance planets defend each other in their system + $self->saw_combat($body); } } - $self->defender_combat(); }; @@ -48,6 +57,13 @@ sub damage_in_combat { my ($self, $defender, $damage) = @_; $self->combat( $self->combat - $damage ); return unless $self->combat < 1; + $self->attacker_shot_down($defender); + $self->delete; + confess [-1] +} + +sub attacker_shot_down { + my ($self, $defender) = @_; my $body_attacked = $self->foreign_body; $self->body->empire->send_predefined_message( tags => ['Alert'], @@ -57,11 +73,25 @@ sub damage_in_combat { $defender->body->empire->send_predefined_message( tags => ['Alert'], filename => 'we_shot_down_a_ship.txt', - params => [$self->type_formatted, $body_attacked->id, $body_attacked->name, $defender->body->empire_id, $defender->body->empire->name], + params => [$self->type_formatted, $body_attacked->id, $body_attacked->name, $self->body->empire_id, $self->body->empire->name], ); - $defender->body->add_news(20, sprintf('An amateur astronomer witnessed an explosion in the sky today over %s.',$body_attacked->name)); - $self->delete; - confess [-1] + $body_attacked->add_news(20, sprintf('An amateur astronomer witnessed an explosion in the sky today over %s.',$body_attacked->name)); +} + +sub defender_shot_down { + my ($self, $defender) = @_; + my $body_attacked = $self->foreign_body; + $self->body->empire->send_predefined_message( + tags => ['Alert'], + filename => 'we_shot_down_a_defender.txt', + params => [$defender->type_formatted, $body_attacked->x, $body_attacked->y, $body_attacked->name, $defender->body->empire_id, $defender->body->empire->name], + ); + $defender->body->empire->send_predefined_message( + tags => ['Alert'], + filename => 'defender_shot_down.txt', + params => [$defender->type_formatted, $defender->body->id, $defender->body->name, $body_attacked->x, $body_attacked->y, $body_attacked->name], + ); + $body_attacked->add_news(20, sprintf('An amateur astronomer witnessed an explosion in the sky today over %s.',$body_attacked->name)); } sub ship_to_ship_combat { @@ -69,18 +99,25 @@ sub ship_to_ship_combat { # if there are ships let's duke it out while (my $ship = $ships->next) { + + # defender dealt this damage my $damage = $ship->combat; if ($ship->type eq 'drone') { $ship->delete; next; } + + # subtract attacker's damage dealt from defender $ship->combat( $ship->combat - $self->combat ); if ($ship->combat < 1) { + $self->defender_shot_down($ship); $ship->delete; } else { + # "reset" $ship->send(target => $self->foreign_body->star); } + $self->damage_in_combat($ship, $damage); } } @@ -99,10 +136,17 @@ sub defender_combat { sub allied_combat { my ($self) = @_; + my $body_attacked = $self->foreign_body; + my $is_planet = $body_attacked->isa('Lacuna::DB::Result::Map::Body::Planet'); + my $is_asteroid = $body_attacked->isa('Lacuna::DB::Result::Map::Body::Asteroid'); - # get allied ships + # get allied defenders my $allied_ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( - { foreign_body_id => $self->foreign_body_id, type => { in => [qw(fighter)]}, task => 'Defend' }, + { + foreign_body_id => $self->foreign_body_id, + type => 'fighter', + task => 'Defend', + }, ); # initiate ship to ship combat between the attackers and the allied ships diff --git a/var/messages/defender_shot_down.txt b/var/messages/defender_shot_down.txt new file mode 100644 index 00000000..a271373d --- /dev/null +++ b/var/messages/defender_shot_down.txt @@ -0,0 +1,7 @@ +Ship Shot Down +~~~ +Our %s from {Planet %s %s} was shot down while defending {Starmap %s %s %s}. + +Regards, + +Your Humble Assistant diff --git a/var/messages/we_shot_down_a_defender.txt b/var/messages/we_shot_down_a_defender.txt new file mode 100644 index 00000000..f9f5111d --- /dev/null +++ b/var/messages/we_shot_down_a_defender.txt @@ -0,0 +1,7 @@ +Target Neutralized +~~~ +Our offensive squadron was able to shoot down a %s that was defending {Starmap %s %s %s}. Its markings indicate that it was from {Empire %s %s}. + +Regards, + +Your Humble Assistant diff --git a/var/messages/we_shot_down_a_ship.txt b/var/messages/we_shot_down_a_ship.txt index 235dd8a9..15f92303 100644 --- a/var/messages/we_shot_down_a_ship.txt +++ b/var/messages/we_shot_down_a_ship.txt @@ -1,6 +1,6 @@ Target Neutralized ~~~ -Our defensive squadron was able to shoot down a %s before it reached {Planet %s %s}. Its markings indicate that it was from {Empire %s %s}. +Our defensive forces were able to shoot down a %s before it reached {Planet %s %s}. Its markings indicate that it was from {Empire %s %s}. Regards, diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 4cecfbd0..8b7625c8 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,6 +2,8 @@ - API: The status for defending fighters will now include from and orbiting blocks (as returned by view_all_ships(), get_ships_for(), etc). The get_ships_for() now includes a recallable block when that lists the fighters that defending that body. - API: Added Lacuna::RCP::Captcha with methods fetch() and solve(). - API: Trade Ministry and Transporter's accept_from_market methods use the new captchas. + - Fix: Attacker shot down messages will once again show the proper Empire. + - Add: Defender shot down messages have been added. 2.4600 - Add: "Allied Defense" as outlined below.