From f4ca169c017054baac0dea20841da33662406eb5 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 27 Mar 2011 14:09:27 -0500 Subject: [PATCH] added ownership transfer --- docs/Parliament.pod | 44 +++++++++++++++++-- .../Propositions/TransferStationOwnership.pm | 27 ++++++++++++ lib/Lacuna/RPC/Building/Parliament.pm | 41 +++++++++++++++-- t/Parliament.t | 5 ++- var/www/public/changes.txt | 1 + 5 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 lib/Lacuna/DB/Result/Propositions/TransferStationOwnership.pm diff --git a/docs/Parliament.pod b/docs/Parliament.pod index fcae072c..04073ea0 100644 --- a/docs/Parliament.pod +++ b/docs/Parliament.pod @@ -122,7 +122,7 @@ The following methods propose laws or actions to be taken by the station on beha =head2 propose_writ ( session_id, building_id, title, description ) -Proproses an unenforceable law. +Proproses an unenforceable law. Only works with Parliament 4 and higher. { "status" : { ... }, @@ -160,6 +160,44 @@ An explict reason why the BFG should be fired upon the target. Same rules as an + + +=head2 propose_transfer_station_ownership ( session_id, building_id, to_empire_id ) + +Transfer the ownership of the station to another member of the alliance. Only works with Parliament 5 and higher. + + { + "status" : { ... }, + "proposition" : { + "id" : "id-goes-here", + "name" : "Transfer Station", + "description" : "Transfer ownership of Deep Space 9 from The Federation to the Klingon Empire.", + "votes_needed" : 7, + "votes_yes" : 0, + "votes_no" : 0, + "status" : "Pending", + "date_ends" : "01 31 2010 13:09:05 +0600", + "proposed_by" : { + "id" : "id-goes-here", + "name" : "Klingons", + } + } + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the parliament. + +=head3 to_empire_id + +The id of an empire within the alliance that wants control over the station. + + + =head2 propose_fire_bfg ( session_id, building_id, target_x, target_y, reason ) Fires the BFG equipped on all space stations at a planet of Parliament's choosing as long as it is within the jurisdiction of the station. Can only be called by Parliament level 30. @@ -169,7 +207,7 @@ Fires the BFG equipped on all space stations at a planet of Parliament's choosin "proposition" : { "id" : "id-goes-here", "name" : "Fire BFG", - "description" : "Fire BFG at 'Bri Prui 7' from 'Deep Space 1'. Reason cited: They smell funny.", + "description" : "Fire BFG at Alderaan from The Death Star. Reason cited: The princess isn't talking!", "votes_needed" : 7, "votes_yes" : 0, "votes_no" : 0, @@ -177,7 +215,7 @@ Fires the BFG equipped on all space stations at a planet of Parliament's choosin "date_ends" : "01 31 2010 13:09:05 +0600", "proposed_by" : { "id" : "id-goes-here", - "name" : "Klingons", + "name" : "Admiral Motti", } } } diff --git a/lib/Lacuna/DB/Result/Propositions/TransferStationOwnership.pm b/lib/Lacuna/DB/Result/Propositions/TransferStationOwnership.pm new file mode 100644 index 00000000..c6daf725 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/TransferStationOwnership.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Propositions::TransferStationOwnership; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $station = $self->station; + my $to_empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($self->scratch->{empire_id}); + if (defined $to_empire) { + if ($to_empire->alliance_id == $station->alliance_id) { + $station->empire_id($to_empire->id); + $station->update; + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the receiving empire was no longer a member of the alliance, effectively nullifying the vote.'); + } + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the receiving empire no longer existed, effectively nullifying the vote.'); + } +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index f390428c..6ae4b475 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -74,7 +74,7 @@ sub propose_fire_bfg { my ($self, $session_id, $building_id, $x, $y, $reason) = @_; my $empire = $self->get_empire_by_session($session_id); if ($empire->current_session->is_sitter) { - confess [1015, 'Sitters cannot vote in parliament.']; + confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); unless ($building->level >= 30) { @@ -112,7 +112,7 @@ sub propose_writ { my ($self, $session_id, $building_id, $title, $writ) = @_; my $empire = $self->get_empire_by_session($session_id); if ($empire->current_session->is_sitter) { - confess [1015, 'Sitters cannot vote in parliament.']; + confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); unless ($building->level >= 4) { @@ -140,8 +140,43 @@ sub propose_writ { }; } +sub propose_transfer_station_ownership { + my ($self, $session_id, $building_id, $to_empire_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + if ($empire->current_session->is_sitter) { + confess [1015, 'Sitters cannot create propositions.']; + } + my $building = $self->get_building($empire, $building_id); + unless ($building->level >= 5) { + confess [1013, 'Parliament must be level 5 to transfer station ownership.',5]; + } + unless ($to_empire_id) { + confess [1002, 'Must specify an empire id to transfer the station to.']; + } + my $to_empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($to_empire_id); + unless (defined $to_empire) { + confess [1002, 'Could not find the empire to transfer the station to.']; + } + unless ($to_empire->alliance_id == $empire->alliance_id) { + confess [1009, 'That empire is not a member of your alliance.']; + } + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'TransferStationOwnership', + name => 'Transfer Station', + description => 'Transfer ownership of station named '.$self->body->name.' from '.$self->body->empire->name.' to '.$to_empire->name.'.', + scratch => { empire_id => $to_empire->id }, + proposed_by_id => $empire->id, + }); + $proposition->station($building->body); + $proposition->proposed_by($empire); + $proposition->insert; + return { + status => $self->format_status($empire, $building->body), + proposition => $proposition->get_status($empire), + }; +} -__PACKAGE__->register_rpc_method_names(qw(view_propositions view_laws cast_vote propose_fire_bfg propose_writ)); +__PACKAGE__->register_rpc_method_names(qw(propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/t/Parliament.t b/t/Parliament.t index a3044312..bf00a4d8 100644 --- a/t/Parliament.t +++ b/t/Parliament.t @@ -1,5 +1,5 @@ use lib '../lib'; -use Test::More tests => 11; +use Test::More tests => 12; use Test::Deep; use Data::Dumper; use 5.010; @@ -56,6 +56,9 @@ $result = $tester->post('parliament', 'cast_vote', [$session_id, $par->id, $resu $result = $tester->post('parliament', 'view_laws', [$session_id, $station->id]); is($result->{result}{laws}[0]{name}, 'Do the big thing.', 'writ enacted'); +$result = $tester->post('parliament', 'propose_transfer_station_ownership', [$session_id, $par->id]); +is($result->{error}{data}, 5, 'transfering ownership of station requires level 5 parliament'); + $result = $tester->post('parliament', 'propose_fire_bfg', [$session_id, $par->id]); is($result->{error}{data}, 30, 'firing bfg requires level 30 parliament'); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 0ab978ea..15782875 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,6 +1,7 @@ 3.0400 - Rule: SAWs now cost less in upkeep. - API: Added proposing enacting writs at Parliament level 4. + - API: Added transfering ownership of stations at Parliament level 5. - API: Added proposing firing the station's BFG at Parliament level 30. - API: Anyone can now view the laws passed by a space station, by simply calling view_laws() on the parliament. - API: The Mercenaries Guild API has been corrected. -- 2.51.2