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 int |
17
|
|
|
*/ |
18
|
|
|
protected $number; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $name; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $family; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string[] |
32
|
|
|
*/ |
33
|
|
|
protected $types; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
protected $cp; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var int |
42
|
|
|
*/ |
43
|
|
|
protected $hp; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var int |
47
|
|
|
*/ |
48
|
|
|
protected $baseAttack; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
protected $baseDefense; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var int |
57
|
|
|
*/ |
58
|
|
|
protected $baseStamina; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var Collection |
62
|
|
|
*/ |
63
|
|
|
protected $ivCombinaisons; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Pokemon constructor. |
67
|
|
|
* @param int $number |
68
|
|
|
* @param string $name |
69
|
|
|
* @param int $baseAttack |
70
|
|
|
* @param int $baseDefense |
71
|
|
|
* @param int $baseStamina |
72
|
|
|
* @param string[] $types |
73
|
|
|
* @param string $familyId |
74
|
|
|
*/ |
75
|
|
|
public function __construct( |
76
|
|
|
int $number, |
77
|
|
|
string $name, |
78
|
|
|
string $familyId, |
79
|
|
|
int $baseAttack, |
80
|
|
|
int $baseDefense, |
81
|
|
|
int $baseStamina, |
82
|
|
|
array $types |
83
|
|
|
) { |
84
|
|
|
$this->number = $number; |
85
|
|
|
$this->name = $name; |
86
|
|
|
$this->family = $familyId; |
87
|
|
|
$this->baseAttack = $baseAttack; |
88
|
|
|
$this->baseDefense = $baseDefense; |
89
|
|
|
$this->baseStamina = $baseStamina; |
90
|
|
|
$this->types = $types; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Return the minimum of perfection of a Pokemon |
95
|
|
|
* @return IvCombinaison|null |
96
|
|
|
*/ |
97
|
|
|
public function getMinimumCombinaison(): ?IvCombinaison |
98
|
|
|
{ |
99
|
|
|
return $this->getIvCombinaisons() |
100
|
|
|
->sortBy( |
101
|
|
|
function (IvCombinaison $combinaison) { |
102
|
|
|
return $combinaison->getPerfection(); |
103
|
|
|
}) |
104
|
|
|
->last(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Return the maximum of perfection of a Pokemon |
109
|
|
|
* @return IvCombinaison|null |
110
|
|
|
*/ |
111
|
|
|
public function getMaximumCombinaison(): ?IvCombinaison |
112
|
|
|
{ |
113
|
|
|
return $this->getIvCombinaisons() |
114
|
|
|
->sortBy( |
115
|
|
|
function (IvCombinaison $combinaison) { |
116
|
|
|
return $combinaison->getPerfection(); |
117
|
|
|
}) |
118
|
|
|
->first(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Return the average perfection of a Pokemon |
123
|
|
|
* @return float|null |
124
|
|
|
*/ |
125
|
|
|
public function getAveragePerfection(): ?float |
126
|
|
|
{ |
127
|
|
|
return $this->getIvCombinaisons()->average( |
128
|
|
|
function (IvCombinaison $combinaison) { |
129
|
|
|
return $combinaison->getPerfection(); |
130
|
|
|
}); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Return the min attack of a Pokemon |
135
|
|
|
* @return int |
136
|
|
|
*/ |
137
|
|
|
public function getMinAttack(): ?int |
138
|
|
|
{ |
139
|
|
|
return $this->getIvCombinaisons()->min( |
140
|
|
|
function (IvCombinaison $combinaison) { |
141
|
|
|
return $combinaison->getAttack(); |
142
|
|
|
}); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Return the max attack of a Pokemon |
147
|
|
|
* @return int |
148
|
|
|
*/ |
149
|
|
|
public function getMaxAttack(): ?int |
150
|
|
|
{ |
151
|
|
|
return $this->getIvCombinaisons()->max( |
152
|
|
|
function (IvCombinaison $combinaison) { |
153
|
|
|
return $combinaison->getAttack(); |
154
|
|
|
}); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Return the min defense of a Pokemon |
159
|
|
|
* @return int |
160
|
|
|
*/ |
161
|
|
|
public function getMinDefense(): ?int |
162
|
|
|
{ |
163
|
|
|
return $this->getIvCombinaisons()->min( |
164
|
|
|
function (IvCombinaison $combinaison) { |
165
|
|
|
return $combinaison->getDefense(); |
166
|
|
|
}); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Return the max defense of a Pokemon |
171
|
|
|
* @return int |
172
|
|
|
*/ |
173
|
|
|
public function getMaxDefense(): ?int |
174
|
|
|
{ |
175
|
|
|
return $this->getIvCombinaisons()->max( |
176
|
|
|
function (IvCombinaison $combinaison) { |
177
|
|
|
return $combinaison->getDefense(); |
178
|
|
|
}); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Return the min stamina of a Pokemon |
183
|
|
|
* @return int |
184
|
|
|
*/ |
185
|
|
|
public function getMinStamina(): ?int |
186
|
|
|
{ |
187
|
|
|
return $this->getIvCombinaisons()->min( |
188
|
|
|
function (IvCombinaison $combinaison) { |
189
|
|
|
return $combinaison->getStamina(); |
190
|
|
|
}); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Return the max stamina of a Pokemon |
195
|
|
|
* @return int |
196
|
|
|
*/ |
197
|
|
|
public function getMaxStamina(): ?int |
198
|
|
|
{ |
199
|
|
|
return $this->getIvCombinaisons()->max( |
200
|
|
|
function (IvCombinaison $combinaison) { |
201
|
|
|
return $combinaison->getStamina(); |
202
|
|
|
}); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Return the min level of a Pokemon |
207
|
|
|
* @return float |
208
|
|
|
*/ |
209
|
|
|
public function getMinLevel(): ?float |
210
|
|
|
{ |
211
|
|
|
return $this->getIvCombinaisons() |
212
|
|
|
->map(function (IvCombinaison $combinaison) { |
213
|
|
|
return $combinaison->getLevel()->getLevel(); |
214
|
|
|
}) |
215
|
|
|
->sortBy(function ($value) { |
216
|
|
|
return $value; |
217
|
|
|
}) |
218
|
|
|
->first(); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Return the max level of a Pokemon |
223
|
|
|
* @return float |
224
|
|
|
*/ |
225
|
|
|
public function getMaxLevel(): ?float |
226
|
|
|
{ |
227
|
|
|
return $this->getIvCombinaisons() |
228
|
|
|
->map(function (IvCombinaison $combinaison) { |
229
|
|
|
return $combinaison->getLevel()->getLevel(); |
230
|
|
|
}) |
231
|
|
|
->sortBy(function ($value) { |
232
|
|
|
return $value; |
233
|
|
|
}) |
234
|
|
|
->last(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Get ivCombinaisons |
239
|
|
|
* |
240
|
|
|
* @return Collection |
241
|
|
|
*/ |
242
|
|
|
public function getIvCombinaisons(): Collection |
243
|
|
|
{ |
244
|
|
|
return $this->ivCombinaisons; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Set ivCombinaisons |
249
|
|
|
* |
250
|
|
|
* @param Collection $ivCombinaisons |
251
|
|
|
* |
252
|
|
|
* @return Pokemon |
253
|
|
|
*/ |
254
|
|
|
public function setIvCombinaisons(Collection $ivCombinaisons) |
255
|
|
|
{ |
256
|
|
|
$this->ivCombinaisons = $ivCombinaisons; |
257
|
|
|
|
258
|
|
|
return $this; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Get number |
263
|
|
|
* |
264
|
|
|
* @return int |
265
|
|
|
*/ |
266
|
|
|
public function getNumber(): int |
267
|
|
|
{ |
268
|
|
|
return $this->number; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Get name |
273
|
|
|
* |
274
|
|
|
* @return string |
275
|
|
|
*/ |
276
|
|
|
public function getName(): string |
277
|
|
|
{ |
278
|
|
|
return $this->name; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Get family |
283
|
|
|
* |
284
|
|
|
* @return string |
285
|
|
|
*/ |
286
|
|
|
public function getFamily(): string |
287
|
|
|
{ |
288
|
|
|
return $this->family; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Get types |
293
|
|
|
* |
294
|
|
|
* @return \string[] |
295
|
|
|
*/ |
296
|
|
|
public function getTypes(): array |
297
|
|
|
{ |
298
|
|
|
return $this->types; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Get cp |
303
|
|
|
* |
304
|
|
|
* @return int|null |
305
|
|
|
*/ |
306
|
|
|
public function getCp(): ?int |
307
|
|
|
{ |
308
|
|
|
return $this->cp; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Set cp |
313
|
|
|
* |
314
|
|
|
* @param int $cp |
315
|
|
|
* |
316
|
|
|
* @return Pokemon |
317
|
|
|
*/ |
318
|
|
|
public function setCp(int $cp) |
319
|
|
|
{ |
320
|
|
|
$this->cp = $cp; |
321
|
|
|
return $this; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Get hp |
326
|
|
|
* |
327
|
|
|
* @return int|null |
328
|
|
|
*/ |
329
|
|
|
public function getHp(): ?int |
330
|
|
|
{ |
331
|
|
|
return $this->hp; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Set hp |
336
|
|
|
* |
337
|
|
|
* @param int $hp |
338
|
|
|
* |
339
|
|
|
* @return Pokemon |
340
|
|
|
*/ |
341
|
|
|
public function setHp(int $hp) |
342
|
|
|
{ |
343
|
|
|
$this->hp = $hp; |
344
|
|
|
return $this; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Get baseAttack |
349
|
|
|
* |
350
|
|
|
* @return int |
351
|
|
|
*/ |
352
|
|
|
public function getBaseAttack(): int |
353
|
|
|
{ |
354
|
|
|
return $this->baseAttack; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Get baseDefense |
359
|
|
|
* |
360
|
|
|
* @return int |
361
|
|
|
*/ |
362
|
|
|
public function getBaseDefense(): int |
363
|
|
|
{ |
364
|
|
|
return $this->baseDefense; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Get baseStamina |
369
|
|
|
* |
370
|
|
|
* @return int |
371
|
|
|
*/ |
372
|
|
|
public function getBaseStamina(): int |
373
|
|
|
{ |
374
|
|
|
return $this->baseStamina; |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|