1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Jérémy Marodon <[email protected]> |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Th3Mouk\PokemonGoIVCalculator\Entities; |
10
|
|
|
|
11
|
|
|
use Th3Mouk\PokemonGoIVCalculator\Exceptions\AbbreviationNotExists; |
12
|
|
|
|
13
|
|
|
class IvCombinaison |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var Level |
17
|
|
|
*/ |
18
|
|
|
protected $level; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
protected $attack; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
protected $defense; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $stamina; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* IvCombinaison constructor. |
37
|
|
|
* @param Level $level |
38
|
|
|
* @param int $attack |
39
|
|
|
* @param int $defense |
40
|
|
|
* @param int $stamina |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
Level $level, |
44
|
|
|
int $attack, |
45
|
|
|
int $defense, |
46
|
|
|
int $stamina |
47
|
|
|
) { |
48
|
|
|
$this->level = $level; |
49
|
|
|
$this->attack = $attack; |
50
|
|
|
$this->defense = $defense; |
51
|
|
|
$this->stamina = $stamina; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get level |
56
|
|
|
* |
57
|
|
|
* @return Level |
58
|
|
|
*/ |
59
|
|
|
public function getLevel(): Level |
60
|
|
|
{ |
61
|
|
|
return $this->level; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get attack |
66
|
|
|
* |
67
|
|
|
* @return int |
68
|
|
|
*/ |
69
|
|
|
public function getAttack(): int |
70
|
|
|
{ |
71
|
|
|
return $this->attack; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get defense |
76
|
|
|
* |
77
|
|
|
* @return int |
78
|
|
|
*/ |
79
|
|
|
public function getDefense(): int |
80
|
|
|
{ |
81
|
|
|
return $this->defense; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get stamina |
86
|
|
|
* |
87
|
|
|
* @return int |
88
|
|
|
*/ |
89
|
|
|
public function getStamina(): int |
90
|
|
|
{ |
91
|
|
|
return $this->stamina; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param $abbr |
96
|
|
|
* @throws AbbreviationNotExists |
97
|
|
|
* @return int |
98
|
|
|
*/ |
99
|
|
|
public function getAbbreviated($abbr): int |
100
|
|
|
{ |
101
|
|
|
switch ($abbr) { |
102
|
|
|
case 'atk': |
103
|
|
|
return $this->getAttack(); |
104
|
|
|
case 'def': |
105
|
|
|
return $this->getDefense(); |
106
|
|
|
case 'hp': |
107
|
|
|
return $this->getStamina(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Return the minimal iv stat |
113
|
|
|
* @return int |
114
|
|
|
*/ |
115
|
|
|
public function getMaximalIv(): int |
116
|
|
|
{ |
117
|
|
|
return max($this->attack, $this->defense, $this->stamina); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Return the maximal iv stat |
122
|
|
|
* @return int |
123
|
|
|
*/ |
124
|
|
|
public function getMinimalIv(): int |
125
|
|
|
{ |
126
|
|
|
return min($this->attack, $this->defense, $this->stamina); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Return the total of iv stats |
131
|
|
|
* @return int |
132
|
|
|
*/ |
133
|
|
|
public function getTotal(): int |
134
|
|
|
{ |
135
|
|
|
return |
136
|
|
|
$this->getAttack() + |
137
|
|
|
$this->getDefense() + |
138
|
|
|
$this->getStamina(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get the average perfection of the combinaison |
143
|
|
|
* @return float |
144
|
|
|
*/ |
145
|
|
|
public function getPerfection(): float |
146
|
|
|
{ |
147
|
|
|
return round($this->getTotal() / 45, 3) * 100; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|