| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::Repair; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1904
|
use 5.010; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
60
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
635
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
|
8
|
|
|
|
|
|
|
with qw(Games::Lacuna::Task::Role::PlanetRun); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub description { |
|
11
|
|
|
|
|
|
|
return q[Repair damaged buildings]; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub process_planet { |
|
15
|
|
|
|
|
|
|
my ($self,$planet_stats) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my @buildings = $self->buildings_body($planet_stats->{id}); |
|
18
|
|
|
|
|
|
|
my $waste_hour = $planet_stats->{waste_hour}+0; |
|
19
|
|
|
|
|
|
|
my $waste_stored = $planet_stats->{waste_stored}+0; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Loop all buildings |
|
22
|
|
|
|
|
|
|
foreach my $building_data (@buildings) { |
|
23
|
|
|
|
|
|
|
# Check if building needs to be repaired |
|
24
|
|
|
|
|
|
|
next |
|
25
|
|
|
|
|
|
|
if $building_data->{efficiency} == 100; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $building_object = $self->build_object($building_data); |
|
28
|
|
|
|
|
|
|
my $building_detail = $self->request( |
|
29
|
|
|
|
|
|
|
object => $building_object, |
|
30
|
|
|
|
|
|
|
method => 'view', |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Check if building really needs repair |
|
34
|
|
|
|
|
|
|
next |
|
35
|
|
|
|
|
|
|
if $building_detail->{building}{efficiency} == 100; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Check if we can afford repair |
|
38
|
|
|
|
|
|
|
next |
|
39
|
|
|
|
|
|
|
unless $self->can_afford($planet_stats,$building_detail->{building}{repair_costs}); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Calc buildings repair impact on waste |
|
42
|
|
|
|
|
|
|
my $waste_hour_calc = $waste_hour + ($building_detail->{building}{waste_hour} * (100 - $building_detail->{building}{efficiency})); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Check if repair of waste recycling building is sustainable |
|
45
|
|
|
|
|
|
|
return |
|
46
|
|
|
|
|
|
|
if $building_detail->{id} ~~ [qw(WaterReclamation WasteDigester WasteEnergy WasteRecycling)] |
|
47
|
|
|
|
|
|
|
&& $waste_hour_calc < 0 |
|
48
|
|
|
|
|
|
|
&& $waste_stored < ($waste_hour_calc * 24); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Repair building |
|
51
|
|
|
|
|
|
|
$self->log('notice',"Repairing %s on %s",$building_data->{name},$planet_stats->{name}); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->request( |
|
54
|
|
|
|
|
|
|
object => $building_object, |
|
55
|
|
|
|
|
|
|
method => 'repair', |
|
56
|
|
|
|
|
|
|
); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$waste_hour = $waste_hour_calc; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$self->clear_cache('body/'.$planet_stats->{id}.'/buildings'); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
65
|
|
|
|
|
|
|
no Moose; |
|
66
|
|
|
|
|
|
|
1; |