Permalink
Browse files

Refactored to move some repetitive code into roles.

  • Loading branch information...
icydee committed Mar 17, 2013
1 parent 6ca1c5c commit 58ba6d109fd592e1c6a73634765a06a903a6470a
Showing with 185 additions and 657 deletions.
  1. +73 −95 lib/Lacuna/DB/Result/Building.pm
  2. +6 −19 lib/Lacuna/DB/Result/Building/Permanent/AlgaePond.pm
  3. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/AmalgusMeadow.pm
  4. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach1.pm
  5. +1 −8 lib/Lacuna/DB/Result/Building/Permanent/Beach10.pm
  6. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach11.pm
  7. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach12.pm
  8. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach13.pm
  9. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach2.pm
  10. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach3.pm
  11. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach4.pm
  12. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach5.pm
  13. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach6.pm
  14. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach7.pm
  15. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach8.pm
  16. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Beach9.pm
  17. +2 −15 lib/Lacuna/DB/Result/Building/Permanent/BeeldebanNest.pm
  18. +2 −15 lib/Lacuna/DB/Result/Building/Permanent/BlackHoleGenerator.pm
  19. +2 −15 lib/Lacuna/DB/Result/Building/Permanent/CitadelOfKnope.pm
  20. +2 −16 lib/Lacuna/DB/Result/Building/Permanent/CrashedShipSite.pm
  21. +1 −7 lib/Lacuna/DB/Result/Building/Permanent/Crater.pm
  22. +2 −15 lib/Lacuna/DB/Result/Building/Permanent/DentonBrambles.pm
  23. +2 −11 lib/Lacuna/DB/Result/Building/Permanent/EssentiaVein.pm
  24. +2 −15 lib/Lacuna/DB/Result/Building/Permanent/Fissure.pm
  25. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/GasGiantPlatform.pm
  26. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/GeoThermalVent.pm
  27. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/GratchsGauntlet.pm
  28. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/GreatBallOfJunk.pm
  29. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/Grove.pm
  30. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm
  31. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/InterDimensionalRift.pm
  32. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/JunkHengeSculpture.pm
  33. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/KalavianRuins.pm
  34. +5 −0 lib/Lacuna/DB/Result/Building/Permanent/KasternsKeep.pm
  35. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/Lagoon.pm
  36. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/Lake.pm
  37. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/LapisForest.pm
  38. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/LibraryOfJith.pm
  39. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/MalcudField.pm
  40. +5 −0 lib/Lacuna/DB/Result/Building/Permanent/MassadsHenge.pm
  41. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/MetalJunkArches.pm
  42. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/NaturalSpring.pm
  43. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/OracleOfAnid.pm
  44. +3 −17 lib/Lacuna/DB/Result/Building/Permanent/PantheonOfHagness.pm
  45. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/PyramidJunkSculpture.pm
  46. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/Ravine.pm
  47. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/RockyOutcrop.pm
  48. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/Sand.pm
  49. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/SpaceJunkPark.pm
  50. +3 −16 lib/Lacuna/DB/Result/Building/Permanent/TempleOfTheDrajilites.pm
  51. +2 −8 lib/Lacuna/DB/Result/Building/Permanent/TerraformingPlatform.pm
  52. +3 −17 lib/Lacuna/DB/Result/Building/Permanent/Volcano.pm
  53. +0 −12 lib/Lacuna/DB/Result/Building/SAW.pm
@@ -75,93 +75,56 @@ sub image_level {
sub produces_food_items { [] };
-use constant time_to_build => 60;
-
-use constant energy_to_build => 0;
-
-use constant food_to_build => 0;
-
-use constant ore_to_build => 0;
-
-use constant water_to_build => 0;
-
-use constant waste_to_build => 0;
-
-use constant happiness_consumption => 0;
-
-use constant energy_consumption => 0;
-
-use constant water_consumption => 0;
-
-use constant waste_consumption => 0;
-
-use constant food_consumption => 0;
-
-use constant ore_consumption => 0;
-
-use constant happiness_production => 0;
-
-use constant energy_production => 0;
-
-use constant water_production => 0;
-
-use constant waste_production => 0;
-
-use constant beetle_production => 0;
-
-use constant shake_production => 0;
-
-use constant burger_production => 0;
-
-use constant fungus_production => 0;
-
-use constant syrup_production => 0;
-
-use constant algae_production => 0;
-
-use constant meal_production => 0;
-
-use constant milk_production => 0;
-
-use constant pancake_production => 0;
-
-use constant pie_production => 0;
-
-use constant chip_production => 0;
-
-use constant soup_production => 0;
-
-use constant bread_production => 0;
-
-use constant wheat_production => 0;
-
-use constant cider_production => 0;
-
-use constant corn_production => 0;
-
-use constant root_production => 0;
-
-use constant bean_production => 0;
-
-use constant cheese_production => 0;
-
-use constant apple_production => 0;
-
-use constant lapis_production => 0;
-
-use constant potato_production => 0;
-
-use constant ore_production => 0;
-
-use constant water_storage => 0;
-
-use constant energy_storage => 0;
-
-use constant food_storage => 0;
-
-use constant ore_storage => 0;
-
-use constant waste_storage => 0;
+use constant time_to_build => 60;
+
+use constant build_with_halls => 0;
+
+use constant energy_to_build => 0;
+use constant food_to_build => 0;
+use constant ore_to_build => 0;
+use constant water_to_build => 0;
+use constant waste_to_build => 0;
+
+use constant happiness_consumption => 0;
+use constant energy_consumption => 0;
+use constant water_consumption => 0;
+use constant waste_consumption => 0;
+use constant food_consumption => 0;
+use constant ore_consumption => 0;
+
+use constant happiness_production => 0;
+use constant energy_production => 0;
+use constant water_production => 0;
+use constant waste_production => 0;
+use constant beetle_production => 0;
+use constant shake_production => 0;
+use constant burger_production => 0;
+use constant fungus_production => 0;
+use constant syrup_production => 0;
+use constant algae_production => 0;
+use constant meal_production => 0;
+use constant milk_production => 0;
+use constant pancake_production => 0;
+use constant pie_production => 0;
+use constant chip_production => 0;
+use constant soup_production => 0;
+use constant bread_production => 0;
+use constant wheat_production => 0;
+use constant cider_production => 0;
+use constant corn_production => 0;
+use constant root_production => 0;
+use constant bean_production => 0;
+use constant cheese_production => 0;
+use constant apple_production => 0;
+use constant lapis_production => 0;
+use constant potato_production => 0;
+use constant ore_production => 0;
+
+use constant water_storage => 0;
+use constant energy_storage => 0;
+use constant food_storage => 0;
+use constant ore_storage => 0;
+use constant waste_storage => 0;
# BASE FORMULAS
@@ -791,14 +754,22 @@ sub cost_to_upgrade {
$time_cost = 5184000 if ($time_cost > 5184000); # 60 Days
$time_cost = 15 if ($time_cost < 15);
- return {
- food => sprintf('%.0f',$self->food_to_build * $upgrade_cost * $upgrade_cost_reduction),
- energy => sprintf('%.0f',$self->energy_to_build * $upgrade_cost * $upgrade_cost_reduction),
- ore => sprintf('%.0f',$self->ore_to_build * $upgrade_cost * $upgrade_cost_reduction),
- water => sprintf('%.0f',$self->water_to_build * $upgrade_cost * $upgrade_cost_reduction),
- waste => sprintf('%.0f',$self->waste_to_build * $upgrade_cost * $upgrade_cost_reduction),
- time => sprintf('%.0f',$time_cost),
- };
+ if ($self->build_with_halls) {
+ return {
+ halls => $self->level + 1,
+ time => sprintf('%.0f',$time_cost),
+ };
+ }
+ else {
+ return {
+ food => sprintf('%.0f',$self->food_to_build * $upgrade_cost * $upgrade_cost_reduction),
+ energy => sprintf('%.0f',$self->energy_to_build * $upgrade_cost * $upgrade_cost_reduction),
+ ore => sprintf('%.0f',$self->ore_to_build * $upgrade_cost * $upgrade_cost_reduction),
+ water => sprintf('%.0f',$self->water_to_build * $upgrade_cost * $upgrade_cost_reduction),
+ waste => sprintf('%.0f',$self->waste_to_build * $upgrade_cost * $upgrade_cost_reduction),
+ time => sprintf('%.0f',$time_cost),
+ };
+ }
}
sub stats_after_upgrade {
@@ -857,6 +828,13 @@ sub start_upgrade {
sub finish_upgrade {
my ($self) = @_;
+ my ($schedule) = Lacuna->db->resultset('Schedule')->search({
+ parent_table => 'Building',
+ parent_id => $self->id,
+ task => 'finish_upgrade',
+ });
+ $schedule->delete if defined $schedule;
+
if ($self->is_upgrading) {
my $body = $self->body;
my $new_level = $self->level+1;
@@ -8,21 +8,8 @@ use Lacuna::Util qw(randint);
use constant controller_class => 'Lacuna::RPC::Building::AlgaePond';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build an Algae Pond. It forms naturally."];
-};
-
-around can_upgrade => sub {
- my ($orig, $self) = @_;
- if ($self->body->get_plan(__PACKAGE__, $self->level + 1)) {
- return $orig->($self);
- }
- confess [1013,"You can't upgrade an Algae Pond. It forms naturally."];
-};
+with "Lacuna::Role::Building::UpgradeWithHalls";
+with "Lacuna::Role::Building::FormsNaturally";
use constant image => 'algaepond';
@@ -36,10 +23,10 @@ after finish_upgrade => sub {
$self->body->add_news(30, sprintf('This is no fisherman\'s tale. A local fisherman caught a '.randint(1,9).' meter Rakl out of an algae pond on %s.', $self->body->name));
};
-use constant name => 'Algae Pond';
-use constant time_to_build => 0;
-use constant max_instances_per_planet => 1;
-use constant algae_production => 4000;
+use constant name => 'Algae Pond';
+use constant time_to_build => 0;
+use constant max_instances_per_planet => 1;
+use constant algae_production => 4000;
around produces_food_items => sub {
my ($orig, $class) = @_;
@@ -5,23 +5,10 @@ use utf8;
no warnings qw(uninitialized);
extends 'Lacuna::DB::Result::Building::Permanent';
-use constant controller_class => 'Lacuna::RPC::Building::AmalgusMeadow';
-
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build an Amalgus Meadow. It forms naturally."];
-};
+with "Lacuna::Role::Building::UpgradeWithHalls";
+with "Lacuna::Role::Building::FormsNaturally";
-around can_upgrade => sub {
- my ($orig, $self) = @_;
- if ($self->body->get_plan(__PACKAGE__, $self->level + 1)) {
- return $orig->($self);
- }
- confess [1013,"You can't upgrade an Amalgus Meadow. It forms naturally."];
-};
+use constant controller_class => 'Lacuna::RPC::Building::AmalgusMeadow';
use constant image => 'amalgusmeadow';
@@ -7,13 +7,7 @@ extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach1';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
@@ -6,14 +6,7 @@ no warnings qw(uninitialized);
extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach10';
-
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
@@ -7,13 +7,7 @@ extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach11';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
@@ -7,13 +7,7 @@ extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach12';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
@@ -7,13 +7,7 @@ extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach13';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
@@ -7,13 +7,7 @@ extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach2';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
@@ -7,13 +7,7 @@ extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach3';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
@@ -7,13 +7,7 @@ extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach4';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
@@ -7,13 +7,7 @@ extends 'Lacuna::DB::Result::Building::Permanent';
use constant controller_class => 'Lacuna::RPC::Building::Beach5';
-around can_build => sub {
- my ($orig, $self, $body) = @_;
- if ($body->get_plan(__PACKAGE__, 1)) {
- return $orig->($self, $body);
- }
- confess [1013,"You can't build a beach. It forms naturally."];
-};
+with "Lacuna::Role::Building::FormsNaturally";
sub can_upgrade {
confess [1013, "You can't upgrade a beach. It forms naturally."];
Oops, something went wrong.

0 comments on commit 58ba6d1

Please sign in to comment.