1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Movement\Component\PreFlight\Condition; |
6
|
|
|
|
7
|
|
|
use Stu\Component\Ship\System\ShipSystemTypeEnum; |
8
|
|
|
use Stu\Module\Ship\Lib\Movement\Component\PreFlight\ConditionCheckResult; |
9
|
|
|
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface; |
10
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperInterface; |
11
|
|
|
|
12
|
|
|
class HealthyDriveCondition implements PreFlightConditionInterface |
13
|
|
|
{ |
14
|
9 |
|
public function check( |
15
|
|
|
ShipWrapperInterface $wrapper, |
16
|
|
|
FlightRouteInterface $flightRoute, |
17
|
|
|
ConditionCheckResult $conditionCheckResult |
18
|
|
|
): void { |
19
|
|
|
|
20
|
9 |
|
if ($flightRoute->isImpulseDriveNeeded()) { |
21
|
3 |
|
$this->checkSystemHealth( |
22
|
3 |
|
$wrapper, |
23
|
3 |
|
ShipSystemTypeEnum::SYSTEM_IMPULSEDRIVE, |
24
|
3 |
|
$conditionCheckResult |
25
|
3 |
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
9 |
|
if ($flightRoute->isWarpDriveNeeded()) { |
29
|
3 |
|
$this->checkSystemHealth( |
30
|
3 |
|
$wrapper, |
31
|
3 |
|
ShipSystemTypeEnum::SYSTEM_WARPDRIVE, |
32
|
3 |
|
$conditionCheckResult |
33
|
3 |
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
9 |
|
if ($flightRoute->isTranswarpCoilNeeded()) { |
37
|
3 |
|
$this->checkSystemHealth( |
38
|
3 |
|
$wrapper, |
39
|
3 |
|
ShipSystemTypeEnum::SYSTEM_TRANSWARP_COIL, |
40
|
3 |
|
$conditionCheckResult |
41
|
3 |
|
); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
9 |
|
private function checkSystemHealth( |
46
|
|
|
ShipWrapperInterface $wrapper, |
47
|
|
|
int $systemId, |
48
|
|
|
ConditionCheckResult $conditionCheckResult |
49
|
|
|
): void { |
50
|
9 |
|
$ship = $wrapper->get(); |
51
|
|
|
|
52
|
9 |
|
if (!$ship->hasShipSystem($systemId)) { |
53
|
3 |
|
$conditionCheckResult->addBlockedShip( |
54
|
3 |
|
$ship, |
55
|
3 |
|
sprintf( |
56
|
3 |
|
'Die %s verfügt über keine(n) %s', |
57
|
3 |
|
$ship->getName(), |
58
|
3 |
|
ShipSystemTypeEnum::getDescription($systemId) |
59
|
3 |
|
) |
60
|
3 |
|
); |
61
|
|
|
|
62
|
3 |
|
return; |
63
|
|
|
} |
64
|
|
|
|
65
|
6 |
|
if (!$ship->isSystemHealthy($systemId)) { |
66
|
3 |
|
$conditionCheckResult->addBlockedShip( |
67
|
3 |
|
$ship, |
68
|
3 |
|
sprintf( |
69
|
3 |
|
'Die %s kann das System %s nicht aktivieren', |
70
|
3 |
|
$ship->getName(), |
71
|
3 |
|
ShipSystemTypeEnum::getDescription($systemId) |
72
|
3 |
|
) |
73
|
3 |
|
); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|