1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Combat; |
5
|
|
|
|
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Pet |
10
|
|
|
* |
11
|
|
|
* @author Jakub Konečný |
12
|
|
|
*/ |
13
|
1 |
|
final class Pet implements ICharacterEffectsProvider { |
14
|
|
|
use \Nette\SmartObject; |
15
|
|
|
|
16
|
|
|
public readonly int $id; |
17
|
|
|
public bool $deployed; |
18
|
|
|
public readonly string $bonusStat; |
19
|
|
|
public readonly int $bonusValue; |
20
|
|
|
|
21
|
|
|
public function __construct(array $data) { |
22
|
1 |
|
$resolver = new OptionsResolver(); |
23
|
1 |
|
$this->configureOptions($resolver); |
24
|
1 |
|
$data = $resolver->resolve($data); |
25
|
1 |
|
$this->id = $data["id"]; |
26
|
1 |
|
$this->deployed = $data["deployed"]; |
27
|
1 |
|
$this->bonusStat = $data["bonusStat"]; |
28
|
1 |
|
$this->bonusValue = $data["bonusValue"]; |
29
|
1 |
|
} |
30
|
|
|
|
31
|
|
|
protected function configureOptions(OptionsResolver $resolver): void { |
32
|
1 |
|
$allStats = ["id", "deployed", "bonusStat", "bonusValue", ]; |
33
|
1 |
|
$resolver->setRequired($allStats); |
34
|
1 |
|
$resolver->setAllowedTypes("id", "integer"); |
35
|
1 |
|
$resolver->setAllowedTypes("deployed", "boolean"); |
36
|
1 |
|
$resolver->setAllowedTypes("bonusStat", "string"); |
37
|
1 |
|
$resolver->setAllowedValues("bonusStat", function(string $value): bool { |
38
|
1 |
|
return in_array($value, $this->getAllowedStats(), true); |
39
|
1 |
|
}); |
40
|
1 |
|
$resolver->setAllowedTypes("bonusValue", "integer"); |
41
|
1 |
|
$resolver->setAllowedValues("bonusValue", function(int $value): bool { |
42
|
1 |
|
return ($value >= 0); |
43
|
1 |
|
}); |
44
|
1 |
|
} |
45
|
|
|
|
46
|
|
|
protected function getAllowedStats(): array { |
47
|
1 |
|
return Character::BASE_STATS; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function getDeployParams(): array { |
51
|
|
|
return [ |
52
|
1 |
|
"id" => "pet" . $this->id . "bonusEffect", |
53
|
1 |
|
"type" => SkillSpecial::TYPE_BUFF, |
54
|
1 |
|
"stat" => $this->bonusStat, |
55
|
1 |
|
"value" => $this->bonusValue, |
56
|
|
|
"valueAbsolute" => false, |
57
|
1 |
|
"duration" => CharacterEffect::DURATION_COMBAT, |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getCombatEffects(): array { |
62
|
1 |
|
if(!$this->deployed) { |
63
|
1 |
|
return []; |
64
|
|
|
} |
65
|
1 |
|
return [new CharacterEffect($this->getDeployParams())]; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
?> |