diff --git a/docs/PlanetaryCommand.pod b/docs/PlanetaryCommand.pod index 4fc4f82e..1ef53722 100644 --- a/docs/PlanetaryCommand.pod +++ b/docs/PlanetaryCommand.pod @@ -53,4 +53,33 @@ Command extends the view method to include a C section. } } + +=head2 view_plans ( session_id, building_id ) + +Returns a list of all the plans you've collected through various means. + + { + "status" : { ... }, + "plans" : [ + { + "name" : "Malcud Fungus Farm", + "level" : 1, + "extra_build_level" : 5 + }, + ... + ] + } + +If the C is 1, and there is an C, that means that the building will be built up to 1 plus the extra build level when complete. So in the example above, it would be a level 6 directly after being built. + + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the PCC. + + =cut \ No newline at end of file diff --git a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm index 32774dc2..03317346 100644 --- a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm +++ b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm @@ -22,6 +22,28 @@ around 'view' => sub { return $out; }; +sub view_plans { + my ($self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my @out; + my $plans = $building->body->plans; + while (my $plan = $plans->next) { + push @out, { + name => $plan->class->name, + level => $plan->level, + extra_build_level => $plan->extra_build_level, + } + } + return { + status => $self->format_status($empire, $building->body), + plans => \@out, + } +} + +__PACKAGE__->register_rpc_method_names(qw(view_plans)); + + no Moose; __PACKAGE__->meta->make_immutable; diff --git a/t/PlanetaryCommand.t b/t/PlanetaryCommand.t new file mode 100644 index 00000000..775f7504 --- /dev/null +++ b/t/PlanetaryCommand.t @@ -0,0 +1,25 @@ +use lib '../lib'; +use Test::More tests => 1; +use Test::Deep; +use Data::Dumper; +use 5.010; + +use TestHelper; +my $tester = TestHelper->new->generate_test_empire; +my $session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; +my $db = Lacuna->db; + +my $result; + +my $pcc = $home->command; + +$result = $tester->post('planetarycommand', 'view_plans', [$session_id, $pcc->id]); + +is(ref $result->{result}{plans}, 'ARRAY', 'can view plans'); + + +END { + $tester->cleanup; +}