Lines
100.00%
16 / 16
Methods
100.00%
4 / 4
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| describe | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| play | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 2 | ||
| minutes | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| 18 | final readonly class Hunt implements Action | |
| 19 | { | |
| 20 | public function __construct( | |
| 21 | public MapSpot $spot, | |
| 22 | public ?MonsterName $monster, | |
| 23 | public ItemId $item, | |
| 24 | public Quantity $quantity, | |
| 25 | public Duration $limit, | |
| 26 | ) {} | |
| 27 | ||
| 28 | #[Override] | |
| 29 | public function describe(): string | |
| 30 | { | |
| 31 | $who = $this->monster === null ? '' : "{$this->monster->value} "; | |
| 32 | ||
| 33 | return "Hunt {$who}in {$this->spot->cell->value} for item {$this->item->value} ×{$this->quantity->value}"; | |
| 34 | } | |
| 35 | ||
| 36 | #[Override] | |
| 37 | public function play(StepScript $bot): Generator | |
| 38 | { | |
| 39 | $hunting = $bot->hunt( | |
| 40 | $this->spot, | |
| 41 | $bot->attackIn($this->spot->cell, $this->monster), | |
| 42 | $this->item, | |
| 43 | $this->quantity, | |
| 44 | $this->limit, | |
| 45 | ); | |
| 46 | yield from $hunting; | |
| 47 | ||
| 48 | return $hunting->getReturn() | |
| 49 | ? null | |
| 50 | : new Failed("item {$this->item->value} ×{$this->quantity->value} was not held after {$this->minutes()}"); | |
| 51 | } | |
| 52 | ||
| 53 | private function minutes(): string | |
| 54 | { | |
| 55 | $minutes = (int) $this->limit->getTotalMinutes(); | |
| 56 | ||
| 57 | return $minutes === 1 ? '1 minute' : "{$minutes} minutes"; | |
| 58 | } | |
| 59 | } |