|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Tick\Spacecraft\Handler; |
|
4
|
|
|
|
|
5
|
|
|
use Override; |
|
|
|
|
|
|
6
|
|
|
use Stu\Component\Spacecraft\Repair\RepairUtilInterface; |
|
7
|
|
|
use Stu\Component\Spacecraft\SpacecraftStateEnum; |
|
8
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface; |
|
9
|
|
|
use Stu\Component\Station\StationUtilityInterface; |
|
10
|
|
|
use Stu\Lib\Information\InformationInterface; |
|
11
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum; |
|
12
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
|
13
|
|
|
use Stu\Module\PlayerSetting\Lib\UserEnum; |
|
|
|
|
|
|
14
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
|
15
|
|
|
use Stu\Module\Station\Lib\StationWrapperInterface; |
|
16
|
|
|
|
|
17
|
|
|
class StationPassiveRepairHandler implements SpacecraftTickHandlerInterface |
|
18
|
|
|
{ |
|
19
|
1 |
|
public function __construct( |
|
20
|
|
|
private StationUtilityInterface $stationUtility, |
|
21
|
|
|
private RepairUtilInterface $repairUtil, |
|
22
|
|
|
private SpacecraftSystemManagerInterface $spacecraftSystemManager, |
|
23
|
|
|
private PrivateMessageSenderInterface $privateMessageSender |
|
24
|
1 |
|
) {} |
|
25
|
|
|
|
|
26
|
|
|
#[Override] |
|
27
|
|
|
public function handleSpacecraftTick( |
|
28
|
|
|
SpacecraftWrapperInterface $wrapper, |
|
29
|
|
|
InformationInterface $information |
|
30
|
|
|
): void { |
|
31
|
|
|
|
|
32
|
|
|
$spacecraft = $wrapper->get(); |
|
33
|
|
|
|
|
34
|
|
|
if ( |
|
35
|
|
|
$wrapper instanceof StationWrapperInterface |
|
36
|
|
|
&& $spacecraft->getState() === SpacecraftStateEnum::REPAIR_PASSIVE |
|
37
|
|
|
) { |
|
38
|
|
|
$this->doRepairStation($wrapper, $information); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function doRepairStation(StationWrapperInterface $wrapper, InformationInterface $information): void |
|
43
|
|
|
{ |
|
44
|
|
|
$station = $wrapper->get(); |
|
45
|
|
|
|
|
46
|
|
|
if (!$this->stationUtility->hasEnoughDockedWorkbees($station, $station->getRump())) { |
|
47
|
|
|
$neededWorkbees = (int)ceil($station->getRump()->getNeededWorkbees() / 5); |
|
48
|
|
|
|
|
49
|
|
|
$information->addInformationf( |
|
50
|
|
|
'Nicht genügend Workbees (%d/%d) angedockt um die Reparatur weiterführen zu können', |
|
51
|
|
|
$this->stationUtility->getDockedWorkbeeCount($station), |
|
52
|
|
|
$neededWorkbees |
|
53
|
|
|
); |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$neededParts = $this->repairUtil->determineSpareParts($wrapper, true); |
|
58
|
|
|
|
|
59
|
|
|
// parts stored? |
|
60
|
|
|
if (!$this->repairUtil->enoughSparePartsOnEntity($neededParts, $station, $station)) { |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
//repair hull |
|
65
|
|
|
$station->setHuell($station->getHull() + $station->getRepairRate()); |
|
66
|
|
|
if ($station->getHull() > $station->getMaxHull()) { |
|
67
|
|
|
$station->setHuell($station->getMaxHull()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
//repair station systems |
|
71
|
|
|
$damagedSystems = $wrapper->getDamagedSystems(); |
|
72
|
|
|
if ($damagedSystems !== []) { |
|
73
|
|
|
$firstSystem = $damagedSystems[0]; |
|
74
|
|
|
$firstSystem->setStatus(100); |
|
75
|
|
|
|
|
76
|
|
|
if ($station->getCrewCount() > 0) { |
|
77
|
|
|
$firstSystem->setMode($this->spacecraftSystemManager->lookupSystem($firstSystem->getSystemType())->getDefaultMode()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// maximum of two systems get repaired |
|
81
|
|
|
if (count($damagedSystems) > 1) { |
|
82
|
|
|
$secondSystem = $damagedSystems[1]; |
|
83
|
|
|
$secondSystem->setStatus(100); |
|
84
|
|
|
|
|
85
|
|
|
if ($station->getCrewCount() > 0) { |
|
86
|
|
|
$secondSystem->setMode($this->spacecraftSystemManager->lookupSystem($secondSystem->getSystemType())->getDefaultMode()); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
// consume spare parts |
|
92
|
|
|
$this->repairUtil->consumeSpareParts($neededParts, $station); |
|
93
|
|
|
|
|
94
|
|
|
if (!$wrapper->canBeRepaired()) { |
|
95
|
|
|
$station->setHuell($station->getMaxHull()); |
|
96
|
|
|
$station->setState(SpacecraftStateEnum::NONE); |
|
97
|
|
|
|
|
98
|
|
|
$shipOwnerMessage = sprintf( |
|
99
|
|
|
"Die Reparatur der %s wurde in Sektor %s fertiggestellt", |
|
100
|
|
|
$station->getName(), |
|
101
|
|
|
$station->getSectorString() |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
$this->privateMessageSender->send( |
|
105
|
|
|
UserEnum::USER_NOONE, |
|
106
|
|
|
$station->getUser()->getId(), |
|
107
|
|
|
$shipOwnerMessage, |
|
108
|
|
|
PrivateMessageFolderTypeEnum::SPECIAL_STATION |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
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