From 652e1a803897e4284cb3004c15f5676407d64ad4 Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Sat, 2 Apr 2011 15:55:29 -0500 Subject: [PATCH] API: Added proposing renaming uninhabited planets at Parliament level 17. --- docs/Parliament.pod | 48 ++++++++++++++++-- lib/Lacuna/DB/Result/Propositions.pm | 1 + .../Result/Propositions/RenameUninhabited.pm | 30 +++++++++++ lib/Lacuna/RPC/Building/Parliament.pm | 50 ++++++++++++++++++- t/Parliament.t | 3 ++ var/www/public/changes.txt | 3 +- 6 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 lib/Lacuna/DB/Result/Propositions/RenameUninhabited.pm diff --git a/docs/Parliament.pod b/docs/Parliament.pod index f4fd1472..a0efb8b2 100644 --- a/docs/Parliament.pod +++ b/docs/Parliament.pod @@ -28,9 +28,9 @@ Returns a list of the laws. A session id. -=head3 building_id +=head3 body_id -The unique id of the parliament. +The unique id of the space station. @@ -488,6 +488,48 @@ A 30 chararacter string without profanity or special characters. +=head2 propose_rename_uninhabited ( session_id, building_id, planet_id, name ) + +Rename any uninhabited planet in the station's jurisdiction. Usable a parliament level 17. + + { + "status" : { ... }, + "proposition" : { + "id" : "id-goes-here", + "name" : "Rename Bebox 4", + "description" : "Rename the planet Bebox 4 to Blue Orb.", + "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 planet_id + +The unique id of an uninhabited planet in the station's jurisdiction to rename. + +=head3 name + +A 30 chararacter string without profanity or special characters. + + + + + =head2 propose_members_only_mining_rights ( session_id, building_id ) If passed, only members of the alliance would be able to set up new mining platforms on asteroids in this station's jurisdiction. Usable a parliament level 13. @@ -597,4 +639,4 @@ A planet to fire at. See C for details. An explict reason why the BFG should be fired upon the target. Same rules as an L message body apply here. -=cut \ No newline at end of file +=cut diff --git a/lib/Lacuna/DB/Result/Propositions.pm b/lib/Lacuna/DB/Result/Propositions.pm index 888b3097..5eeb4a4d 100644 --- a/lib/Lacuna/DB/Result/Propositions.pm +++ b/lib/Lacuna/DB/Result/Propositions.pm @@ -36,6 +36,7 @@ __PACKAGE__->typecast_map(type => { RenameAsteroid => 'Lacuna::DB::Result::Propositions::RenameAsteroid', RenameStar => 'Lacuna::DB::Result::Propositions::RenameStar', RenameStation => 'Lacuna::DB::Result::Propositions::RenameStation', + RenameUninhabited => 'Lacuna::DB::Result::Propositions::RenameUninhabited', RepairModule => 'Lacuna::DB::Result::Propositions::RepairModule', RepealLaw => 'Lacuna::DB::Result::Propositions::RepealLaw', SeizeStar => 'Lacuna::DB::Result::Propositions::SeizeStar', diff --git a/lib/Lacuna/DB/Result/Propositions/RenameUninhabited.pm b/lib/Lacuna/DB/Result/Propositions/RenameUninhabited.pm new file mode 100644 index 00000000..ae596a23 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/RenameUninhabited.pm @@ -0,0 +1,30 @@ +package Lacuna::DB::Result::Propositions::RenameUninhabited; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $station = $self->station; + my $bodies = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body'); + my $planet = $bodies->find($self->scratch->{planet_id}); + my $name = $self->scratch->{name}; + if ($bodies->search({name=>$name, 'body_id'=>{'!='=>$planet->id}})->count) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the name *'.$name.'* had already taken, effectively nullifying the vote.'); + } + elsif ($planet->star->station_id = $station->id) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the planet was no longer under the jurisdiction of this station, effectively nullifying the vote.'); + } + elsif ($planet->empire_id) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the planet had been inhabited.'); + } + else { + $planet->name($name); + $planet->update; + } +}; + +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 c7a9494f..8dd248ce 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -401,7 +401,7 @@ sub propose_rename_asteroid { } my $building = $self->get_building($empire, $building_id); unless ($building->level >= 12) { - confess [1013, 'Parliament must be level 12 to rename a star.',12]; + confess [1013, 'Parliament must be level 12 to rename an asteroid.',12]; } unless ($asteroid_id) { confess [1002, 'Must specify a asteroid id to rename.']; @@ -436,6 +436,52 @@ sub propose_rename_asteroid { }; } +sub propose_rename_uninhabited { + my ($self, $session_id, $building_id, $planet_id, $name) = @_; + 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 >= 17) { + confess [1013, 'Parliament must be level 17 to rename an uninhabited planet.',17]; + } + unless ($planet_id) { + confess [1002, 'Must specify a planet id to rename.']; + } + my $planet = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($planet_id); + unless (defined $planet) { + confess [1002, 'Could not find the planet.']; + } + unless ($planet->star->station_id == $self->body_id) { + confess [1009, 'That planet is not controlled by this station.']; + } + if ($planet->empire_id) { + confess [1013, 'That planet is inhabited.']; + } + Lacuna::Verify->new(content=>\$name, throws=>[1000,'Name not available.',$name]) + ->length_gt(2) + ->length_lt(31) + ->no_restricted_chars + ->no_profanity + ->no_padding + ->not_ok(Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search({name=>$name, 'body_id'=>{'!='=>$planet->id}})->count); # name available + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'RenameUninhabited', + name => 'Rename '.$planet->name, + description => 'Rename {Starmap '.$planet->x.' '.$planet->y.' '.$planet->name.'} to '.$name.'.', + scratch => { planet_id => $planet->id, name => $name }, + 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), + }; +} + sub propose_members_only_mining_rights { my ($self, $session_id, $building_id) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -497,7 +543,7 @@ sub propose_evict_mining_platform { }; } -__PACKAGE__->register_rpc_method_names(qw(get_bodies_for_star_in_jurisdiction get_mining_platforms_for_asteroid_in_jurisdiction propose_evict_mining_platform propose_members_only_mining_rights propose_rename_asteroid propose_broadcast_on_network19 get_stars_in_jurisdiction propose_rename_star propose_repeal_law propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ)); +__PACKAGE__->register_rpc_method_names(qw(get_bodies_for_star_in_jurisdiction get_mining_platforms_for_asteroid_in_jurisdiction propose_evict_mining_platform propose_members_only_mining_rights propose_rename_asteroid propose_rename_uninhabited propose_broadcast_on_network19 get_stars_in_jurisdiction propose_rename_star propose_repeal_law propose_seize_star 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 38586a5a..1b95a50f 100644 --- a/t/Parliament.t +++ b/t/Parliament.t @@ -83,6 +83,9 @@ is($result->{error}{data}, 13, 'members mining rights requires level 13 parliame $result = $tester->post('parliament', 'propose_evict_mining_platform', [$session_id, $par->id]); is($result->{error}{data}, 14, 'evict mining platform requires level 14 parliament'); +$result = $tester->post('parliament', 'propose_rename_uninhabited', [$session_id, $par->id]); +is($result->{error}{data}, 17, 'renaming uninhabited requires level 17 parliament'); + $result = $tester->post('parliament', 'propose_fire_bfg', [$session_id, $par->id]); is($result->{error}{data}, 25, 'firing bfg requires level 25 parliament'); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 456367fb..285dc80e 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,4 +1,5 @@ -3.0403 +3.0500 + - API: Added proposing renaming uninhabited planets at Parliament level 17. - Fix: Police Station docs now show up under Modules instead of Buildings. 3.0402 -- 2.51.2