|
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 Illuminate\Support\Collection; |
|
12
|
|
|
|
|
13
|
|
|
class Pokemon |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $name; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var int |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $cp; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var int |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $hp; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var int |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $baseAttack; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var int |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $baseDefense; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var int |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $baseStamina; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var Collection |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $ivCombinaisons; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Pokemon constructor. |
|
52
|
|
|
* @param string $name |
|
53
|
|
|
* @param int $baseAttack |
|
54
|
|
|
* @param int $baseDefense |
|
55
|
|
|
* @param int $baseStamina |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct( |
|
58
|
|
|
string $name, |
|
59
|
|
|
int $baseAttack, |
|
60
|
|
|
int $baseDefense, |
|
61
|
|
|
int $baseStamina |
|
62
|
|
|
) { |
|
63
|
|
|
$this->name = $name; |
|
64
|
|
|
$this->baseAttack = $baseAttack; |
|
65
|
|
|
$this->baseDefense = $baseDefense; |
|
66
|
|
|
$this->baseStamina = $baseStamina; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Return the minimum of perfection of a Pokemon |
|
71
|
|
|
* @return IvCombinaison|null |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getMinimumCombinaison(): ?IvCombinaison |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->getIvCombinaisons() |
|
76
|
|
|
->sortBy( |
|
77
|
|
|
function (IvCombinaison $combinaison) { |
|
78
|
|
|
return $combinaison->getPerfection(); |
|
79
|
|
|
}) |
|
80
|
|
|
->last(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Return the maximum of perfection of a Pokemon |
|
85
|
|
|
* @return IvCombinaison|null |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getMaximumCombinaison(): ?IvCombinaison |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->getIvCombinaisons() |
|
90
|
|
|
->sortBy( |
|
91
|
|
|
function (IvCombinaison $combinaison) { |
|
92
|
|
|
return $combinaison->getPerfection(); |
|
93
|
|
|
}) |
|
94
|
|
|
->first(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Return the average perfection of a Pokemon |
|
99
|
|
|
* @return float|null |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getAveragePerfection(): ?float |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->getIvCombinaisons()->average( |
|
104
|
|
|
function (IvCombinaison $combinaison) { |
|
105
|
|
|
return $combinaison->getPerfection(); |
|
106
|
|
|
}); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Return the min attack of a Pokemon |
|
111
|
|
|
* @return int |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getMinAttack(): ?int |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->getIvCombinaisons()->min( |
|
116
|
|
|
function (IvCombinaison $combinaison) { |
|
117
|
|
|
return $combinaison->getAttack(); |
|
118
|
|
|
}); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Return the max attack of a Pokemon |
|
123
|
|
|
* @return int |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getMaxAttack(): ?int |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->getIvCombinaisons()->max( |
|
128
|
|
|
function (IvCombinaison $combinaison) { |
|
129
|
|
|
return $combinaison->getAttack(); |
|
130
|
|
|
}); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Return the min defense of a Pokemon |
|
135
|
|
|
* @return int |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getMinDefense(): ?int |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->getIvCombinaisons()->min( |
|
140
|
|
|
function (IvCombinaison $combinaison) { |
|
141
|
|
|
return $combinaison->getDefense(); |
|
142
|
|
|
}); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Return the max defense of a Pokemon |
|
147
|
|
|
* @return int |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getMaxDefense(): ?int |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->getIvCombinaisons()->max( |
|
152
|
|
|
function (IvCombinaison $combinaison) { |
|
153
|
|
|
return $combinaison->getDefense(); |
|
154
|
|
|
}); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Return the min stamina of a Pokemon |
|
159
|
|
|
* @return int |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getMinStamina(): ?int |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->getIvCombinaisons()->min( |
|
164
|
|
|
function (IvCombinaison $combinaison) { |
|
165
|
|
|
return $combinaison->getStamina(); |
|
166
|
|
|
}); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Return the max stamina of a Pokemon |
|
171
|
|
|
* @return int |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getMaxStamina(): ?int |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->getIvCombinaisons()->max( |
|
176
|
|
|
function (IvCombinaison $combinaison) { |
|
177
|
|
|
return $combinaison->getStamina(); |
|
178
|
|
|
}); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Get ivCombinaisons |
|
183
|
|
|
* |
|
184
|
|
|
* @return Collection |
|
185
|
|
|
*/ |
|
186
|
|
|
public function getIvCombinaisons(): Collection |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->ivCombinaisons; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Set ivCombinaisons |
|
193
|
|
|
* |
|
194
|
|
|
* @param Collection $ivCombinaisons |
|
195
|
|
|
* |
|
196
|
|
|
* @return Pokemon |
|
197
|
|
|
*/ |
|
198
|
|
|
public function setIvCombinaisons(Collection $ivCombinaisons) |
|
199
|
|
|
{ |
|
200
|
|
|
$this->ivCombinaisons = $ivCombinaisons; |
|
201
|
|
|
|
|
202
|
|
|
return $this; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Get name |
|
207
|
|
|
* |
|
208
|
|
|
* @return string |
|
209
|
|
|
*/ |
|
210
|
|
|
public function getName(): string |
|
211
|
|
|
{ |
|
212
|
|
|
return $this->name; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Get cp |
|
217
|
|
|
* |
|
218
|
|
|
* @return int|null |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getCp(): ?int |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->cp; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Set cp |
|
227
|
|
|
* |
|
228
|
|
|
* @param int $cp |
|
229
|
|
|
* |
|
230
|
|
|
* @return Pokemon |
|
231
|
|
|
*/ |
|
232
|
|
|
public function setCp(int $cp) |
|
233
|
|
|
{ |
|
234
|
|
|
$this->cp = $cp; |
|
235
|
|
|
return $this; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Get hp |
|
240
|
|
|
* |
|
241
|
|
|
* @return int|null |
|
242
|
|
|
*/ |
|
243
|
|
|
public function getHp(): ?int |
|
244
|
|
|
{ |
|
245
|
|
|
return $this->hp; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Set hp |
|
250
|
|
|
* |
|
251
|
|
|
* @param int $hp |
|
252
|
|
|
* |
|
253
|
|
|
* @return Pokemon |
|
254
|
|
|
*/ |
|
255
|
|
|
public function setHp(int $hp) |
|
256
|
|
|
{ |
|
257
|
|
|
$this->hp = $hp; |
|
258
|
|
|
return $this; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Get baseAttack |
|
263
|
|
|
* |
|
264
|
|
|
* @return int |
|
265
|
|
|
*/ |
|
266
|
|
|
public function getBaseAttack(): int |
|
267
|
|
|
{ |
|
268
|
|
|
return $this->baseAttack; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Get baseDefense |
|
273
|
|
|
* |
|
274
|
|
|
* @return int |
|
275
|
|
|
*/ |
|
276
|
|
|
public function getBaseDefense(): int |
|
277
|
|
|
{ |
|
278
|
|
|
return $this->baseDefense; |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
/** |
|
282
|
|
|
* Get baseStamina |
|
283
|
|
|
* |
|
284
|
|
|
* @return int |
|
285
|
|
|
*/ |
|
286
|
|
|
public function getBaseStamina(): int |
|
287
|
|
|
{ |
|
288
|
|
|
return $this->baseStamina; |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
|