Lines
78.00%
39 / 50
Methods
50.00%
3 / 6
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| summary | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| read | 93.54% | 29 / 31 | 0.00% | 0 / 1 | 2.00 | ||
| pad | 30.00% | 3 / 10 | 0.00% | 0 / 1 | 44.30 | ||
| state | 50.00% | 2 / 4 | 0.00% | 0 / 1 | 6.00 | ||
| [Lorekeeper\Server\Event\Map\MapArrivalEvent] from | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | ||
| 19 | final readonly class PlayersSeenEvent extends MapArrivalEvent | |
| 20 | { | |
| 21 | /** @param list<SeenPlayer> $players */ | |
| 22 | public function __construct( | |
| 23 | public array $players, | |
| 24 | ) {} | |
| 25 | ||
| 26 | #[Override] | |
| 27 | public function summary(): string | |
| 28 | { | |
| 29 | return count($this->players) . ' players are in the map'; | |
| 30 | } | |
| 31 | ||
| 32 | #[Override] | |
| 33 | protected static function read(array $data): static | |
| 34 | { | |
| 35 | try { | |
| 36 | $players = Type\shape([ | |
| 37 | 'uoBranch' => Type\vec(Type\shape([ | |
| 38 | 'strUsername' => Type\non_empty_string(), | |
| 39 | 'intLevel' => Type\int_range(min: 1, max: 100), | |
| 40 | 'strFrame' => Type\non_empty_string(), | |
| 41 | 'strPad' => Type\non_empty_string(), | |
| 42 | 'intState' => Type\int_range(min: 0, max: 2), | |
| 43 | 'intHP' => Type\uint(), | |
| 44 | 'intHPMax' => Type\uint(), | |
| 45 | 'intMP' => Type\uint(), | |
| 46 | 'intMPMax' => Type\uint(), | |
| 47 | 'afk' => Type\bool(), | |
| 48 | ], allowUnknownFields: true)), | |
| 49 | ], allowUnknownFields: true)->coerce($data)['uoBranch']; | |
| 50 | } catch (CoercionException $exception) { | |
| 51 | throw new MalformedEventException(static::class, 'players are missing or invalid', $exception); | |
| 52 | } | |
| 53 | ||
| 54 | return new static(array_map( | |
| 55 | static fn(array $player): SeenPlayer => new SeenPlayer( | |
| 56 | new PlayerName($player['strUsername']), | |
| 57 | new PlayerLevel($player['intLevel']), | |
| 58 | new Cell($player['strFrame']), | |
| 59 | self::pad($player['strPad']), | |
| 60 | self::state($player['intState']), | |
| 61 | new Health($player['intHP']), | |
| 62 | new Health($player['intHPMax']), | |
| 63 | new Mana($player['intMP']), | |
| 64 | new Mana($player['intMPMax']), | |
| 65 | $player['afk'], | |
| 66 | ), | |
| 67 | $players, | |
| 68 | )); | |
| 69 | } | |
| 70 | ||
| 71 | /** @throws MalformedEventException */ | |
| 72 | private static function pad(string $pad): Pad | |
| 73 | { | |
| 74 | return match (strtolower($pad)) { | |
| 75 | 'left' => Pad::Left, | |
| 76 | 'right' => Pad::Right, | |
| 77 | 'top' => Pad::Top, | |
| 78 | 'bottom' => Pad::Bottom, | |
| 79 | 'up' => Pad::Up, | |
| 80 | 'down' => Pad::Down, | |
| 81 | 'center' => Pad::Center, | |
| 82 | 'spawn' => Pad::Spawn, | |
| 83 | default => throw new MalformedEventException(static::class, "unknown pad '{$pad}'"), | |
| 84 | }; | |
| 85 | } | |
| 86 | ||
| 87 | private static function state(int $state): CombatState | |
| 88 | { | |
| 89 | return match ($state) { | |
| 90 | 0 => CombatState::Dead, | |
| 91 | 2 => CombatState::Fighting, | |
| 92 | default => CombatState::Idle, | |
| 93 | }; | |
| 94 | } | |
| 95 | } |
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 | } |