Lines
100.00%
18 / 18
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| describe | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| play | 100.00% | 14 / 14 | 100.00% | 1 / 1 | 5 | ||
| 15 | final readonly class TurnInQuest implements Action | |
| 16 | { | |
| 17 | public function __construct( | |
| 18 | public QuestId $quest, | |
| 19 | public ?ItemId $reward, | |
| 20 | ) {} | |
| 21 | ||
| 22 | #[Override] | |
| 23 | public function describe(): string | |
| 24 | { | |
| 25 | return $this->reward === null | |
| 26 | ? "Turn in quest {$this->quest->value}" | |
| 27 | : "Turn in quest {$this->quest->value} for item {$this->reward->value}"; | |
| 28 | } | |
| 29 | ||
| 30 | #[Override] | |
| 31 | public function play(StepScript $bot): Generator | |
| 32 | { | |
| 33 | $heldBefore = $this->reward === null ? 0 : $bot->me()->hero()->inventory->quantity($this->reward); | |
| 34 | $turningIn = $bot->turnIn($this->quest); | |
| 35 | yield from $turningIn; | |
| 36 | $refusal = $turningIn->getReturn(); | |
| 37 | if ($refusal !== null) { | |
| 38 | return new Failed("the game would not complete the quest ({$refusal})"); | |
| 39 | } | |
| 40 | ||
| 41 | $reward = $this->reward; | |
| 42 | if ($reward === null) { | |
| 43 | return null; | |
| 44 | } | |
| 45 | ||
| 46 | $collecting = $bot->collect($reward, $heldBefore); | |
| 47 | yield from $collecting; | |
| 48 | ||
| 49 | return $collecting->getReturn() | |
| 50 | ? null | |
| 51 | : new Failed("the quest was completed, but item {$reward->value} could not be picked up"); | |
| 52 | } | |
| 53 | } |