From 9ce54a2c2dfde645c9d598534f2561e9d1328083 Mon Sep 17 00:00:00 2001 From: Darin McBride Date: Thu, 18 Dec 2014 20:04:57 -0700 Subject: [PATCH] First stab at an effective_level / effective_efficiency --- lib/Lacuna/DB/Result/Building.pm | 51 +++++++++++--- lib/Lacuna/DB/Result/Building/Archaeology.pm | 11 ++-- lib/Lacuna/DB/Result/Building/Capitol.pm | 2 +- .../DB/Result/Building/DeployedBleeder.pm | 11 +--- .../DB/Result/Building/DistributionCenter.pm | 6 +- lib/Lacuna/DB/Result/Building/Embassy.pm | 8 +-- lib/Lacuna/DB/Result/Building/Espionage.pm | 2 +- lib/Lacuna/DB/Result/Building/GeneticsLab.pm | 6 +- .../DB/Result/Building/IntelTraining.pm | 2 +- lib/Lacuna/DB/Result/Building/Intelligence.pm | 10 +-- lib/Lacuna/DB/Result/Building/LCOTa.pm | 66 +++++++------------ .../DB/Result/Building/MayhemTraining.pm | 2 +- .../DB/Result/Building/MercenariesGuild.pm | 4 +- lib/Lacuna/DB/Result/Building/Module.pm | 10 +-- .../Result/Building/Module/PoliceStation.pm | 2 +- lib/Lacuna/DB/Result/Building/Observatory.pm | 2 +- lib/Lacuna/DB/Result/Building/Ore/Ministry.pm | 2 +- lib/Lacuna/DB/Result/Building/Park.pm | 4 +- .../Building/Permanent/GasGiantPlatform.pm | 16 ++--- .../Result/Building/Permanent/OracleOfAnid.pm | 2 +- .../Permanent/TerraformingPlatform.pm | 16 ++--- .../Building/Permanent/TheDillonForge.pm | 9 +-- .../DB/Result/Building/PlanetaryCommand.pm | 2 +- .../DB/Result/Building/PoliticsTraining.pm | 2 +- lib/Lacuna/DB/Result/Building/SSLa.pm | 4 +- lib/Lacuna/DB/Result/Building/Security.pm | 4 +- lib/Lacuna/DB/Result/Building/Shipyard.pm | 44 ++++++------- lib/Lacuna/DB/Result/Building/Stockpile.pm | 4 +- lib/Lacuna/DB/Result/Building/SupplyPod.pm | 11 +--- .../DB/Result/Building/TheftTraining.pm | 2 +- lib/Lacuna/DB/Result/Building/ThemePark.pm | 2 +- lib/Lacuna/DB/Result/Building/Trade.pm | 8 +-- lib/Lacuna/DB/Result/Building/Transporter.pm | 6 +- .../DB/Result/Building/Waste/Exchanger.pm | 6 +- .../DB/Result/Building/Waste/Recycling.pm | 6 +- lib/Lacuna/DB/Result/Empire.pm | 2 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 24 +++---- .../DB/Result/Map/Body/Planet/Station.pm | 4 +- .../DB/Result/Propositions/InductMember.pm | 15 ++--- lib/Lacuna/DB/Result/Spies.pm | 10 +-- lib/Lacuna/RPC/Body.pm | 4 +- lib/Lacuna/RPC/Building.pm | 5 +- lib/Lacuna/RPC/Building/Archaeology.pm | 3 +- lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 27 ++++---- lib/Lacuna/RPC/Building/Development.pm | 4 +- lib/Lacuna/RPC/Building/IntelTraining.pm | 4 +- lib/Lacuna/RPC/Building/Intelligence.pm | 2 +- lib/Lacuna/RPC/Building/LibraryOfJith.pm | 2 +- lib/Lacuna/RPC/Building/MayhemTraining.pm | 4 +- lib/Lacuna/RPC/Building/MercenariesGuild.pm | 8 +-- lib/Lacuna/RPC/Building/MissionCommand.pm | 2 +- lib/Lacuna/RPC/Building/Network19.pm | 2 +- lib/Lacuna/RPC/Building/Parliament.pm | 42 ++++++------ lib/Lacuna/RPC/Building/PoliceStation.pm | 8 +-- lib/Lacuna/RPC/Building/PoliticsTraining.pm | 4 +- lib/Lacuna/RPC/Building/Shipyard.pm | 2 +- lib/Lacuna/RPC/Building/SpacePort.pm | 14 ++-- .../RPC/Building/TempleOfTheDrajilites.pm | 4 +- lib/Lacuna/RPC/Building/TheftTraining.pm | 2 +- lib/Lacuna/RPC/Building/Trade.pm | 10 +-- lib/Lacuna/RPC/Building/Transporter.pm | 8 +-- .../Role/Building/IgnoresUniversityLevel.pm | 11 ++++ lib/Lacuna/Role/Influencer.pm | 2 +- .../Role/Ship/Arrive/AddGasGiantPlatform.pm | 2 +- .../Ship/Arrive/AddTerraformingPlatform.pm | 2 +- .../Role/Ship/Arrive/CaptureWithSpies.pm | 2 +- lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm | 8 +-- .../Role/Ship/Arrive/DeployExcavator.pm | 4 +- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 10 +-- 69 files changed, 289 insertions(+), 313 deletions(-) create mode 100644 lib/Lacuna/Role/Building/IgnoresUniversityLevel.pm diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index e68d18a2..566859d3 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -5,7 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; use Lacuna::Constants ':all'; -use List::Util qw(shuffle); +use List::Util qw(shuffle min); use List::MoreUtils qw(first_index); use Lacuna::Util qw(format_date); @@ -132,13 +132,44 @@ use constant waste_storage => 0; # BASE FORMULAS +has effective_level => ( + is => 'rw', + lazy => 1, + builder => '_build_effective_level', + clearer => 'clear_effective_level', +); + +sub _build_effective_level +{ + my $self = shift; + my $uni_prod = ($self->body->empire) ? $self->body->empire->university_level + 1 : 1; + my $real_level = $self->level; + # take whichever one is lower. + my $eff_level = min($uni_prod + 1, $real_level); + + # room for objects/boosts/whatever to override this. + + $eff_level; +} + +has effective_efficiency => ( + is => 'rw', + lazy => 1, + builder => '_build_effective_efficiency', + clearer => 'clear_effective_efficiency', +); + +sub _build_effective_efficiency { + my $self = shift; + $self->efficiency; # with rare exceptions +} + sub production_hour { my $self = shift; - return 0 unless $self->level; - my $uni_prod = ($self->body->empire) ? $self->body->empire->university_level + 1 : 1; - my $prod_level = ($self->level > $uni_prod) ? $uni_prod : $self->level; + return 0 unless $self->effective_level; + my $prod_level = $self->effective_level; my $production = (GROWTH ** ( $prod_level - 1)); - $production = ($production * $self->efficiency) / 100; + $production = ($production * $self->effective_efficiency) / 100; return $production; } @@ -387,7 +418,7 @@ sub mining_production_bonus { my $empire = $self->body->empire; return 1 unless defined $empire; my $refinery = $self->body->refinery; - my $refinery_bonus = (defined $refinery) ? $refinery->level * 5 : 0; + my $refinery_bonus = (defined $refinery) ? $refinery->effective_level * 5 : 0; my $boost = (time < $empire->ore_boost->epoch) ? 25 : 0; return (100 + $boost + $refinery_bonus + $empire->mining_affinity * 4) / 100; } @@ -799,8 +830,7 @@ sub cost_to_upgrade { } my $oversight_reduction = 1; if (defined $self->body->oversight) { - my $om_level = ($self->body->oversight->level > $self->body->empire->university_level + 1) ? - $self->body->empire->university_level + 1 : $self->body->oversight->level; + my $om_level = $self->body->oversight->effective_level; $oversight_reduction = (100 - ($om_level * 3)) / 100; } my $time_inflator = ($self->level * 2) - 1; @@ -834,12 +864,14 @@ sub stats_after_upgrade { my ($self) = @_; my $current_level = $self->level; $self->level($current_level + 1); + $self->clear_effective_level; my %stats; my @list = qw(food_hour food_capacity ore_hour ore_capacity water_hour water_capacity waste_hour waste_capacity energy_hour energy_capacity happiness_hour); foreach my $resource (@list) { $stats{$resource} = $self->$resource; } $self->level($current_level); + $self->clear_effective_level; return \%stats; } @@ -915,6 +947,7 @@ sub finish_upgrade { $self->reschedule_queue; $self->level($new_level); + $self->clear_effective_level(); $self->is_upgrading(0); $self->update; @@ -1100,7 +1133,7 @@ sub last_check_formatted { sub is_offline { my $self = shift; - if ($self->efficiency == 0) { + if ($self->effective_efficiency == 0) { confess [1013, $self->name.' is currently offline.']; } } diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 7cadc274..91e49906 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -47,8 +47,7 @@ use constant waste_production => 20; sub chance_of_glyph { my $self = shift; - my $chance = ($self->level > $self->body->empire->university_level + 1) ? - $self->body->empire->university_level + 1 : $self->level; + my $chance = $self->effective_level; return $chance; } @@ -72,8 +71,7 @@ sub get_ores_available_for_processing { sub max_excavators { my $self = shift; - my $level = ($self->level > $self->body->empire->university_level + 1) ? - $self->body->empire->university_level + 1 : $self->level; + my $level = $self->effective_level; return 0 if ($level < 11); return ($level - 10); } @@ -82,8 +80,7 @@ sub run_excavators { my $self = shift; my $results; - my $level = ($self->level > $self->body->empire->university_level + 1) ? - $self->body->empire->university_level + 1 : $self->level; + my $level = $self->effective_level; my $empire = $self->body->empire; # Do once for arch itself. No chance of destroy or artifacts. my $result = $self->dig_it($self->body, $level, 1); @@ -616,7 +613,7 @@ sub remove_excavator { sub can_search_for_glyph { my ($self, $ore) = @_; - unless ($self->level > 0) { + unless ($self->effective_level > 0) { confess [1010, 'The Archaeology Ministry is not finished building yet.']; } unless ($ore ~~ [ ORE_TYPES ]) { diff --git a/lib/Lacuna/DB/Result/Building/Capitol.pm b/lib/Lacuna/DB/Result/Building/Capitol.pm index e52f3f72..6b8175fb 100644 --- a/lib/Lacuna/DB/Result/Building/Capitol.pm +++ b/lib/Lacuna/DB/Result/Building/Capitol.pm @@ -80,7 +80,7 @@ after finish_upgrade => sub { sub rename_empire_cost { my $self = shift; - return 30 - $self->level; + return 30 - $self->effective_level; } diff --git a/lib/Lacuna/DB/Result/Building/DeployedBleeder.pm b/lib/Lacuna/DB/Result/Building/DeployedBleeder.pm index 3b8f6e87..df476ef4 100644 --- a/lib/Lacuna/DB/Result/Building/DeployedBleeder.pm +++ b/lib/Lacuna/DB/Result/Building/DeployedBleeder.pm @@ -7,6 +7,8 @@ extends 'Lacuna::DB::Result::Building'; use Lacuna::Util qw(randint); use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES GROWTH INFLATION); +with 'Lacuna::Role::Building::IgnoresUniversityLevel'; + use constant controller_class => 'Lacuna::RPC::Building::DeployedBleeder'; around can_build => sub { @@ -49,15 +51,6 @@ sub finish_upgrade_news } } -sub production_hour { - my $self = shift; - return 0 unless $self->level; - my $prod_level = $self->level; - my $production = (GROWTH ** ( $prod_level - 1)); - $production = ($production * $self->efficiency) / 100; - return $production; -} - sub cost_to_upgrade { my ($self) = @_; my $upgrade_cost = $self->upgrade_cost; diff --git a/lib/Lacuna/DB/Result/Building/DistributionCenter.pm b/lib/Lacuna/DB/Result/Building/DistributionCenter.pm index 11da3329..f7ffcfc4 100755 --- a/lib/Lacuna/DB/Result/Building/DistributionCenter.pm +++ b/lib/Lacuna/DB/Result/Building/DistributionCenter.pm @@ -53,16 +53,16 @@ use constant max_instances_per_planet => 2; sub max_reserve_size { my $self = shift; - return int($self->level * 10000 * (10 ** ($self->level/10+1))); + return int($self->effective_level * 10000 * (10 ** ($self->effective_level/10+1))); } sub reserve_duration { my $self = shift; - return $self->level * 2 * 60 * 60; + return $self->effective_level * 2 * 60 * 60; } sub can_reserve { my ($self) = @_; - if ($self->level < 1) { + if ($self->effective_level < 1) { confess [1010, "You can't reserve until the Distribution Center is built."]; } if ($self->is_working) { diff --git a/lib/Lacuna/DB/Result/Building/Embassy.pm b/lib/Lacuna/DB/Result/Building/Embassy.pm index 4f842b45..c4ad8a29 100644 --- a/lib/Lacuna/DB/Result/Building/Embassy.pm +++ b/lib/Lacuna/DB/Result/Building/Embassy.pm @@ -45,10 +45,10 @@ use constant water_consumption => 6; use constant waste_production => 1; # by accepting an optional level, we can centralise the calculation. -# default level, of course, is the embassy's level. +# default level, of course, is the embassy's effective level (based on uni level, etc). sub max_members { my $self = shift; - my $level = @_ ? shift : $self->level; + my $level = @_ ? shift : $self->effective_level; return $level * 2; } @@ -264,7 +264,7 @@ sub exchange_with_stash { sub max_exchange_size { my $self = shift; - return $self->level * 10000; + return $self->effective_level * 10000; } has exchanges_remaining_today => ( @@ -272,7 +272,7 @@ has exchanges_remaining_today => ( lazy => 1, default => sub { my $self = shift; - return $self->level - Lacuna->cache->get('stash_exchanges_'.format_date(undef,'%d'), $self->body_id); + return $self->effective_level - Lacuna->cache->get('stash_exchanges_'.format_date(undef,'%d'), $self->body_id); }, ); diff --git a/lib/Lacuna/DB/Result/Building/Espionage.pm b/lib/Lacuna/DB/Result/Building/Espionage.pm index 97d6504f..a1618506 100644 --- a/lib/Lacuna/DB/Result/Building/Espionage.pm +++ b/lib/Lacuna/DB/Result/Building/Espionage.pm @@ -50,7 +50,7 @@ after finish_upgrade => sub { $empire->is_isolationist(0); $empire->update; } - my $offense = ($empire->deception_affinity * 50) + ($self->level * 75); + my $offense = ($empire->deception_affinity * 50) + ($self->effective_level * 75); my $spies = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({ on_body_id => $self->body_id, from_body_id => $self->body_id, diff --git a/lib/Lacuna/DB/Result/Building/GeneticsLab.pm b/lib/Lacuna/DB/Result/Building/GeneticsLab.pm index 11f21d12..0acf70bf 100644 --- a/lib/Lacuna/DB/Result/Building/GeneticsLab.pm +++ b/lib/Lacuna/DB/Result/Building/GeneticsLab.pm @@ -82,7 +82,7 @@ sub get_possible_grafts { sub graft_odds { my $self = shift; - return $self->level + $self->body->empire->science_affinity; + return $self->effective_level + $self->body->empire->science_affinity; } sub is_graft_success { @@ -92,7 +92,7 @@ sub is_graft_success { sub survival_odds { my $self = shift; - return ($self->level * 3) + $self->body->empire->science_affinity; + return ($self->effective_level * 3) + $self->body->empire->science_affinity; } sub is_survival_success { @@ -120,7 +120,7 @@ sub total_grafts { sub can_experiment { my $self = shift; - if ($self->total_grafts >= $self->level) { + if ($self->total_grafts >= $self->effective_level) { confess [1013, 'You need to raise your genetics lab level to run more experiments.']; } return 1; diff --git a/lib/Lacuna/DB/Result/Building/IntelTraining.pm b/lib/Lacuna/DB/Result/Building/IntelTraining.pm index c4585011..67b3ab0c 100644 --- a/lib/Lacuna/DB/Result/Building/IntelTraining.pm +++ b/lib/Lacuna/DB/Result/Building/IntelTraining.pm @@ -82,7 +82,7 @@ has training_multiplier => ( lazy => 1, default => sub { my $self = shift; - my $multiplier = $self->level; + my $multiplier = $self->effective_level; $multiplier = 1 if $multiplier < 1; return $multiplier; } diff --git a/lib/Lacuna/DB/Result/Building/Intelligence.pm b/lib/Lacuna/DB/Result/Building/Intelligence.pm index c0b29b84..309aae65 100644 --- a/lib/Lacuna/DB/Result/Building/Intelligence.pm +++ b/lib/Lacuna/DB/Result/Building/Intelligence.pm @@ -45,7 +45,7 @@ use constant waste_production => 1; sub max_spies { my ($self) = @_; # Just temporary until the major change - return ($self->level * 3); + return ($self->effective_level * 3); } has spy_count => ( @@ -110,7 +110,7 @@ has espionage_level => ( default => sub { my $self = shift; my $building = $self->body->get_building_of_class('Lacuna::DB::Result::Building::Espionage'); - return (defined $building) ? $building->level : 0; + return (defined $building) ? $building->effective_level : 0; }, ); @@ -120,7 +120,7 @@ has security_level => ( default => sub { my $self = shift; my $building = $self->body->get_building_of_class('Lacuna::DB::Result::Building::Security'); - return (defined $building) ? $building->level : 0; + return (defined $building) ? $building->effective_level : 0; }, ); @@ -129,7 +129,7 @@ has training_multiplier => ( lazy => 1, default => sub { my $self = shift; -# my $multiplier = $self->level +# my $multiplier = $self->effective_level my $multiplier = 1 - $self->body->empire->deception_affinity + $self->espionage_level @@ -208,7 +208,7 @@ sub train_spy { ->insert; $self->latest_spy($spy); my $count = $self->spy_count($self->spy_count + 1); - if ($count < $self->level) { + if ($count < $self->effective_level) { $self->body->add_news(20,'A source inside %s admitted that they are underprepared for the threats they face.', $empire->name); } if ($self->is_working) { diff --git a/lib/Lacuna/DB/Result/Building/LCOTa.pm b/lib/Lacuna/DB/Result/Building/LCOTa.pm index 8fe6a720..e1277889 100644 --- a/lib/Lacuna/DB/Result/Building/LCOTa.pm +++ b/lib/Lacuna/DB/Result/Building/LCOTa.pm @@ -36,66 +36,46 @@ around produces_food_items => sub { has effective_efficiency => ( is => 'rw', lazy => 1, - predicate => 'has_effective_efficiency', default => 0, ); -has effective_level => ( - is => 'rw', - lazy => 1, +has '+effective_level' => ( predicate => 'has_effective_level', - default => 0, ); -sub production_hour { - my $self = shift; - return 0 unless $self->level; - unless ($self->has_effective_level) { - $self->calculate_effective_stats; - } - my $production = (GROWTH ** ( $self->effective_level - 1)); - $production = ($production * $self->effective_efficiency) / 100; - return $production; -} - - -sub stats_after_upgrade { - my ($self) = @_; - unless ($self->has_effective_level) { - $self->calculate_effective_stats; - } - my $current_level = $self->effective_level; - $self->effective_level($current_level + 1); - my %stats; - my @list = qw(food_hour food_capacity ore_hour ore_capacity water_hour water_capacity waste_hour waste_capacity energy_hour energy_capacity happiness_hour); - foreach my $resource (@list) { - $stats{$resource} = $self->$resource; +around '_build_effective_level' => sub { + my ($orig, $self) = @_; + my $level = $self->$orig; + my $body = $self->body; + foreach my $ext (qw(b c d e f g h i)) { + my $part = $body->get_building_of_class('Lacuna::DB::Result::Building::LCOT'.$ext); + if (defined $part) { + $level = $part->effective_level < $level ? $part->effective_level : $level; + } + else { + $level = 0; + } + last if $level < 1; } - $self->effective_level($current_level); - return \%stats; -} + return $level; +}; -sub calculate_effective_stats { - my $self = shift; - my $level = $self->level; - my $efficiency = $self->efficiency; +around '_build_effective_efficiency' => sub { + my ($orig, $self) = @_; + my $efficiency = $self->$orig; my $body = $self->body; foreach my $ext (qw(b c d e f g h i)) { my $part = $body->get_building_of_class('Lacuna::DB::Result::Building::LCOT'.$ext); if (defined $part) { - $level = $part->level < $level ? $part->level : $level; - $efficiency = $part->efficiency < $efficiency ? $part->efficiency : $efficiency; + $efficiency = $part->effective_efficiency < $efficiency ? $part->effective_efficiency : $efficiency; } else { - $level = 0; $efficiency = 0; } - last if $level < 1 || $efficiency < 1; + last if $efficiency < 1; } - $self->effective_level($level); - $self->effective_efficiency($efficiency); -} - + return $efficiency; +}; before 'can_demolish' => sub { my $self = shift; diff --git a/lib/Lacuna/DB/Result/Building/MayhemTraining.pm b/lib/Lacuna/DB/Result/Building/MayhemTraining.pm index 9ad5ff5b..0e7898bf 100644 --- a/lib/Lacuna/DB/Result/Building/MayhemTraining.pm +++ b/lib/Lacuna/DB/Result/Building/MayhemTraining.pm @@ -85,7 +85,7 @@ has training_multiplier => ( lazy => 1, default => sub { my $self = shift; - my $multiplier = $self->level; + my $multiplier = $self->effective_level; $multiplier = 1 if $multiplier < 1; return $multiplier; } diff --git a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm index 17d976ee..af0d609c 100644 --- a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm +++ b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm @@ -74,8 +74,8 @@ sub add_to_market { unless (defined $ship) { confess [1011, "You do not have any spy pods available."]; } - unless ($self->level > $self->my_market->count) { - confess [1009, "This Mercenaries Guild can only support ".$self->level." spies at one time."]; + unless ($self->effective_level > $self->my_market->count) { + confess [1009, "This Mercenaries Guild can only support ".$self->effective_level." spies at one time."]; } my $spy = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->find($spy_id); confess $have_exception unless (defined $spy && $self->body_id eq $spy->on_body_id && $spy->task ~~ ['Counter Espionage','Idle']); diff --git a/lib/Lacuna/DB/Result/Building/Module.pm b/lib/Lacuna/DB/Result/Building/Module.pm index 60ed6030..5268d5e7 100644 --- a/lib/Lacuna/DB/Result/Building/Module.pm +++ b/lib/Lacuna/DB/Result/Building/Module.pm @@ -6,6 +6,8 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building'; use Lacuna::Constants qw(GROWTH); +with 'Lacuna::Role::Building::IgnoresUniversityLevel'; + around 'build_tags' => sub { my ($orig, $class) = @_; return ($orig->($class), qw(Infrastructure)); @@ -56,14 +58,6 @@ around spend_efficiency => sub { return $self; }; -sub production_hour { - my $self = shift; - return 0 unless $self->level; - my $production = (GROWTH ** ( $self->level - 1)); - $production = ($production * $self->efficiency) / 100; - return $production; -} - sub cost_to_upgrade { return { food => 0, diff --git a/lib/Lacuna/DB/Result/Building/Module/PoliceStation.pm b/lib/Lacuna/DB/Result/Building/Module/PoliceStation.pm index d6a41f85..eb8c065d 100644 --- a/lib/Lacuna/DB/Result/Building/Module/PoliceStation.pm +++ b/lib/Lacuna/DB/Result/Building/Module/PoliceStation.pm @@ -19,7 +19,7 @@ sub foreign_spies { return Lacuna ->db ->resultset('Lacuna::DB::Result::Spies') - ->search({ level => { '<=' => int($self->level * 1.25)}, + ->search({ level => { '<=' => int($self->effective_level * 1.25)}, task => { 'not in' => [ 'Captured', 'Prisoner Transport' ] }, on_body_id => $self->body_id, empire_id => { '!=' => $self->body->empire_id } }); } diff --git a/lib/Lacuna/DB/Result/Building/Observatory.pm b/lib/Lacuna/DB/Result/Building/Observatory.pm index 9458de03..8ddbf1b4 100644 --- a/lib/Lacuna/DB/Result/Building/Observatory.pm +++ b/lib/Lacuna/DB/Result/Building/Observatory.pm @@ -7,7 +7,7 @@ extends 'Lacuna::DB::Result::Building'; sub max_probes { my $self = shift; - return $self->level * 3; + return $self->effective_level * 3; } around 'build_tags' => sub { diff --git a/lib/Lacuna/DB/Result/Building/Ore/Ministry.pm b/lib/Lacuna/DB/Result/Building/Ore/Ministry.pm index a46a9b00..68c97128 100644 --- a/lib/Lacuna/DB/Result/Building/Ore/Ministry.pm +++ b/lib/Lacuna/DB/Result/Building/Ore/Ministry.pm @@ -19,7 +19,7 @@ sub ships { sub max_platforms { my $self = shift; - return ceil($self->level / 2); + return ceil($self->effective_level / 2); } sub add_ship { diff --git a/lib/Lacuna/DB/Result/Building/Park.pm b/lib/Lacuna/DB/Result/Building/Park.pm index 8f1b11fb..70adb1dd 100644 --- a/lib/Lacuna/DB/Result/Building/Park.pm +++ b/lib/Lacuna/DB/Result/Building/Park.pm @@ -15,7 +15,7 @@ around 'build_tags' => sub { sub can_throw_a_party { my ($self) = @_; - if ($self->level < 1) { + if ($self->effective_level < 1) { confess [1010, "You can't throw a party until the park is built."]; } if ($self->is_working) { @@ -33,7 +33,7 @@ sub throw_a_party { my $body = $self->body; my $eat = 10_000; - my $food_multiplier = $self->level * 0.3; + my $food_multiplier = $self->effective_level * 0.3; foreach my $food (FOOD_TYPES) { if ($body->type_stored($food) >= 500) { $food_multiplier++; diff --git a/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm b/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm index 2cc5bf6a..4d5b4808 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm @@ -7,6 +7,7 @@ use Lacuna::Constants qw(GROWTH); extends 'Lacuna::DB::Result::Building::Permanent'; with "Lacuna::Role::Building::CantBuildWithoutPlan"; +with 'Lacuna::Role::Building::IgnoresUniversityLevel'; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -28,7 +29,7 @@ before 'can_demolish' => sub { my @buildings = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform'} @{$body->building_cache}; foreach my $gg_bld (@buildings) { $gg_cnt++; - $gg_plots += int($gg_bld->level * $gg_bld->efficiency/100); + $gg_plots += int($gg_bld->effective_level * $gg_bld->effective_efficiency/100); } return if ($gg_cnt <= 1); # If we only have the one platform, they can destroy it. my $bld_count = $body->building_count; @@ -36,7 +37,7 @@ before 'can_demolish' => sub { if ($excess_plots < 0) { confess [1013, 'Your Gas Giant shows that you are at negative plots.']; } - if ($excess_plots < int($self->level * $self->efficiency/100) ) { + if ($excess_plots < int($self->effective_level * $self->effective_efficiency/100) ) { confess [1013, 'You need to demolish a building before you can demolish this Gas Giant Settlement Platform.']; } }; @@ -51,7 +52,7 @@ before 'can_downgrade' => sub { my @buildings = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform'} @{$body->building_cache}; foreach my $gg_bld (@buildings) { $gg_cnt++; - $gg_plots += int($gg_bld->level * $gg_bld->efficiency/100); + $gg_plots += int($gg_bld->effective_level * $gg_bld->effective_efficiency/100); } my $bld_count = $body->building_count; my $excess_plots = $gg_plots - $bld_count; @@ -75,15 +76,6 @@ before has_special_resources => sub { } }; -sub production_hour { - my $self = shift; - return 0 unless $self->level; - my $prod_level = $self->level; - my $production = (GROWTH ** ( $prod_level - 1)); - $production = ($production * $self->efficiency) / 100; - return $production; -} - use constant name => 'Gas Giant Settlement Platform'; use constant food_to_build => 0; diff --git a/lib/Lacuna/DB/Result/Building/Permanent/OracleOfAnid.pm b/lib/Lacuna/DB/Result/Building/Permanent/OracleOfAnid.pm index c9ff7fa0..0d652122 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/OracleOfAnid.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/OracleOfAnid.pm @@ -63,7 +63,7 @@ after finish_work => sub { sub range { my ($self) = @_; - my $range = $self->level * 1000 * $self->efficiency / 100; + my $range = $self->effective_level * 1000 * $self->effective_efficiency / 100; } diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm index bfbe5e8d..6ed5e434 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm @@ -7,6 +7,7 @@ use Lacuna::Constants qw(GROWTH); extends 'Lacuna::DB::Result::Building::Permanent'; with "Lacuna::Role::Building::CantBuildWithoutPlan"; +with 'Lacuna::Role::Building::IgnoresUniversityLevel'; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -26,7 +27,7 @@ before 'can_demolish' => sub { my @buildings = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform'} @{$body->building_cache}; foreach my $tp_bld (@buildings) { $tp_cnt++; - $tp_plots += int($tp_bld->level * $tp_bld->efficiency/100); + $tp_plots += int($tp_bld->effective_level * $tp_bld->effective_efficiency/100); } return if ($tp_cnt <= 1); # If we only have the one platform, they can destroy it. my $bld_count = $body->building_count; @@ -34,7 +35,7 @@ before 'can_demolish' => sub { if ($excess_plots < 0) { confess [1013, 'Your planet shows that you are at negative plots.']; } - if ($excess_plots < int($self->level * $self->efficiency/100) ) { + if ($excess_plots < int($self->effective_level * $self->effective_efficiency/100) ) { confess [1013, 'You need to demolish a building before you can demolish this Terraforming Platform.']; } }; @@ -50,7 +51,7 @@ before 'can_downgrade' => sub { my @buildings = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform'} @{$body->building_cache}; foreach my $tp_bld (@buildings) { $tp_cnt++; - $tp_plots += int($tp_bld->level * $tp_bld->efficiency/100); + $tp_plots += int($tp_bld->effective_level * $tp_bld->effective_efficiency/100); } return if ($tp_cnt <= 1); # If we only have the one platform, they can destroy it. my $bld_count = $body->building_count; @@ -71,15 +72,6 @@ before has_special_resources => sub { } }; -sub production_hour { - my $self = shift; - return 0 unless $self->level; - my $prod_level = $self->level; - my $production = (GROWTH ** ( $prod_level - 1)); - $production = ($production * $self->efficiency) / 100; - return $production; -} - use constant image => 'terraformingplatform'; use constant name => 'Terraforming Platform'; diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm b/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm index 3dd3163c..f4dbd8b9 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm @@ -77,8 +77,7 @@ sub split_plan { and $_->extra_build_level == $extra_build_level } @{$body->plan_cache}; - my $effective_level = ($self->level > $self->body->empire->university_level + 1) ? - $self->body->empire->university_level + 1 : $self->level; + my $effective_level = $self->effective_level; if (not $plan) { confess [1002, 'You cannot split a plan you do not have.']; @@ -104,8 +103,7 @@ sub split_plan { sub make_plan { my ($self, $plan_class, $level) = @_; - my $effective_level = ($self->level > $self->body->empire->university_level + 1) ? - $self->body->empire->university_level + 1 : $self->level; + my $effective_level = $self->effective_level; if ($level > $effective_level) { confess [1002, 'Your Dillon Forge or your tech level is not high enough to build that high a plan level.']; } @@ -163,8 +161,7 @@ before finish_work => sub { $body->add_news(100, sprintf('%s used the Dillon Forge to create a %s plan level %s on %s.', $empire->name, $plan_class->name, $work->{level}, $body->name)); } if ($work->{task} eq 'split_plan') { - my $effective_level = ($self->level > $self->body->empire->university_level + 1) ? - $self->body->empire->university_level + 1 : $self->level; + my $effective_level = $self->effective_level; # calculate the probability of success my $success_percent = $effective_level * 3; my $halls = $self->equivalent_halls($work->{level}, $work->{extra_build_level}); diff --git a/lib/Lacuna/DB/Result/Building/PlanetaryCommand.pm b/lib/Lacuna/DB/Result/Building/PlanetaryCommand.pm index 0a4f8fb7..e0dc8bd7 100644 --- a/lib/Lacuna/DB/Result/Building/PlanetaryCommand.pm +++ b/lib/Lacuna/DB/Result/Building/PlanetaryCommand.pm @@ -75,7 +75,7 @@ sub sent_a_pod { my ($self) = @_; - my $level = $self->level; + my $level = $self->effective_level; my $cooldown = int( 28.747 * $level * $level - 2877.4 * $level diff --git a/lib/Lacuna/DB/Result/Building/PoliticsTraining.pm b/lib/Lacuna/DB/Result/Building/PoliticsTraining.pm index b4c6b8ab..8908b042 100644 --- a/lib/Lacuna/DB/Result/Building/PoliticsTraining.pm +++ b/lib/Lacuna/DB/Result/Building/PoliticsTraining.pm @@ -82,7 +82,7 @@ has training_multiplier => ( lazy => 1, default => sub { my $self = shift; - my $multiplier = $self->level; + my $multiplier = $self->effective_level; $multiplier = 1 if $multiplier < 1; return $multiplier; } diff --git a/lib/Lacuna/DB/Result/Building/SSLa.pm b/lib/Lacuna/DB/Result/Building/SSLa.pm index 9a12fc32..76866f72 100644 --- a/lib/Lacuna/DB/Result/Building/SSLa.pm +++ b/lib/Lacuna/DB/Result/Building/SSLa.pm @@ -145,12 +145,12 @@ has max_level => ( lazy => 1, default => sub { my $self = shift; - my $level = $self->level; + my $level = $self->effective_level; my $body = $self->body; foreach my $part (qw(b c d)) { my $building = $body->get_building_of_class('Lacuna::DB::Result::Building::SSL'.$part); if (defined $building) { - $level = ($level > $building->level) ? $building->level : $level; + $level = ($level > $building->effective_level) ? $building->effective_level : $level; } else { $level = 0; diff --git a/lib/Lacuna/DB/Result/Building/Security.pm b/lib/Lacuna/DB/Result/Building/Security.pm index 467f43ea..920bbef0 100644 --- a/lib/Lacuna/DB/Result/Building/Security.pm +++ b/lib/Lacuna/DB/Result/Building/Security.pm @@ -50,7 +50,7 @@ sub foreign_spies { return Lacuna ->db ->resultset('Lacuna::DB::Result::Spies') - ->search({ level => { '<=' => $self->level }, + ->search({ level => { '<=' => $self->effective_level }, task => { 'not in' => [ 'Captured', 'Prisoner Transport'] }, on_body_id => $self->body_id, empire_id => { '!=' => $self->body->empire_id } }); } @@ -75,7 +75,7 @@ sub prisoners { after finish_upgrade => sub { my $self = shift; - my $defense = ($self->body->empire->deception_affinity * 50) + ($self->level * 75); + my $defense = ($self->body->empire->deception_affinity * 50) + ($self->effective_level * 75); my $spies = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({ on_body_id => $self->body_id, from_body_id => $self->body_id, diff --git a/lib/Lacuna/DB/Result/Building/Shipyard.pm b/lib/Lacuna/DB/Result/Building/Shipyard.pm index cf1e5dbc..acd28b96 100644 --- a/lib/Lacuna/DB/Result/Building/Shipyard.pm +++ b/lib/Lacuna/DB/Result/Building/Shipyard.pm @@ -20,34 +20,34 @@ sub get_ship_costs { if ($ship->base_hold_size) { my $trade = $self->trade_ministry; if (defined $trade) { - $percentage_of_cost += $trade->level * 3; + $percentage_of_cost += $trade->effective_level * 3; } } if ($ship->base_combat) { my $munitions = $self->munitions_lab; if (defined $munitions) { - $percentage_of_cost += $munitions->level * 3; + $percentage_of_cost += $munitions->effective_level * 3; } } if ($ship->base_stealth) { my $cloak = $self->cloaking_lab; if (defined $cloak) { - $percentage_of_cost += $cloak->level * 3; + $percentage_of_cost += $cloak->effective_level * 3; } } if ($ship->pilotable) { my $pilot = $self->pilot_training_facility; if (defined $pilot) { - $percentage_of_cost += $pilot->level * 3; + $percentage_of_cost += $pilot->effective_level * 3; } } my $propulsion = $self->propulsion_factory; if (defined $propulsion) { - $percentage_of_cost += $propulsion->level * 3; + $percentage_of_cost += $propulsion->effective_level * 3; } $percentage_of_cost /= 100; my $throttle = Lacuna->config->get('ship_build_speed') || 0; - my $seconds = sprintf('%0.f', $ship->base_time_cost * $self->time_cost_reduction_bonus(($self->level * 3) + $throttle)); + my $seconds = sprintf('%0.f', $ship->base_time_cost * $self->time_cost_reduction_bonus(($self->effective_level * 3) + $throttle)); $seconds = 15 if $seconds < 15; $seconds = 5184000 if ($seconds > 5184000); # 60 Days my $bonus = $self->manufacturing_cost_reduction_bonus; @@ -85,7 +85,7 @@ sub can_build_ship { $ship->shipyard_id($self->id); my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships'); $costs ||= $self->get_ship_costs($ship); - if ($self->level < 1) { + if ($self->effective_level < 1) { confess [1013, "You can't build a ship if the shipyard isn't complete."]; } my $reason = ''; @@ -274,29 +274,29 @@ has munitions_lab => ( sub set_ship_speed { my ($self, $ship) = @_; - my $propulsion_level = (defined $self->propulsion_factory) ? $self->propulsion_factory->level : 0; - my $css_level = (defined $self->crashed_ship_site) ? $self->crashed_ship_site->level : 0; - my $ptf = ($ship->pilotable && defined $self->pilot_training_facility) ? $self->pilot_training_facility->level : 0; - my $improvement = 1 + ($self->level * 0.01) + ($ptf * 0.03) + ($propulsion_level * 0.05) + ($css_level * 0.05) + ($self->body->empire->science_affinity * 0.03); + my $propulsion_level = (defined $self->propulsion_factory) ? $self->propulsion_factory->effective_level : 0; + my $css_level = (defined $self->crashed_ship_site) ? $self->crashed_ship_site->effective_level : 0; + my $ptf = ($ship->pilotable && defined $self->pilot_training_facility) ? $self->pilot_training_facility->effective_level : 0; + my $improvement = 1 + ($self->effective_level * 0.01) + ($ptf * 0.03) + ($propulsion_level * 0.05) + ($css_level * 0.05) + ($self->body->empire->science_affinity * 0.03); $ship->speed(sprintf('%.0f', $ship->base_speed * $improvement)); return $ship->speed; } sub set_ship_combat { my ($self, $ship) = @_; - my $css_level = (defined $self->crashed_ship_site) ? $self->crashed_ship_site->level : 0; - my $munitions = (defined $self->munitions_lab) ? $self->munitions_lab->level : 0; - my $ptf = ($ship->pilotable && defined $self->pilot_training_facility) ? $self->pilot_training_facility->level : 0; - my $improvement = 1 + ($self->level * 0.01) + ($ptf * 0.03) + ($munitions * 0.05) + ($css_level * 0.05) + ($self->body->empire->deception_affinity * 0.03) + ($self->body->empire->science_affinity * 0.03); + my $css_level = (defined $self->crashed_ship_site) ? $self->crashed_ship_site->effective_level : 0; + my $munitions = (defined $self->munitions_lab) ? $self->munitions_lab->effective_level : 0; + my $ptf = ($ship->pilotable && defined $self->pilot_training_facility) ? $self->pilot_training_facility->effective_level : 0; + my $improvement = 1 + ($self->effective_level * 0.01) + ($ptf * 0.03) + ($munitions * 0.05) + ($css_level * 0.05) + ($self->body->empire->deception_affinity * 0.03) + ($self->body->empire->science_affinity * 0.03); $ship->combat(sprintf('%.0f', $ship->base_combat * $improvement)); return $ship->combat; } sub set_ship_hold_size { my ($self, $ship) = @_; - my $trade_ministry_level = (defined $self->trade_ministry) ? $self->trade_ministry->level : 0; - my $css_level = (defined $self->crashed_ship_site) ? $self->crashed_ship_site->level : 0; - my $improvement = 1 + ($self->level * 0.01) + ($css_level * 0.05); + my $trade_ministry_level = (defined $self->trade_ministry) ? $self->trade_ministry->effective_level : 0; + my $css_level = (defined $self->crashed_ship_site) ? $self->crashed_ship_site->effective_level : 0; + my $improvement = 1 + ($self->effective_level * 0.01) + ($css_level * 0.05); my $trade_bonus = $self->body->empire->trade_affinity * ( $trade_ministry_level || 0.1 ); $ship->hold_size(sprintf('%.0f', $ship->base_hold_size * $trade_bonus * $improvement)); return $ship->hold_size; @@ -304,10 +304,10 @@ sub set_ship_hold_size { sub set_ship_stealth { my ($self, $ship) = @_; - my $cloaking_level = (defined $self->cloaking_lab) ? $self->cloaking_lab->level : 0; - my $ptf = ($ship->pilotable && defined $self->pilot_training_facility) ? $self->pilot_training_facility->level : 0; - my $css_level = (defined $self->crashed_ship_site) ? $self->crashed_ship_site->level : 0; - my $improvement = 1 + ($self->level * 0.01) + ($ptf * 0.03) + ($cloaking_level * 0.05) + ($css_level * 0.05) + ($self->body->empire->deception_affinity * 0.03); + my $cloaking_level = (defined $self->cloaking_lab) ? $self->cloaking_lab->effective_level : 0; + my $ptf = ($ship->pilotable && defined $self->pilot_training_facility) ? $self->pilot_training_facility->effective_level : 0; + my $css_level = (defined $self->crashed_ship_site) ? $self->crashed_ship_site->effective_level : 0; + my $improvement = 1 + ($self->effective_level * 0.01) + ($ptf * 0.03) + ($cloaking_level * 0.05) + ($css_level * 0.05) + ($self->body->empire->deception_affinity * 0.03); $ship->stealth(sprintf('%.0f', $ship->base_stealth * $improvement )); return $ship->stealth; } diff --git a/lib/Lacuna/DB/Result/Building/Stockpile.pm b/lib/Lacuna/DB/Result/Building/Stockpile.pm index 70c79699..e1995aed 100644 --- a/lib/Lacuna/DB/Result/Building/Stockpile.pm +++ b/lib/Lacuna/DB/Result/Building/Stockpile.pm @@ -52,7 +52,7 @@ use constant water_storage => 300; before 'can_downgrade' => sub { my $self = shift; - my $max_level = 15 + int(($self->level-1)/3); + my $max_level = 15 + int(($self->effective_level-1)/3); if ($self->body->empire->university_level > 25) { $max_level += ($self->body->empire->university_level - 25); } @@ -89,7 +89,7 @@ before 'can_demolish' => sub { sub extra_resource_levels { my $self = shift; - return int($self->level / 3); + return int($self->effective_level / 3); } no Moose; diff --git a/lib/Lacuna/DB/Result/Building/SupplyPod.pm b/lib/Lacuna/DB/Result/Building/SupplyPod.pm index 0765ad11..1eab86fd 100644 --- a/lib/Lacuna/DB/Result/Building/SupplyPod.pm +++ b/lib/Lacuna/DB/Result/Building/SupplyPod.pm @@ -9,6 +9,8 @@ use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES GROWTH); use constant controller_class => 'Lacuna::RPC::Building::SupplyPod'; +with 'Lacuna::Role::Building::IgnoresUniversityLevel'; + around can_build => sub { my ($orig, $self, $body) = @_; if ($body->get_plan(__PACKAGE__, 1)) { @@ -46,15 +48,6 @@ after finish_work => sub { $self->update({class=>'Lacuna::DB::Result::Building::Permanent::Crater'}); }; -sub production_hour { - my $self = shift; - return 0 unless $self->level; - my $prod_level = $self->level; - my $production = (GROWTH ** ( $prod_level - 1)); - $production = ($production * $self->efficiency) / 100; - return $production; -} - # allow demolishing even when working sub can_demolish { return 1; diff --git a/lib/Lacuna/DB/Result/Building/TheftTraining.pm b/lib/Lacuna/DB/Result/Building/TheftTraining.pm index 2d2ce173..4fe34841 100644 --- a/lib/Lacuna/DB/Result/Building/TheftTraining.pm +++ b/lib/Lacuna/DB/Result/Building/TheftTraining.pm @@ -82,7 +82,7 @@ has training_multiplier => ( lazy => 1, default => sub { my $self = shift; - my $multiplier = $self->level; + my $multiplier = $self->effective_level; $multiplier = 1 if $multiplier < 1; return $multiplier; } diff --git a/lib/Lacuna/DB/Result/Building/ThemePark.pm b/lib/Lacuna/DB/Result/Building/ThemePark.pm index ad1ad01f..ea99200f 100644 --- a/lib/Lacuna/DB/Result/Building/ThemePark.pm +++ b/lib/Lacuna/DB/Result/Building/ThemePark.pm @@ -70,7 +70,7 @@ sub happiness_production { sub can_operate { my ($self) = @_; - if ($self->level < 1) { + if ($self->effective_level < 1) { confess [1010, "You can't operate the Theme Park until it is built."]; } my $types; diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index 0fe8e04b..10de89da 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -135,7 +135,7 @@ sub all_waste_ships { sub max_chains { my $self = shift; - return ceil($self->level); + return ceil($self->effective_level); } sub add_waste_ship { @@ -320,8 +320,8 @@ sub add_to_market { unless ($ask >= 0.1 && $ask <= 100 ) { confess [1009, "You must ask for between 0.1 and 100 essentia to create a trade."]; } - unless ($self->level > $self->my_market->count) { - confess [1009, "This Trade Ministry can only support ".$self->level." trades at one time."]; + unless ($self->effective_level > $self->my_market->count) { + confess [1009, "This Trade Ministry can only support ".$self->effective_level." trades at one time."]; } my $space_used; ($space_used, $offer ) = $self->check_payload($offer, $ship->hold_size, undef, $ship); @@ -339,7 +339,7 @@ sub add_to_market { x => $body->x, y => $body->y, speed => $ship->speed, - trade_range => int(450 + (15 * $self->level)), + trade_range => int(450 + (15 * $self->effective_level)), ); return Lacuna->db->resultset('Market')->new(\%trade)->insert; } diff --git a/lib/Lacuna/DB/Result/Building/Transporter.pm b/lib/Lacuna/DB/Result/Building/Transporter.pm index f5302374..f3d01aa2 100644 --- a/lib/Lacuna/DB/Result/Building/Transporter.pm +++ b/lib/Lacuna/DB/Result/Building/Transporter.pm @@ -53,8 +53,8 @@ sub add_to_market { unless ($ask >= 0.1 && $ask <= 100 ) { confess [1009, "You must ask for between 0.1 and 100 essentia to create a trade."]; } - unless ($self->level > $self->my_market->count) { - confess [1009, "This Subspace Transporter can only support ".$self->level." trades at one time."]; + unless ($self->effective_level > $self->my_market->count) { + confess [1009, "This Subspace Transporter can only support ".$self->effective_level." trades at one time."]; } my $space_used; ($space_used, $offer) = $self->check_payload($offer, $self->determine_available_cargo_space); @@ -85,7 +85,7 @@ sub available_market { sub determine_available_cargo_space { my ($self) = @_; - return 12500 * $self->level * $self->body->empire->trade_affinity; + return 12500 * $self->effective_level * $self->body->empire->trade_affinity; } sub trade_one_for_one { diff --git a/lib/Lacuna/DB/Result/Building/Waste/Exchanger.pm b/lib/Lacuna/DB/Result/Building/Waste/Exchanger.pm index 18bca5cf..263b3b8b 100644 --- a/lib/Lacuna/DB/Result/Building/Waste/Exchanger.pm +++ b/lib/Lacuna/DB/Result/Building/Waste/Exchanger.pm @@ -39,7 +39,7 @@ has max_recycle => ( lazy => 1, default => sub { my $self = shift; - return $self->level * 17_500 * $self->body->empire->environmental_affinity; + return $self->effective_level * 17_500 * $self->body->empire->environmental_affinity; }, ); @@ -48,7 +48,7 @@ has seconds_per_resource => ( lazy => 1, default => sub { my $self = shift; - return 0.75 * $self->time_cost_reduction_bonus($self->level * 3); + return 0.75 * $self->time_cost_reduction_bonus($self->effective_level * 3); }, ); @@ -57,7 +57,7 @@ sub can_recycle { $water ||= 0; $ore ||= 0; $energy ||= 0; - if ($self->level < 1) { + if ($self->effective_level < 1) { confess [1010, "You can't recycle until the Waste Exchanger is built."]; } if ($self->is_working) { diff --git a/lib/Lacuna/DB/Result/Building/Waste/Recycling.pm b/lib/Lacuna/DB/Result/Building/Waste/Recycling.pm index 1304e78a..73e6e269 100644 --- a/lib/Lacuna/DB/Result/Building/Waste/Recycling.pm +++ b/lib/Lacuna/DB/Result/Building/Waste/Recycling.pm @@ -10,7 +10,7 @@ has max_recycle => ( lazy => 1, default => sub { my $self = shift; - return $self->level * 3_500 * $self->body->empire->environmental_affinity; + return $self->effective_level * 3_500 * $self->body->empire->environmental_affinity; }, ); @@ -19,7 +19,7 @@ has seconds_per_resource => ( lazy => 1, default => sub { my $self = shift; - return 3 * $self->time_cost_reduction_bonus($self->level * 3); + return 3 * $self->time_cost_reduction_bonus($self->effective_level * 3); }, ); @@ -28,7 +28,7 @@ sub can_recycle { $water ||= 0; $ore ||= 0; $energy ||= 0; - if ($self->level < 1) { + if ($self->effective_level < 1) { confess [1010, "You can't recycle until the Recycling Center is built."]; } if ($self->is_working) { diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 1d337dcf..077652ce 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -1110,7 +1110,7 @@ sub highest_embassy { body_id => { "!=" => $excluding_body_id }, }); } - my ($embassy) = $search_rs->search; + my $embassy = $search_rs->search->first; return $embassy; } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 765b3c80..bdab467b 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -607,7 +607,7 @@ sub _build_population { foreach my $building (@{$self->building_cache}) { next if $building->class =~ /Lacuna::DB::Result::Building::Permanent/; next if $building->class eq 'Lacuna::DB::Result::Building::DeployedBleeder'; - $population += $building->level * 10_000; + $population += $building->effective_level * 10_000; } return $population; } @@ -835,7 +835,7 @@ sub has_room_in_build_queue { my $max = 1; my $dev_ministry = $self->development; if (defined $dev_ministry) { - $max += $dev_ministry->level; + $max += $dev_ministry->effective_level; } my $count = @{$self->builds}; if ($count >= $max) { @@ -1202,7 +1202,7 @@ sub recalc_stats { $food_production_hour += $building->$method(); } if ($building->isa('Lacuna::DB::Result::Building::SpacePort') and $building->efficiency == 100) { - $stats{max_berth} = $building->level if ($building->level > $stats{max_berth}); + $stats{max_berth} = $building->effective_level if ($building->effective_level > $stats{max_berth}); } if ($building->isa('Lacuna::DB::Result::Building::Ore::Ministry')) { my $platforms = Lacuna->db->resultset('MiningPlatforms')->search({planet_id => $self->id}); @@ -1238,22 +1238,22 @@ sub recalc_stats { } } if ($building->isa('Lacuna::DB::Result::Building::Permanent::GasGiantPlatform')) { - $gas_giant_platforms += int($building->level * $building->efficiency/100); + $gas_giant_platforms += int($building->effective_level * $building->effective_efficiency/100); } if ($building->isa('Lacuna::DB::Result::Building::Permanent::TerraformingPlatform')) { - $terraforming_platforms += int($building->level * $building->efficiency/100); + $terraforming_platforms += int($building->effective_level * $building->effective_efficiency/100); } if ($building->isa('Lacuna::DB::Result::Building::Permanent::PantheonOfHagness')) { - $pantheon_of_hagness += int($building->level * $building->efficiency/100); + $pantheon_of_hagness += int($building->effective_level * $building->effective_efficiency/100); } if ($building->isa('Lacuna::DB::Result::Building::Module::StationCommand')) { - $station_command += $building->level; + $station_command += $building->effective_level; } if ($building->isa('Lacuna::DB::Result::Building::Permanent::Fissure')) { # A fissure is controlled by maintenance equipment. The less efficient # the equipment, the more energy the Fissure will suck in. # Fissure affect on energy_hour is 1% per level subject to efficiency - $fissure_percent += $building->level * (100 - $building->efficiency) / 100; + $fissure_percent += $building->effective_level * (100 - $building->effective_efficiency) / 100; } } # Energy reduced by Fissure action @@ -1377,8 +1377,8 @@ sub add_news { if ($self->restrict_coverage) { my $network19 = $self->network19; if (defined $network19) { - $chance += $network19->level * 2; - $chance = $chance / $self->command->level; + $chance += $network19->effective_level * 2; + $chance = $chance / $self->command->effective_level; } } if (randint(1,100) <= $chance) { @@ -1548,7 +1548,7 @@ sub tick_to { } # Process excavator sites if ( my $arch = $self->archaeology) { - if ($arch->efficiency == 100 and $arch->level > 0) { + if ($arch->efficiency == 100 and $arch->effective_level > 0) { my $dig_sec = $now->epoch - $arch->last_check->epoch; if ($dig_sec >= 3600) { my $dig_hours = int($dig_sec/3600); @@ -2562,7 +2562,7 @@ sub complain_about_lack_of_resources { my $building_name; Lacuna->cache->set('lack_of_'.$resource,$self->id, 1, 60 * 60 * 2); if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { - foreach my $building ( sort { $b->level <=> $a->level || $b->efficiency <=> $a->efficiency || rand() <=> rand() } @{$self->building_cache} ) { + foreach my $building ( sort { $b->effective_level <=> $a->effective_level || $b->efficiency <=> $a->efficiency || rand() <=> rand() } @{$self->building_cache} ) { if ($building->class eq 'Lacuna::DB::Result::Building::Module::Parliament' || $building->class eq 'Lacuna::DB::Result::Building::Module::StationCommand') { my $others = grep {$_->class !~ /Parliament$|StationCommand$|Crater$/} @{$self->building_cache}; if ($others) { diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index 955d89e9..33933a27 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -138,7 +138,7 @@ sub _build_total_influence { $building->class eq 'Lacuna::DB::Result::Building::Module::CulinaryInstitute' or $building->class eq 'Lacuna::DB::Result::Building::Module::ArtMuseum' ) { - $influence += $building->level; + $influence += $building->effective_level; } } return $influence; @@ -170,7 +170,7 @@ sub _build_range_of_influence { my $range = 0; my ($ibs) = grep {$_->class eq 'Lacuna::DB::Result::Building::Module::IBS'} @{$self->building_cache}; if (defined $ibs) { - $range = $ibs->level * 1000; + $range = $ibs->effective_level * 1000; } return $range; } diff --git a/lib/Lacuna/DB/Result/Propositions/InductMember.pm b/lib/Lacuna/DB/Result/Propositions/InductMember.pm index c810b88e..fd1145e0 100644 --- a/lib/Lacuna/DB/Result/Propositions/InductMember.pm +++ b/lib/Lacuna/DB/Result/Propositions/InductMember.pm @@ -4,6 +4,7 @@ use Moose; use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Propositions'; +use List::Util qw(max); before pass => sub { my ($self) = @_; @@ -19,21 +20,13 @@ before pass => sub { my $building = Lacuna->db->resultset('Lacuna::DB::Result::Building')->find($self->scratch->{building_id}); my $leader_emp = $building->body->empire; - my $leader_planets = $leader_emp->planets; - my @planet_ids; - while ( my $planet = $leader_planets->next ) { - push @planet_ids, $planet->id; - } - my $embassy = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search( - { body_id => { in => \@planet_ids }, class => 'Lacuna::DB::Result::Building::Embassy' }, - { order_by => { -desc => 'level' } } - )->first; - my $max_members = ( $building->level >= $embassy->level ) ? 2 * $building->level : 2 * $embassy->level; + my $embassy = $leader_emp->highest_embassy; + my $max_members = max($embassy->max_members(), $embassy->max_members($building->effective_level)); if ($count < $max_members ) { my $can = eval{$alliance->send_invite($invite_empire, $self->scratch->{message})}; unless ($can) { - $self->pass_extra_message('Empire has already accepted an invite, effectively wasting Parliaments time.'); + $self->pass_extra_message(q[Empire has already accepted an invite, effectively wasting Parliaments' time.]); } } else { diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 991229bf..2c1d0fe4 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -416,7 +416,7 @@ sub is_available { $tr_skill = "theft_xp"; } if ($train_bld) { - my $max_points = 350 + $train_bld->level * 75; + my $max_points = 350 + $train_bld->effective_level * 75; if ($self->$tr_skill >= $max_points) { $self->task('Idle'); $self->update_level; @@ -431,7 +431,7 @@ sub is_available { on_body_id => $train_bld->body_id, empire_id => $train_bld->body->empire_id})->count; my $boost = (time < $self->empire->spy_training_boost->epoch) ? 1.5 : 1; - my $points_hour = $train_bld->level * $boost; + my $points_hour = $train_bld->effective_level * $boost; my $points_to_add = 0; if ($points_hour > 0 and $train_cnt > 0) { $points_to_add = int( ($points_hour * $minutes)/60/$train_cnt); @@ -509,7 +509,7 @@ sub is_available { } my $gauntlet = $self->on_body->get_building_of_class('Lacuna::DB::Result::Building::'.$building); if (defined $gauntlet) { - my $level = $gauntlet->level; + my $level = $gauntlet->effective_level; $level = $uni_level if ($level > $uni_level); $seconds += int(3600 * (($level * 3 * $gauntlet->efficiency)/100 + 1)); } @@ -737,8 +737,8 @@ has home_field_advantage => ( } my $hq = $body->get_building_of_class('Lacuna::DB::Result::Building::'.$building); if (defined $hq) { - my $bld_level = ($uni_level < $hq->level) ? $uni_level : $hq->level; - return $bld_level * $hq->efficiency / $div; + my $bld_level = $hq->effective_level; + return $bld_level * $hq->effective_efficiency / $div; } else { return 0; diff --git a/lib/Lacuna/RPC/Body.pm b/lib/Lacuna/RPC/Body.pm index 7c9b4da8..5855cf24 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -65,7 +65,7 @@ sub rename { my $empire = $self->get_empire_by_session($session_id); my $body = $self->get_body($empire, $body_id); if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { - unless ($body->parliament->level >= 3) { + unless ($body->parliament->effective_level >= 3) { confess [1013, 'You need to have a level 3 Parliament to rename a station.']; } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ @@ -444,7 +444,7 @@ sub get_buildable { my $dev = $body->development; my $max_items_in_build_queue = 1; if (defined $dev) { - $max_items_in_build_queue += $dev->level; + $max_items_in_build_queue += $dev->effective_level; } my $items_in_build_queue = scalar @{$body->builds}; diff --git a/lib/Lacuna/RPC/Building.pm b/lib/Lacuna/RPC/Building.pm index c5e1c613..9226eaff 100644 --- a/lib/Lacuna/RPC/Building.pm +++ b/lib/Lacuna/RPC/Building.pm @@ -225,7 +225,7 @@ sub demolish { my $body = $building->body; $building->can_demolish; if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { - unless ($body->parliament->level >= 2) { + unless ($body->parliament->effective_level >= 2) { confess [1013, 'You need to have a level 2 Parliament to demolish a module.']; } my $name = $building->name.' ('.$building->x.','.$building->y.')'; @@ -255,7 +255,7 @@ sub downgrade { my $body = $building->body; $building->can_downgrade; if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { - unless ($body->parliament->level >= 2) { + unless ($body->parliament->effective_level >= 2) { confess [1013, 'You need to have a level 2 Parliament to downgrade a module.']; } my $name = $building->name.' ('.$building->x.','.$building->y.')'; @@ -284,6 +284,7 @@ sub get_stats_for_level { confess [1009, 'Level must be an integer between 1 and 100.']; } $building->level($level); + $building->clear_effective_level; my $image_after_upgrade = $building->image_level($building->level + 1); return { building => { diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 8489785e..9ae62591 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -135,8 +135,7 @@ sub view_excavators { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); my @sites; - my $level = ($building->level > $building->body->empire->university_level + 1) ? - $building->body->empire->university_level + 1 : $building->level; + my $level = $building->effective_level; my $chances = $building->can_you_dig_it($building->body, $level, 1); push @sites, { body => $building->body->get_status, diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 4821036b..40cd9efb 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -326,7 +326,7 @@ sub task_chance { $return->{reason} = $task->{reason}; return $return; } - unless ($building->level >= $task->{min_level}) { + unless ($building->effective_level >= $task->{min_level}) { $return->{throw} = 1013; $return->{reason} = sprintf( "You need a Level %d Black Hole Generator to do that", @@ -792,7 +792,7 @@ sub generate_singularity { my $defense = 0; my $hq = $body->get_building_of_class('Lacuna::DB::Result::Building::Security'); if (defined $hq) { - $defense = $hq->level * $hq->efficiency; + $defense = $hq->effective_level * $hq->effective_efficiency; } my $breakthru = int(($power - $defense + $lock_down->luck)/100 + 0.5)+50; $breakthru = 5 if $breakthru < 5; @@ -1499,7 +1499,7 @@ sub bhg_make_asteroid { my @fissures = $body->get_buildings_of_class('Lacuna::DB::Result::Building::Permanent::Fissure'); my @to_demolish = @{$body->building_cache}; $body->delete_buildings(\@to_demolish); - my $new_size = int($building->level/5); + my $new_size = int($building->effective_level/5); $new_size = 10 if $new_size > 10; $body->update({ class => 'Lacuna::DB::Result::Map::Body::Asteroid::A'.randint(1,Lacuna::DB::Result::Map::Body->asteroid_types), @@ -1806,6 +1806,7 @@ sub bhg_self_destruct { }; $body->waste_stored(0); + # yes, ->level, not ->effective_level for (1..$building->level) { my ($placement) = sort { @@ -1841,16 +1842,16 @@ sub bhg_decor { ); my $plant; my $max_level; if ($variance == -1) { - $plant = randint(1, int($building->level/10)+1); + $plant = randint(1, int($building->effective_level/10)+1); $max_level = 3; } elsif ($variance == 0) { - $plant = randint(1, int($building->level/5)+1); + $plant = randint(1, int($building->effective_level/5)+1); $max_level = int($building->level/5); } else { - $plant = randint(1, int($building->level/3)+1); - $max_level = $building->level; + $plant = randint(1, int($building->effective_level/3)+1); + $max_level = $building->effective_level; } $max_level = 30 if $max_level > 30; my $planted = 0; @@ -2085,7 +2086,7 @@ sub bhg_size { my $btype = $body->get_type; if ($btype eq 'asteroid') { if ($variance == -1) { - $current_size -= randint(1, int($building->level/10)+1); + $current_size -= randint(1, int($building->effective_level/10)+1); $current_size = 1 if ($current_size < 1); } elsif ($variance == 1) { @@ -2094,7 +2095,7 @@ sub bhg_size { $current_size = 20 if ($current_size > 20); } else { - $current_size += int($building->level/5); + $current_size += int($building->effective_level/5); $current_size = 10 if ($current_size > 10); } } @@ -2109,7 +2110,7 @@ sub bhg_size { } elsif ($btype eq 'habitable planet') { if ($variance == -1) { - $current_size -= randint(1,$building->level); + $current_size -= randint(1,$building->effective_level); $current_size = 30 if ($current_size < 30); } elsif ($variance == 1) { @@ -2118,7 +2119,7 @@ sub bhg_size { $current_size = 75 if ($current_size > 75); } else { - $current_size += $building->level; + $current_size += $building->effective_level; $current_size = 70 if ($current_size > 70); } } @@ -2165,7 +2166,7 @@ sub bhg_size { sub bhg_tasks { my ($building) = @_; my $day_sec = 60 * 60 * 24; - my $blevel = $building->level == 0 ? 1 : $building->level; + my $blevel = $building->effective_level == 0 ? 1 : $building->effective_level; my $map_size = Lacuna->config->get('map_size'); my $max_dist = sprintf "%0.2f", sqrt(($map_size->{x}[0] - $map_size->{x}[1])**2 + ($map_size->{y}[0] - $map_size->{y}[1])**2); @@ -2181,7 +2182,7 @@ sub bhg_tasks { range => 15 * $blevel, recovery => int($day_sec * 90/$blevel), waste_cost => 50_000_000, - base_fail => 40 - $building->level, # 10% - 40% + base_fail => 40 - $building->effective_level, # 10% - 40% side_chance => 25, subsidy_mult => .75, }, diff --git a/lib/Lacuna/RPC/Building/Development.pm b/lib/Lacuna/RPC/Building/Development.pm index 7d2eccc3..595d6415 100644 --- a/lib/Lacuna/RPC/Building/Development.pm +++ b/lib/Lacuna/RPC/Building/Development.pm @@ -29,7 +29,7 @@ sub subsidize_build_queue { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - unless ($building->level > 0 and $building->efficiency == 100) { + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { confess [1003, "You must have a functional development ministry!"]; } my $subsidy = $building->calculate_subsidy; @@ -56,7 +56,7 @@ sub subsidize_one_build { } my $empire = $self->get_empire_by_session($args->{session_id}); my $building = $self->get_building($empire, $args->{building_id}); - unless ($building->level > 0 and $building->efficiency == 100) { + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { confess [1003, "You must have a functional development ministry!"]; } my $scheduled_building = Lacuna->db->resultset('Building')->find({id => $args->{scheduled_id}}); diff --git a/lib/Lacuna/RPC/Building/IntelTraining.pm b/lib/Lacuna/RPC/Building/IntelTraining.pm index 03a9d92b..302d131d 100644 --- a/lib/Lacuna/RPC/Building/IntelTraining.pm +++ b/lib/Lacuna/RPC/Building/IntelTraining.pm @@ -20,9 +20,9 @@ around 'view' => sub { my $building = $self->get_building($empire, $building_id, skip_offline => 1); my $out = $orig->($self, $empire, $building); my $boost = (time < $empire->spy_training_boost->epoch) ? 1.5 : 1; - my $points_per = $building->level * $boost; + my $points_per = $building->effective_level * $boost; $out->{spies} = { - max_points => 350 + $building->level * 75, + max_points => 350 + $building->effective_level * 75, points_per => $points_per, in_training => $building->spies_in_training_count, }; diff --git a/lib/Lacuna/RPC/Building/Intelligence.pm b/lib/Lacuna/RPC/Building/Intelligence.pm index 141879ac..90906c36 100644 --- a/lib/Lacuna/RPC/Building/Intelligence.pm +++ b/lib/Lacuna/RPC/Building/Intelligence.pm @@ -202,7 +202,7 @@ sub train_spy { } my $trained = 0; my $body = $building->body; - if ($building->level < 1) { + if ($building->effective_level < 1) { confess [1013, "You can't train spies until your Intelligence Ministry is completed."]; } my $costs = $building->training_costs; diff --git a/lib/Lacuna/RPC/Building/LibraryOfJith.pm b/lib/Lacuna/RPC/Building/LibraryOfJith.pm index 55f9591c..ed64513b 100644 --- a/lib/Lacuna/RPC/Building/LibraryOfJith.pm +++ b/lib/Lacuna/RPC/Building/LibraryOfJith.pm @@ -26,7 +26,7 @@ sub research_species { confess [1010, 'The researchers are busy now. Come back later.']; } - $building->start_work({}, 15 + ((60 * 60) * ((30-$building->level)/30))); + $building->start_work({}, 15 + ((60 * 60) * ((30-$building->effective_level)/30))); return { status => $self->format_status($empire, $building->body), diff --git a/lib/Lacuna/RPC/Building/MayhemTraining.pm b/lib/Lacuna/RPC/Building/MayhemTraining.pm index e04ec32f..f4867baa 100644 --- a/lib/Lacuna/RPC/Building/MayhemTraining.pm +++ b/lib/Lacuna/RPC/Building/MayhemTraining.pm @@ -20,9 +20,9 @@ around 'view' => sub { my $building = $self->get_building($empire, $building_id, skip_offline => 1); my $out = $orig->($self, $empire, $building); my $boost = (time < $empire->spy_training_boost->epoch) ? 1.5 : 1; - my $points_per = $building->level * $boost; + my $points_per = $building->effective_level * $boost; $out->{spies} = { - max_points => 350 + $building->level * 75, + max_points => 350 + $building->effective_level * 75, points_per => $points_per, in_training => $building->spies_in_training_count, }; diff --git a/lib/Lacuna/RPC/Building/MercenariesGuild.pm b/lib/Lacuna/RPC/Building/MercenariesGuild.pm index 4bd56762..60013e45 100644 --- a/lib/Lacuna/RPC/Building/MercenariesGuild.pm +++ b/lib/Lacuna/RPC/Building/MercenariesGuild.pm @@ -68,8 +68,8 @@ sub accept_from_market { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a mercenaries guild that has not yet been built.'] unless $building->level > 0; - confess [1013, 'You cannot use a mercenaries guild that has not yet been built.'] unless $building->efficiency == 100; + confess [1013, 'You cannot use a mercenaries guild that has not yet been built.'] unless $building->effective_level > 0; + confess [1013, 'You cannot use a mercenaries guild that is not fully operational.'] unless $building->effective_efficiency == 100; my $int_min = $building->body->get_building_of_class('Lacuna::DB::Result::Building::Intelligence'); unless (defined($int_min) and $int_min->spy_count < $int_min->max_spies) { @@ -137,8 +137,8 @@ sub add_to_market { my ($self, $session_id, $building_id, $spy_id, $ask, $ship_id) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a mercenaries guild that has not yet been built.'] unless $building->level > 0; - my $cost = sprintf "%.1f", 3 - $building->level * 0.1; + confess [1013, 'You cannot use a mercenaries guild that has not yet been built.'] unless $building->effective_level > 0; + my $cost = sprintf "%.1f", 3 - $building->effective_level * 0.1; unless ($empire->essentia >= $cost) { confess [1011, "You need $cost essentia to make a trade using the Mercenaries Guild."]; } diff --git a/lib/Lacuna/RPC/Building/MissionCommand.pm b/lib/Lacuna/RPC/Building/MissionCommand.pm index cf0c773b..3a1a7a98 100644 --- a/lib/Lacuna/RPC/Building/MissionCommand.pm +++ b/lib/Lacuna/RPC/Building/MissionCommand.pm @@ -41,7 +41,7 @@ sub get_missions { date_posted => $mission->date_posted_formatted, }; $count++; - last if ($count >= $building->level); + last if ($count >= $building->effective_level); } return { status => $self->format_status($empire, $building->body), diff --git a/lib/Lacuna/RPC/Building/Network19.pm b/lib/Lacuna/RPC/Building/Network19.pm index 07baf440..0c01139a 100644 --- a/lib/Lacuna/RPC/Building/Network19.pm +++ b/lib/Lacuna/RPC/Building/Network19.pm @@ -21,7 +21,7 @@ sub view_news { my $body = $building->body; my @all = ($body->zone, $body->adjacent_zones); my @zones; - foreach (1..(($building->level + 1) / 2)) { + foreach (1..(($building->effective_level + 1) / 2)) { last if !@all; push @zones, shift @all; } diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index b89f6c72..bd4d6a67 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -28,7 +28,7 @@ sub max_members { { body_id => { in => \@planet_ids }, class => 'Lacuna::DB::Result::Building::Embassy' }, { order_by => { -desc => 'level' } } )->first; - return ( $building->level >= $embassy->level ) ? 2 * $building->level : 2 * $embassy->level; + return ( $building->effective_level >= $embassy->effective_level ) ? 2 * $building->effective_level : 2 * $embassy->effective_level; } sub view_propositions { @@ -175,7 +175,7 @@ sub propose_fire_bfg { } $empire->current_session->check_captcha; my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 25) { + unless ($building->effective_level >= 25) { confess [1013, 'Parliament must be level 25 to propose using the BFG.',25]; } Lacuna::Verify->new(content=>\$reason, throws=>[1005,'Reason cannot be empty.',$reason])->not_empty; @@ -216,7 +216,7 @@ sub propose_writ { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 4) { + unless ($building->effective_level >= 4) { confess [1013, 'Parliament must be level 4 to propose a writ.',4]; } Lacuna::Verify->new(content=>\$title, throws=>[1005,'Title cannot be empty.',$title])->not_empty; @@ -248,7 +248,7 @@ sub propose_transfer_station_ownership { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 6) { + unless ($building->effective_level >= 6) { confess [1013, 'Parliament must be level 6 to transfer station ownership.',6]; } unless ($to_empire_id) { @@ -287,7 +287,7 @@ sub propose_seize_star { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 7) { + unless ($building->effective_level >= 7) { confess [1013, 'Parliament must be level 7 to seize control of a star.',7]; } unless ($star_id) { @@ -341,7 +341,7 @@ sub propose_repeal_law { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 5) { + unless ($building->effective_level >= 5) { confess [1013, 'Parliament must be level 5 to repeal a law.',5]; } unless ($law_id) { @@ -374,7 +374,7 @@ sub propose_rename_star { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 8) { + unless ($building->effective_level >= 8) { confess [1013, 'Parliament must be level 8 to rename a star.',8]; } unless ($star_id) { @@ -417,7 +417,7 @@ sub propose_broadcast_on_network19 { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 9) { + unless ($building->effective_level >= 9) { confess [1013, 'Parliament must be level 9 to propose a broadcast.',9]; } Lacuna::Verify->new(content=>\$message, throws=>[1005,'Message cannot be empty.',$message])->not_empty; @@ -448,7 +448,7 @@ sub propose_rename_asteroid { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 12) { + unless ($building->effective_level >= 12) { confess [1013, 'Parliament must be level 12 to rename an asteroid.',12]; } unless ($asteroid_id) { @@ -491,7 +491,7 @@ sub propose_rename_uninhabited { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 17) { + unless ($building->effective_level >= 17) { confess [1013, 'Parliament must be level 17 to rename an uninhabited planet.',17]; } unless ($planet_id) { @@ -537,7 +537,7 @@ sub propose_members_only_mining_rights { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 13) { + unless ($building->effective_level >= 13) { confess [1013, 'Parliament must be level 13 to propose members only mining rights.',13]; } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ @@ -562,7 +562,7 @@ sub propose_members_only_excavation { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 20) { + unless ($building->effective_level >= 20) { confess [1013, 'Parliament must be level 20 to propose members only excavation rights.',20]; } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ @@ -587,7 +587,7 @@ sub propose_members_only_colonization { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 18) { + unless ($building->effective_level >= 18) { confess [1013, 'Parliament must be level 18 to propose members only colonization.',18]; } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ @@ -612,7 +612,7 @@ sub propose_neutralize_bhg { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 23) { + unless ($building->effective_level >= 23) { confess [1013, 'Parliament must be level 23 to propose to neutralize black hole generators.',23]; } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ @@ -637,7 +637,7 @@ sub propose_evict_mining_platform { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 14) { + unless ($building->effective_level >= 14) { confess [1013, 'Parliament must be level 14 to evict a mining platform.',14]; } unless ($platform_id) { @@ -673,7 +673,7 @@ sub propose_evict_excavator { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 21) { + unless ($building->effective_level >= 21) { confess [1013, 'Parliament must be level 21 to evict an excavator.',21]; } unless ($excav_id) { @@ -709,7 +709,7 @@ sub propose_elect_new_leader { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 11) { + unless ($building->effective_level >= 11) { confess [1013, 'Parliament must be level 11 to elect a new alliance leader.',11]; } unless ($to_empire_id) { @@ -745,7 +745,7 @@ sub propose_induct_member { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 10) { + unless ($building->effective_level >= 10) { confess [1013, 'Parliament must be level 10 to induct a new alliance member.',10]; } my $alliance = $building->body->alliance; @@ -788,7 +788,7 @@ sub propose_expel_member { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 10) { + unless ($building->effective_level >= 10) { confess [1013, 'Parliament must be level 10 to expel an alliance member.',10]; } unless ($empire_id) { @@ -827,7 +827,7 @@ sub propose_taxation { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 15) { + unless ($building->effective_level >= 15) { confess [1013, 'Parliament must be level 15 to propose taxation.',15]; } unless ($taxes =~ /^\d+$/ && $taxes > 0 ) @@ -857,7 +857,7 @@ sub propose_foreign_aid { confess [1015, 'Sitters cannot create propositions.']; } my $building = $self->get_building($empire, $building_id); - unless ($building->level >= 16) { + unless ($building->effective_level >= 16) { confess [1013, 'Parliament must be level 16 to send out foreign aid packages.',16]; } unless ($planet_id) { diff --git a/lib/Lacuna/RPC/Building/PoliceStation.pm b/lib/Lacuna/RPC/Building/PoliceStation.pm index d9f12c9b..de28e8be 100644 --- a/lib/Lacuna/RPC/Building/PoliceStation.pm +++ b/lib/Lacuna/RPC/Building/PoliceStation.pm @@ -149,8 +149,8 @@ sub view_foreign_ships { my @fleet; my $now = time; my $ships = $building->foreign_ships->search({}, {rows=>25, page=>$page_number, join => 'body' }); - my $see_ship_type = ($building->level * 350) * ( $building->efficiency / 100 ); - my $see_ship_path = ($building->level * 450) * ( $building->efficiency / 100 ); + my $see_ship_type = ($building->effective_level * 350) * ( $building->effective_efficiency / 100 ); + my $see_ship_path = ($building->effective_level * 450) * ( $building->effective_efficiency / 100 ); my @my_planets = $empire->planets->get_column('id')->all; while (my $ship = $ships->next) { if ($ship->date_available->epoch <= $now) { @@ -198,8 +198,8 @@ sub view_ships_orbiting { my @fleet; my $now = time; my $ships = $building->orbiting_ships->search({}, {rows=>25, page=>$page_number, join => 'body' }); - my $see_ship_type = ($building->level * 350) * ( $building->efficiency / 100 ); - my $see_ship_path = ($building->level * 450) * ( $building->efficiency / 100 ); + my $see_ship_type = ($building->effective_level * 350) * ( $building->effective_efficiency / 100 ); + my $see_ship_path = ($building->effective_level * 450) * ( $building->effective_efficiency / 100 ); my @my_planets = $empire->planets->get_column('id')->all; while (my $ship = $ships->next) { if ($ship->date_available->epoch <= $now) { diff --git a/lib/Lacuna/RPC/Building/PoliticsTraining.pm b/lib/Lacuna/RPC/Building/PoliticsTraining.pm index 27658d23..432c8524 100644 --- a/lib/Lacuna/RPC/Building/PoliticsTraining.pm +++ b/lib/Lacuna/RPC/Building/PoliticsTraining.pm @@ -20,9 +20,9 @@ around 'view' => sub { my $building = $self->get_building($empire, $building_id, skip_offline => 1); my $out = $orig->($self, $empire, $building); my $boost = (time < $empire->spy_training_boost->epoch) ? 1.5 : 1; - my $points_per = $building->level * $boost; + my $points_per = $building->effective_level * $boost; $out->{spies} = { - max_points => 350 + $building->level * 75, + max_points => 350 + $building->effective_level * 75, points_per => $points_per, in_training => $building->spies_in_training_count, }; diff --git a/lib/Lacuna/RPC/Building/Shipyard.pm b/lib/Lacuna/RPC/Building/Shipyard.pm index 2695030d..e87b5c0a 100644 --- a/lib/Lacuna/RPC/Building/Shipyard.pm +++ b/lib/Lacuna/RPC/Building/Shipyard.pm @@ -86,7 +86,7 @@ sub subsidize_ship { } my $empire = $self->get_empire_by_session($args->{session_id}); my $building = $self->get_building($empire, $args->{building_id}); - unless ($building->level > 0 and $building->efficiency == 100) { + unless ($building->effective_level > 0 and $building->efficiency == 100) { confess [1003, "You must have a functional Space Port!"]; } my $scheduled_ship = Lacuna->db->resultset('Ships')->find({id => $args->{ship_id}}); diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 89bdb400..310b75d7 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -901,8 +901,8 @@ sub view_foreign_ships { my @fleet; my $now = time; my $ships = $building->foreign_ships->search({}, {rows=>25, page=>$page_number, join => 'body' }); - my $see_ship_type = ($building->level * 350) * ( $building->efficiency / 100 ); - my $see_ship_path = ($building->level * 450) * ( $building->efficiency / 100 ); + my $see_ship_type = ($building->effective_level * 350) * ( $building->effective_efficiency / 100 ); + my $see_ship_path = ($building->effective_level * 450) * ( $building->effective_efficiency / 100 ); my @my_planets = $empire->planets->get_column('id')->all; while (my $ship = $ships->next) { if ($ship->date_available->epoch <= $now) { @@ -952,8 +952,8 @@ sub view_ships_orbiting { my @fleet; my $now = time; my $ships = $building->orbiting_ships->search({}, {rows=>25, page=>$page_number, join => 'body' }); - my $see_ship_type = ($building->level * 350) * ( $building->efficiency / 100 ); - my $see_ship_path = ($building->level * 450) * ( $building->efficiency / 100 ); + my $see_ship_type = ($building->effective_level * 350) * ( $building->effective_efficiency / 100 ); + my $see_ship_path = ($building->effective_level * 450) * ( $building->effective_efficiency / 100 ); my @my_planets = $empire->planets->get_column('id')->all; while (my $ship = $ships->next) { if ($ship->date_available->epoch <= $now) { @@ -998,8 +998,8 @@ sub _view_ships { my @fleet; my $now = time; my $ships = $building->$method->search({}, {rows=>25, page=>$page_number, join => 'body' }); - my $see_ship_type = ($building->level * 350) * ( $building->efficiency / 100 ); - my $see_ship_path = ($building->level * 450) * ( $building->efficiency / 100 ); + my $see_ship_type = ($building->effective_level * 350) * ( $building->effective_efficiency / 100 ); + my $see_ship_path = ($building->effective_level * 450) * ( $building->effective_efficiency / 100 ); my @my_planets = $empire->planets->get_column('id')->all; while (my $ship = $ships->next) { if ($ship->date_available->epoch <= $now) { @@ -1146,7 +1146,7 @@ around 'view' => sub { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id, skip_offline => 1); my $out = $orig->($self, $empire, $building); - return $out unless $building->level > 0; + return $out unless $building->effective_level > 0; my $docked = $building->ships->search({ task => 'Docked' }); my %ships; while (my $ship = $docked->next) { diff --git a/lib/Lacuna/RPC/Building/TempleOfTheDrajilites.pm b/lib/Lacuna/RPC/Building/TempleOfTheDrajilites.pm index 6eba4ca4..775679ff 100644 --- a/lib/Lacuna/RPC/Building/TempleOfTheDrajilites.pm +++ b/lib/Lacuna/RPC/Building/TempleOfTheDrajilites.pm @@ -26,7 +26,7 @@ sub view_planet { unless ($planet->isa('Lacuna::DB::Result::Map::Body::Planet')) { confess [1009, 'The Temple can only view nearby planets.']; } - unless ($building->body->calculate_distance_to_target($planet) < $building->level * 1000) { + unless ($building->body->calculate_distance_to_target($planet) < $building->effective_level * 1000) { confess [1009, 'That planet is too far away.']; } @@ -62,7 +62,7 @@ sub list_planets { else { $star = $building->body->star; } - unless ($building->body->calculate_distance_to_target($star) < $building->level * 1000) { + unless ($building->body->calculate_distance_to_target($star) < $building->effective_level * 1000) { confess [1009, 'That star is too far away.']; } my @planets; diff --git a/lib/Lacuna/RPC/Building/TheftTraining.pm b/lib/Lacuna/RPC/Building/TheftTraining.pm index e32ab060..a4e03de0 100644 --- a/lib/Lacuna/RPC/Building/TheftTraining.pm +++ b/lib/Lacuna/RPC/Building/TheftTraining.pm @@ -20,7 +20,7 @@ around 'view' => sub { my $building = $self->get_building($empire, $building_id, skip_offline => 1); my $out = $orig->($self, $empire, $building); my $boost = (time < $empire->spy_training_boost->epoch) ? 1.5 : 1; - my $points_per = $building->level * $boost; + my $points_per = $building->effective_level * $boost; $out->{spies} = { max_points => 350 + $building->level * 75, points_per => $points_per, diff --git a/lib/Lacuna/RPC/Building/Trade.pm b/lib/Lacuna/RPC/Building/Trade.pm index b714cb1f..2be0d34c 100644 --- a/lib/Lacuna/RPC/Building/Trade.pm +++ b/lib/Lacuna/RPC/Building/Trade.pm @@ -211,7 +211,7 @@ sub view_supply_chains { confess [1002, "Cannot find that building."]; } - my $max_chains = $building->level * 3; + my $max_chains = $building->effective_level * 3; my @supply_chains; my $chains = $building->supply_chains; while (my $chain = $chains->next) { @@ -272,7 +272,7 @@ sub create_supply_chain { confess [1002, "Cannot find that building."]; } my $body = $building->body; - my $max_chains = $building->level * 3; + my $max_chains = $building->effective_level * 3; if ($body->out_supply_chains->count >= $max_chains) { confess [1002, "You cannot create any more supply chains outgoing from this planet."]; } @@ -387,7 +387,7 @@ sub push_items { my ($self, $session_id, $building_id, $target_id, $items, $options) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a trade ministry that has not yet been built.'] unless $building->level > 0; + confess [1013, 'You cannot use a trade ministry that has not yet been built.'] unless $building->effective_level > 0; my $cache = Lacuna->cache; if (! $cache->add('trade_add_lock', $building_id, 1, 5)) { confess [1013, 'You have a trade setup in progress. Please wait a few moments and try again.']; @@ -471,7 +471,7 @@ sub accept_from_market { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a trade ministry that has not yet been built.'] unless $building->level > 0; + confess [1013, 'You cannot use a trade ministry that has not yet been built.'] unless $building->effective_level > 0; $empire->current_session->check_captcha; @@ -523,7 +523,7 @@ sub add_to_market { my ($self, $session_id, $building_id, $offer, $ask, $options) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a trade ministry that has not yet been built.'] unless $building->level > 0; + confess [1013, 'You cannot use a trade ministry that has not yet been built.'] unless $building->effective_level > 0; my $cache = Lacuna->cache; if (! $cache->add('trade_add_lock', $building_id, 1, 5)) { confess [1013, 'You have a trade setup in progress. Please wait a few moments and try again.']; diff --git a/lib/Lacuna/RPC/Building/Transporter.pm b/lib/Lacuna/RPC/Building/Transporter.pm index 01fffbdb..c0a35e23 100644 --- a/lib/Lacuna/RPC/Building/Transporter.pm +++ b/lib/Lacuna/RPC/Building/Transporter.pm @@ -29,7 +29,7 @@ sub push_items { my ($self, $session_id, $building_id, $target_id, $items) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a transporter that has not yet been built.'] unless $building->level > 0; + confess [1013, 'You cannot use a transporter that has not yet been built.'] unless $building->effective_level > 0; my $cache = Lacuna->cache; if (! $cache->add('trade_add_lock', $building_id, 1, 5)) { confess [1013, 'You have a trade setup in progress. Please wait a few moments and try again.']; @@ -69,7 +69,7 @@ sub add_to_market { my ($self, $session_id, $building_id, $offer, $ask) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a transporter that has not yet been built.'] unless $building->level > 0; + confess [1013, 'You cannot use a transporter that has not yet been built.'] unless $building->effective_level > 0; my $cache = Lacuna->cache; if (! $cache->add('trade_add_lock', $building_id, 1, 5)) { confess [1013, 'You have a trade setup in progress. Please wait a few moments and try again.']; @@ -128,7 +128,7 @@ sub accept_from_market { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a transporter that has not yet been built.'] unless $building->level > 0; + confess [1013, 'You cannot use a transporter that has not yet been built.'] unless $building->effective_level > 0; $empire->current_session->check_captcha; @@ -181,7 +181,7 @@ sub trade_one_for_one { my ($self, $session_id, $building_id, $have, $want, $quantity) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - confess [1013, 'You cannot use a transporter that has not yet been built.'] unless $building->level > 0; + confess [1013, 'You cannot use a transporter that has not yet been built.'] unless $building->effective_level > 0; $building->trade_one_for_one($have, $want, $quantity); return { status => $self->format_status($empire, $building->body), diff --git a/lib/Lacuna/Role/Building/IgnoresUniversityLevel.pm b/lib/Lacuna/Role/Building/IgnoresUniversityLevel.pm new file mode 100644 index 00000000..4470c3fa --- /dev/null +++ b/lib/Lacuna/Role/Building/IgnoresUniversityLevel.pm @@ -0,0 +1,11 @@ +package Lacuna::Role::Building::IgnoresUniversityLevel; + +use Moose::Role; + +override _build_effective_level => sub { + my ($self) = shift; + $self->level; +}; + +1; + diff --git a/lib/Lacuna/Role/Influencer.pm b/lib/Lacuna/Role/Influencer.pm index d03a644b..349167c7 100644 --- a/lib/Lacuna/Role/Influencer.pm +++ b/lib/Lacuna/Role/Influencer.pm @@ -5,7 +5,7 @@ use Moose::Role; before demolish => sub { my $self = shift; my $station = $self->body; - my $influence_remaining = $station->influence_remaining - $self->level; + my $influence_remaining = $station->influence_remaining - $self->effective_level; my $laws = $station->laws->search({type => 'Jurisdiction'},{order_by => { -desc => 'date_enacted'}}); while (my $law = $laws->next) { last if $influence_remaining >= 0; diff --git a/lib/Lacuna/Role/Ship/Arrive/AddGasGiantPlatform.pm b/lib/Lacuna/Role/Ship/Arrive/AddGasGiantPlatform.pm index 3bcb2d47..10965a2c 100644 --- a/lib/Lacuna/Role/Ship/Arrive/AddGasGiantPlatform.pm +++ b/lib/Lacuna/Role/Ship/Arrive/AddGasGiantPlatform.pm @@ -11,7 +11,7 @@ after handle_arrival_procedures => sub { # add plan my $lab = $self->body->get_building_of_class('Lacuna::DB::Result::Building::GasGiantLab'); - $self->foreign_body->add_plan('Lacuna::DB::Result::Building::Permanent::GasGiantPlatform', 1, (defined $lab) ? $lab->level : 0); + $self->foreign_body->add_plan('Lacuna::DB::Result::Building::Permanent::GasGiantPlatform', 1, (defined $lab) ? $lab->effective_level : 0); # all pow $self->delete; diff --git a/lib/Lacuna/Role/Ship/Arrive/AddTerraformingPlatform.pm b/lib/Lacuna/Role/Ship/Arrive/AddTerraformingPlatform.pm index 7175a0a2..cbbecee1 100644 --- a/lib/Lacuna/Role/Ship/Arrive/AddTerraformingPlatform.pm +++ b/lib/Lacuna/Role/Ship/Arrive/AddTerraformingPlatform.pm @@ -11,7 +11,7 @@ after handle_arrival_procedures => sub { # add plan my $lab = $self->body->get_building_of_class('Lacuna::DB::Result::Building::TerraformingLab'); - $self->foreign_body->add_plan('Lacuna::DB::Result::Building::Permanent::TerraformingPlatform', 1, (defined $lab) ? $lab->level : 0); + $self->foreign_body->add_plan('Lacuna::DB::Result::Building::Permanent::TerraformingPlatform', 1, (defined $lab) ? $lab->effective_level : 0); # all pow $self->delete; diff --git a/lib/Lacuna/Role/Ship/Arrive/CaptureWithSpies.pm b/lib/Lacuna/Role/Ship/Arrive/CaptureWithSpies.pm index f3d0e8a0..cf77d8ff 100644 --- a/lib/Lacuna/Role/Ship/Arrive/CaptureWithSpies.pm +++ b/lib/Lacuna/Role/Ship/Arrive/CaptureWithSpies.pm @@ -36,7 +36,7 @@ after handle_arrival_procedures => sub { return unless defined $security && $security->efficiency > 0; # lets see if we can detect the ship - my $security_detection = ($security->level * 700) * ( $security->efficiency / 100 ); + my $security_detection = ($security->effective_level * 700) * ( $security->effective_efficiency / 100 ); if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { $security_detection *= 1.5; } diff --git a/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm b/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm index a7c1798f..c1b3f425 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm @@ -19,8 +19,8 @@ after handle_arrival_procedures => sub { my $body_attacked = $self->foreign_body; my ($citadel) = grep { $_->class eq 'Lacuna::DB::Result::Building::Permanent::CitadelOfKnope' - and $_->efficiency == 100 - and $_->level > 0 + and $_->effective_efficiency == 100 + and $_->effective_level > 0 and $_->is_upgrading == 0 } @{$body_attacked->building_cache}; @@ -29,7 +29,7 @@ after handle_arrival_procedures => sub { # Can we add one more ship? my $now = DateTime->now; my $cooldown = $citadel->work_ends->epoch - $now->epoch; - my $add_secs = 900 / $citadel->level; + my $add_secs = 900 / $citadel->effective_level; if ($cooldown + $add_secs > 3600) { # we can't add any more time undef $citadel; @@ -136,7 +136,7 @@ after handle_arrival_procedures => sub { # $log->victory_to('defender'); - my $add_secs = 900 / $citadel->level; + my $add_secs = 900 / $citadel->effective_level; if ($citadel->is_working) { $citadel->reschedule_work($citadel->work_ends->add( seconds => $add_secs)); } diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index c1c2e092..ade24f6c 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -12,7 +12,7 @@ after handle_arrival_procedures => sub { # do we have archaeology of level 11 or greater, if not, turn around my $body = $self->body; my $archaeology = $body->archaeology; - return unless ((defined $archaeology) && ($archaeology->level >= 11)); + return unless ((defined $archaeology) && ($archaeology->effective_level >= 11)); # can we deploy a excavator my $empire = $body->empire; @@ -50,7 +50,7 @@ after can_send_to_target => sub { confess [1009, 'Can only be sent to asteroids and habitable planets.'] if ($target->isa('Lacuna::DB::Result::Map::Body::Planet::GasGiant')); my $archaeology = $self->body->archaeology; confess [1013, 'Cannot control excavators without an Archaeology.'] unless (defined $archaeology); - confess [1013, 'Your Archaeology Ministry must be level 11 or higher in order to send excavators.'] unless ($archaeology->level >= 11); + confess [1013, 'Your Archaeology Ministry must be level 11 or higher in order to send excavators.'] unless ($archaeology->effective_level >= 11); $archaeology->can_add_excavator($target); if ($target->star->station_id) { if ($target->star->station->laws->search({type => 'MembersOnlyExcavation'})->count) { diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index 99b96573..23004b09 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -373,9 +373,9 @@ sub saw_stats { my @defending_saws; for my $saw (@planet_saws) { $cnt++; - next if $saw->level < 1; - next if $saw->efficiency < 1; - $planet_combat += int( (5 * ($saw->level + 1) * ($saw->level+1) * $saw->efficiency)/2 + 0.5); + next if $saw->effective_level < 1; + next if $saw->effective_efficiency < 1; + $planet_combat += int( (5 * ($saw->effective_level + 1) * ($saw->effective_level+1) * $saw->effective_efficiency)/2 + 0.5); push @defending_saws, $saw; last if $cnt >= 10; } @@ -387,7 +387,7 @@ sub saw_combat { return if ($saw->efficiency == 0); # printf "ship:%6d:%5d saw:%6d:%2d:%3d total:%8d ", -# $self->id, $self->combat, $saw->id, $saw->level, $saw->efficiency, $total_combat; +# $self->id, $self->combat, $saw->id, $saw->effective_level, $saw->effective_efficiency, $total_combat; if ($self->combat >= $total_combat) { $saw->spend_efficiency(100); $self->saw_disabled($saw); @@ -396,7 +396,7 @@ sub saw_combat { else { my $perc_1 = int( ($self->combat * 100)/$total_combat + 0.5); my $perc_2 = int( $self->combat * 100/ - (5 * ($saw->level + 1) * ($saw->level+1) * $saw->efficiency)); + (5 * ($saw->effective_level + 1) * ($saw->effective_level+1) * $saw->effective_efficiency)); $perc_2 = 100 if $perc_2 > 99; if ($perc_1 < 1) { $perc_2 = $perc_2 > 1 ? $perc_2 : 1; -- 2.51.2