1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Combat; |
5
|
|
|
|
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Data structure for combat action |
10
|
|
|
* |
11
|
|
|
* @author Jakub Konečný |
12
|
|
|
*/ |
13
|
1 |
|
final class CombatLogEntry { |
14
|
|
|
use \Nette\SmartObject; |
15
|
|
|
|
16
|
|
|
/** @internal */ |
17
|
|
|
public const ACTION_POISON = "poison"; |
18
|
|
|
|
19
|
|
|
public readonly Character $character1; |
20
|
|
|
public readonly Character $character2; |
21
|
|
|
public readonly string $action; |
22
|
|
|
public readonly string $name; |
23
|
|
|
public readonly bool $result; |
24
|
|
|
public readonly int $amount; |
25
|
|
|
|
26
|
|
|
public function __construct(array $action) { |
27
|
1 |
|
$resolver = new OptionsResolver(); |
28
|
1 |
|
$this->configureOptions($resolver); |
29
|
1 |
|
$action = $resolver->resolve($action); |
30
|
1 |
|
$this->action = $action["action"]; |
31
|
1 |
|
$this->result = $action["result"]; |
32
|
1 |
|
$this->amount = $action["amount"]; |
33
|
1 |
|
$this->character1 = clone $action["character1"]; |
34
|
1 |
|
$this->character2 = clone $action["character2"]; |
35
|
1 |
|
$this->name = $action["name"]; |
36
|
1 |
|
} |
37
|
|
|
|
38
|
|
|
protected function configureOptions(OptionsResolver $resolver): void { |
39
|
1 |
|
$requiredStats = ["action", "result", "character1", "character2", ]; |
40
|
1 |
|
$resolver->setDefined(["amount", "name", ]); |
41
|
1 |
|
$resolver->setRequired($requiredStats); |
42
|
1 |
|
$resolver->setAllowedTypes("action", "string"); |
43
|
1 |
|
$resolver->setAllowedTypes("result", "bool"); |
44
|
1 |
|
$resolver->setAllowedTypes("amount", "integer"); |
45
|
1 |
|
$resolver->setDefault("amount", 0); |
46
|
1 |
|
$resolver->setAllowedTypes("name", "string"); |
47
|
1 |
|
$resolver->setDefault("name", ""); |
48
|
1 |
|
$resolver->setAllowedTypes("character1", Character::class); |
49
|
1 |
|
$resolver->setAllowedTypes("character2", Character::class); |
50
|
1 |
|
} |
51
|
|
|
} |
52
|
|
|
?> |