From b3287544ab8a76a460c4e12f5c568a017474a5c2 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 1 Nov 2010 15:59:07 -0500 Subject: [PATCH] added citadel --- lib/Lacuna/DB/Result/Ships.pm | 33 +++++++++++++++++++------- var/messages/our_ship_hit_building.txt | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index b921185f..957d0cbc 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -330,22 +330,37 @@ sub trigger_defense { sub damage_building { my ($self, $building) = @_; my $body_attacked = $self->foreign_body; - $building ||= Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( + my $buildings = Lacuna->db->resultset('Lacuna::DB::Result::Building'); + $building ||= $buildings->search( { body_id => $self->foreign_body_id }, {order_by => { -desc => 'efficiency'}, rows=>1} )->single; $building->body($body_attacked); - $building->spend_efficiency(randint(5,35)); - $building->update; + my $amount = randint(10,70); + my $citadel = $buildings->search({class=>'Lacuna::DB::Result::Building::Permanent::Citadel'},{rows=>1})->single; + if (defined $citadel) { + if ($citadel->level == 1) { + $citadel->delete; + } + else { + $citadel->level($citadel->level - 1); + $citadel->update; + } + $building = $citadel; + } + else { + $building->spend_efficiency($amount); + $building->update; + $body_attacked->empire->send_predefined_message( + tags => ['Alert'], + filename => 'ship_hit_building.txt', + params => [$self->type_formatted, $building->name, $body_attacked->id, $body_attacked->name, $self->body->empire_id, $self->body->empire->name], + ); + } $self->body->empire->send_predefined_message( tags => ['Alert'], filename => 'our_ship_hit_building.txt', - params => [$self->type_formatted, $body_attacked->x, $body_attacked->y, $body_attacked->name, $building->name], - ); - $body_attacked->empire->send_predefined_message( - tags => ['Alert'], - filename => 'ship_hit_building.txt', - params => [$self->type_formatted, $building->name, $body_attacked->id, $body_attacked->name, $self->body->empire_id, $self->body->empire->name], + params => [$self->type_formatted, $body_attacked->x, $body_attacked->y, $body_attacked->name, $building->name, $amount], ); $body_attacked->add_news(70, sprintf('An attack ship screamed out of the sky and damaged the %s on %s.',$building->name, $body_attacked->name)); $self->delete; diff --git a/var/messages/our_ship_hit_building.txt b/var/messages/our_ship_hit_building.txt index f90a10f4..48974d33 100644 --- a/var/messages/our_ship_hit_building.txt +++ b/var/messages/our_ship_hit_building.txt @@ -1,6 +1,6 @@ Target Hit ~~~ -Our %s reached {Starmap %s %s %s} and damaged the %s. +Our %s reached {Starmap %s %s %s} and damaged the %s by %s%%. Regards, -- 2.51.2