heroesofabenez /
combat
| 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 string TYPE_BUFF = "buff"; |
||
| 17 | public const string TYPE_DEBUFF = "debuff"; |
||
| 18 | public const string TYPE_STUN = "stun"; |
||
| 19 | public const string TYPE_POISON = "poison"; |
||
| 20 | public const string TYPE_HIDE = "hide"; |
||
| 21 | public const string TARGET_SELF = "self"; |
||
| 22 | public const string TARGET_ENEMY = "enemy"; |
||
| 23 | public const string TARGET_PARTY = "party"; |
||
| 24 | public const string TARGET_ENEMY_PARTY = "enemy_party"; |
||
| 25 | /** @var string[] */ |
||
| 26 | public const array 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( |
|
| 57 | 1 | "type", |
|
| 58 | 1 | static fn(string $value): bool => in_array($value, Constants::getConstantsValues(self::class, "TYPE_"), true) |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 59 | 1 | ); |
|
| 60 | 1 | $resolver->setAllowedTypes("stat", ["string", "null"]); |
|
| 61 | 1 | $resolver->setAllowedValues( |
|
| 62 | 1 | "stat", |
|
| 63 | 1 | static fn(?string $value): bool => $value === null || in_array($value, Character::SECONDARY_STATS, true) |
|
| 64 | 1 | ); |
|
| 65 | 1 | $resolver->setAllowedTypes("value", "integer"); |
|
| 66 | 1 | $resolver->setAllowedValues("value", static fn(int $value): bool => ($value >= 0)); |
|
| 67 | 1 | $resolver->setAllowedTypes("valueGrowth", "integer"); |
|
| 68 | 1 | $resolver->setAllowedValues("valueGrowth", static fn(int $value): bool => ($value >= 0)); |
|
| 69 | 1 | $resolver->setAllowedTypes("duration", "integer"); |
|
| 70 | 1 | $resolver->setAllowedValues("duration", static fn(int $value): bool => ($value >= 0)); |
|
| 71 | 1 | } |
|
| 72 | |||
| 73 | protected function getCooldown(): int |
||
| 74 | { |
||
| 75 | 1 | return 5; |
|
| 76 | } |
||
| 77 | } |
||
| 78 |