diff --git a/docs/SpacePort.pod b/docs/SpacePort.pod index a3e53c3f..23e4eb98 100644 --- a/docs/SpacePort.pod +++ b/docs/SpacePort.pod @@ -26,6 +26,75 @@ This method is extended to include a list of docked ships. } } + +=head2 view_ships ( session_id, building_id ) + +Shows you the ships that are working in the mining fleet, and available to work in the mining fleet. + + { + "ships" : [ + { + "name" : "CS4", + "id" : "id-goes-here", + "task" : "Mining", + "speed" : 350, + "hold_size" : 5600 + "type" : "cargo_ship", + }, + ... + ], + "number_of_ships" : 13, + "status" : { get_status() } + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the space port. + + +=head2 name_ship ( session_id, building_id, ship_id, name ) + +Set the name of a ship. + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id for the space port. + +=head3 ship_id + +The unique id of the ship you want to name. + +=head3 name + +The name you want to give the ship. 1 to 30 characters. No profanity. No funky characters. + + + +=head2 scuttle_ship ( session_id, building_id, ship_id ) + +Destroy a ship that you no longer need. It must be docked to scuttle it. + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id for the space port. + +=head3 ship_id + +The unique id of the ship you want to destroy. + + =head2 view_ships_travelling ( session_id, building_id, [ page_number ]) diff --git a/lib/Lacuna/Building/MiningMinistry.pm b/lib/Lacuna/Building/MiningMinistry.pm index b9b87ee1..036ee824 100644 --- a/lib/Lacuna/Building/MiningMinistry.pm +++ b/lib/Lacuna/Building/MiningMinistry.pm @@ -84,6 +84,9 @@ sub abandon_platform { unless (defined $platform) { confess [1002, "Platform not found."]; } + unless ($platform->planet_id eq $building->body_id) { + confess [1013, "You can't abandon a platform that is not yours."]; + } $building->remove_platform($platform); return { status => $empire->get_status, @@ -101,6 +104,9 @@ sub add_cargo_ship_to_fleet { unless ($ship->task eq 'Docked') { confess [1009, "That ship is not available."]; } + unless ($ship->body_id eq $building->body_id) { + confess [1013, "You can't manage a ship that is not yours."]; + } $building->add_ship($ship); return { status => $empire->get_status, @@ -118,6 +124,9 @@ sub remove_cargo_ship_from_fleet { unless ($ship->task eq 'Mining') { confess [1009, "That ship is not mining."]; } + unless ($ship->body_id eq $building->body_id) { + confess [1013, "You can't manage a ship that is not yours."]; + } $building->send_ship_home($ship); return { status => $empire->get_status, diff --git a/lib/Lacuna/Building/SpacePort.pm b/lib/Lacuna/Building/SpacePort.pm index c6f4b06f..7240cdfe 100644 --- a/lib/Lacuna/Building/SpacePort.pm +++ b/lib/Lacuna/Building/SpacePort.pm @@ -210,6 +210,7 @@ sub view_ships_travelling { } push @travelling, { id => $ship->id, + name => $ship->name, ship_type => $ship->ship_type, to => $to, from => $from, @@ -223,6 +224,74 @@ sub view_ships_travelling { }; } +sub view_all_ships { + my ($self, $session_id, $building_id, $page_number) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $empire->get_building($self->model_class, $building_id); + $page_number ||= 1; + my $body = $building->body; + my @fleet; + my $ships = $building->ships->search({}, {rows=>25, page=>$page_number}); + while (my $ship = $ships->next) { + push @fleet, { + id => $ship->id, + name => $ship->name, + ship_type => $ship->ship_type, + task => $ship->task, + speed => $ship->speed, + hold_size => $ship->hold_size, + }; + } + return { + status => $empire->get_status, + number_of_ships => $ships->pager->total_entries, + ships => \@fleet, + }; +} + +sub name_ship { + my ($self, $session_id, $building_id, $ship_id, $name) = @_; + Lacuna::Verify->new(content=>\$name, throws=>[1005, 'Invalid name for a ship.']) + ->not_empty + ->no_profanity + ->length_lt(31) + ->no_restricted_chars; + my $empire = $self->get_empire_by_session($session_id); + my $building = $empire->get_building($self->model_class, $building_id); + my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($ship_id); + unless (defined $ship) { + confess [1002, "Ship not found."]; + } + unless ($ship->body_id eq $building->body_id) { + confess [1013, "You can't manage a ship that is not yours."]; + } + $ship->name($name); + $ship->update; + return { + status => $empire->get_status, + }; +} + +sub scuttle_ship { + my ($self, $session_id, $building_id, $ship_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $empire->get_building($self->model_class, $building_id); + my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($ship_id); + unless (defined $ship) { + confess [1002, "Ship not found."]; + } + unless ($ship->task eq 'Docked') { + confess [1013, "You can't scuttle a ship that's not docked."]; + } + unless ($ship->body_id eq $building->body_id) { + confess [1013, "You can't manage a ship that is not yours."]; + } + $ship->delete; + return { + status => $empire->get_status, + }; +} + around 'view' => sub { my ($orig, $self, $session_id, $building_id) = @_; my $empire = $self->get_empire_by_session($session_id);