line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Report::Battle; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1569
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
68
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
481
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with qw(Games::Lacuna::Task::Role::Stars); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Games::Lacuna::Task::Utils qw(parse_date); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub report_battle { |
12
|
|
|
|
|
|
|
my ($self) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $table = Games::Lacuna::Task::Table->new( |
15
|
|
|
|
|
|
|
headline=> 'Battle Report', |
16
|
|
|
|
|
|
|
columns => ['Planet','System','Attacker','Attacking Ship','Defending Ship','Victory'], |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
foreach my $planet_id ($self->my_planets) { |
20
|
|
|
|
|
|
|
return $table |
21
|
|
|
|
|
|
|
if $self->_report_battle_body($planet_id,$table); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return $table; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _report_battle_body { |
28
|
|
|
|
|
|
|
my ($self,$planet_id,$table) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $planet_stats = $self->my_body_status($planet_id); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $limit = time() - (60 * 60 * 24); # 24 hours |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Get mining ministry |
35
|
|
|
|
|
|
|
my ($spaceport) = $self->find_building($planet_stats->{id},'SpacePort'); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return |
38
|
|
|
|
|
|
|
unless $spaceport; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $spaceport_object = $self->build_object($spaceport); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $battle_data = $self->paged_request( |
43
|
|
|
|
|
|
|
object => $spaceport_object, |
44
|
|
|
|
|
|
|
method => 'view_battle_logs', |
45
|
|
|
|
|
|
|
total => 'number_of_logs', |
46
|
|
|
|
|
|
|
data => 'battle_log', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my @excavators_lost_star; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
foreach my $battle (@{$battle_data->{battle_log}}) { |
52
|
|
|
|
|
|
|
my $date = parse_date($battle->{date}); |
53
|
|
|
|
|
|
|
next |
54
|
|
|
|
|
|
|
if $date < $limit; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if (lc($battle->{attacking_empire}) eq lc($self->empire_name) |
57
|
|
|
|
|
|
|
&& $battle->{attacking_type} eq 'Excavator') { |
58
|
|
|
|
|
|
|
my $body = $self->get_body_by_id($battle->{defending_body_id}); |
59
|
|
|
|
|
|
|
push(@excavators_lost_star,$body->{star_id}) |
60
|
|
|
|
|
|
|
unless $body->{star_id} ~~ \@excavators_lost_star; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$table->add_row({ |
65
|
|
|
|
|
|
|
planet => $planet_stats->{name}, |
66
|
|
|
|
|
|
|
system => $battle->{defending_body}, |
67
|
|
|
|
|
|
|
attacker => $battle->{attacking_empire}, |
68
|
|
|
|
|
|
|
attacking_ship => $battle->{attacking_unit}, |
69
|
|
|
|
|
|
|
defending_ship => $battle->{defending_unit}, |
70
|
|
|
|
|
|
|
victory => $battle->{victory_to}, |
71
|
|
|
|
|
|
|
}); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
foreach my $star_id (@excavators_lost_star) { |
75
|
|
|
|
|
|
|
$self->_get_star_api($star_id); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
no Moose::Role; |
82
|
|
|
|
|
|
|
1; |