From 503af388fae03082945b00cbf080ec143e87119d Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 21 Mar 2011 14:59:16 -0500 Subject: [PATCH] added upgrade/build module, and some fixes --- lib/Lacuna/DB/Result/Building.pm | 3 +- .../DB/Result/Propositions/AbandonStation.pm | 4 -- .../Result/Propositions/DemolishBuilding.pm | 26 ------------ .../DB/Result/Propositions/DemolishModule.pm | 7 +--- .../DB/Result/Propositions/RenameStation.pm | 4 -- .../DB/Result/Propositions/UpgradeModule.pm | 41 +++++++++++++++++++ lib/Lacuna/RPC/Body.pm | 3 ++ lib/Lacuna/RPC/Building.pm | 32 ++++++++++++++- var/www/public/changes.txt | 3 +- 9 files changed, 80 insertions(+), 43 deletions(-) delete mode 100644 lib/Lacuna/DB/Result/Propositions/DemolishBuilding.pm create mode 100644 lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index e8646a8c..f5f1f125 100644 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -780,7 +780,8 @@ sub start_upgrade { # set time to build, plus what's in the queue my $time_to_build = $in_parallel ? DateTime->now : $body->get_existing_build_queue_time; - $time_to_build->add(seconds=>$cost->{time}); + my $time_to_add = $body->isa('Lacuna::DB::Result::Map::Body::Planet::Station') ? 60 * 60 * 72 : $cost->{time}; + $time_to_build->add(seconds=>$time_to_add); # add to queue $self->update({ is_upgrading => 1, diff --git a/lib/Lacuna/DB/Result/Propositions/AbandonStation.pm b/lib/Lacuna/DB/Result/Propositions/AbandonStation.pm index ff4a53f7..1732735c 100644 --- a/lib/Lacuna/DB/Result/Propositions/AbandonStation.pm +++ b/lib/Lacuna/DB/Result/Propositions/AbandonStation.pm @@ -10,10 +10,6 @@ before pass => sub { $self->station->sanitize; }; -before fail => sub { - my ($self) = @_; -}; - no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Propositions/DemolishBuilding.pm b/lib/Lacuna/DB/Result/Propositions/DemolishBuilding.pm deleted file mode 100644 index 0c973b6b..00000000 --- a/lib/Lacuna/DB/Result/Propositions/DemolishBuilding.pm +++ /dev/null @@ -1,26 +0,0 @@ -package Lacuna::DB::Result::Propositions::DemolishBuilding; - -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->demolish; - } - else { - $self->pass_extra_message('Unfortunately by the time the proposition passed, the building had already been demolished, effectively nullifying the vote.'); - } -}; - -before fail => sub { - my ($self) = @_; -}; - - -no Moose; -__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm b/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm index 070ccf05..6f0122d4 100644 --- a/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm +++ b/lib/Lacuna/DB/Result/Propositions/DemolishModule.pm @@ -13,14 +13,9 @@ before pass => sub { $building->demolish; } else { - $self->pass_extra_message('Unfortunately by the time the proposition passed, the building had already been demolished, effectively nullifying the vote.'); + $self->pass_extra_message('Unfortunately by the time the proposition passed, the module had already been demolished, effectively nullifying the vote.'); } }; -before fail => sub { - my ($self) = @_; -}; - - no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Propositions/RenameStation.pm b/lib/Lacuna/DB/Result/Propositions/RenameStation.pm index 7d46b222..4d22d34e 100644 --- a/lib/Lacuna/DB/Result/Propositions/RenameStation.pm +++ b/lib/Lacuna/DB/Result/Propositions/RenameStation.pm @@ -18,10 +18,6 @@ before pass => sub { } }; -before fail => sub { - my ($self) = @_; -}; - no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm b/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm new file mode 100644 index 00000000..af8a7261 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/UpgradeModule.pm @@ -0,0 +1,41 @@ +package Lacuna::DB::Result::Propositions::UpgradeModule; + +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, $building->level + 1); + if ($building->level == 0 ) { + $building->demolish; + } + else { + $building->is_upgrading(0); + $building->update; + } + } + 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 cb512736..c4594254 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -50,6 +50,9 @@ 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) { + confess [1013, 'You need to have a level 3 Parliament to rename a station.']; + } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ type => 'RenameStation', name => 'Rename Station', diff --git a/lib/Lacuna/RPC/Building.pm b/lib/Lacuna/RPC/Building.pm index f5facc2e..dd511f4f 100644 --- a/lib/Lacuna/RPC/Building.pm +++ b/lib/Lacuna/RPC/Building.pm @@ -52,6 +52,21 @@ sub upgrade { $building->start_upgrade($cost); + # add vote + 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', + name => 'Upgrade '.$name, + description => 'Upgrade '.$name.' on the station named "'.$body->name.'" from level '.$building->level.' to '.($building->level + 1).'.', + scratch => { building_id => $building->id }, + proposed_by_id => $empire->id, + }); + $proposition->station($body); + $proposition->proposed_by($empire); + $proposition->insert; + } + return { status => $self->format_status($empire, $body), building => { @@ -164,6 +179,21 @@ sub build { # build it $body->build_building($building); + # add vote + 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', + name => 'Install '.$name, + description => 'Install '.$name.' on the station named "'.$body->name.'".', + scratch => { building_id => $building->id }, + proposed_by_id => $empire->id, + }); + $proposition->station($body); + $proposition->proposed_by($empire); + $proposition->insert; + } + # show the user return { status => $self->format_status($empire, $body), @@ -184,7 +214,7 @@ sub demolish { 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 => 'DemolishBuilding', + type => 'DemolishModule', name => 'Demolish '.$name, description => 'Demolish '.$name.' on the station named "'.$body->name.'".', scratch => { building_id => $building->id }, diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index bf9f0183..0f5888ba 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,7 +1,8 @@ 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 a station, abandon a station, demolish a building on a station. + - Add: Through parliamentary vote you can now: rename and abandon a station; build, upgrade, 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. - Fix: P16 type planets were being misidentified as P17 planets. -- 2.51.2