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 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| PlayersHealthChangedEvent | 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\Player\PlayerName; | |
| 9 | use Override; | |
| 10 | use Psl\Option; | |
| 11 | ||
| 12 | final readonly class PlayersHealthChangedEvent extends CombatRoundEvent | |
| 13 | { | |
| 14 | /** @param non-empty-list<PlayerHealth> $players */ | |
| 15 | public function __construct( | |
| 16 | public array $players, | |
| 17 | ) {} | |
| 18 | ||
| 19 | #[Override] | |
| 20 | protected static function read(array $monsters, array $players): Option\Option | |
| 21 | { | |
| 22 | $changed = []; | |
| 23 | foreach ($players as $name => $player) { | |
| 24 | if (!array_key_exists('intHP', $player)) { | |
| 25 | continue; | |
| 26 | } | |
| 27 | ||
| 28 | $changed[] = new PlayerHealth(new PlayerName($name), new Health($player['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(PlayerHealth $player): string => "{$player->player->value} has {$player->health->value} health", | |
| 39 | $this->players, | |
| 40 | )); | |
| 41 | } | |
| 42 | } |