Issues (30)

src/CombatActions/SkillSpecial.php (2 issues)

Severity
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
  public const ACTION_NAME = "skill_special";
16
17
  public function getName(): string {
18 1
    return self::ACTION_NAME;
19
  }
20
21
  public function getPriority(): int {
22 1
    return 1000;
23
  }
24
25
  public function shouldUse(CombatBase $combat, Character $character): bool {
26
    $attackTarget = $combat->selectAttackTarget($character);
27
    if($attackTarget === null) {
28
      return false;
29
    }
30
    if(count($character->usableSkills) < 1) {
31
      return false;
32
    }
33
    return ($character->usableSkills[0] instanceof CharacterSpecialSkill);
34
  }
35
36
  protected function doSingleTarget(Character $character1, Character $target, CharacterSpecialSkill $skill, CombatBase $combat): void {
0 ignored issues
show
Line exceeds 120 characters; contains 135 characters
Loading history...
37 1
    $result = [
38 1
      "result" => true, "amount" => 0, "action" => $this->getName(), "name" => $skill->skill->name,
39 1
      "character1" => $character1, "character2" => $target,
40
    ];
41 1
    $effect = new CharacterEffect([
42 1
      "id" => "skill{$skill->skill->id}Effect",
43 1
      "type" => $skill->skill->type,
44 1
      "stat" => ((in_array($skill->skill->type, Skill::NO_STAT_TYPES, true)) ? null : $skill->skill->stat),
45 1
      "value" => $skill->value,
46
      "valueAbsolute" => false,
47 1
      "duration" => $skill->skill->duration,
48
    ]);
49 1
    $target->effects[] = $effect;
50 1
    $combat->log->log($result);
51 1
    $skill->resetCooldown();
52 1
  }
53
54
  /**
55
   * @throws NotImplementedException
56
   */
57
  public function do(CombatBase $combat, Character $character): void {
58
    /** @var CharacterSpecialSkill $skill */
59 1
    $skill = $character->usableSkills[0];
60 1
    $targets = match($skill->skill->target) {
61
      Skill::TARGET_ENEMY => [$combat->selectAttackTarget($character)],
62 1
      Skill::TARGET_SELF => [$character],
63
      Skill::TARGET_PARTY => $combat->getTeam($character)->toArray(),
64
      Skill::TARGET_ENEMY_PARTY => $combat->getEnemyTeam($character)->toArray(),
65
      default => throw new NotImplementedException("Target {$skill->skill->target} for special skills is not implemented."),
0 ignored issues
show
Line exceeds 120 characters; contains 124 characters
Loading history...
66
    };
67 1
    foreach($targets as $target) {
68 1
      $this->doSingleTarget($character, $target, $skill, $combat);
69
    }
70 1
  }
71
}
72
?>