line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::WasteMonument; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1539
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
56
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
474
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
8
|
|
|
|
|
|
|
with 'Games::Lacuna::Task::Role::Building', |
9
|
|
|
|
|
|
|
'Games::Lacuna::Task::Role::Waste', |
10
|
|
|
|
|
|
|
'Games::Lacuna::Task::Role::PlanetRun', |
11
|
|
|
|
|
|
|
'Games::Lacuna::Task::Role::CommonAttributes' => { attributes => ['dispose_percentage','start_building_at'] }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @WASTE_MONUMENTS = ( |
14
|
|
|
|
|
|
|
'Junk Henge Sculpture', |
15
|
|
|
|
|
|
|
'Great Ball of Junk', |
16
|
|
|
|
|
|
|
'Metal Junk Arches', |
17
|
|
|
|
|
|
|
'Space Junk Park', |
18
|
|
|
|
|
|
|
'Pyramid Junk Sculpture', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub description { |
22
|
|
|
|
|
|
|
return q[Demolish and rebuild waste monuments]; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub process_planet { |
26
|
|
|
|
|
|
|
my ($self,$planet_stats) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Check min university level |
29
|
|
|
|
|
|
|
return |
30
|
|
|
|
|
|
|
if $self->university_level < 21; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $timestamp = time(); |
33
|
|
|
|
|
|
|
my $build_queue_size = $self->build_queue_size($planet_stats->{id}); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Check if build queue is filled |
36
|
|
|
|
|
|
|
return |
37
|
|
|
|
|
|
|
if ($build_queue_size > $self->start_building_at); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Get stored waste |
40
|
|
|
|
|
|
|
my $waste_stored = $planet_stats->{waste_stored}; |
41
|
|
|
|
|
|
|
my $waste_capacity = $planet_stats->{waste_capacity}; |
42
|
|
|
|
|
|
|
my $waste_filled = ($waste_stored / $waste_capacity) * 100; |
43
|
|
|
|
|
|
|
my $waste_disposeable = $self->disposeable_waste($planet_stats); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Check if waste is overflowing |
46
|
|
|
|
|
|
|
return |
47
|
|
|
|
|
|
|
if ($waste_filled < $self->dispose_percentage); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my (@existing_monuments); |
50
|
|
|
|
|
|
|
foreach my $monument_type (reverse @WASTE_MONUMENTS) { |
51
|
|
|
|
|
|
|
my ($existing_monument) = $self->find_building($planet_stats->{id},$monument_type); |
52
|
|
|
|
|
|
|
next |
53
|
|
|
|
|
|
|
unless defined $existing_monument; |
54
|
|
|
|
|
|
|
next |
55
|
|
|
|
|
|
|
if defined $existing_monument->{pending_build}; |
56
|
|
|
|
|
|
|
# Ignore buildings that have already have been upgraded |
57
|
|
|
|
|
|
|
next |
58
|
|
|
|
|
|
|
if $existing_monument->{level} > 1; |
59
|
|
|
|
|
|
|
push(@existing_monuments,$existing_monument); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# We have no waste monument yet |
63
|
|
|
|
|
|
|
return |
64
|
|
|
|
|
|
|
unless (scalar @existing_monuments); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Check if monument is buildable |
67
|
|
|
|
|
|
|
my $buildable_spots = $self->find_buildspot($planet_stats); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return |
70
|
|
|
|
|
|
|
if scalar @{$buildable_spots} == 0; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $build_spot = $buildable_spots->[int(rand(scalar @{$buildable_spots}))]; |
73
|
|
|
|
|
|
|
my $body_object = $self->build_object('Body', id => $planet_stats->{id}); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $buildable_data = $self->request( |
76
|
|
|
|
|
|
|
object => $body_object, |
77
|
|
|
|
|
|
|
method => 'get_buildable', |
78
|
|
|
|
|
|
|
params => [ $build_spot->[0],$build_spot->[1],'Waste' ], |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
BUILDABLE: |
82
|
|
|
|
|
|
|
foreach my $existing_monument (@existing_monuments) { |
83
|
|
|
|
|
|
|
next BUILDABLE |
84
|
|
|
|
|
|
|
unless $buildable_data->{buildable}{$existing_monument->{name}}; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $buildable_data_monument = $buildable_data->{buildable}{$existing_monument->{name}}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
next BUILDABLE |
89
|
|
|
|
|
|
|
if $buildable_data_monument->{build}{cost}{waste} >= 0 |
90
|
|
|
|
|
|
|
|| ($buildable_data_monument->{build}{cost}{waste} * -1) > $waste_disposeable; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
next BUILDABLE |
93
|
|
|
|
|
|
|
unless $buildable_data_monument->{build}{reason}[0] == 1009; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $existing_monument_object = $self->build_object($existing_monument); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$self->log('notice',"Demolish %s on %s",$existing_monument->{name},$planet_stats->{name}); |
98
|
|
|
|
|
|
|
$self->request( |
99
|
|
|
|
|
|
|
object => $existing_monument_object, |
100
|
|
|
|
|
|
|
method => 'demolish', |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $new_monument_object = $self->build_object($buildable_data_monument->{url}); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$self->log('notice',"Building %s on %s",$existing_monument->{name},$planet_stats->{name}); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$self->request( |
108
|
|
|
|
|
|
|
object => $new_monument_object, |
109
|
|
|
|
|
|
|
method => 'build', |
110
|
|
|
|
|
|
|
params => [ $planet_stats->{id}, $existing_monument->{x},$existing_monument->{y}], |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$build_queue_size ++; |
114
|
|
|
|
|
|
|
$waste_disposeable += $buildable_data_monument->{build}{cost}{waste}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Check if build queue is filled |
117
|
|
|
|
|
|
|
return |
118
|
|
|
|
|
|
|
if ($build_queue_size > $self->start_building_at); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
123
|
|
|
|
|
|
|
no Moose; |
124
|
|
|
|
|
|
|
1; |