Lines
87.50%
7 / 8
Functions and Methods
66.66%
2 / 3
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MonsterRewardedEvent | 87.50% | 7 / 8 | 66.66% | 2 / 3 | 5.05 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| read | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 3 | |||||
| summary | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Server\Event\Reward; | |
| 6 | ||
| 7 | use Lorekeeper\Core\Currency\Gold; | |
| 8 | use Lorekeeper\Core\Progression\ClassPoints; | |
| 9 | use Lorekeeper\Core\Progression\Experience; | |
| 10 | use Lorekeeper\Core\World\Monster\MonsterSpawnId; | |
| 11 | use Lorekeeper\Server\Exception\MalformedEventException; | |
| 12 | use Override; | |
| 13 | use Psl\Option; | |
| 14 | use Psl\Type; | |
| 15 | use Psl\Type\Exception\CoercionException; | |
| 16 | ||
| 17 | final readonly class MonsterRewardedEvent extends RewardedEvent | |
| 18 | { | |
| 19 | public function __construct( | |
| 20 | Gold $gold, | |
| 21 | Experience $experience, | |
| 22 | ClassPoints $classPoints, | |
| 23 | public MonsterSpawnId $monster, | |
| 24 | ) { | |
| 25 | parent::__construct($gold, $experience, $classPoints); | |
| 26 | } | |
| 27 | ||
| 28 | #[Override] | |
| 29 | protected static function read( | |
| 30 | array $data, | |
| 31 | Gold $gold, | |
| 32 | Experience $experience, | |
| 33 | ClassPoints $classPoints, | |
| 34 | ): Option\Option { | |
| 35 | if (($data['typ'] ?? null) !== 'm') { | |
| 36 | return Option\none(); | |
| 37 | } | |
| 38 | ||
| 39 | try { | |
| 40 | $monster = Type\positive_int()->coerce($data['id'] ?? null); | |
| 41 | } catch (CoercionException $exception) { | |
| 42 | throw new MalformedEventException(static::class, 'rewarding monster is missing or invalid', $exception); | |
| 43 | } | |
| 44 | ||
| 45 | return Option\some(new static($gold, $experience, $classPoints, new MonsterSpawnId($monster))); | |
| 46 | } | |
| 47 | ||
| 48 | #[Override] | |
| 49 | public function summary(): string | |
| 50 | { | |
| 51 | return "Earned {$this->experience->value} experience and {$this->gold->value} gold from monster {$this->monster->value}"; | |
| 52 | } | |
| 53 | } |