Lines
100.00%
12 / 12
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| 64 | final readonly class Events | |
| 65 | { | |
| 66 | /** @var non-empty-list<class-string<Event>> */ | |
| 67 | public const array ALL = [ | |
| 68 | ActionTooSoonEvent::class, | |
| 69 | TooSoonAfterCombatEvent::class, | |
| 70 | AttackRejectedEvent::class, | |
| 71 | ClassChangedEvent::class, | |
| 72 | MonsterRespawnedEvent::class, | |
| 73 | MonsterRewardedEvent::class, | |
| 74 | MonstersDiedEvent::class, | |
| 75 | MonstersHealthChangedEvent::class, | |
| 76 | LeveledUpEvent::class, | |
| 77 | PlayersHealthChangedEvent::class, | |
| 78 | PlayersManaChangedEvent::class, | |
| 79 | PlayersStateChangedEvent::class, | |
| 80 | ResurrectedEvent::class, | |
| 81 | SkillsLoadedEvent::class, | |
| 82 | ConnectionEstablishedEvent::class, | |
| 83 | InventoryLoadedEvent::class, | |
| 84 | QuestItemsReceivedEvent::class, | |
| 85 | ItemsIncreasedEvent::class, | |
| 86 | QuestItemsIncreasedEvent::class, | |
| 87 | ItemDroppedEvent::class, | |
| 88 | ItemsEnhancedEvent::class, | |
| 89 | DropPickedUpEvent::class, | |
| 90 | ItemEquippedEvent::class, | |
| 91 | ItemUnequippedEvent::class, | |
| 92 | ItemUnwornEvent::class, | |
| 93 | ItemWornEvent::class, | |
| 94 | LoginFailedEvent::class, | |
| 95 | LoginSucceededEvent::class, | |
| 96 | AlreadyInMapEvent::class, | |
| 97 | MapLockedEvent::class, | |
| 98 | MapMemberOnlyEvent::class, | |
| 99 | MapNotAvailableEvent::class, | |
| 100 | MapRequiresQuestEvent::class, | |
| 101 | MovedToMapEvent::class, | |
| 102 | RoomJoinedEvent::class, | |
| 103 | PlayerEnteredEvent::class, | |
| 104 | PlayerLeftEvent::class, | |
| 105 | PlayerUpdatedEvent::class, | |
| 106 | PlayerAwayUpdatedEvent::class, | |
| 107 | PlayerMovedEvent::class, | |
| 108 | PlayerVitalsUpdatedEvent::class, | |
| 109 | HeroStatsUpdatedEvent::class, | |
| 110 | PlayerStateUpdatedEvent::class, | |
| 111 | HeroDataLoadedEvent::class, | |
| 112 | HeroSettingsLoadedEvent::class, | |
| 113 | PlayerDataLoadedEvent::class, | |
| 114 | QuestLoadedEvent::class, | |
| 115 | ItemsTurnedInEvent::class, | |
| 116 | QuestAcceptedEvent::class, | |
| 117 | QuestCompletedEvent::class, | |
| 118 | QuestTurnInRefusedEvent::class, | |
| 119 | QuestMarkedEvent::class, | |
| 120 | ShopLoadedEvent::class, | |
| 121 | ]; | |
| 122 | ||
| 123 | /** @return list<Event|MalformedEventException> */ | |
| 124 | public static function recognize(Message $message): array | |
| 125 | { | |
| 126 | $recognized = []; | |
| 127 | ||
| 128 | foreach (self::ALL as $event) { | |
| 129 | try { | |
| 130 | $heard = self::read($event, $message); | |
| 131 | } catch (MalformedEventException $malformed) { | |
| 132 | $recognized[] = $malformed; | |
| 133 | ||
| 134 | continue; | |
| 135 | } | |
| 136 | ||
| 137 | if ($heard->isSome()) { | |
| 138 | $recognized[] = $heard->unwrap(); | |
| 139 | } | |
| 140 | } | |
| 141 | ||
| 142 | return $recognized; | |
| 143 | } | |
| 144 | ||
| 145 | /** | |
| 146 | * @param class-string<Event> $event | |
| 147 | * | |
| 148 | * @throws MalformedEventException | |
| 149 | * | |
| 150 | * @return Option\Option<Event> | |
| 151 | */ | |
| 152 | public static function read(string $event, Message $message): Option\Option | |
| 153 | { | |
| 154 | try { | |
| 155 | /** @mago-expect analysis:possibly-static-access-on-interface */ | |
| 156 | return $event::from($message); | |
| 157 | } catch (InvalidArgumentException|TypeException $exception) { | |
| 158 | throw new MalformedEventException($event, $exception->getMessage(), $exception); | |
| 159 | } | |
| 160 | } | |
| 161 | } |