1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Spacecraft\Lib\Battle; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use Stu\Component\Spacecraft\SpacecraftAlertStateEnum; |
9
|
|
|
use Stu\Component\Spacecraft\System\Exception\InsufficientEnergyException; |
10
|
|
|
use Stu\Component\Spacecraft\System\Exception\SpacecraftSystemException; |
11
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface; |
12
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
13
|
|
|
use Stu\Lib\Information\InformationInterface; |
14
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
15
|
|
|
use Stu\Orm\Entity\ShipInterface; |
16
|
|
|
|
17
|
|
|
final class AlertLevelBasedReaction implements AlertLevelBasedReactionInterface |
18
|
|
|
{ |
19
|
9 |
|
public function __construct(private SpacecraftSystemManagerInterface $spacecraftSystemManager) {} |
20
|
|
|
|
21
|
7 |
|
#[Override] |
22
|
|
|
public function react(SpacecraftWrapperInterface $wrapper, InformationInterface $informations): void |
23
|
|
|
{ |
24
|
7 |
|
if ($this->changeFromGreenToYellow($wrapper, $informations)) { |
25
|
1 |
|
return; |
26
|
|
|
} |
27
|
|
|
|
28
|
6 |
|
if ($wrapper->getAlertState() === SpacecraftAlertStateEnum::ALERT_YELLOW && $this->doAlertYellowReactions($wrapper, $informations)) { |
29
|
1 |
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
5 |
|
if ($wrapper->getAlertState() === SpacecraftAlertStateEnum::ALERT_RED) { |
33
|
1 |
|
if ($this->doAlertYellowReactions($wrapper, $informations)) { |
34
|
|
|
return; |
35
|
|
|
} |
36
|
1 |
|
$this->doAlertRedReactions($wrapper, $informations); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
7 |
|
private function changeFromGreenToYellow(SpacecraftWrapperInterface $wrapper, InformationInterface $informations): bool |
41
|
|
|
{ |
42
|
7 |
|
if ($wrapper->getAlertState() == SpacecraftAlertStateEnum::ALERT_GREEN) { |
43
|
|
|
try { |
44
|
1 |
|
$alertMsg = $wrapper->setAlertState(SpacecraftAlertStateEnum::ALERT_YELLOW); |
45
|
1 |
|
$informations->addInformation("- Erhöhung der Alarmstufe wurde durchgeführt, Grün -> Gelb"); |
46
|
1 |
|
if ($alertMsg !== null) { |
47
|
1 |
|
$informations->addInformation("- " . $alertMsg); |
48
|
|
|
} |
49
|
1 |
|
return true; |
50
|
|
|
} catch (InsufficientEnergyException) { |
51
|
|
|
$informations->addInformation("- Nicht genügend Energie vorhanden um auf Alarm-Gelb zu wechseln"); |
52
|
|
|
return true; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
6 |
|
return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
6 |
|
private function doAlertYellowReactions(SpacecraftWrapperInterface $wrapper, InformationInterface $informations): bool |
60
|
|
|
{ |
61
|
6 |
|
$ship = $wrapper->get(); |
62
|
|
|
|
63
|
6 |
|
if ($ship->isCloaked()) { |
64
|
|
|
try { |
65
|
1 |
|
$this->spacecraftSystemManager->deactivate($wrapper, SpacecraftSystemTypeEnum::CLOAK); |
66
|
1 |
|
$informations->addInformation("- Die Tarnung wurde deaktiviert"); |
67
|
|
|
} catch (SpacecraftSystemException) { |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
5 |
|
if (!$ship->isTractoring() && (!$ship instanceof ShipInterface || !$ship->isTractored())) { |
74
|
|
|
try { |
75
|
3 |
|
$this->spacecraftSystemManager->activate($wrapper, SpacecraftSystemTypeEnum::SHIELDS); |
76
|
|
|
|
77
|
2 |
|
$informations->addInformation("- Die Schilde wurden aktiviert"); |
78
|
1 |
|
} catch (SpacecraftSystemException) { |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} else { |
81
|
2 |
|
$informations->addInformation("- Die Schilde konnten wegen aktiviertem Traktorstrahl nicht aktiviert werden"); |
82
|
|
|
} |
83
|
|
|
try { |
84
|
5 |
|
$this->spacecraftSystemManager->activate($wrapper, SpacecraftSystemTypeEnum::NBS); |
85
|
|
|
|
86
|
4 |
|
$informations->addInformation("- Die Nahbereichssensoren wurden aktiviert"); |
87
|
1 |
|
} catch (SpacecraftSystemException) { |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
try { |
91
|
5 |
|
$this->spacecraftSystemManager->activate($wrapper, SpacecraftSystemTypeEnum::PHASER); |
92
|
|
|
|
93
|
4 |
|
$informations->addInformation("- Die Energiewaffe wurde aktiviert"); |
94
|
1 |
|
} catch (SpacecraftSystemException) { |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
5 |
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
1 |
|
private function doAlertRedReactions(SpacecraftWrapperInterface $wrapper, InformationInterface $informations): void |
101
|
|
|
{ |
102
|
|
|
try { |
103
|
1 |
|
$this->spacecraftSystemManager->activate($wrapper, SpacecraftSystemTypeEnum::TORPEDO); |
104
|
|
|
|
105
|
1 |
|
$informations->addInformation("- Der Torpedowerfer wurde aktiviert"); |
106
|
|
|
} catch (SpacecraftSystemException) { |
|
|
|
|
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
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