From aac160a9884658dc7a6faa53350fec6fca44103d Mon Sep 17 00:00:00 2001 From: Iain C Docherty Date: Sun, 17 Mar 2013 11:54:09 -0400 Subject: [PATCH] Added missing files --- .../Role/Building/CantBuildWithoutPlan.pm | 14 ++++++++ lib/Lacuna/Role/Building/FormsNaturally.pm | 14 ++++++++ lib/Lacuna/Role/Building/UpgradeWithHalls.pm | 34 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 lib/Lacuna/Role/Building/CantBuildWithoutPlan.pm create mode 100644 lib/Lacuna/Role/Building/FormsNaturally.pm create mode 100644 lib/Lacuna/Role/Building/UpgradeWithHalls.pm diff --git a/lib/Lacuna/Role/Building/CantBuildWithoutPlan.pm b/lib/Lacuna/Role/Building/CantBuildWithoutPlan.pm new file mode 100644 index 00000000..2a30e657 --- /dev/null +++ b/lib/Lacuna/Role/Building/CantBuildWithoutPlan.pm @@ -0,0 +1,14 @@ +package Lacuna::Role::Building::CantBuildWithoutPlan; + +use Moose::Role; + +around can_build => sub { + my ($orig, $self, $body) = @_; + if ($body->get_plan(__PACKAGE__, 1)) { + return $orig->($self, $body); + } + confess [1013,"You can't build ".$self->name.", unless you have a plan."]; +}; + +1; + diff --git a/lib/Lacuna/Role/Building/FormsNaturally.pm b/lib/Lacuna/Role/Building/FormsNaturally.pm new file mode 100644 index 00000000..78e2cc07 --- /dev/null +++ b/lib/Lacuna/Role/Building/FormsNaturally.pm @@ -0,0 +1,14 @@ +package Lacuna::Role::Building::FormsNaturally; + +use Moose::Role; + +around can_build => sub { + my ($orig, $self, $body) = @_; + if ($body->get_plan(__PACKAGE__, 1)) { + return $orig->($self, $body); + } + confess [1013,"You can't build ".$self->name.". It forms naturally."]; +}; + +1; + diff --git a/lib/Lacuna/Role/Building/UpgradeWithHalls.pm b/lib/Lacuna/Role/Building/UpgradeWithHalls.pm new file mode 100644 index 00000000..3431ac43 --- /dev/null +++ b/lib/Lacuna/Role/Building/UpgradeWithHalls.pm @@ -0,0 +1,34 @@ +package Lacuna::Role::Building::UpgradeWithHalls; + +use Moose::Role; + +use constant build_with_halls => 1; + +around can_upgrade => sub { + my $orig = shift; + my $self = shift; + + my $body = $self->body; + if ($body->get_plan(__PACKAGE__, $self->level + 1)) { + return $orig->$self(@_); + } + + # Do we have enough hall (plans) to upgrade? + my ($plan) = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk'} @{$body->plan_cache}; + my $plans = defined $plan ? $plan->quantity : 0; + + if ($plans < $self->level + 1) { + confess [1013, "You can't upgrade ".$self->name.", you don't have enough Halls of Vrbansk plans."]; + } + return $self->$orig(@_); +}; + +before start_upgrade => sub { + my ($self, $cost) = @_; + + my ($plans) = grep {$_->class eq 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk'} @{$self->body->plan_cache}; + $self->body->delete_many_plans($plans, $self->level + 1); +}; + +1; + -- 2.51.2