diff --git a/docs/EssentiaVein.pod b/docs/EssentiaVein.pod index 8da9134a..d81fb3c7 100644 --- a/docs/EssentiaVein.pod +++ b/docs/EssentiaVein.pod @@ -4,4 +4,24 @@ Essentia Vein is accessible via the URL C. The list of methods below represents changes and additions to the methods that all L share. +=head2 view ( session_id, building_id ) + + { + "status" : { ... }, + "building" : { + "drain_capable" : 3, + ... + }, + } + +Addition of a drain_capable flag indicating how many groups of 30 days +can be drained. Above example shows 90-119 days remaining. + +=head2 drain ( session_id, building_id[, times] ) + +Allows draining of an evein quickly. Instead of 4e per day over 30 days, +this will use up 30 days and provide 30e instantly. The optional C +parameter allows draining of multiple months' worth in a single RPC. Periods +less than 30 days cannot be drained quickly. + =cut \ No newline at end of file diff --git a/lib/Lacuna/RPC/Building/EssentiaVein.pm b/lib/Lacuna/RPC/Building/EssentiaVein.pm index fc5175f4..94df18a0 100644 --- a/lib/Lacuna/RPC/Building/EssentiaVein.pm +++ b/lib/Lacuna/RPC/Building/EssentiaVein.pm @@ -13,6 +13,44 @@ sub model_class { return 'Lacuna::DB::Result::Building::Permanent::EssentiaVein'; } +around view => sub { + my ($orig, $self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my $out = $orig->($self, $empire, $building); + + $out->{building}{drain_capable} = int($building->work_seconds_remaining() / (30 * 24 * 60 * 60)); + + return $out; +}; + +sub drain { + my ($self, $session_id, $building_id, $times) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + + $times ||= 1; + my $days = $times * 30; + + my $work_reduction = $days * 24 * 60 * 60; + confess [1010, "The essentia vein does not have $days days left on it."] + unless $building->work_ends > DateTime->now->add(seconds => $work_reduction); + + $empire->add_essentia({ + amount => $days, + reason => "Essentia Vein (drain: $days)", + }); + $empire->update; + + my $work_ends = $building->work_ends->subtract(seconds => $work_reduction); + $building->reschedule_work($work_ends); + $building->update; + + return $self->view($session_id, $building_id); +} + +__PACKAGE__->register_rpc_method_names(qw(drain)); + no Moose; __PACKAGE__->meta->make_immutable;