Lines
100.00%
10 / 10
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Rests | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 5 | 100.00% | 1 / 1 | |||
| rest | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 5 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Bot\Abilities\Moves; | |
| 6 | ||
| 7 | use Generator; | |
| 8 | use Lorekeeper\Client\Script\Await; | |
| 9 | use Lorekeeper\Client\Script\Instruction; | |
| 10 | use Lorekeeper\Client\Script\Pause; | |
| 11 | use Lorekeeper\Client\Script\TimedOut; | |
| 12 | use Lorekeeper\Core\Game\Combat\CombatState; | |
| 13 | use Lorekeeper\Core\World\Map\MapCell; | |
| 14 | use Lorekeeper\Core\World\Map\MapPad; | |
| 15 | use Lorekeeper\Core\World\Map\MapSpot; | |
| 16 | use Lorekeeper\Server\Event\Combat\PlayersStateChangedEvent; | |
| 17 | use Lorekeeper\Server\Event\Event; | |
| 18 | use Lorekeeper\Server\Event\Player\PlayerStateUpdatedEvent; | |
| 19 | use Psl\DateTime\Duration; | |
| 20 | ||
| 21 | trait Rests | |
| 22 | { | |
| 23 | use Jumps; | |
| 24 | ||
| 25 | private const int SECONDS_TO_STOP_FIGHTING = 15; | |
| 26 | ||
| 27 | private const int SECONDS_TO_COOL_DOWN = 5; | |
| 28 | ||
| 29 | /** @return Generator<int, Instruction, null|Event|TimedOut, void> */ | |
| 30 | protected function rest(): Generator | |
| 31 | { | |
| 32 | $fought = $this->me()->state() === CombatState::Fighting; | |
| 33 | if ($this->me()->location()->spot->cell->value !== 'Enter') { | |
| 34 | yield from $this->jump(new MapSpot(new MapCell('Enter'), MapPad::Spawn)); | |
| 35 | } | |
| 36 | ||
| 37 | for ($second = 0; $second < self::SECONDS_TO_STOP_FIGHTING; $second++) { | |
| 38 | if ($this->me()->state() !== CombatState::Fighting) { | |
| 39 | break; | |
| 40 | } | |
| 41 | ||
| 42 | $fought = true; | |
| 43 | yield new Await([PlayerStateUpdatedEvent::class, PlayersStateChangedEvent::class], Duration::seconds(1)); | |
| 44 | } | |
| 45 | ||
| 46 | if ($fought) { | |
| 47 | yield new Pause(Duration::seconds(self::SECONDS_TO_COOL_DOWN)); | |
| 48 | } | |
| 49 | } | |
| 50 | } |