Lines
100.00%
13 / 13
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AttackMonsterCommand | 100.00% | 13 / 13 | 100.00% | 5 / 5 | 12 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 7 | |||||
| target | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| with | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| at | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | |||||
| toMessage | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Client\Command\Combat; | |
| 6 | ||
| 7 | use InvalidArgumentException; | |
| 8 | use Lorekeeper\Core\Game\Combat\Traits\Targetable; | |
| 9 | use Lorekeeper\Core\Item\Equipment\CharacterClass\Skill\SkillSlot; | |
| 10 | use Lorekeeper\Core\World\Monster\MonsterSpawnId; | |
| 11 | use Lorekeeper\Server\AreaId; | |
| 12 | use Override; | |
| 13 | ||
| 14 | final readonly class AttackMonsterCommand implements Attack | |
| 15 | { | |
| 16 | private string $code; | |
| 17 | ||
| 18 | /** @throws InvalidArgumentException */ | |
| 19 | public function __construct( | |
| 20 | private AreaId $area, | |
| 21 | private SkillSlot $skill, | |
| 22 | private MonsterSpawnId $monster, | |
| 23 | ) { | |
| 24 | $this->code = match ($skill) { | |
| 25 | SkillSlot::AutoAttack => 'aa', | |
| 26 | SkillSlot::First => 'a1', | |
| 27 | SkillSlot::Second => 'a2', | |
| 28 | SkillSlot::Third => 'a3', | |
| 29 | SkillSlot::Fourth => 'a4', | |
| 30 | SkillSlot::Potion => throw new InvalidArgumentException('A potion is not an attack.'), | |
| 31 | }; | |
| 32 | } | |
| 33 | ||
| 34 | #[Override] | |
| 35 | public function target(): MonsterSpawnId | |
| 36 | { | |
| 37 | return $this->monster; | |
| 38 | } | |
| 39 | ||
| 40 | #[Override] | |
| 41 | public function with(SkillSlot $skill): static | |
| 42 | { | |
| 43 | return new static($this->area, $skill, $this->monster); | |
| 44 | } | |
| 45 | ||
| 46 | #[Override] | |
| 47 | public function at(Targetable $target): static | |
| 48 | { | |
| 49 | if (!$target instanceof MonsterSpawnId) { | |
| 50 | throw new InvalidArgumentException('A monster attack can only aim at a monster.'); | |
| 51 | } | |
| 52 | ||
| 53 | return new static($this->area, $this->skill, $target); | |
| 54 | } | |
| 55 | ||
| 56 | #[Override] | |
| 57 | public function toMessage(): string | |
| 58 | { | |
| 59 | return "%xt%zm%gar%{$this->area}%0%{$this->code}>m:{$this->monster}%wvz%"; | |
| 60 | } | |
| 61 | } |