| 1 | package Data::Pokemon::Go::IV; | ||||||||||
| 2 | 1 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use YAML::XS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use List::Util qw(first); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use File::Share 'dist_dir'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | my $dir = dist_dir('Data-Pokemon-Go'); | |||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 11 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | my $data = YAML::XS::LoadFile("$dir/LV.yaml"); | |||||||||
| 14 | 1 | my %Dust = (); | |||||||||
| 15 | 1 | push @{ $Dust{ $_->{Dust} } }, { LV => $_->{LV}, Candy => $_->{Candy} } foreach @$data; | |||||||||
| 16 | |||||||||||
| 17 | 1242 | ▶ | sub _calculate_CP { | ||||||||
|
Subroutine
_calculate_CP: called CC=7 SCAR=20.6
| |||||||||||
| 18 | 1242 | my $self = shift; | |||||||||
| 19 | 1242 | my %arg = @_; | |||||||||
| 20 | 1242 | ▶ | croak "argument 'name' is required" unless exists $arg{name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 1242 | ▶ | croak "argument 'LV' is required" unless exists $arg{LV}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 1242 | ▶ | croak "argument 'ST' is required" unless exists $arg{ST}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1242 | ▶ | croak "argument 'AT' is required" unless exists $arg{AT}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 1242 | ▶ | croak "argument 'DF' is required" unless exists $arg{DF}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | 1242 | my $pg = Data::Pokemon::Go::Pokemon->new( name => $arg{name} ); | |||||||||
| 27 | 1242 | my $stamina = $pg->stamina() + $arg{ST}; | |||||||||
| 28 | 1242 | my $attack = $pg->attack() + $arg{AT}; | |||||||||
| 29 | 1242 | my $defense = $pg->defense() + $arg{DF}; | |||||||||
| 30 | 1242 | my $CPM = $self->_calculate_CPM( from => $arg{LV} ); | |||||||||
| 31 | 1242 | my $CP = int( sqrt($stamina) * $attack * sqrt($defense) * $CPM ** 2 / 10 ); | |||||||||
| 32 | 1242 | ▶ | return $CP if $CP > 10; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | return 10; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 1242 | ▶ | sub _calculate_CPM { | ||||||||
|
Subroutine
_calculate_CPM: called CC=2 SCAR=7.0
| |||||||||||
| 37 | 1242 | my $self = shift; | |||||||||
| 38 | 1242 | my %arg = @_; | |||||||||
| 39 | 1242 | ▶ | croak "argument 'from' is required" unless exists $arg{from}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1242 | ▶ | my $ref = first{ $_->{LV} == $arg{from} } @$data; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 1242 | return $ref->{CPM}; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub _calculate_HP { | ||||||||
|
Subroutine
_calculate_HP: not called CC=4 SCAR=30.0
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | my %arg = @_; | |||||||||
| 47 | 0 | ▶ | croak "argument 'name' is required" unless exists $arg{name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | ▶ | croak "argument 'LV' is required" unless exists $arg{LV}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | ▶ | croak "argument 'ST' is required" unless exists $arg{ST}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | 0 | my $CPM = $self->_calculate_CPM( from => $arg{LV} ); | |||||||||
| 52 | 0 | my $pg = Data::Pokemon::Go::Pokemon->new( name => $arg{name} ); | |||||||||
| 53 | 0 | return int ( ( $pg->stamina() + $arg{ST} ) * $CPM ); | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub _guess_LV { | ||||||||
|
Subroutine
_guess_LV: not called CC=6 SCAR=37.4
| |||||||||||
| 57 | 0 | my $self = shift; | |||||||||
| 58 | 0 | my %arg = @_; | |||||||||
| 59 | 0 | ▶ | croak "argument 'name' is required" unless exists $arg{name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | ▶ | croak "argument 'HP' is required" unless exists $arg{HP}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | ▶ | croak "argument 'ST' is required" unless exists $arg{ST}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | 0 | my $pg = Data::Pokemon::Go::Pokemon->new( name => $arg{name} ); | |||||||||
| 64 | 0 | my @LV = (); | |||||||||
| 65 | 0 | ▶ | for( my $i = 1.0; $i <= 40.5; $i += 0.5 ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | ▶ | push @LV, $i if $self->_calculate_HP( @_, LV => $i ) == $arg{HP}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | } | ||||||||||
| 68 | 0 | return @LV; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | sub _guess_ST { | ||||||||
|
Subroutine
_guess_ST: not called CC=5 SCAR=34.0
| |||||||||||
| 72 | 0 | my $self = shift; | |||||||||
| 73 | 0 | my %arg = @_; | |||||||||
| 74 | 0 | ▶ | croak "argument 'name' is required" unless exists $arg{name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 0 | ▶ | croak "argument 'HP' is required" unless exists $arg{HP}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | my $ST = 0; | |||||||||
| 77 | 0 | ▶ | for( my $i = 0; $i <= 15; $i++ ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | ▶ | return $i if $self->_guess_LV( @_, ST => $i ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | } | ||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 1 | 1; | |||||||||
| 83 | __END__ | ||||||||||