line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Role::Waste; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1511
|
use 5.010; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
62
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
652
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use List::Util qw(max sum min); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our %STORAGE_BUILDINGS = ( |
11
|
|
|
|
|
|
|
ore => 'OreStorage', |
12
|
|
|
|
|
|
|
food => 'FoodReserve', |
13
|
|
|
|
|
|
|
water => 'WaterStorage', |
14
|
|
|
|
|
|
|
energy => 'EnergyReserve', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub disposeable_waste { |
18
|
|
|
|
|
|
|
my ($self,$planet_stats) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $recycleable_waste = 0; |
21
|
|
|
|
|
|
|
my $keep_waste_hours = 24; |
22
|
|
|
|
|
|
|
$keep_waste_hours = $self->keep_waste_hours |
23
|
|
|
|
|
|
|
if $self->can('keep_waste_hours'); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Get recycleable waste |
26
|
|
|
|
|
|
|
if ($planet_stats->{waste_hour} > 0) { |
27
|
|
|
|
|
|
|
$recycleable_waste = $planet_stats->{waste_stored}; |
28
|
|
|
|
|
|
|
} else { |
29
|
|
|
|
|
|
|
$recycleable_waste = $planet_stats->{waste_stored} + ($planet_stats->{waste_hour} * $keep_waste_hours) |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return max($recycleable_waste,0); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub convert_waste { |
36
|
|
|
|
|
|
|
my ($self,$planet_stats,$quantity) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my @resources_ordered = sort { $planet_stats->{$b.'_stored'} <=> $planet_stats->{$a.'_stored'} } |
39
|
|
|
|
|
|
|
@Games::Lacuna::Task::Constants::RESOURCES; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# my $resources_total = sum map { $planet_stats->{$_.'_stored'} } @resource_types; |
42
|
|
|
|
|
|
|
# my $resources_avg = $resources_total / scalar @resource_types; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
RESOURCE_TYPE: |
45
|
|
|
|
|
|
|
foreach my $resource_type (@resources_ordered) { |
46
|
|
|
|
|
|
|
my $resource_dump = $quantity; |
47
|
|
|
|
|
|
|
my $resources_stored = $planet_stats->{$resource_type.'_stored'} * 0.9; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $storage_builiding = $self->find_building($planet_stats->{id},$STORAGE_BUILDINGS{$resource_type}); |
50
|
|
|
|
|
|
|
my $storage_builiding_object = $self->build_object($storage_builiding); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my ($resource_subtype,@dump_params); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
if ($resource_type ~~ [qw(food ore)]) { |
55
|
|
|
|
|
|
|
my $response = $self->request( |
56
|
|
|
|
|
|
|
object => $storage_builiding_object, |
57
|
|
|
|
|
|
|
method => 'view', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $resources_sub_stored = $response->{$resource_type.'_stored'}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
($resource_subtype) = |
63
|
|
|
|
|
|
|
sort { $resources_sub_stored->{$b} <=> $resources_sub_stored->{$a} } |
64
|
|
|
|
|
|
|
keys %{$resources_sub_stored}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$resource_dump = min($resources_sub_stored->{$resource_subtype},$resource_dump); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
push(@dump_params,$resource_subtype); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$self->log('notice','Dumping %i %s on %s',$quantity,$resource_subtype,$planet_stats->{name}); |
71
|
|
|
|
|
|
|
} else { |
72
|
|
|
|
|
|
|
$resource_dump = min($resources_stored,$resource_dump); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->log('notice','Dumping %i %s on %s',$quantity,$resource_type,$planet_stats->{name}); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
push(@dump_params,$resource_dump); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->request( |
80
|
|
|
|
|
|
|
object => $storage_builiding_object, |
81
|
|
|
|
|
|
|
method => 'dump', |
82
|
|
|
|
|
|
|
params => \@dump_params, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$quantity -= $resource_dump; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
last RESOURCE_TYPE |
88
|
|
|
|
|
|
|
if $quantity <= 0; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
no Moose::Role; |
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=encoding utf8 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Games::Lacuna::Task::Role::Waste -Â Waste helper methods |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::MyTask; |
104
|
|
|
|
|
|
|
use Moose; |
105
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
106
|
|
|
|
|
|
|
with qw(Games::Lacuna::Task::Role::Waste); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 DESCRIPTION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This role provides helper method to work with waste diposal |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 disposeable_waste |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $quantity = $self->disposeable_waste($planet_stats); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns the amout of waste that is available for disposal |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 convert_waste |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$self->convert_waste($planet_stats,$quantity); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Produces the requested amout of waste by dumping resources from storage |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |