Lines
100.00%
12 / 12
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| QuestItemsReceivedEvent | 100.00% | 12 / 12 | 100.00% | 3 / 3 | 6 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| from | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 4 | |||||
| summary | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Server\Event\Inventory; | |
| 6 | ||
| 7 | use Lorekeeper\Core\Support\Quantity; | |
| 8 | use Lorekeeper\Server\Event\Inventory\Helper\ItemArrival; | |
| 9 | use Lorekeeper\Server\Event\Inventory\Helper\ItemArrivals; | |
| 10 | use Lorekeeper\Server\Event\Item\Helper\ItemKinds; | |
| 11 | use Lorekeeper\Server\Message\Message; | |
| 12 | use Override; | |
| 13 | use Psl\Option; | |
| 14 | ||
| 15 | /** | |
| 16 | * Our player received one or more temporary quest items for the first time. | |
| 17 | */ | |
| 18 | final readonly class QuestItemsReceivedEvent extends InventoryUpdatedEvent | |
| 19 | { | |
| 20 | /** @param non-empty-list<HeldItem> $items */ | |
| 21 | public function __construct( | |
| 22 | public array $items, | |
| 23 | ) {} | |
| 24 | ||
| 25 | /** @return Option\Option<static> */ | |
| 26 | #[Override] | |
| 27 | public static function from(Message $message): Option\Option | |
| 28 | { | |
| 29 | $items = []; | |
| 30 | foreach (ItemArrivals::of($message, static::class) ?? [] as [$kind, $entry]) { | |
| 31 | if ($kind !== ItemArrival::QuestItemReceived) { | |
| 32 | continue; | |
| 33 | } | |
| 34 | ||
| 35 | $items[] = new HeldItem(ItemKinds::read($entry, static::class), new Quantity($entry['iQty'])); | |
| 36 | } | |
| 37 | ||
| 38 | return $items === [] ? Option\none() : Option\some(new static($items)); | |
| 39 | } | |
| 40 | ||
| 41 | #[Override] | |
| 42 | public function summary(): string | |
| 43 | { | |
| 44 | return 'Got for now ' | |
| 45 | . implode(', ', array_map( | |
| 46 | static fn(HeldItem $held): string => "{$held->quantity->value} {$held->item->name->value}", | |
| 47 | $this->items, | |
| 48 | )); | |
| 49 | } | |
| 50 | } |