Lines
86.36%
19 / 22
Methods
50.00%
2 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| read | 88.23% | 15 / 17 | 0.00% | 0 / 1 | 2.01 | ||
| summary | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| [Lorekeeper\Server\Event\Map\MapArrivalEvent] from | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | ||
| 15 | final readonly class MonstersPlacedEvent extends MapArrivalEvent | |
| 16 | { | |
| 17 | /** @param list<MonsterPlacement> $placements */ | |
| 18 | public function __construct( | |
| 19 | public array $placements, | |
| 20 | ) {} | |
| 21 | ||
| 22 | #[Override] | |
| 23 | protected static function read(array $data): static | |
| 24 | { | |
| 25 | try { | |
| 26 | $data = Type\shape([ | |
| 27 | 'monmap' => Type\optional(Type\vec(Type\shape([ | |
| 28 | 'MonMapID' => Type\positive_int(), | |
| 29 | 'MonID' => Type\positive_int(), | |
| 30 | 'strFrame' => Type\non_empty_string(), | |
| 31 | ], allowUnknownFields: true))), | |
| 32 | ], allowUnknownFields: true)->coerce($data); | |
| 33 | } catch (CoercionException $exception) { | |
| 34 | throw new MalformedEventException(static::class, 'monster placements are invalid', $exception); | |
| 35 | } | |
| 36 | ||
| 37 | return new static(array_map( | |
| 38 | static fn(array $placement): MonsterPlacement => new MonsterPlacement( | |
| 39 | new MonsterSpawnId($placement['MonMapID']), | |
| 40 | new MonsterId($placement['MonID']), | |
| 41 | new Cell($placement['strFrame']), | |
| 42 | ), | |
| 43 | $data['monmap'] ?? [], | |
| 44 | )); | |
| 45 | } | |
| 46 | ||
| 47 | #[Override] | |
| 48 | public function summary(): string | |
| 49 | { | |
| 50 | return count($this->placements) . ' monsters stand in the map'; | |
| 51 | } | |
| 52 | } |
Inherited from Lorekeeper\Server\Event\Map\MapArrivalEvent
| 28 | final public static function from(Message $message): Option\Option | |
| 29 | { | |
| 30 | if (!$message instanceof JsonMessage || ($message->data['cmd'] ?? null) !== 'moveToArea') { | |
| 31 | return Option\none(); | |
| 32 | } | |
| 33 | ||
| 34 | return Option\some(static::read($message->data)); | |
| 35 | } |