| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::CollectExcavatorBooty; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1595
|
use 5.010; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
79
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
690
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
|
8
|
|
|
|
|
|
|
with 'Games::Lacuna::Task::Role::Ships', |
|
9
|
|
|
|
|
|
|
'Games::Lacuna::Task::Role::PlanetRun', |
|
10
|
|
|
|
|
|
|
'Games::Lacuna::Task::Role::CommonAttributes' => { attributes => ['home_planet'] }; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'plans' => ( |
|
13
|
|
|
|
|
|
|
is => 'rw', |
|
14
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
|
15
|
|
|
|
|
|
|
required => 1, |
|
16
|
|
|
|
|
|
|
documentation => 'Automatic plans to be transported', |
|
17
|
|
|
|
|
|
|
default => sub { |
|
18
|
|
|
|
|
|
|
[ |
|
19
|
|
|
|
|
|
|
'Grove of Trees', |
|
20
|
|
|
|
|
|
|
'Algae Pond', |
|
21
|
|
|
|
|
|
|
'Amalgus Meadow', |
|
22
|
|
|
|
|
|
|
'Beach [1]', |
|
23
|
|
|
|
|
|
|
'Beach [2]', |
|
24
|
|
|
|
|
|
|
'Beach [3]', |
|
25
|
|
|
|
|
|
|
'Beach [4]', |
|
26
|
|
|
|
|
|
|
'Beach [5]', |
|
27
|
|
|
|
|
|
|
'Beach [6]', |
|
28
|
|
|
|
|
|
|
'Beach [7]', |
|
29
|
|
|
|
|
|
|
'Beach [8]', |
|
30
|
|
|
|
|
|
|
'Beach [9]', |
|
31
|
|
|
|
|
|
|
'Beach [10]', |
|
32
|
|
|
|
|
|
|
'Beach [11]', |
|
33
|
|
|
|
|
|
|
'Beach [12]', |
|
34
|
|
|
|
|
|
|
'Beach [13]', |
|
35
|
|
|
|
|
|
|
'Beeldeban Nest', |
|
36
|
|
|
|
|
|
|
'Crater', |
|
37
|
|
|
|
|
|
|
'Denton Brambles', |
|
38
|
|
|
|
|
|
|
'Geo Thermal Vent', |
|
39
|
|
|
|
|
|
|
'Grove of Trees', |
|
40
|
|
|
|
|
|
|
'Lagoon', |
|
41
|
|
|
|
|
|
|
'Lake', |
|
42
|
|
|
|
|
|
|
'Lapis Forest', |
|
43
|
|
|
|
|
|
|
'Malcud Field', |
|
44
|
|
|
|
|
|
|
'Natural Spring', |
|
45
|
|
|
|
|
|
|
'Patch of Sand', |
|
46
|
|
|
|
|
|
|
'Ravine', |
|
47
|
|
|
|
|
|
|
'Rocky Outcropping', |
|
48
|
|
|
|
|
|
|
'Volcano', |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
'Citadel of Knope', |
|
51
|
|
|
|
|
|
|
'Black Hole Generator', |
|
52
|
|
|
|
|
|
|
'Oracle of Anid', |
|
53
|
|
|
|
|
|
|
'Temple of the Drajilites', |
|
54
|
|
|
|
|
|
|
'Library of Jith', |
|
55
|
|
|
|
|
|
|
'Kalavian Ruins', |
|
56
|
|
|
|
|
|
|
'Interdimensional Rift', |
|
57
|
|
|
|
|
|
|
'Gratch\'s Gauntlet', |
|
58
|
|
|
|
|
|
|
'Crashed Ship Site', |
|
59
|
|
|
|
|
|
|
'Pantheon of Hagness', |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
] |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has 'extra_build_level' => ( |
|
66
|
|
|
|
|
|
|
is => 'rw', |
|
67
|
|
|
|
|
|
|
isa => 'Int', |
|
68
|
|
|
|
|
|
|
required => 1, |
|
69
|
|
|
|
|
|
|
documentation => 'Ignore plans with extra build level above this value [Default: 2]', |
|
70
|
|
|
|
|
|
|
default => 2, |
|
71
|
|
|
|
|
|
|
); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has 'min_items' => ( |
|
74
|
|
|
|
|
|
|
is => 'rw', |
|
75
|
|
|
|
|
|
|
isa => 'Int', |
|
76
|
|
|
|
|
|
|
required => 1, |
|
77
|
|
|
|
|
|
|
documentation => 'Only send ship if we have n-items to be sent [Default: 1]', |
|
78
|
|
|
|
|
|
|
default => 1, |
|
79
|
|
|
|
|
|
|
); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub description { |
|
83
|
|
|
|
|
|
|
return q[Ship excavator booty to a selected planet]; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub process_planet { |
|
87
|
|
|
|
|
|
|
my ($self,$planet_stats) = @_; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return |
|
90
|
|
|
|
|
|
|
if $planet_stats->{id} == $self->home_planet_data->{id}; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Get trade ministry |
|
93
|
|
|
|
|
|
|
my $tradeministry = $self->find_building($planet_stats->{id},'Trade'); |
|
94
|
|
|
|
|
|
|
return |
|
95
|
|
|
|
|
|
|
unless $tradeministry; |
|
96
|
|
|
|
|
|
|
my $tradeministry_object = $self->build_object($tradeministry); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Get glyphs |
|
99
|
|
|
|
|
|
|
my $available_glyphs = $self->request( |
|
100
|
|
|
|
|
|
|
object => $tradeministry_object, |
|
101
|
|
|
|
|
|
|
method => 'get_glyphs', |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Get plans |
|
105
|
|
|
|
|
|
|
my $available_plans = $self->request( |
|
106
|
|
|
|
|
|
|
object => $tradeministry_object, |
|
107
|
|
|
|
|
|
|
method => 'get_plans', |
|
108
|
|
|
|
|
|
|
); |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $total_cargo; |
|
111
|
|
|
|
|
|
|
my @cargo; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# Get all glyphs |
|
114
|
|
|
|
|
|
|
foreach my $glyph (@{$available_glyphs->{glyphs}}) { |
|
115
|
|
|
|
|
|
|
push(@cargo,{ |
|
116
|
|
|
|
|
|
|
"type" => "glyph", |
|
117
|
|
|
|
|
|
|
"glyph_id" => $glyph->{id}, |
|
118
|
|
|
|
|
|
|
}); |
|
119
|
|
|
|
|
|
|
$total_cargo += $available_glyphs->{cargo_space_used_each}; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Get all plans |
|
123
|
|
|
|
|
|
|
PLANS: |
|
124
|
|
|
|
|
|
|
foreach my $plan (@{$available_plans->{plans}}) { |
|
125
|
|
|
|
|
|
|
next PLANS |
|
126
|
|
|
|
|
|
|
unless $plan->{level} == 1; |
|
127
|
|
|
|
|
|
|
next PLANS |
|
128
|
|
|
|
|
|
|
unless $plan->{name} ~~ $self->plans; |
|
129
|
|
|
|
|
|
|
next PLANS |
|
130
|
|
|
|
|
|
|
if $plan->{extra_build_level} > $self->{extra_build_level}; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
push(@cargo,{ |
|
133
|
|
|
|
|
|
|
"type" => "plan", |
|
134
|
|
|
|
|
|
|
"plan_id" => $plan->{id}, |
|
135
|
|
|
|
|
|
|
}); |
|
136
|
|
|
|
|
|
|
$total_cargo += $available_plans->{cargo_space_used_each}; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return |
|
140
|
|
|
|
|
|
|
unless scalar @cargo; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
return |
|
143
|
|
|
|
|
|
|
if scalar @cargo < $self->min_items; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Get trade ships |
|
146
|
|
|
|
|
|
|
my $available_trade_ships = $self->request( |
|
147
|
|
|
|
|
|
|
object => $tradeministry_object, |
|
148
|
|
|
|
|
|
|
method => 'get_trade_ships', |
|
149
|
|
|
|
|
|
|
params => [ $self->home_planet_data->{id} ], |
|
150
|
|
|
|
|
|
|
); |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
return |
|
153
|
|
|
|
|
|
|
unless scalar @{$available_trade_ships->{ships}}; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my $trade_ship_id; |
|
156
|
|
|
|
|
|
|
TRADE_SHIP: |
|
157
|
|
|
|
|
|
|
foreach my $ship (sort { $b->{speed} <=> $a->{speed} } @{$available_trade_ships->{ships}}) { |
|
158
|
|
|
|
|
|
|
# TODO send multiple ships if cargo requirements exceed capacity of single ship |
|
159
|
|
|
|
|
|
|
next TRADE_SHIP |
|
160
|
|
|
|
|
|
|
if $ship->{hold_size} < $total_cargo; |
|
161
|
|
|
|
|
|
|
next TRADE_SHIP |
|
162
|
|
|
|
|
|
|
if $ship->{name} =~ m/!/; |
|
163
|
|
|
|
|
|
|
$trade_ship_id = $ship->{id}; |
|
164
|
|
|
|
|
|
|
last TRADE_SHIP; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
my $response = $self->request( |
|
168
|
|
|
|
|
|
|
object => $tradeministry_object, |
|
169
|
|
|
|
|
|
|
method => 'push_items', |
|
170
|
|
|
|
|
|
|
params => [ $self->home_planet_data->{id} , \@cargo, { ship_id => $trade_ship_id } ] |
|
171
|
|
|
|
|
|
|
); |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$self->log('notice','Sending %i item(s) from %s to %s',scalar(@cargo),$planet_stats->{name},$self->home_planet_data->{name}); |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
177
|
|
|
|
|
|
|
no Moose; |
|
178
|
|
|
|
|
|
|
1; |