|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Combat; |
|
5
|
|
|
|
|
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
7
|
|
|
use Nexendrie\Utils\Constants; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Skill special |
|
11
|
|
|
* |
|
12
|
|
|
* @author Jakub Konečný |
|
13
|
|
|
*/ |
|
14
|
1 |
|
final class SkillSpecial extends BaseSkill |
|
15
|
|
|
{ |
|
16
|
|
|
public const TYPE_BUFF = "buff"; |
|
17
|
|
|
public const TYPE_DEBUFF = "debuff"; |
|
18
|
|
|
public const TYPE_STUN = "stun"; |
|
19
|
|
|
public const TYPE_POISON = "poison"; |
|
20
|
|
|
public const TYPE_HIDE = "hide"; |
|
21
|
|
|
public const TARGET_SELF = "self"; |
|
22
|
|
|
public const TARGET_ENEMY = "enemy"; |
|
23
|
|
|
public const TARGET_PARTY = "party"; |
|
24
|
|
|
public const TARGET_ENEMY_PARTY = "enemy_party"; |
|
25
|
|
|
/** @var string[] */ |
|
26
|
|
|
public const NO_STAT_TYPES = [self::TYPE_STUN, self::TYPE_POISON, self::TYPE_HIDE,]; |
|
27
|
|
|
|
|
28
|
|
|
public readonly string $type; |
|
29
|
|
|
public readonly ?string $stat; |
|
30
|
|
|
public readonly int $value; |
|
31
|
|
|
public readonly int $valueGrowth; |
|
32
|
|
|
public readonly int $duration; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct(array $data) |
|
35
|
|
|
{ |
|
36
|
1 |
|
$resolver = new OptionsResolver(); |
|
37
|
1 |
|
$this->configureOptions($resolver); |
|
38
|
1 |
|
$data = $resolver->resolve($data); |
|
39
|
1 |
|
$this->id = $data["id"]; |
|
40
|
1 |
|
$this->name = $data["name"]; |
|
41
|
1 |
|
$this->type = $data["type"]; |
|
42
|
1 |
|
$this->target = $data["target"]; |
|
43
|
1 |
|
$this->stat = $data["stat"]; |
|
44
|
1 |
|
$this->value = $data["value"]; |
|
45
|
1 |
|
$this->valueGrowth = $data["valueGrowth"]; |
|
46
|
1 |
|
$this->levels = $data["levels"]; |
|
47
|
1 |
|
$this->duration = $data["duration"]; |
|
48
|
1 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function configureOptions(OptionsResolver $resolver): void |
|
51
|
|
|
{ |
|
52
|
1 |
|
parent::configureOptions($resolver); |
|
53
|
1 |
|
$allStats = ["type", "stat", "value", "valueGrowth", "duration",]; |
|
54
|
1 |
|
$resolver->setRequired($allStats); |
|
55
|
1 |
|
$resolver->setAllowedTypes("type", "string"); |
|
56
|
1 |
|
$resolver->setAllowedValues("type", function (string $value): bool { |
|
57
|
1 |
|
return in_array($value, $this->getAllowedTypes(), true); |
|
58
|
1 |
|
}); |
|
59
|
1 |
|
$resolver->setAllowedTypes("stat", ["string", "null"]); |
|
60
|
1 |
|
$resolver->setAllowedValues("stat", function (?string $value): bool { |
|
61
|
1 |
|
return $value === null || in_array($value, $this->getAllowedStats(), true); |
|
62
|
1 |
|
}); |
|
63
|
1 |
|
$resolver->setAllowedTypes("value", "integer"); |
|
64
|
1 |
|
$resolver->setAllowedValues("value", function (int $value): bool { |
|
65
|
1 |
|
return ($value >= 0); |
|
66
|
1 |
|
}); |
|
67
|
1 |
|
$resolver->setAllowedTypes("valueGrowth", "integer"); |
|
68
|
1 |
|
$resolver->setAllowedValues("valueGrowth", function (int $value): bool { |
|
69
|
1 |
|
return ($value >= 0); |
|
70
|
1 |
|
}); |
|
71
|
1 |
|
$resolver->setAllowedTypes("duration", "integer"); |
|
72
|
1 |
|
$resolver->setAllowedValues("duration", function (int $value): bool { |
|
73
|
1 |
|
return ($value >= 0); |
|
74
|
1 |
|
}); |
|
75
|
1 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
protected function getAllowedTypes(): array |
|
78
|
|
|
{ |
|
79
|
1 |
|
return Constants::getConstantsValues(self::class, "TYPE_"); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function getAllowedStats(): array |
|
83
|
|
|
{ |
|
84
|
1 |
|
return Character::SECONDARY_STATS; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
protected function getCooldown(): int |
|
88
|
|
|
{ |
|
89
|
1 |
|
return 5; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|