Lines
100.00%
11 / 11
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MonstersHealthChangedEvent | 100.00% | 11 / 11 | 100.00% | 3 / 3 | 6 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| read | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 4 | |||||
| summary | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Server\Event\Combat; | |
| 6 | ||
| 7 | use Lorekeeper\Core\Attribute\Health; | |
| 8 | use Lorekeeper\Core\World\Monster\MonsterSpawnId; | |
| 9 | use Override; | |
| 10 | use Psl\Option; | |
| 11 | ||
| 12 | final readonly class MonstersHealthChangedEvent extends CombatRoundEvent | |
| 13 | { | |
| 14 | /** @param non-empty-list<MonsterHealth> $monsters */ | |
| 15 | public function __construct( | |
| 16 | public array $monsters, | |
| 17 | ) {} | |
| 18 | ||
| 19 | #[Override] | |
| 20 | protected static function read(array $monsters, array $players): Option\Option | |
| 21 | { | |
| 22 | $changed = []; | |
| 23 | foreach ($monsters as $id => $monster) { | |
| 24 | if (!array_key_exists('intHP', $monster)) { | |
| 25 | continue; | |
| 26 | } | |
| 27 | ||
| 28 | $changed[] = new MonsterHealth(new MonsterSpawnId($id), new Health($monster['intHP'])); | |
| 29 | } | |
| 30 | ||
| 31 | return $changed === [] ? Option\none() : Option\some(new static($changed)); | |
| 32 | } | |
| 33 | ||
| 34 | #[Override] | |
| 35 | public function summary(): string | |
| 36 | { | |
| 37 | return implode(', ', array_map( | |
| 38 | static fn(MonsterHealth $monster): string => "Monster {$monster->monster->value} has {$monster->health->value} health", | |
| 39 | $this->monsters, | |
| 40 | )); | |
| 41 | } | |
| 42 | } |