1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Combat; |
5
|
|
|
|
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Skill attack |
10
|
|
|
* |
11
|
|
|
* @author Jakub Konečný |
12
|
|
|
*/ |
13
|
1 |
|
final class SkillAttack extends BaseSkill { |
14
|
|
|
public const TARGET_SINGLE = "single"; |
15
|
|
|
public const TARGET_ROW = "row"; |
16
|
|
|
public const TARGET_COLUMN = "column"; |
17
|
|
|
|
18
|
|
|
public readonly string $baseDamage; |
19
|
|
|
public readonly string $damageGrowth; |
20
|
|
|
public readonly int $strikes; |
21
|
|
|
public readonly ?string $hitRate; |
22
|
|
|
|
23
|
|
|
public function __construct(array $data) { |
24
|
1 |
|
$resolver = new OptionsResolver(); |
25
|
1 |
|
$this->configureOptions($resolver); |
26
|
1 |
|
$data = $resolver->resolve($data); |
27
|
1 |
|
$this->id = $data["id"]; |
28
|
1 |
|
$this->name = $data["name"]; |
29
|
1 |
|
$this->baseDamage = $data["baseDamage"]; |
30
|
1 |
|
$this->damageGrowth = $data["damageGrowth"]; |
31
|
1 |
|
$this->levels = $data["levels"]; |
32
|
1 |
|
$this->target = $data["target"]; |
33
|
1 |
|
$this->strikes = $data["strikes"]; |
34
|
1 |
|
$this->hitRate = $data["hitRate"]; |
35
|
1 |
|
} |
36
|
|
|
|
37
|
|
|
protected function configureOptions(OptionsResolver $resolver): void { |
38
|
1 |
|
parent::configureOptions($resolver); |
39
|
1 |
|
$allStats = ["baseDamage", "damageGrowth", "strikes", "hitRate", ]; |
40
|
1 |
|
$resolver->setRequired($allStats); |
41
|
1 |
|
$resolver->setAllowedTypes("baseDamage", "string"); |
42
|
1 |
|
$resolver->setAllowedTypes("damageGrowth", "string"); |
43
|
1 |
|
$resolver->setAllowedTypes("strikes", "integer"); |
44
|
1 |
|
$resolver->setAllowedValues("strikes", function(int $value): bool { |
45
|
1 |
|
return ($value > 0); |
46
|
1 |
|
}); |
47
|
1 |
|
$resolver->setAllowedTypes("hitRate", ["string", "null"]); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
protected function getCooldown(): int { |
51
|
1 |
|
return 3; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
?> |