|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Combat; |
|
5
|
|
|
|
|
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver, |
|
7
|
|
|
Nexendrie\Utils\Constants; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Skill special |
|
11
|
|
|
* |
|
12
|
|
|
* @author Jakub Konečný |
|
13
|
|
|
* @property-read string $type |
|
14
|
|
|
* @property-read string|NULL $stat |
|
15
|
|
|
* @property-read int $value |
|
16
|
|
|
* @property-read int $valueGrowth |
|
17
|
|
|
* @property-read int $duration |
|
18
|
|
|
*/ |
|
19
|
1 |
|
class SkillSpecial extends BaseSkill { |
|
20
|
|
|
public const TYPE_BUFF = "buff"; |
|
21
|
|
|
public const TYPE_DEBUFF = "debuff"; |
|
22
|
|
|
public const TYPE_STUN = "stun"; |
|
23
|
|
|
public const TYPE_POISON = "poison"; |
|
24
|
|
|
public const TARGET_SELF = "self"; |
|
25
|
|
|
public const TARGET_ENEMY = "enemy"; |
|
26
|
|
|
public const TARGET_PARTY = "party"; |
|
27
|
|
|
public const TARGET_ENEMY_PARTY = "enemy_party"; |
|
28
|
|
|
public const STAT_HITPOINTS = "maxHitpoints"; |
|
29
|
|
|
public const STAT_DAMAGE = "damage"; |
|
30
|
|
|
public const STAT_DEFENSE = "defense"; |
|
31
|
|
|
public const STAT_HIT = "hit"; |
|
32
|
|
|
public const STAT_DODGE = "dodge"; |
|
33
|
|
|
public const STAT_INITIATIVE = "initiative"; |
|
34
|
|
|
/** @var string[] */ |
|
35
|
|
|
public const NO_STAT_TYPES = [self::TYPE_STUN, self::TYPE_POISON,]; |
|
36
|
|
|
|
|
37
|
|
|
/** @var string */ |
|
38
|
|
|
protected $type; |
|
39
|
|
|
/** @var string|NULL */ |
|
40
|
|
|
protected $stat; |
|
41
|
|
|
/** @var int */ |
|
42
|
|
|
protected $value; |
|
43
|
|
|
/** @var int */ |
|
44
|
|
|
protected $valueGrowth; |
|
45
|
|
|
/** @var int */ |
|
46
|
|
|
protected $duration; |
|
47
|
|
|
|
|
48
|
|
|
public function __construct(array $data) { |
|
49
|
1 |
|
$resolver = new OptionsResolver(); |
|
50
|
1 |
|
$this->configureOptions($resolver); |
|
51
|
1 |
|
$data = $resolver->resolve($data); |
|
52
|
1 |
|
$this->id = $data["id"]; |
|
53
|
1 |
|
$this->name = $data["name"]; |
|
54
|
1 |
|
$this->description = $data["description"]; |
|
55
|
1 |
|
$this->neededClass = $data["neededClass"]; |
|
56
|
1 |
|
$this->neededSpecialization = $data["neededSpecialization"]; |
|
57
|
1 |
|
$this->neededLevel = $data["neededLevel"]; |
|
58
|
1 |
|
$this->type = $data["type"]; |
|
59
|
1 |
|
$this->target = $data["target"]; |
|
60
|
1 |
|
$this->stat = $data["stat"]; |
|
61
|
1 |
|
$this->value = $data["value"]; |
|
62
|
1 |
|
$this->valueGrowth = $data["valueGrowth"]; |
|
63
|
1 |
|
$this->levels = $data["levels"]; |
|
64
|
1 |
|
$this->duration = $data["duration"]; |
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function configureOptions(OptionsResolver $resolver): void { |
|
68
|
1 |
|
parent::configureOptions($resolver); |
|
69
|
1 |
|
$allStats = ["type", "stat", "value", "valueGrowth", "duration",]; |
|
70
|
1 |
|
$resolver->setRequired($allStats); |
|
71
|
1 |
|
$resolver->setAllowedTypes("type", "string"); |
|
72
|
1 |
|
$resolver->setAllowedValues("type", function(string $value) { |
|
73
|
1 |
|
return in_array($value, $this->getAllowedTypes(), true); |
|
74
|
1 |
|
}); |
|
75
|
1 |
|
$resolver->setAllowedTypes("stat", ["string", "null"]); |
|
76
|
1 |
|
$resolver->setAllowedValues("stat", function(?string $value) { |
|
77
|
1 |
|
return is_null($value) OR in_array($value, $this->getAllowedStats(), true); |
|
78
|
1 |
|
}); |
|
79
|
1 |
|
$resolver->setAllowedTypes("value", "integer"); |
|
80
|
1 |
|
$resolver->setAllowedValues("value", function(int $value) { |
|
81
|
1 |
|
return ($value >= 0); |
|
82
|
1 |
|
}); |
|
83
|
1 |
|
$resolver->setAllowedTypes("valueGrowth", "integer"); |
|
84
|
1 |
|
$resolver->setAllowedValues("valueGrowth", function(int $value) { |
|
85
|
1 |
|
return ($value >= 0); |
|
86
|
1 |
|
}); |
|
87
|
1 |
|
$resolver->setAllowedTypes("duration", "integer"); |
|
88
|
1 |
|
$resolver->setAllowedValues("duration", function(int $value) { |
|
89
|
1 |
|
return ($value >= 0); |
|
90
|
1 |
|
}); |
|
91
|
1 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function getAllowedTypes(): array { |
|
94
|
1 |
|
return Constants::getConstantsValues(static::class, "TYPE_"); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
protected function getAllowedStats(): array { |
|
98
|
1 |
|
return Constants::getConstantsValues(static::class, "STAT_"); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function getCooldown(): int { |
|
102
|
1 |
|
return 5; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getType(): string { |
|
106
|
1 |
|
return $this->type; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getStat(): ?string { |
|
110
|
1 |
|
return $this->stat; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function getValue(): int { |
|
114
|
1 |
|
return $this->value; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getValueGrowth(): int { |
|
118
|
1 |
|
return $this->valueGrowth; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function getDuration(): int { |
|
122
|
1 |
|
return $this->duration; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
?> |