line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::Bleeder; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1473
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
58
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
435
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
8
|
|
|
|
|
|
|
with qw(Games::Lacuna::Task::Role::Notify |
9
|
|
|
|
|
|
|
Games::Lacuna::Task::Role::PlanetRun); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub description { |
12
|
|
|
|
|
|
|
return q[Report deployed bleeders]; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'known_bleeder' => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
isa => 'ArrayRef', |
18
|
|
|
|
|
|
|
lazy_build => 1, |
19
|
|
|
|
|
|
|
traits => ['Array','NoGetopt'], |
20
|
|
|
|
|
|
|
handles => { |
21
|
|
|
|
|
|
|
add_known_bleeder => 'push', |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'new_bleeder' => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
isa => 'ArrayRef', |
28
|
|
|
|
|
|
|
default => sub { [] }, |
29
|
|
|
|
|
|
|
traits => ['Array','NoGetopt'], |
30
|
|
|
|
|
|
|
handles => { |
31
|
|
|
|
|
|
|
add_new_bleeder => 'push', |
32
|
|
|
|
|
|
|
has_new_bleeder => 'count', |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _build_known_bleeder { |
37
|
|
|
|
|
|
|
my ($self) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $bleeder = $self->get_cache('report/known_bleeder'); |
40
|
|
|
|
|
|
|
$bleeder ||= []; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return $bleeder; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
after 'run' => sub { |
46
|
|
|
|
|
|
|
my ($self) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if ($self->has_new_bleeder) { |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$self->add_known_bleeder(map { $_->{id} } @{$self->new_bleeder}); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $message = join ("\n",map { |
53
|
|
|
|
|
|
|
sprintf('%s: Found deployed bleeder level %i',$_->{planet},$_->{level}) |
54
|
|
|
|
|
|
|
} @{$self->new_bleeder}); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $empire_name = $self->empire_name; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self->notify( |
59
|
|
|
|
|
|
|
"[$empire_name] Bleeders detected!", |
60
|
|
|
|
|
|
|
$message |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->set_cache( |
64
|
|
|
|
|
|
|
key => 'report/known_bleeder', |
65
|
|
|
|
|
|
|
value => $self->known_bleeder, |
66
|
|
|
|
|
|
|
max_age => (60*60*24*7), # Cache one week |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub process_planet { |
72
|
|
|
|
|
|
|
my ($self,$planet_stats) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Get space port |
75
|
|
|
|
|
|
|
my @bleeders = $self->find_building($planet_stats->{id},'DeployedBleeder'); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return |
78
|
|
|
|
|
|
|
unless scalar @bleeders; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
foreach my $bleeder (@bleeders) { |
81
|
|
|
|
|
|
|
$self->log('warn','Found deployed bleeder at %s',$planet_stats->{name}); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Check if we already know this ship |
84
|
|
|
|
|
|
|
next |
85
|
|
|
|
|
|
|
if $bleeder->{id} ~~ $self->known_bleeder; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$self->add_new_bleeder({ |
88
|
|
|
|
|
|
|
planet => $planet_stats->{name}, |
89
|
|
|
|
|
|
|
id => $bleeder->{id}, |
90
|
|
|
|
|
|
|
level => $bleeder->{level}, |
91
|
|
|
|
|
|
|
}); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
96
|
|
|
|
|
|
|
no Moose; |
97
|
|
|
|
|
|
|
1; |