1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Movement\Component\Consequence\Flight; |
6
|
|
|
|
7
|
|
|
use RuntimeException; |
8
|
|
|
use Stu\Module\Ship\Lib\Message\MessageCollectionInterface; |
9
|
|
|
use Stu\Module\Ship\Lib\Movement\Component\Consequence\AbstractFlightConsequence; |
10
|
|
|
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface; |
11
|
|
|
use Stu\Module\Ship\Lib\Movement\Route\RouteModeEnum; |
12
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperInterface; |
13
|
|
|
use Stu\Orm\Entity\MapInterface; |
14
|
|
|
use Stu\Orm\Entity\ShipInterface; |
15
|
|
|
|
16
|
|
|
class EpsConsequence extends AbstractFlightConsequence |
17
|
|
|
{ |
18
|
9 |
|
protected function triggerSpecific( |
19
|
|
|
ShipWrapperInterface $wrapper, |
20
|
|
|
FlightRouteInterface $flightRoute, |
21
|
|
|
MessageCollectionInterface $messages |
22
|
|
|
): void { |
23
|
9 |
|
if ($wrapper->get()->isTractored()) { |
24
|
1 |
|
return; |
25
|
|
|
} |
26
|
|
|
|
27
|
8 |
|
$epsSystem = $wrapper->getEpsSystemData(); |
28
|
8 |
|
if ($epsSystem === null) { |
29
|
|
|
throw new RuntimeException('this should not happen'); |
30
|
|
|
} |
31
|
|
|
|
32
|
8 |
|
$neededEps = $this->getEpsNeededForFlight($flightRoute, $wrapper->get()); |
33
|
|
|
|
34
|
8 |
|
if ($neededEps > 0) { |
35
|
2 |
|
$epsSystem->lowerEps($neededEps)->update(); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
8 |
|
private function getEpsNeededForFlight(FlightRouteInterface $flightRoute, ShipInterface $ship): int |
40
|
|
|
{ |
41
|
8 |
|
if ($flightRoute->getRouteMode() !== RouteModeEnum::ROUTE_MODE_FLIGHT) { |
42
|
5 |
|
return 0; |
43
|
|
|
} |
44
|
|
|
|
45
|
3 |
|
$nextWaypoint = $flightRoute->getNextWaypoint(); |
46
|
3 |
|
if ($nextWaypoint instanceof MapInterface) { |
47
|
1 |
|
return 0; |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
$result = $ship->getRump()->getFlightEcost(); |
51
|
|
|
|
52
|
2 |
|
$tractoredShip = $ship->getTractoredShip(); |
53
|
2 |
|
if ($tractoredShip !== null) { |
54
|
1 |
|
$result += $tractoredShip->getRump()->getFlightEcost(); |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
return $result; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|