File Coverage

blib/lib/Games/Lacuna/Task/Action/VrbanskCombine.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Games::Lacuna::Task::Action::VrbanskCombine;
2              
3 1     1   1567 use 5.010;
  1         4  
  1         56  
4             our $VERSION = $Games::Lacuna::Task::VERSION;
5              
6 1     1   827 use Moose;
  0            
  0            
7             extends qw(Games::Lacuna::Task::Action);
8             with qw(Games::Lacuna::Task::Role::PlanetRun);
9              
10             use Games::Lacuna::Client::Types qw(ore_types);
11              
12             our @RECIPIES = (
13             [qw(goethite halite gypsum trona)],
14             [qw(gold anthracite uraninite bauxite)],
15             [qw(kerogen methane sulfur zircon)],
16             [qw(monazite fluorite beryl magnetite)],
17             [qw(rutile chromite chalcopyrite galena)],
18             );
19              
20             has 'keep_gylphs' => (
21             isa => 'Int',
22             is => 'rw',
23             required => 1,
24             documentation => 'Keep N-gylps in storage (do not combine them) [Default: 5]',
25             default => 5,
26             );
27              
28             sub description {
29             return q[Cobine glyphs to get Halls of Vrbansk plans];
30             }
31              
32             sub process_planet {
33             my ($self,$planet_stats) = @_;
34              
35             # Get archaeology ministry
36             my $archaeology_ministry = $self->find_building($planet_stats->{id},'Archaeology');
37            
38             return
39             unless defined $archaeology_ministry;
40              
41             # Get all glyphs
42             my $archaeology_ministry_object = $self->build_object($archaeology_ministry);
43             my $gylph_data = $self->request(
44             object => $archaeology_ministry_object,
45             method => 'get_glyphs',
46             );
47              
48             my $available_gylphs = { map { $_ => [] } ore_types() };
49            
50             foreach my $glyph (@{$gylph_data->{glyphs}}) {
51             push(@{$available_gylphs->{$glyph->{type}}},$glyph->{id});
52             }
53              
54             # Sutract keep_glyphs
55             foreach my $glyph (keys %$available_gylphs) {
56             for (1..$self->keep_gylphs) {
57             pop(@{$available_gylphs->{$glyph}});
58             }
59             }
60            
61             # Get possible recipies
62             RECIPIES:
63             foreach my $recipie (@RECIPIES) {
64             while (1) {
65             my (@recipie,@recipie_name);
66             foreach my $glyph (@{$recipie}) {
67             next RECIPIES
68             unless scalar @{$available_gylphs->{$glyph}};
69             }
70             foreach my $glyph (@{$recipie}) {
71             push(@recipie_name,$glyph);
72             push(@recipie,pop(@{$available_gylphs->{$glyph}}));
73             }
74            
75             $self->log('notice','Combining glyphs %s',join(', ',@recipie_name));
76            
77             $self->request(
78             object => $archaeology_ministry_object,
79             method => 'assemble_glyphs',
80             params => [\@recipie],
81             );
82             }
83             }
84             }
85              
86             __PACKAGE__->meta->make_immutable;
87             no Moose;
88             1;