| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::Mission; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1701
|
use 5.010; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
63
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
486
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
|
8
|
|
|
|
|
|
|
with qw(Games::Lacuna::Task::Role::PlanetRun |
|
9
|
|
|
|
|
|
|
Games::Lacuna::Task::Role::Storage); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub description { |
|
12
|
|
|
|
|
|
|
return q[Automatically accept missions]; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'missions' => ( |
|
16
|
|
|
|
|
|
|
is => 'rw', |
|
17
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
|
18
|
|
|
|
|
|
|
required => 1, |
|
19
|
|
|
|
|
|
|
documentation => 'Automatic missions [Required, Multiple]', |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub process_planet { |
|
23
|
|
|
|
|
|
|
my ($self,$planet_stats) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $timestamp = time(); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Get mission command |
|
28
|
|
|
|
|
|
|
my $missioncommand = $self->find_building($planet_stats->{id},'MissionCommand'); |
|
29
|
|
|
|
|
|
|
return |
|
30
|
|
|
|
|
|
|
unless $missioncommand; |
|
31
|
|
|
|
|
|
|
my $missioncommand_object = $self->build_object($missioncommand); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $mission_data = $self->request( |
|
34
|
|
|
|
|
|
|
object => $missioncommand_object, |
|
35
|
|
|
|
|
|
|
method => 'get_missions', |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $plans; |
|
39
|
|
|
|
|
|
|
my $glyphs; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
MISSIONS: |
|
42
|
|
|
|
|
|
|
foreach my $mission (@{$mission_data->{missions}}) { |
|
43
|
|
|
|
|
|
|
next MISSIONS |
|
44
|
|
|
|
|
|
|
unless $mission->{name} ~~ $self->missions; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $objectives = $self->parse_mission($mission->{objectives}); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Check if we have the required resources |
|
49
|
|
|
|
|
|
|
my @used_plans; |
|
50
|
|
|
|
|
|
|
foreach my $objective (@{$objectives}) { |
|
51
|
|
|
|
|
|
|
given ($objective->{type}) { |
|
52
|
|
|
|
|
|
|
when ('plan') { |
|
53
|
|
|
|
|
|
|
$plans ||= $self->plans_stored($planet_stats->{id}); |
|
54
|
|
|
|
|
|
|
my $found_plan = 0; |
|
55
|
|
|
|
|
|
|
PLANS: |
|
56
|
|
|
|
|
|
|
foreach my $plan (@$plans) { |
|
57
|
|
|
|
|
|
|
next PLANS |
|
58
|
|
|
|
|
|
|
unless $plan->{name} eq $objective->{plan}; |
|
59
|
|
|
|
|
|
|
next PLANS |
|
60
|
|
|
|
|
|
|
if $plan->{level} != $objective->{level}; |
|
61
|
|
|
|
|
|
|
next PLANS |
|
62
|
|
|
|
|
|
|
if $plan->{extra_build_level} != $objective->{extra_build_level}; |
|
63
|
|
|
|
|
|
|
next PLANS |
|
64
|
|
|
|
|
|
|
if grep { $plan == $_ } @used_plans; |
|
65
|
|
|
|
|
|
|
push (@used_plans,$plan); |
|
66
|
|
|
|
|
|
|
$found_plan ++; |
|
67
|
|
|
|
|
|
|
last PLANS; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
next MISSIONS |
|
70
|
|
|
|
|
|
|
unless $found_plan; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
when ('resource') { |
|
73
|
|
|
|
|
|
|
next MISSIONS |
|
74
|
|
|
|
|
|
|
if $objective->{quantity} > $self->check_stored($planet_stats,$objective->{resource}); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $rewards = $self->parse_mission($mission->{rewards}); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my %rewards_resources = map { $_ => 0 } @Games::Lacuna::Task::Constants::RESOURCES; |
|
82
|
|
|
|
|
|
|
# Check if we have can handle the reward |
|
83
|
|
|
|
|
|
|
foreach my $reward (@{$rewards}) { |
|
84
|
|
|
|
|
|
|
if ($reward->{type} eq 'resource') { |
|
85
|
|
|
|
|
|
|
my $resource_type = $self->resource_type($reward->{resource}); |
|
86
|
|
|
|
|
|
|
$rewards_resources{$resource_type} += $reward->{quantity}; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
foreach my $resource_type (@Games::Lacuna::Task::Constants::RESOURCES) { |
|
91
|
|
|
|
|
|
|
my $capacity = $planet_stats->{$resource_type.'_capacity'} - $planet_stats->{$resource_type.'_stored'} - $rewards_resources{$resource_type}; |
|
92
|
|
|
|
|
|
|
next MISSIONS |
|
93
|
|
|
|
|
|
|
if $capacity < -100000; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$self->log('notice',"Completing mission %s on %s",$mission->{name},$planet_stats->{name}); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $response = $self->request( |
|
99
|
|
|
|
|
|
|
object => $missioncommand_object, |
|
100
|
|
|
|
|
|
|
method => 'complete_mission', |
|
101
|
|
|
|
|
|
|
params => [$mission->{id}], |
|
102
|
|
|
|
|
|
|
catch => [ |
|
103
|
|
|
|
|
|
|
[ |
|
104
|
|
|
|
|
|
|
1013, |
|
105
|
|
|
|
|
|
|
sub { |
|
106
|
|
|
|
|
|
|
my ($error) = @_; |
|
107
|
|
|
|
|
|
|
$self->log('debug',"Could not complete mission %s: %s",$mission->{name},$error->message); |
|
108
|
|
|
|
|
|
|
next MISSION; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
] |
|
111
|
|
|
|
|
|
|
], |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
$planet_stats = $response->{status}{body}; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $body = sprintf("We have completed the mission *%s* on {Planet %i %s}\nObjective: %s\nReward:%s", |
|
117
|
|
|
|
|
|
|
$mission->{name}, |
|
118
|
|
|
|
|
|
|
$planet_stats->{id}, |
|
119
|
|
|
|
|
|
|
$planet_stats->{name}, |
|
120
|
|
|
|
|
|
|
join (", ",@{$mission->{objectives}}), |
|
121
|
|
|
|
|
|
|
join (", ",@{$mission->{rewards}}), |
|
122
|
|
|
|
|
|
|
); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$self->send_message('Mission completed',$body); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub parse_mission { |
|
129
|
|
|
|
|
|
|
my ($self,$list) = @_; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my @parsed; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
foreach my $element (@{$list}) { |
|
134
|
|
|
|
|
|
|
given ($element) { |
|
135
|
|
|
|
|
|
|
when (m/^ |
|
136
|
|
|
|
|
|
|
(?<plan>[^(]+) |
|
137
|
|
|
|
|
|
|
\s |
|
138
|
|
|
|
|
|
|
\( |
|
139
|
|
|
|
|
|
|
(>=\s)? |
|
140
|
|
|
|
|
|
|
(?<level>\d+) |
|
141
|
|
|
|
|
|
|
(\+(?<extra_build_level>\d+))? |
|
142
|
|
|
|
|
|
|
\) |
|
143
|
|
|
|
|
|
|
\s |
|
144
|
|
|
|
|
|
|
plan$/x) { |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
push(@parsed,{ |
|
147
|
|
|
|
|
|
|
type => 'plan', |
|
148
|
|
|
|
|
|
|
level => $+{level}, |
|
149
|
|
|
|
|
|
|
plan => $+{plan}, |
|
150
|
|
|
|
|
|
|
extra_build_level => ($+{extra_build_level} // 0) |
|
151
|
|
|
|
|
|
|
}); |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
when (m/^(?<quantity>[,0-9]+)\s(?<resource>.+)$/) { |
|
154
|
|
|
|
|
|
|
my $quantity = $+{quantity}; |
|
155
|
|
|
|
|
|
|
my $resource = $+{resource}; |
|
156
|
|
|
|
|
|
|
$quantity =~ s/\D//g; |
|
157
|
|
|
|
|
|
|
$quantity += 0; |
|
158
|
|
|
|
|
|
|
push(@parsed,{ |
|
159
|
|
|
|
|
|
|
type => 'resource', |
|
160
|
|
|
|
|
|
|
resource => $resource, |
|
161
|
|
|
|
|
|
|
quantity => $quantity, |
|
162
|
|
|
|
|
|
|
}); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
when (m/^(?<glyph>.+)\sglyph$/) { |
|
165
|
|
|
|
|
|
|
push(@parsed,{ |
|
166
|
|
|
|
|
|
|
type => 'glyph', |
|
167
|
|
|
|
|
|
|
glyph => $+{glyph}, |
|
168
|
|
|
|
|
|
|
}); |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
when (m/^ |
|
171
|
|
|
|
|
|
|
(?<ship>[^(]+) |
|
172
|
|
|
|
|
|
|
\s |
|
173
|
|
|
|
|
|
|
\( |
|
174
|
|
|
|
|
|
|
speed \s >= \s (?<speed>[0-9,]+), |
|
175
|
|
|
|
|
|
|
\s |
|
176
|
|
|
|
|
|
|
stealth \s >= \s (?<stealth>[0-9,]+), |
|
177
|
|
|
|
|
|
|
\s |
|
178
|
|
|
|
|
|
|
hold \s size \s >= \s (?<hold>[0-9,]+), |
|
179
|
|
|
|
|
|
|
\s |
|
180
|
|
|
|
|
|
|
combat \s >= \s (?<combat>[0-9,]+) |
|
181
|
|
|
|
|
|
|
\) |
|
182
|
|
|
|
|
|
|
$/x) { |
|
183
|
|
|
|
|
|
|
my $ship = $+{ship}; |
|
184
|
|
|
|
|
|
|
my $speed = $+{speed}; |
|
185
|
|
|
|
|
|
|
my $hold = $+{hold}; |
|
186
|
|
|
|
|
|
|
my $stealth = $+{stealth}; |
|
187
|
|
|
|
|
|
|
my $combat = $+{combat}; |
|
188
|
|
|
|
|
|
|
$speed =~ s/\D//g; |
|
189
|
|
|
|
|
|
|
$hold =~ s/\D//g; |
|
190
|
|
|
|
|
|
|
$stealth =~ s/\D//g; |
|
191
|
|
|
|
|
|
|
$combat =~ s/\D//g; |
|
192
|
|
|
|
|
|
|
push(@parsed,{ |
|
193
|
|
|
|
|
|
|
type => 'ship', |
|
194
|
|
|
|
|
|
|
ship => $ship, |
|
195
|
|
|
|
|
|
|
stealth => $stealth, |
|
196
|
|
|
|
|
|
|
hold => $hold, |
|
197
|
|
|
|
|
|
|
combat => $combat, |
|
198
|
|
|
|
|
|
|
speed => $speed, |
|
199
|
|
|
|
|
|
|
}); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
when (m/^Send |
|
202
|
|
|
|
|
|
|
\s |
|
203
|
|
|
|
|
|
|
(?<ship>.+?) |
|
204
|
|
|
|
|
|
|
\s to \s |
|
205
|
|
|
|
|
|
|
(?<planet>.+?) |
|
206
|
|
|
|
|
|
|
\s |
|
207
|
|
|
|
|
|
|
\( |
|
208
|
|
|
|
|
|
|
(?<x>-?\d+) |
|
209
|
|
|
|
|
|
|
, |
|
210
|
|
|
|
|
|
|
(?<y>-?\d+) |
|
211
|
|
|
|
|
|
|
\)/x) { |
|
212
|
|
|
|
|
|
|
push(@parsed,{ |
|
213
|
|
|
|
|
|
|
type => 'send', |
|
214
|
|
|
|
|
|
|
ship => $+{ship}, |
|
215
|
|
|
|
|
|
|
planet => $+{planet}, |
|
216
|
|
|
|
|
|
|
x => $+{x}, |
|
217
|
|
|
|
|
|
|
y => $+{y}, |
|
218
|
|
|
|
|
|
|
}); |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
default { |
|
221
|
|
|
|
|
|
|
$self->log("warn","Unknown mission item: %s",$_); |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
return \@parsed; |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
230
|
|
|
|
|
|
|
no Moose; |
|
231
|
|
|
|
|
|
|
1; |