1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Movement\Route; |
6
|
|
|
|
7
|
|
|
use Stu\Module\Control\StuTime; |
8
|
|
|
use Stu\Orm\Entity\MapInterface; |
9
|
|
|
use Stu\Orm\Entity\ShipInterface; |
10
|
|
|
use Stu\Orm\Entity\StarSystemMapInterface; |
11
|
|
|
use Stu\Orm\Entity\WormholeEntryInterface; |
12
|
|
|
use Stu\Orm\Repository\WormholeEntryRepositoryInterface; |
13
|
|
|
|
14
|
|
|
final class EnterWaypoint implements EnterWaypointInterface |
15
|
|
|
{ |
16
|
|
|
private WormholeEntryRepositoryInterface $wormholeEntryRepository; |
17
|
|
|
|
18
|
|
|
private StuTime $stuTime; |
19
|
|
|
|
20
|
5 |
|
public function __construct( |
21
|
|
|
WormholeEntryRepositoryInterface $wormholeEntryRepository, |
22
|
|
|
StuTime $stuTime |
23
|
|
|
) { |
24
|
5 |
|
$this->wormholeEntryRepository = $wormholeEntryRepository; |
25
|
5 |
|
$this->stuTime = $stuTime; |
26
|
|
|
} |
27
|
|
|
|
28
|
5 |
|
public function enterNextWaypoint( |
29
|
|
|
ShipInterface $ship, |
30
|
|
|
bool $isTraversing, |
31
|
|
|
MapInterface|StarSystemMapInterface $waypoint, |
32
|
|
|
?WormholeEntryInterface $wormholeEntry |
33
|
|
|
): void { |
34
|
|
|
|
35
|
5 |
|
$ship->updateLocation( |
36
|
5 |
|
$waypoint instanceof MapInterface ? $waypoint : null, |
37
|
5 |
|
$waypoint instanceof StarSystemMapInterface ? $waypoint : null |
38
|
5 |
|
); |
39
|
|
|
|
40
|
5 |
|
if ($this->isWormhole($waypoint)) { |
41
|
1 |
|
$ship->setCx(0); |
42
|
1 |
|
$ship->setCy(0); |
43
|
|
|
} |
44
|
|
|
|
45
|
5 |
|
if ($wormholeEntry !== null) { |
46
|
1 |
|
$wormholeEntry->setLastUsed($this->stuTime->time()); |
47
|
1 |
|
$this->wormholeEntryRepository->save($wormholeEntry); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
5 |
|
private function isWormhole(MapInterface|StarSystemMapInterface $waypoint): bool |
52
|
|
|
{ |
53
|
5 |
|
if ($waypoint instanceof MapInterface) { |
54
|
2 |
|
return false; |
55
|
|
|
} |
56
|
|
|
|
57
|
3 |
|
return $waypoint->getSystem()->isWormhole(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|