1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Spacecraft\Lib; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use Stu\Component\Ship\Mining\CancelMiningInterface; |
9
|
|
|
use Stu\Component\Spacecraft\Repair\CancelRepairInterface; |
10
|
|
|
use Stu\Component\Ship\Retrofit\CancelRetrofitInterface; |
11
|
|
|
use Stu\Component\Spacecraft\SpacecraftAlertStateEnum; |
12
|
|
|
use Stu\Component\Spacecraft\SpacecraftStateEnum; |
13
|
|
|
use Stu\Component\Spacecraft\System\Exception\InsufficientEnergyException; |
14
|
|
|
use Stu\Module\Ship\Lib\AstroEntryLibInterface; |
15
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperInterface; |
16
|
|
|
use Stu\Module\Spacecraft\Lib\Interaction\ShipTakeoverManagerInterface; |
17
|
|
|
use Stu\Module\Ship\Lib\TholianWebUtilInterface; |
18
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
19
|
|
|
use Stu\Orm\Entity\ShipInterface; |
20
|
|
|
use Stu\Orm\Repository\SpacecraftRepositoryInterface; |
21
|
|
|
|
22
|
|
|
final class SpacecraftStateChanger implements SpacecraftStateChangerInterface |
23
|
|
|
{ |
24
|
14 |
|
public function __construct( |
25
|
|
|
private CancelMiningInterface $cancelMining, |
26
|
|
|
private CancelRepairInterface $cancelRepair, |
27
|
|
|
private AstroEntryLibInterface $astroEntryLib, |
28
|
|
|
private SpacecraftRepositoryInterface $spacecraftRepository, |
29
|
|
|
private TholianWebUtilInterface $tholianWebUtil, |
30
|
|
|
private ShipTakeoverManagerInterface $shipTakeoverManager, |
31
|
|
|
private CancelRetrofitInterface $cancelRetrofit |
32
|
14 |
|
) {} |
33
|
|
|
|
34
|
5 |
|
#[Override] |
35
|
|
|
public function changeState(SpacecraftWrapperInterface $wrapper, SpacecraftStateEnum $newState): void |
36
|
|
|
{ |
37
|
5 |
|
$ship = $wrapper->get(); |
38
|
5 |
|
$currentState = $ship->getState(); |
39
|
|
|
|
40
|
|
|
//nothing to do |
41
|
|
|
if ( |
42
|
5 |
|
$currentState === SpacecraftStateEnum::DESTROYED |
43
|
5 |
|
|| $currentState === $newState |
44
|
|
|
) { |
45
|
2 |
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
//repair stuff |
49
|
3 |
|
if ($ship->isUnderRepair()) { |
50
|
1 |
|
$this->cancelRepair->cancelRepair($ship); |
51
|
2 |
|
} elseif ($currentState === SpacecraftStateEnum::ASTRO_FINALIZING) { |
52
|
1 |
|
$this->astroEntryLib->cancelAstroFinalizing($wrapper); |
53
|
1 |
|
} elseif ($currentState === SpacecraftStateEnum::RETROFIT && $ship instanceof ShipInterface) { |
54
|
|
|
$this->cancelRetrofit->cancelRetrofit($ship); |
55
|
1 |
|
} elseif ($currentState === SpacecraftStateEnum::WEB_SPINNING && $wrapper instanceof ShipWrapperInterface) { |
56
|
1 |
|
$this->tholianWebUtil->releaseWebHelper($wrapper); |
57
|
|
|
} elseif ($currentState === SpacecraftStateEnum::ACTIVE_TAKEOVER) { |
58
|
|
|
$this->shipTakeoverManager->cancelTakeover( |
59
|
|
|
$ship->getTakeoverActive(), |
60
|
|
|
null, |
61
|
|
|
true |
62
|
|
|
); |
63
|
|
|
} elseif ($currentState === SpacecraftStateEnum::GATHER_RESOURCES && $wrapper instanceof ShipWrapperInterface) { |
64
|
|
|
$this->cancelMining->cancelMining($wrapper); |
65
|
|
|
} |
66
|
|
|
|
67
|
3 |
|
$ship->setState($newState); |
68
|
3 |
|
$this->spacecraftRepository->save($ship); |
69
|
|
|
} |
70
|
|
|
|
71
|
7 |
|
#[Override] |
72
|
|
|
public function changeAlertState( |
73
|
|
|
SpacecraftWrapperInterface $wrapper, |
74
|
|
|
SpacecraftAlertStateEnum $alertState |
75
|
|
|
): ?string { |
76
|
|
|
|
77
|
7 |
|
$currentAlertState = $wrapper->getAlertState(); |
78
|
|
|
|
79
|
|
|
//nothing to do |
80
|
7 |
|
if ($currentAlertState === $alertState) { |
81
|
1 |
|
return null; |
82
|
|
|
} |
83
|
|
|
|
84
|
6 |
|
if (!$wrapper->get()->hasComputer()) { |
85
|
1 |
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
//check if enough energy |
89
|
|
|
if ( |
90
|
5 |
|
$alertState === SpacecraftAlertStateEnum::ALERT_YELLOW |
91
|
5 |
|
&& $currentAlertState === SpacecraftAlertStateEnum::ALERT_GREEN |
92
|
|
|
) { |
93
|
2 |
|
$this->consumeEnergyForAlertChange($wrapper, $alertState->getEpsUsage()); |
94
|
|
|
} |
95
|
|
|
if ( |
96
|
4 |
|
$alertState === SpacecraftAlertStateEnum::ALERT_RED |
97
|
4 |
|
&& $currentAlertState !== SpacecraftAlertStateEnum::ALERT_RED |
98
|
|
|
) { |
99
|
2 |
|
$this->consumeEnergyForAlertChange($wrapper, $alertState->getEpsUsage()); |
100
|
|
|
} |
101
|
|
|
|
102
|
3 |
|
$msg = null; |
103
|
3 |
|
$ship = $wrapper->get(); |
104
|
|
|
|
105
|
|
|
// cancel repair if not on alert green |
106
|
3 |
|
if ($alertState !== SpacecraftAlertStateEnum::ALERT_GREEN && $this->cancelRepair->cancelRepair($ship)) { |
107
|
1 |
|
$msg = _('Die Reparatur wurde abgebrochen'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ( |
111
|
3 |
|
$alertState !== SpacecraftAlertStateEnum::ALERT_GREEN |
112
|
3 |
|
&& $ship instanceof ShipInterface |
113
|
3 |
|
&& $this->cancelRetrofit->cancelRetrofit($ship) |
114
|
|
|
) { |
115
|
|
|
$msg = _('Die Umrüstung wurde abgebrochen'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
// now change |
119
|
3 |
|
$wrapper->getComputerSystemDataMandatory()->setAlertState($alertState); |
120
|
|
|
|
121
|
3 |
|
return $msg; |
122
|
|
|
} |
123
|
|
|
|
124
|
4 |
|
private function consumeEnergyForAlertChange(SpacecraftWrapperInterface $wrapper, int $amount): void |
125
|
|
|
{ |
126
|
4 |
|
$eps = $wrapper->getEpsSystemData(); |
127
|
|
|
|
128
|
4 |
|
if ($eps === null || $eps->getEps() < $amount) { |
129
|
2 |
|
throw new InsufficientEnergyException($amount); |
130
|
|
|
} |
131
|
2 |
|
$eps->lowerEps($amount)->update(); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths