Lines
93.10%
27 / 29
Methods
75.00%
3 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| read | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 4 | ||
| summary | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 1 | ||
| [Lorekeeper\Server\Event\Combat\CombatRoundEvent] from | 85.71% | 12 / 14 | 0.00% | 0 / 1 | 4.05 | ||
| 11 | final readonly class MonstersDiedEvent extends CombatRoundEvent | |
| 12 | { | |
| 13 | /** @param non-empty-list<MonsterSpawnId> $monsters */ | |
| 14 | public function __construct( | |
| 15 | public array $monsters, | |
| 16 | ) {} | |
| 17 | ||
| 18 | #[Override] | |
| 19 | protected static function read(array $monsters, array $players): Option\Option | |
| 20 | { | |
| 21 | $died = []; | |
| 22 | foreach ($monsters as $id => $monster) { | |
| 23 | if (($monster['intState'] ?? null) !== 0) { | |
| 24 | continue; | |
| 25 | } | |
| 26 | ||
| 27 | $died[] = new MonsterSpawnId($id); | |
| 28 | } | |
| 29 | ||
| 30 | return $died === [] ? Option\none() : Option\some(new static($died)); | |
| 31 | } | |
| 32 | ||
| 33 | #[Override] | |
| 34 | public function summary(): string | |
| 35 | { | |
| 36 | return ( | |
| 37 | 'Monster ' | |
| 38 | . implode(', ', array_map( | |
| 39 | static fn(MonsterSpawnId $monster): string => (string) $monster->value, | |
| 40 | $this->monsters, | |
| 41 | )) | |
| 42 | . ' died' | |
| 43 | ); | |
| 44 | } | |
| 45 | } |
Inherited from Lorekeeper\Server\Event\Combat\CombatRoundEvent
| 31 | final public static function from(Message $message): Option\Option | |
| 32 | { | |
| 33 | if (!$message instanceof JsonMessage || ($message->data['cmd'] ?? null) !== 'ct') { | |
| 34 | return Option\none(); | |
| 35 | } | |
| 36 | ||
| 37 | $status = Type\shape([ | |
| 38 | 'intHP' => Type\optional(Type\uint()), | |
| 39 | 'intMP' => Type\optional(Type\uint()), | |
| 40 | 'intState' => Type\optional(Type\int_range(min: 0, max: 2)), | |
| 41 | ], allowUnknownFields: true); | |
| 42 | ||
| 43 | try { | |
| 44 | $round = Type\shape([ | |
| 45 | 'm' => Type\optional(Type\dict(Type\positive_int(), $status)), | |
| 46 | 'p' => Type\optional(Type\dict(Type\non_empty_string(), $status)), | |
| 47 | ], allowUnknownFields: true)->coerce($message->data); | |
| 48 | } catch (CoercionException $exception) { | |
| 49 | throw new MalformedEventException(static::class, 'combat round is invalid', $exception); | |
| 50 | } | |
| 51 | ||
| 52 | return static::read($round['m'] ?? [], $round['p'] ?? []); | |
| 53 | } |