From d7b1e04552208d5304c6d0aa467719a345de435f Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 21 Mar 2011 15:14:35 -0500 Subject: [PATCH] downgrade and fixes --- .../DB/Result/Map/Body/Planet/Station.pm | 13 +++++++ .../DB/Result/Propositions/DowngradeModule.pm | 21 +++++++++++ .../DB/Result/Propositions/InstallModule.pm | 35 +++++++++++++++++++ lib/Lacuna/RPC/Body.pm | 2 +- lib/Lacuna/RPC/Building.pm | 22 +++++++++++- var/www/public/changes.txt | 2 +- 6 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm create mode 100644 lib/Lacuna/DB/Result/Propositions/InstallModule.pm diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index f40675f3..826960eb 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -9,6 +9,19 @@ use Lacuna::Util qw(randint); use constant image => 'station'; __PACKAGE__->has_many('propositions','Lacuna::DB::Result::Propositions','station_id'); +has parliament => ( + is => 'rw', + lazy => 1, + default => sub { + my $self = shift; + my $parliament = $self->get_building_by_class('Lacuna::DB::Result::Building::Module::Parliament'); + if (defined $parliament) { + $parliament->body($self); + } + return $parliament; + }, +); + before sanitize => sub { my $self = shift; $self->propositions->delete_all; diff --git a/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm b/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm new file mode 100644 index 00000000..327c89cd --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/DowngradeModule.pm @@ -0,0 +1,21 @@ +package Lacuna::DB::Result::Propositions::DowngradeModule; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $station = $self->station; + my $building = $station->buildings->find($self->scratch->{building_id}); + if (defined $building) { + $building->downgrade; + } + else { + $self->pass_extra_message('Unfortunately by the time the proposition passed, the module had been demolished, effectively nullifying the vote.'); + } +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Propositions/InstallModule.pm b/lib/Lacuna/DB/Result/Propositions/InstallModule.pm new file mode 100644 index 00000000..e97e85e8 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/InstallModule.pm @@ -0,0 +1,35 @@ +package Lacuna::DB::Result::Propositions::InstallModule; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $station = $self->station; + my $building = $station->buildings->find($self->scratch->{building_id}); + if (defined $building) { + $building->finish_upgrade; + } + else { + $self->pass_extra_message('Unfortunately by the time the proposition passed, the module had been demolished, effectively nullifying the vote.'); + } +}; + +before fail => sub { + my ($self) = @_; + my $station = $self->station; + my $building = $station->buildings->find($self->scratch->{building_id}); + if (defined $building) { + $station->add_plan($building->class, 1, $building->level); + $building->demolish; + } + else { + $self->pass_extra_message('Unfortunately by the time the proposition passed, the module had been demolished, effectively nullifying the vote.'); + } +}; + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Body.pm b/lib/Lacuna/RPC/Body.pm index c4594254..7fa27123 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -50,7 +50,7 @@ sub rename { my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { - unless ($body->get_building_by_class('Lacuna::DB::Result::Building::Module::Parliament')->level >= 3) { + unless ($body->parliament->level >= 3) { confess [1013, 'You need to have a level 3 Parliament to rename a station.']; } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ diff --git a/lib/Lacuna/RPC/Building.pm b/lib/Lacuna/RPC/Building.pm index dd511f4f..e89e74cf 100644 --- a/lib/Lacuna/RPC/Building.pm +++ b/lib/Lacuna/RPC/Building.pm @@ -183,7 +183,7 @@ sub build { if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { my $name = $building->name.' ('.$building->x.','.$building->y.')'; my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ - type => 'UpgradeModule', + type => 'InstallModule', name => 'Install '.$name, description => 'Install '.$name.' on the station named "'.$body->name.'".', scratch => { building_id => $building->id }, @@ -212,6 +212,9 @@ sub demolish { my $body = $building->body; $building->can_demolish; if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { + unless ($body->parliament->level >= 2) { + confess [1013, 'You need to have a level 2 Parliament to demolish a module.']; + } my $name = $building->name.' ('.$building->x.','.$building->y.')'; my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ type => 'DemolishModule', @@ -238,6 +241,23 @@ sub downgrade { my $building = $self->get_building($empire, $building_id); my $body = $building->body; $building->can_downgrade; + if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { + unless ($body->parliament->level >= 2) { + confess [1013, 'You need to have a level 2 Parliament to downgrade a module.']; + } + my $name = $building->name.' ('.$building->x.','.$building->y.')'; + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'DowngradeModule', + name => 'Downgrade '.$name, + description => 'Downgrade '.$name.' on the station named "'.$body->name.'" from level '.$self->level.' to '.($self->level - 1).'.', + scratch => { building_id => $building->id }, + proposed_by_id => $empire->id, + }); + $proposition->station($body); + $proposition->proposed_by($empire); + $proposition->insert; + confess [1017, 'The downgrade order has been delayed pending a parliamentary vote.']; + } $building->downgrade; $body->tick; return $self->view($empire, $building); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 0f5888ba..05c14704 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,7 +1,7 @@ 3.0200 - Add: Added Amalgus Meadow and Denton Brambles glyph buildings. - Add: Added {VoteYes 0 0 0} and {VoteNo 0 0 0} formatters to the email DSL. - - Add: Through parliamentary vote you can now: rename and abandon a station; build, upgrade, and demolish a module on a station. + - Add: Through parliamentary vote you can now: rename and abandon a station; build, upgrade, downgrade, and demolish a module on a station. - Add: Small improvements to starting player experience. - Rule: Surveyors now return efficiency information in the table of building data. - API: Slight change to the Space Station Lab API to accomodate displaying descriptions and images for the plans. -- 2.51.2