diff --git a/docs/PlanetaryCommand.pod b/docs/PlanetaryCommand.pod index 20d2cb21..8e95de13 100644 --- a/docs/PlanetaryCommand.pod +++ b/docs/PlanetaryCommand.pod @@ -1,8 +1,8 @@ =head1 Planetary Command Methods -Planetary Command is accessible via the URL C. +Planetary Command Center is accessible via the URL C. -The Planetary Command, or just Command, is the hub of your empire on a planet. It gives you the resources and storage you need to get a foothold on a planet. +The Planetary Command Center (PCC), or just Command, is the hub of your empire on a planet. It gives you the resources and storage you need to get a foothold on a planet. The list of methods below represents changes and additions to the methods that all L share. @@ -51,4 +51,26 @@ Command extends the view method to include a C section. } } + +=head2 view_freebies ( session_id, building_id ) + +Freebies are buildings you can build for free. You can get them from contests, tutorials, and from spy missions. You can only have one freebie of each building type at once. And you can only have 10 freebies queued up at once. You must either spend them, or lose them. + + { + "freebies" : { + "Subspace Transporter" : 1, + "Wheat Farm" : 4, + }, + "status" : { get_status() } + } + +=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/Building.pm b/lib/Lacuna/Building.pm index 450867fe..8253cd3d 100644 --- a/lib/Lacuna/Building.pm +++ b/lib/Lacuna/Building.pm @@ -52,7 +52,7 @@ sub upgrade { my $body = $building->body; $body->empire($empire); if ($building->has_free_upgrade) { - $body->spend_free_upgrade($building->class)->put; + $body->spend_freebie($building->class)->put; } else { $body->spend_water($cost->{water}); @@ -159,8 +159,7 @@ sub build { # adjust resources if ($building->has_free_build) { - $building->level($body->get_free_build($building->class) - 1); - $body->spend_free_build($building->class)->put; + $body->spend_freebie($building->class)->put; } else { $body->spend_food($building->food_to_build); diff --git a/lib/Lacuna/Building/Network19.pm b/lib/Lacuna/Building/Network19.pm index e4de9faa..7047c0a1 100644 --- a/lib/Lacuna/Building/Network19.pm +++ b/lib/Lacuna/Building/Network19.pm @@ -16,9 +16,6 @@ sub view_news { my ($self, $session_id, $building_id) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $empire->get_building($self->model_class, $building_id); - if ($building->class ne 'Lacuna::DB::Building::Network19') { - confess [1002, 'Building is not a Network 19 Affilliate.']; - } my $body = $building->body; my @all = ($body->zone, $body->adjacent_zones); my @zones; diff --git a/lib/Lacuna/Building/PlanetaryCommand.pm b/lib/Lacuna/Building/PlanetaryCommand.pm index 3d2e1343..45ff8b01 100644 --- a/lib/Lacuna/Building/PlanetaryCommand.pm +++ b/lib/Lacuna/Building/PlanetaryCommand.pm @@ -20,6 +20,24 @@ around 'view' => sub { return $out; }; +sub view_freebies { + my ($self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $empire->get_building($self->model_class, $building_id); + my $free_stuff = $building->body->freebies; + my %freebies; + foreach my $class (keys %{$free_stuff}) { + $freebies{$class->name} = $free_stuff->{$class}; + } + return { + freebies => \%freebies, + status => $empire->get_status, + }; +} + +__PACKAGE__->register_rpc_method_names(qw(view_freebies)); + + no Moose; __PACKAGE__->meta->make_immutable; diff --git a/lib/Lacuna/DB/Body/Planet.pm b/lib/Lacuna/DB/Body/Planet.pm index da010934..cfd8325d 100644 --- a/lib/Lacuna/DB/Body/Planet.pm +++ b/lib/Lacuna/DB/Body/Planet.pm @@ -350,44 +350,23 @@ has interceptors => ( # FREEBIES -sub get_free_upgrade { +sub get_freebie { my ($self, $class) = @_; - return $self->freebies->{upgrades}{$class} || 0; + return $self->freebies->{$class} || 0; } -sub add_free_upgrade { +sub add_freebie { my ($self, $class, $level) = @_; my $freebies = $self->freebies; - $freebies->{upgrades}{$class} = $level; + $freebies->{$class} = $level; $self->freebies($freebies); return $self; } -sub spend_free_upgrade { +sub spend_freebie { my ($self, $class) = @_; my $freebies = $self->freebies; - delete $freebies->{upgrades}{$class}; - $self->freebies($freebies); - return $self; -} - -sub get_free_build { - my ($self, $class) = @_; - return $self->freebies->{builds}{$class} || 0; -} - -sub add_free_build { - my ($self, $class, $level) = @_; - my $freebies = $self->freebies; - $freebies->{builds}{$class} = $level; - $self->freebies($freebies); - return $self; -} - -sub spend_free_build { - my ($self, $class) = @_; - my $freebies = $self->freebies; - delete $freebies->{builds}{$class}; + delete $freebies->{$class}; $self->freebies($freebies); return $self; } diff --git a/lib/Lacuna/DB/Building.pm b/lib/Lacuna/DB/Building.pm index 960b16ee..5cfefb14 100644 --- a/lib/Lacuna/DB/Building.pm +++ b/lib/Lacuna/DB/Building.pm @@ -520,12 +520,12 @@ sub time_cost_reduction_bonus { sub has_free_build { my $self = shift; - return ($self->level == 0 && $self->body->get_free_build($self->class)) ? 1 : 0; + return ($self->level == 0 && $self->body->get_freebie($self->class) == 1) ? 1 : 0; } sub has_free_upgrade { my $self = shift; - return ($self->body->get_free_upgrade($self->class) == $self->level + 1) ? 1 : 0; + return ($self->body->get_freebie($self->class) == $self->level + 1) ? 1 : 0; } sub cost_to_upgrade { diff --git a/lib/Lacuna/DB/Spies.pm b/lib/Lacuna/DB/Spies.pm index 8ab71640..ef313429 100644 --- a/lib/Lacuna/DB/Spies.pm +++ b/lib/Lacuna/DB/Spies.pm @@ -64,12 +64,7 @@ sub assign { sub steal_a_building { my ($self, $building) = @_; my $body = $building->body; - if ($building->level == 0) { - $self->from_body->add_free_build($building->class, 1); - } - else { - $self->from_body->add_free_upgrade($building->class, $building->level + 1); - } + $self->from_body->add_freebie($building->class, $building->level + 1); $self->empire->send_predefined_message( tags => ['Alert'], filename => 'building_theft_report.txt', diff --git a/lib/Lacuna/Tutorial.pm b/lib/Lacuna/Tutorial.pm index 83c52bb5..abd7fc79 100644 --- a/lib/Lacuna/Tutorial.pm +++ b/lib/Lacuna/Tutorial.pm @@ -48,7 +48,7 @@ sub explore_the_ui { if ($finish) { if ($home->name ne $empire->tutorial_scratch) { $empire->add_medal('pleased_to_meet_you'); - $home->add_free_build('Lacuna::DB::Building::Food::Farm::Malcud', 1)->put; + $home->add_freebie('Lacuna::DB::Building::Food::Farm::Malcud', 1)->put; $self->start('get_food'); return undef; } @@ -165,7 +165,7 @@ sub pawn { if ($finish) { my $building = $home->get_buildings_of_class('Lacuna::DB::Building::Intelligence')->next; if (defined $building && $building->level >= 1) { - $home->add_free_upgrade('Lacuna::DB::Building::Intelligence', 2)->put; + $home->add_freebie('Lacuna::DB::Building::Intelligence', 2)->put; $building->train_spy; $self->start('counter_spy'); return undef; @@ -215,7 +215,7 @@ sub explore { my $empire = $self->empire; if ($finish) { if ($empire->count_probed_stars > 1) { - $empire->home_planet->add_free_build('Lacuna::DB::Building::Transporter', 1)->put; + $empire->home_planet->add_freebie('Lacuna::DB::Building::Transporter', 1)->put; $self->start('the_end'); return undef; } @@ -367,7 +367,7 @@ sub fool { my $home = $empire->home_planet; if ($finish) { if ($home->food_hour >= $empire->tutorial_scratch) { - $home->add_free_upgrade('Lacuna::DB::Building::Food::Reserve', 2)->put; + $home->add_freebie('Lacuna::DB::Building::Food::Reserve', 2)->put; $empire->add_essentia(35)->put; $self->start('essentia'); return undef; @@ -405,7 +405,7 @@ sub energy { my $home = $empire->home_planet; if ($finish) { if ($home->energy_hour >= $empire->tutorial_scratch) { - $home->add_free_upgrade('Lacuna::DB::Building::Energy::Reserve', 2)->put; + $home->add_freebie('Lacuna::DB::Building::Energy::Reserve', 2)->put; $self->start('the_300'); return undef; } @@ -427,8 +427,8 @@ sub the_300 { my $home = $empire->home_planet; if ($finish) { if ($home->ore_hour >= 50 && $home->water_hour >= 50) { - $home->add_free_upgrade('Lacuna::DB::Building::Ore::Storage', 2) - ->add_free_upgrade('Lacuna::DB::Building::Water::Storage', 2) + $home->add_freebie('Lacuna::DB::Building::Ore::Storage', 2) + ->add_freebie('Lacuna::DB::Building::Water::Storage', 2) ->put; $self->start('news'); return undef;