Lines
100.00%
9 / 9
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| LocationTracking | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 2 | 100.00% | 1 / 1 | |||
| follow | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Client\Tracking; | |
| 6 | ||
| 7 | use Lorekeeper\Client\Location; | |
| 8 | use Lorekeeper\Core\World\Map\MapPlayer; | |
| 9 | use Lorekeeper\Core\World\Map\MapSpot; | |
| 10 | use Lorekeeper\Server\Event\Event; | |
| 11 | use Lorekeeper\Server\Event\Map\MovedToMapEvent; | |
| 12 | ||
| 13 | final readonly class LocationTracking | |
| 14 | { | |
| 15 | public static function follow(Location $location, Event $event, Identity $me): Location | |
| 16 | { | |
| 17 | if (!$event instanceof MovedToMapEvent) { | |
| 18 | return $location; | |
| 19 | } | |
| 20 | ||
| 21 | $spot = $event | |
| 22 | ->map | |
| 23 | ->players | |
| 24 | ->find($me->spawnId) | |
| 25 | ->map(static fn(MapPlayer $seen): MapSpot => $seen->spot) | |
| 26 | ->unwrapOr($location->spot); | |
| 27 | ||
| 28 | return new Location($event->areaId, $event->map, $spot); | |
| 29 | } | |
| 30 | } |