heroesofabenez /
combat
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | |||
| 4 | namespace HeroesofAbenez\Combat\CombatActions; |
||
| 5 | |||
| 6 | use HeroesofAbenez\Combat\Character; |
||
| 7 | use HeroesofAbenez\Combat\CombatBase; |
||
| 8 | use HeroesofAbenez\Combat\CharacterSpecialSkill; |
||
| 9 | use HeroesofAbenez\Combat\ICombatAction; |
||
| 10 | use HeroesofAbenez\Combat\SkillSpecial as Skill; |
||
| 11 | use HeroesofAbenez\Combat\NotImplementedException; |
||
| 12 | use HeroesofAbenez\Combat\CharacterEffect; |
||
| 13 | |||
| 14 | 1 | final class SkillSpecial implements ICombatAction |
|
| 15 | { |
||
| 16 | public const ACTION_NAME = "skill_special"; |
||
| 17 | |||
| 18 | public function getName(): string |
||
| 19 | { |
||
| 20 | 1 | return self::ACTION_NAME; |
|
| 21 | } |
||
| 22 | |||
| 23 | public function getPriority(): int |
||
| 24 | { |
||
| 25 | 1 | return 1000; |
|
| 26 | } |
||
| 27 | |||
| 28 | public function shouldUse(CombatBase $combat, Character $character): bool |
||
| 29 | { |
||
| 30 | $attackTarget = $combat->selectAttackTarget($character); |
||
| 31 | if ($attackTarget === null) { |
||
| 32 | return false; |
||
| 33 | } |
||
| 34 | if (count($character->usableSkills) < 1) { |
||
| 35 | return false; |
||
| 36 | } |
||
| 37 | return ($character->usableSkills[0] instanceof CharacterSpecialSkill); |
||
| 38 | } |
||
| 39 | |||
| 40 | private function doSingleTarget( |
||
| 41 | Character $character1, |
||
| 42 | Character $target, |
||
| 43 | CharacterSpecialSkill $skill, |
||
| 44 | CombatBase $combat |
||
| 45 | ): void { |
||
| 46 | 1 | $result = [ |
|
| 47 | 1 | "result" => true, "amount" => 0, "action" => $this->getName(), "name" => $skill->skill->name, |
|
| 48 | 1 | "character1" => $character1, "character2" => $target, |
|
| 49 | ]; |
||
| 50 | 1 | $effect = new CharacterEffect([ |
|
| 51 | 1 | "id" => "skill{$skill->skill->id}Effect", |
|
| 52 | 1 | "type" => $skill->skill->type, |
|
| 53 | 1 | "stat" => ((in_array($skill->skill->type, Skill::NO_STAT_TYPES, true)) ? null : $skill->skill->stat), |
|
| 54 | 1 | "value" => $skill->value, |
|
| 55 | "valueAbsolute" => false, |
||
| 56 | 1 | "duration" => $skill->skill->duration, |
|
| 57 | ]); |
||
| 58 | 1 | $target->effects[] = $effect; |
|
| 59 | 1 | $combat->log->log($result); |
|
| 60 | 1 | $skill->resetCooldown(); |
|
| 61 | 1 | } |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @throws NotImplementedException |
||
| 65 | */ |
||
| 66 | public function do(CombatBase $combat, Character $character): void |
||
| 67 | { |
||
| 68 | /** @var CharacterSpecialSkill $skill */ |
||
| 69 | 1 | $skill = $character->usableSkills[0]; |
|
| 70 | 1 | $targets = match ($skill->skill->target) { |
|
| 71 | Skill::TARGET_ENEMY => [$combat->selectAttackTarget($character)], |
||
| 72 | 1 | Skill::TARGET_SELF => [$character], |
|
| 73 | Skill::TARGET_PARTY => $combat->getTeam($character)->toArray(), |
||
| 74 | Skill::TARGET_ENEMY_PARTY => $combat->getEnemyTeam($character)->toArray(), |
||
| 75 | default => throw new NotImplementedException("Target {$skill->skill->target} for special skills is not implemented."), |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 76 | }; |
||
| 77 | 1 | foreach ($targets as $target) { |
|
| 78 | 1 | $this->doSingleTarget($character, $target, $skill, $combat); |
|
| 79 | } |
||
| 80 | 1 | } |
|
| 81 | } |
||
| 82 |