diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm b/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm index 619ce72f..c835d0e4 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm @@ -52,13 +52,15 @@ use constant max_instances_per_planet => 1; sub split_plan { my ($self, $plan_class, $level, $extra_build_level) = @_; - my $halls = $self->equivalent_halls($level, $extra_build_level); - my $class = 'Lacuna::DB::Result::Building::'.$plan_class; - my ($plan) = $self->body->plans->search({ - level => $level, - extra_build_level => $extra_build_level, - class => $class, - }); + my $halls = $self->equivalent_halls($level, $extra_build_level); + my $class = 'Lacuna::DB::Result::Building::'.$plan_class; + my $body = $self->body; + my ($plan) = grep { + $_->level == $level + and $_->class eq $class + and $_->extra_build_level == $extra_build_level + } @{$body->plan_cache}; + if (not $plan) { confess [1002, 'You cannot split a plan you do not have.']; } @@ -67,9 +69,10 @@ sub split_plan { confess [1002, 'You can only split plans that have a glyph recipe.']; } if ($class =~ m/Platform$/) { - confess [1002, 'You cannot split a plan for a Platform.']; + confess [1002, 'You cannot split a Platform plan.']; } - $plan->delete; + $body->delete_one_plan($plan); + my $build_secs = int($halls * 30 * 3600 / $self->level); $self->start_work({task => 'split_plan', class => $class, level => $level, extra_build_level => $extra_build_level}, $build_secs)->update; } @@ -77,28 +80,30 @@ sub split_plan { sub make_plan { my ($self, $plan_class, $level) = @_; - # Do we have the requisite number of level 1 plans? - my $class = 'Lacuna::DB::Result::Building::'.$plan_class; - - my $plans_rs = $self->body->plans->search({ - level => 1, - extra_build_level => 0, - class => $class, - }); - my $have_plans = $plans_rs->count; - if ($have_plans < $level * 2) { - confess [1002, 'You do not have enough level 1+0 plans.']; - } if ($level > $self->level) { confess [1002, 'Your Dillon Forge level is not high enough to build that high a plan level.']; } - if ($class =~ m/HallsOfVrbansk/) { + if ($plan_class =~ m/HallsOfVrbansk/) { confess [1002, 'It is not a good idea to create a plan you cannot use.']; } - $plans_rs->search({},{ - rows => $level * 2, - })->delete_all; + my $body = $self->body; + # Do we have the requisite number of level 1 plans? + my $class = 'Lacuna::DB::Result::Building::'.$plan_class; + + my ($plan) = grep { + $_->level => 1, + $_->extra_build_level => 0, + $_->class eq $class + } @{$body->plan_cache}; + + my $quantity_to_delete = $level * 2; + + if (not defined $plan or $plan->quantity < $quantity_to_delete) { + confess [1002, 'You do not have enough level 1+0 plans.']; + } + + $body->delete_many_plans($plan, $quantity_to_delete); $self->start_work({task => 'make_plan', level => $level, class => $class}, ($level * 5000))->update; } diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index b42727e0..6c8892d5 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -337,7 +337,7 @@ sub add_to_market { speed => $ship->speed, trade_range => max (250, $self->level * 20), ); - return Lacuna->db->resultset('Lacuna::DB::Result::Market')->new(\%trade)->insert; + return Lacuna->db->resultset('Market')->new(\%trade)->insert; } sub transfer_type { diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index f8820d7c..fd1ee563 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -14,7 +14,7 @@ use Scalar::Util qw(weaken); no warnings 'uninitialized'; __PACKAGE__->has_many('ships','Lacuna::DB::Result::Ships','body_id'); -__PACKAGE__->has_many('plans','Lacuna::DB::Result::Plan','body_id'); +__PACKAGE__->has_many('_plans','Lacuna::DB::Result::Plan','body_id'); __PACKAGE__->has_many('glyphs','Lacuna::DB::Result::Glyphs','body_id'); __PACKAGE__->has_many('waste_chains', 'Lacuna::DB::Result::WasteChain','planet_id'); __PACKAGE__->has_many('out_supply_chains', 'Lacuna::DB::Result::SupplyChain','planet_id'); @@ -24,52 +24,100 @@ has plan_cache => ( is => 'rw', lazy => 1, builder => '_build_plan_cache', + clearer => 'clear_plan_cache', ); sub _build_plan_cache { my ($self) = @_; - - my @plans = $self->plans; - return \@plans; + my $plans = []; + my $plan_rs = $self->_plans->search({}); + while (my $plan = $plan_rs->next) { + $plan->body($self); + weaken($plan->{_relationship_data}{body}); + push @$plans,$plan; + } + return $plans; } # Sort plans by name (asc), by level (asc), by extra_build_level (desc) sub sorted_plans { my ($self) = @_; - my @sorted_plans = sort {$a->class->name cmp $b->class->name || $a->level cmp $b->level || $b->extra_build_level cmp $a->extra_build_level } @{$self->plan_cache}; + my @sorted_plans = sort { + $a->class->name cmp $b->class->name + || $a->level cmp $b->level + || $b->extra_build_level cmp $a->extra_build_level + } @{$self->plan_cache}; return \@sorted_plans; } -sub delete_building { - my ($self, $building) = @_; +sub _delete_building { + my ($self, $building) = @_; - my $i = 0; - BUILDING: - foreach my $b (@{$self->building_cache}) { - if ($b->id == $building->id) { - my @buildings = splice(@{$self->building_cache}, $i, 1); - $self->building_cache(\@buildings); -# $b->delete; - last BUILDING; + my $i = 0; + BUILDING: + foreach my $b (@{$self->building_cache}) { + if ($b->id == $building->id) { + my @buildings = splice(@{$self->building_cache}, $i, 1); + $self->building_cache(\@buildings); + last BUILDING; + } + $i++; } - $i++; - } - $self->update; + $self->update; } sub delete_buildings { - my ($self, $buildings) = @_; + my ($self, $buildings) = @_; + + foreach my $building (@$buildings) { + $self->_delete_building($building); + $building->delete; + } + $self->needs_recalc(1); + $self->needs_surface_refresh(1); + $self->update; +} + +sub delete_one_plan { + my ($self, $plan) = @_; - foreach my $building (@$buildings) { - $self->delete_building($building); - $building->delete; - } - $self->needs_recalc(1); - $self->needs_surface_refresh(1); - $self->update; + $self->delete_many_plans($plan, 1); } +sub delete_many_plans { + my ($self, $plan, $quantity) = @_; + + if ($plan->quantity > $quantity) { + $plan->quantity($plan->quantity - $quantity); + $plan->update; + } + else { + my $i = 0; + BUILDING: + foreach my $p (@{$self->plan_cache}) { + if ($p->id == $plan->id) { + my @plans = splice(@{$self->plan_cache}, $i, 1); + $self->plan_cache(\@plans); + $p->delete; + last BUILDING; + } + $i++; + } + $self->update; + } +} + +sub delete_plans { + my ($self, $plans) = @_; + + foreach my $plan (@$plans) { + $self->delete_plan($plan); + $plan->delete; + } + $self->update; +} + sub surface { my $self = shift; return 'surface-'.$self->image; @@ -147,7 +195,8 @@ sub get_plan { } sub add_plan { - my ($self, $class, $level, $extra_build_level) = @_; + my ($self, $class, $level, $extra_build_level, $quantity) = @_; + $quantity = 1 unless defined $quantity; # add it my ($plan) = grep { @@ -156,16 +205,16 @@ sub add_plan { and $_->extra_build_level == $extra_build_level, } @{$self->plan_cache}; if ($plan) { - $plan->quantity($plan->quantity + 1); + $plan->quantity($plan->quantity + $quantity); $plan->update; } else { - $plan = $self->plans->create({ + $plan = $self->_plans->create({ body_id => $self->id, class => $class, level => $level, extra_build_level => $extra_build_level, - quantity => 1, + quantity => $quantity, }); push @{$self->plan_cache}, $plan; } @@ -197,7 +246,7 @@ sub sanitize { $self->plans->delete; $self->glyphs->delete; $self->waste_chains->delete; - # do indivitual deletes so the remote ends can be titied up too + # do individual deletes so the remote ends can be tidied up too foreach my $chain ($self->out_supply_chains) { $chain->delete; } diff --git a/lib/Lacuna/DB/Result/Mission.pm b/lib/Lacuna/DB/Result/Mission.pm index 29262b1e..15e00f2f 100644 --- a/lib/Lacuna/DB/Result/Mission.pm +++ b/lib/Lacuna/DB/Result/Mission.pm @@ -191,10 +191,17 @@ sub spend_objectives { # plans if (exists $objectives->{plans}) { foreach my $plan (@{$objectives->{plans}}) { - $body->plans->search( - { class => $plan->{classname}, level => {'>=' => $plan->{level}}, extra_build_level => {'>=' => $plan->{extra_build_level}} }, - {rows => 1, order_by => 'id'}, - )->single->delete; + # Get the lowest level/extra plan that meet the criteria + my ($plan) = sort { + $a->level <=> $b->level + || $a->extra_build_level <=> $b->extra_build_level + } + grep { + $_->class eq $plan->{classname} + and $_->level >= $plan->{level} + and $_->extra_build_level >= $plan->{extra_build_level} + } @{$body->plan_cache}; + $body->delete_one_plan($plan); } } } @@ -290,21 +297,25 @@ sub check_objectives { # plans if (exists $objectives->{plans}) { - my @ids; + # Count how many plans of each type are needed + my $requirements; foreach my $plan (@{$objectives->{plans}}) { - my $this = $body->plans->search({ - class => $plan->{classname}, - level => {'>=' => $plan->{level}}, - extra_build_level => {'>=' => $plan->{extra_build_level}}, - id => { 'not in' => \@ids }, - },{ - rows => 1, order_by => 'id' - })->single; - if (defined $this) { - push @ids, $this->id; - } - else { - confess [1013, 'You do not have the '.$plan->{classname}->name.' plan needed to complete this mission.']; + $requirements->{$plan->{classname}.'#'.$plan->{level}.'#'.$plan->{extra_build_level}}++; + } + foreach my $key (keys %$requirements) { + my ($class,$level,$extra) = split('#', $key); + # Get the lowest level/extra plan that meet the criteria + my ($plan) = sort { + $a->level <=> $b->level + || $a->extra_build_level <=> $b->extra_build_level + } + grep { + $_->class eq $class + and $_->level >= $level + and $_->extra_build_level >= $extra + } @{$body->plan_cache}; + if (not defined $plan or $requirements->{$key} > $plan->quantity) { + confess [1013, 'You do not have the '.$class->name.' plan needed to complete this mission.']; } } } diff --git a/lib/Lacuna/DB/Result/Plan.pm b/lib/Lacuna/DB/Result/Plan.pm index 5d975c5d..74d184d3 100644 --- a/lib/Lacuna/DB/Result/Plan.pm +++ b/lib/Lacuna/DB/Result/Plan.pm @@ -101,14 +101,22 @@ sub check_glyph_recipe { } # Delete one plan -sub delete_one_plan { +sub delete_one { my ($self) = @_; - if ($self->quantity <= 1) { + $self->delete_many(1); +} + +# Delete many plans +sub delete_many { + my ($self, $quantity) = @_; + + if ($self->quantity <= $quantity) { + plan_cache $self->delete; } else { - $self->quantity($self->quantity - 1); + $self->quantity($self->quantity - $quantity); $self->update; } } diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index c7e33a2b..1674af8b 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1838,10 +1838,16 @@ sub destroy_ship { sub destroy_plan { my ($self, $defender) = @_; - my $plan = $self->on_body->plans->search(undef, {rows => 1, order_by => 'rand()'})->single; - return $self->mission_objective_not_found('plan')->id unless defined $plan; + + my $number_of_plans = @{$self->on_body->plan_cache}; + return $self->mission_objective_not_found('plan')->id unless $number_of_plans; + + my $destroyed_plan = random_element($self->on_body->plan_cache); + my $destroyed_quantity = int(rand($destroyed_plan->quantity / 10)) + 1; + $self->things_destroyed( $self->things_destroyed + 1 ); - my $stolen = 'level '.$plan->level_formatted.' '.$plan->class->name.' plan'; + my $plural = $destroyed_quantity > 1 ? 's' : ''; + my $stolen = $destroyed_quantity.' level '.$destroyed_plan->level_formatted.' '.$destroyed_plan->class->name." plan$plural"; $self->on_body->empire->send_predefined_message( tags => ['Spies','Alert'], filename => 'item_destroyed.txt', @@ -1850,18 +1856,21 @@ sub destroy_plan { my $message = $self->empire->send_predefined_message( tags => ['Intelligence'], filename => 'sabotage_report.txt', - params => [$stolen, - $self->on_body->x, - $self->on_body->y, - $self->on_body->name, - $self->name, - $self->from_body->id, - $self->from_body->name], + params => [ + $stolen, + $self->on_body->x, + $self->on_body->y, + $self->on_body->name, + $self->name, + $self->from_body->id, + $self->from_body->name], ); - $self->on_body->add_news(70, - 'The Planetary Command on %s was torched. While the building itself survived a critical plan was lost.', - $self->on_body->name); - $plan->delete; + $self->on_body->add_news( + 70, + 'The Planetary Command on %s was torched. While the building itself survived, critical plans were lost.', + $self->on_body->name, + ); + $self->on_body->delete_many_plans($destroyed_plan, $destroyed_quantity); return $message->id; } @@ -2197,27 +2206,33 @@ sub steal_building { sub steal_plan { my ($self, $defender) = @_; - my $plan = $self->on_body->plans->search( - { class => { '!=' => 'Lacuna::DB::Result::Building::DeployedBleeder' } }, - { rows=>1, order_by => 'rand()' } - )->single; - return $self->mission_objective_not_found('plan')->id unless defined $plan; + + my $number_of_plans = @{$self->on_body->plan_cache}; + return $self->mission_objective_not_found('plan')->id unless $number_of_plans; + + my $stolen_plan = random_element($self->on_body->plan_cache); + my $stolen_quantity = int(rand($stolen_plan->quantity / 10)) + 1; + $self->things_stolen( $self->things_stolen + 1 ); - $plan->body_id($self->from_body_id); - $plan->update; + my $plural = $stolen_quantity > 1 ? 's' : ''; + + my $stolen = $stolen_quantity.' level '.$stolen_plan->level_formatted.' '.$stolen_plan->class->name." plan$plural"; + + $self->from_body->add_plan($stolen_plan->class, $stolen_plan->level, $stolen_plan->extra_build_level, $stolen_quantity); + + $self->on_body->delete_many_plans($stolen_plan, $stolen_quantity); + $self->on_body->empire->send_predefined_message( tags => ['Spies','Alert'], filename => 'plan_stolen.txt', - params => [$plan->level_formatted, - $plan->class->name, + params => [$stolen, $self->on_body->id, $self->on_body->name], ); return $self->empire->send_predefined_message( tags => ['Intelligence'], - filename => 'building_theft_report.txt', - params => [$plan->level_formatted, - $plan->class->name, + filename => 'plan_theft_report.txt', + params => [$stolen, $self->name, $self->from_body->id, $self->from_body->name], diff --git a/lib/Lacuna/RPC/Building.pm b/lib/Lacuna/RPC/Building.pm index c1caf44b..195ea3bd 100644 --- a/lib/Lacuna/RPC/Building.pm +++ b/lib/Lacuna/RPC/Building.pm @@ -39,7 +39,7 @@ sub upgrade { my $body = $building->body; my $plan = $body->get_plan($building->class, $building->level + 1); if (defined $plan) { - $plan->delete; + $plan->delete_one; } else { $body->spend_water($cost->{water}); @@ -173,7 +173,7 @@ sub build { if ($plan->extra_build_level) { $building->level( $plan->extra_build_level); } - $plan->delete_one_plan; + $plan->delete_one; } else { $body->spend_food($cost->{food}, 0); diff --git a/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm b/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm index f052267b..3eeadbf1 100644 --- a/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm +++ b/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm @@ -59,17 +59,17 @@ sub sacrifice_to_upgrade { my $plans_needed = $upgrade->level + 1 - scalar @halls; my @plans; if ($plans_needed > 0) { - @plans = $body->plans->search({ - class => 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk' - },{rows => $plans_needed} - ); + my ($plan) = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk'} @{$body->plans_cache}; + if ($plan) { + if ($plan->quantity < $plans_needed) { + confess [1009, 'The Halls of Vrbansk do not have the knowledge necessary to upgrade the '.$upgrade->name]; + } + $plan->delete_many($plans_needed); + } } foreach my $hall (@halls) { $hall->delete; } - foreach my $plan (@plans) { - $plan->delete; - } $body->needs_surface_refresh(1); $body->update; return { status => $self->format_status($empire, $body) }; diff --git a/lib/Lacuna/Role/Container.pm b/lib/Lacuna/Role/Container.pm index ad98e0c0..c9b4a01c 100644 --- a/lib/Lacuna/Role/Container.pm +++ b/lib/Lacuna/Role/Container.pm @@ -23,21 +23,6 @@ sub format_body_stats_for_log { sub unload { my ($self, $body, $withdraw) = @_; my $payload = $self->payload; - #my $cargo_log = Lacuna->db->resultset('Lacuna::DB::Result::Log::Cargo'); - #$cargo_log->new({ - # message => 'payload to unload', - # body_id => $body->id, - # data => $payload, - # object_type => ref($self), - # object_id => $self->id, - #})->insert; - #$cargo_log->new({ - # message => 'before unload', - # body_id => $body->id, - # data => $self->format_body_stats_for_log($body), - # object_type => ref($self), - # object_id => $self->id, - #})->insert; if (exists $payload->{prisoners}) { foreach my $id (@{$payload->{prisoners}}) { my $prisoner = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->find($id); @@ -89,7 +74,7 @@ sub unload { } if (exists $payload->{plans}) { foreach my $plan (@{$payload->{plans}}) { - $body->add_plan($plan->{class}, $plan->{level}, $plan->{extra_build_level}); + $body->add_plan($plan->{class}, $plan->{level}, $plan->{extra_build_level}, $plan->{quantity}); } delete $payload->{plans}; } @@ -158,9 +143,8 @@ sub format_description_of_payload { $level .= '+'.$stats->{extra_build_level}; } my $pattern = '%s (%s) plan'; - push @{$scratch}, sprintf($pattern, $stats->{class}->name, $level); + push @{$item_arr}, sprintf('%s %s (%s) plan', $stats->{quantity}, $stats->{class}->name, $level); } - push @{$item_arr}, @{consolidate_items($scratch)} if (defined($scratch)); # spies undef $scratch; diff --git a/lib/Lacuna/Role/Trader.pm b/lib/Lacuna/Role/Trader.pm index 2c326d2b..b544b4ac 100644 --- a/lib/Lacuna/Role/Trader.pm +++ b/lib/Lacuna/Role/Trader.pm @@ -69,10 +69,7 @@ sub check_payload { } when ('plan') { if ($item->{plan_id}) { - my $plan = Lacuna->db->resultset('Lacuna::DB::Result::Plans')->find($item->{plan_id}); - confess $have_exception unless (defined $plan && $self->body_id eq $plan->body_id); - push @expanded_items, $item; - $space_used += 10000; + confess [1002, 'Plan IDs are no longer supported']; } elsif ($item->{quantity}) { confess $offer_nothing_exception unless ($item->{quantity} > 0); @@ -84,19 +81,19 @@ sub check_payload { my $plan_class = $item->{plan_type}; $plan_class =~ s/_/::/g; $plan_class = "Lacuna::DB::Result::Building::$plan_class"; - my @plans = Lacuna->db->resultset('Lacuna::DB::Result::Plans')->search({ - class => $plan_class, - body_id => $self->body_id, - level => $item->{level}, - extra_build_level => $item->{extra_build_level}, - }); - confess [1002, "You don't have ".$item->{quantity}." plans of type ".$item->{plan_type}." you only have ".scalar(@plans)] unless scalar(@plans) >= $item->{quantity}; - push @expanded_items, map { {type => 'plan',plan_id => $_->id} } splice @plans, 0, $item->{quantity}; +print STDERR "###### [$plan_class] ######\n"; + my ($plan) = grep { + $_->class eq $plan_class + and $_->level == $item->{level} + and $_->extra_build_level == $item->{extra_build_level} + } @{$body->plan_cache}; + confess [1002, "You don't have ".$item->{quantity}." plans of type ".$item->{plan_type}] unless defined $plan and $plan->quantity >= $item->{quantity}; + + push @expanded_items, {type => 'plan', plan_id => $plan->id, quantity => $item->{quantity} }; $space_used += 10000 * $item->{quantity}; - } else { - confess [1002, 'You must specify either a plan_id, or a quantity if you are pushing a plan.']; + confess [1002, 'You must specify a quantity if you are pushing a plan.']; } } when ('prisoner') { @@ -145,7 +142,6 @@ sub check_payload { } } } -# push @$items, @expanded_items; $items = \@expanded_items; confess $offer_nothing_exception unless $space_used; confess [1011, sprintf($space_exception,$space_used)] unless ($space_used <= $available_cargo_space); @@ -187,9 +183,14 @@ sub structure_payload { } when ('plan') { if ($item->{plan_id}) { - my $plan = Lacuna->db->resultset('Lacuna::DB::Result::Plans')->find($item->{plan_id}); - $plan->delete; - push @{$payload->{plans}}, { class => $plan->class, level => $plan->level, extra_build_level => $plan->extra_build_level }; + my ($plan) = grep {$_->id == $item->{plan_id}} @{$body->plan_cache}; + $body->delete_many_plans($plan, $item->{quantity}); + push @{$payload->{plans}}, { + class => $plan->class, + level => $plan->level, + extra_build_level => $plan->extra_build_level, + quantity => $item->{quantity}, + }; $meta{has_plan} = 1; } } diff --git a/lib/Lacuna/Role/TraderRpc.pm b/lib/Lacuna/Role/TraderRpc.pm index 54b9660a..18b4a858 100644 --- a/lib/Lacuna/Role/TraderRpc.pm +++ b/lib/Lacuna/Role/TraderRpc.pm @@ -181,7 +181,7 @@ sub get_plan_summary { my @out; my $sorted_plans = $building->body->sorted_plans; foreach my $plan (@$sorted_plans) { - my $plan_type = $plan->class->name; + my $plan_type = $plan->class; $plan_type =~ s/Lacuna::DB::Result::Building:://; $plan_type =~ s/::/_/g; push @out, { diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 923a4432..2b51377e 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -464,20 +464,14 @@ sub www_delete_glyph { sub www_view_plans { my ($self, $request, $body_id) = @_; $body_id ||= $request->param('body_id'); - my $plans = Lacuna->db->resultset('Lacuna::DB::Result::Plans')->search({ - body_id => $body_id, - }, { - order_by => ['class'], - group_by => ['class','level','extra_build_level'], - select => ['class','level','extra_build_level', {count => 'id', -as => 'count_plans'}], - as => ['class','level','extra_build_level','no_of_plans'], - }); + my $body = Lacuna->db->resultset('Body')->find($request->param('body_id')); + my @plans = $body->sorted_plans; my $out = '

View Plans

'; $out .= sprintf('Back To Body', $body_id); $out .= ''; - while (my $plan = $plans->next) { - $out .= sprintf('
LevelNameExtra Build LevelQuantityAction
%s%s%s%s',$plan->level, $plan->class->name, $plan->extra_build_level, $plan->get_column('no_of_plans')); + for my $plan (@plans) { + $out .= sprintf('
%s%s%s%s',$plan->level, $plan->class->name, $plan->extra_build_level, $plan->quantity); $out .= sprintf('
'); $out .= sprintf('',$plan->level); $out .= sprintf('',$plan->class); @@ -519,28 +513,25 @@ sub www_add_plan { sub www_delete_plan { my ($self, $request) = @_; - my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($request->param('body_id')); + my $body = Lacuna->db->resultset('Body')->find($request->param('body_id')); unless (defined $body) { confess [404, 'Body not found.']; } # Find a plan - my $plan_rs = $body->plans->search({ - level => $request->param('level'), - class => $request->param('class'), - extra_build_level => $request->param('extra'), - }); - if ($plan_rs < 1 and $request->param('delete_one')) { + my $plan = grep { + $_->level == $request->param('level') + and $_->class eq $request->param('class') + and $_->extra_build_level == $request->param('extra') + } @{$body->plan_cache}; + + if (not defined $plan) { confess [404, 'Plan not found.']; } if ($request->param('delete_one')) { - if ($plan_rs < 1) { - confess [404, 'Plan not found.']; - } - my $plan = $plan_rs->next; - $plan->delete; + $body->delete_one_plan($plan); } if ($request->param('delete_all')) { - $plan_rs->delete_all; + $body->delete_many_plans($plan, $plan->quantity); } return $self->www_view_plans($request, $body->id); } diff --git a/var/messages/plan_stolen.txt b/var/messages/plan_stolen.txt index a14e14b7..a1ebe72f 100644 --- a/var/messages/plan_stolen.txt +++ b/var/messages/plan_stolen.txt @@ -1,6 +1,6 @@ Plan Stolen ~~~ -Thieves have our level %s %s plan from {Planet %s %s}. +Thieves have stolen %s from {Planet %s %s}. Regards, diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 4b60b9d0..6fc44ac0 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,9 @@ +3.0859: + - Mod: Spies now have a higher chance of stealing or destroying a 'useful' plan + - Mod: Spies may now steal or destroy more than one plan of a type + - Mod: Missions that require a plan, now take the lowest level/extra that meet the criteria + - Mod: Improved efficiency on planets with lots of glyphs and plans + 3.0858: - Add: Resources per hour for all food/ore types now shown in PCC and SCC - Add: PCC and SCC now show all incoming supply chains