diff --git a/lib/Lacuna/DB/Result/Building/Permanent/EssentiaVein.pm b/lib/Lacuna/DB/Result/Building/Permanent/EssentiaVein.pm index 401debb2..78bacb2a 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/EssentiaVein.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/EssentiaVein.pm @@ -7,13 +7,44 @@ extends 'Lacuna::DB::Result::Building::Permanent'; use constant controller_class => 'Lacuna::RPC::Building::EssentiaVein'; -with "Lacuna::Role::Building::UpgradeWithHalls"; with "Lacuna::Role::Building::CantBuildWithoutPlan"; sub can_downgrade { confess [1013, "You can't downgrade an Essentia Vein."]; } +around can_upgrade => sub { + my $orig = shift; + my $self = shift; + + # Can't upgrade a permanent e-vein (i.e. one that is not working + if (not $self->is_working) { + confess [1013, "You can't upgrade a permanent Essentia Vein."]; + } + + my $body = $self->body; + if ($body->get_plan(ref $self, $self->level + 1)) { + return $self->$orig(@_); + } + + # 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); +}; + + use constant image => 'essentiavein'; sub image_level { diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 75f34af8..36a35351 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -5,6 +5,7 @@ - Mod: Glyph buildings can now be upgraded (with halls) via update button - Mod: All Halls of Vrbansk building have been replaced with hall plans - Mod: The Halls of Vrbansk can no longer be built from a plan. + - Mod: Disable upgrade button on Permanent E-Veins 3.0882: - Fix: Timers on int ministries get zeroed on flipped planets.