Lines
100.00%
7 / 7
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| FightToLevel | 100.00% | 7 / 7 | 100.00% | 3 / 3 | 5 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| describe | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| play | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Bot\Steps\Fights; | |
| 6 | ||
| 7 | use Generator; | |
| 8 | use Lorekeeper\Bot\Steps\Action; | |
| 9 | use Lorekeeper\Bot\Steps\StepScript; | |
| 10 | use Lorekeeper\Core\Player\PlayerLevel; | |
| 11 | use Lorekeeper\Core\World\Map\MapSpot; | |
| 12 | use Lorekeeper\Core\World\Monster\MonsterName; | |
| 13 | use Override; | |
| 14 | ||
| 15 | final readonly class FightToLevel implements Action | |
| 16 | { | |
| 17 | public function __construct( | |
| 18 | public MapSpot $spot, | |
| 19 | public ?MonsterName $monster, | |
| 20 | public PlayerLevel $level, | |
| 21 | ) {} | |
| 22 | ||
| 23 | #[Override] | |
| 24 | public function describe(): string | |
| 25 | { | |
| 26 | $who = $this->monster === null ? '' : " {$this->monster->value}"; | |
| 27 | ||
| 28 | return "Fight{$who} in {$this->spot->cell->value} until level {$this->level->value}"; | |
| 29 | } | |
| 30 | ||
| 31 | #[Override] | |
| 32 | public function play(StepScript $bot): Generator | |
| 33 | { | |
| 34 | $reached = fn(): bool => $bot->me()->hero()->level->value >= $this->level->value; | |
| 35 | if (!$reached()) { | |
| 36 | yield from $bot->kill($this->spot, $bot->attackIn($this->spot->cell, $this->monster), $reached); | |
| 37 | } | |
| 38 | ||
| 39 | return null; | |
| 40 | } | |
| 41 | } |