From 9e6ab9d3c35d606cbc2a94d038f5ce7041470508 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 28 Mar 2011 18:58:14 -0500 Subject: [PATCH] Added renaming asteroids at parliament level 11. --- docs/Parliament.pod | 43 ++++++++++++++++++ .../DB/Result/Propositions/RenameAsteroid.pm | 27 +++++++++++ lib/Lacuna/RPC/Building/Parliament.pm | 45 ++++++++++++++++++- t/Parliament.t | 3 ++ var/www/public/changes.txt | 1 + 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 lib/Lacuna/DB/Result/Propositions/RenameAsteroid.pm diff --git a/docs/Parliament.pod b/docs/Parliament.pod index c9c75d2e..f22b266a 100644 --- a/docs/Parliament.pod +++ b/docs/Parliament.pod @@ -390,6 +390,49 @@ A 140 character string that cannot contain special characters or profanity. +=head2 propose_rename_asteroid ( session_id, building_id, asteroid_id, name ) + +Rename any asteroid in the station's jurisdiction. Usable a parliament level 11. + + { + "status" : { ... }, + "proposition" : { + "id" : "id-goes-here", + "name" : "Rename Bebox 3", + "description" : "Rename the asteroid Bebox 3 to Big Rock.", + "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 asteroid_id + +The unique id of an asteroid in the station's jurisdiction to rename. + +=head3 name + +A 30 chararacter string without profanity or special characters. + + + + + + =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 25. diff --git a/lib/Lacuna/DB/Result/Propositions/RenameAsteroid.pm b/lib/Lacuna/DB/Result/Propositions/RenameAsteroid.pm new file mode 100644 index 00000000..3782385b --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/RenameAsteroid.pm @@ -0,0 +1,27 @@ +package Lacuna::DB::Result::Propositions::RenameAsteroid; + +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 $asteroid = $bodies->find($self->scratch->{asteroid_id}); + my $name = $self->scratch->{name}; + if ($bodies->search({name=>$name, 'body_id'=>{'!='=>$asteroid->id}})->count) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the name *'.$name.'* had already taken, effectively nullifying the vote.'); + } + elsif ($asteroid->star->station_id = $station->id) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the asteroid was no longer under the jurisdiction of this station, effectively nullifying the vote.'); + } + else { + $asteroid->name($name); + $asteroid->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 f91f880a..70a74e7d 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -339,7 +339,50 @@ sub propose_broadcast_on_network19 { } -__PACKAGE__->register_rpc_method_names(qw(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)); +sub propose_rename_asteroid { + my ($self, $session_id, $building_id, $asteroid_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 >= 12) { + confess [1013, 'Parliament must be level 12 to rename a star.',12]; + } + unless ($asteroid_id) { + confess [1002, 'Must specify a asteroid id to rename.']; + } + my $asteroid = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($asteroid_id); + unless (defined $asteroid) { + confess [1002, 'Could not find the asteroid.']; + } + unless ($asteroid->star->station_id == $self->body_id) { + confess [1009, 'That asteroid is not controlled by this station.']; + } + 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'=>{'!='=>$asteroid->id}})->count); # name available + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'RenameAsteroid', + name => 'Rename '.$asteroid->name, + description => 'Rename '.$asteroid->name.' ('.$asteroid->x.','.$asteroid->y.') to '.$name.'.', + scratch => { asteroid_id => $asteroid->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), + }; +} + +__PACKAGE__->register_rpc_method_names(qw(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)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/t/Parliament.t b/t/Parliament.t index a9207179..27e0bcf3 100644 --- a/t/Parliament.t +++ b/t/Parliament.t @@ -74,6 +74,9 @@ is($result->{error}{data}, 8, 'renaming star requires level 8 parliament'); $result = $tester->post('parliament', 'propose_broadcast_on_network19', [$session_id, $par->id]); is($result->{error}{data}, 9, 'broadcasting on network 19 requires level 9 parliament'); +$result = $tester->post('parliament', 'propose_rename_asteroid', [$session_id, $par->id]); +is($result->{error}{data}, 11, 'renaming asteroid requires level 11 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 613ee069..fb2b0717 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -11,6 +11,7 @@ - API: Added seizing control of stars at Parliament level 7. - API: Added renaming stars at Parliament level 8, along with a method to get the list of stars in the jurisdiction. - API: Added broadcasting on Network 19 at parliament level 9. + - API: Added renaming asteroids at parliament level 11. - API: Added proposing firing the station's BFG at Parliament level 25. - API: Anyone can now view the laws passed by a space station, by simply calling view_laws() on the parliament. - API: The stations list is now populated in the /alliance.view_profile() method. -- 2.51.2