Lines 100.00% 29 / 29
Methods 100.00% 4 / 4
Classes 100.00% 1 / 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 100.00% 14 / 14 100.00% 1 / 1 4
14final readonly class MonstersDiedEvent extends CombatRoundEvent
15{
16    /** @param non-empty-list<MonsterSpawnId> $monsters */
17    public function __construct(
18        public array $monsters,
19    ) {}
20
21    #[Override]
22    protected static function read(array $monsters, array $players): Option\Option
23    {
24        $died = [];
25        foreach ($monsters as $id => $monster) {
26            if (($monster['intState'] ?? null) !== 0) {
27                continue;
28            }
29
30            $died[] = new MonsterSpawnId($id);
31        }
32
33        return $died === [] ? Option\none() : Option\some(new static($died));
34    }
35
36    #[Override]
37    public function summary(): string
38    {
39        return (
40            'Monster '
41            . implode(', ', array_map(
42                static fn(MonsterSpawnId $monster): string => (string) $monster->value,
43                $this->monsters,
44            ))
45            . ' died'
46        );
47    }
48}

Inherited from Lorekeeper\Server\Event\Combat\CombatRoundEvent

34    final public static function from(Message $message): Option\Option
35    {
36        if (!$message instanceof JsonMessage || ($message->data['cmd'] ?? null) !== 'ct') {
37            return Option\none();
38        }
39
40        $status = Type\shape([
41            'intHP' => Type\optional(Type\uint()),
42            'intMP' => Type\optional(Type\uint()),
43            'intState' => Type\optional(Type\int_range(min: 0, max: 2)),
44        ], allowUnknownFields: true);
45
46        try {
47            $round = Type\shape([
48                'm' => Type\optional(Type\dict(Type\positive_int(), $status)),
49                'p' => Type\optional(Type\dict(Type\non_empty_string(), $status)),
50            ], allowUnknownFields: true)->coerce($message->data);
51        } catch (CoercionException $exception) {
52            throw new MalformedEventException(static::class, 'combat round is invalid', $exception);
53        }
54
55        return static::read($round['m'] ?? [], $round['p'] ?? []);
56    }