1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Component\Ship\Retrofit; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use Stu\Component\Spacecraft\SpacecraftStateEnum; |
9
|
|
|
use Stu\Component\Spacecraft\SpacecraftModuleTypeEnum; |
10
|
|
|
use Stu\Lib\Transfer\Storage\StorageManagerInterface; |
11
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum; |
12
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
13
|
|
|
use Stu\Module\PlayerSetting\Lib\UserConstants; |
|
|
|
|
14
|
|
|
use Stu\Orm\Entity\Module; |
15
|
|
|
use Stu\Orm\Entity\Ship; |
16
|
|
|
use Stu\Orm\Repository\ColonyShipQueueRepositoryInterface; |
17
|
|
|
use Stu\Orm\Repository\ShipRepositoryInterface; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
|
21
|
|
|
|
22
|
|
|
final class CancelRetrofit implements CancelRetrofitInterface |
23
|
|
|
{ |
24
|
2 |
|
public function __construct( |
25
|
|
|
private ShipRepositoryInterface $shipRepository, |
26
|
|
|
private ColonyShipQueueRepositoryInterface $colonyShipQueueRepository, |
27
|
|
|
private readonly StorageManagerInterface $storageManager, |
28
|
|
|
private readonly PrivateMessageSenderInterface $privateMessageSender |
29
|
2 |
|
) {} |
30
|
|
|
|
31
|
|
|
|
32
|
8 |
|
#[Override] |
33
|
|
|
public function cancelRetrofit(Ship $ship): bool |
34
|
|
|
{ |
35
|
8 |
|
$state = $ship->getState(); |
36
|
8 |
|
if ($state === SpacecraftStateEnum::RETROFIT) { |
37
|
|
|
$queueEntry = $this->colonyShipQueueRepository->getByShip($ship->getId()); |
38
|
|
|
if ($queueEntry === null) { |
39
|
|
|
$this->setStateNoneAndSave($ship); |
40
|
|
|
return true; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$colony = $queueEntry->getColony(); |
44
|
|
|
$newBuildplan = $queueEntry->getSpacecraftBuildplan(); |
45
|
|
|
$oldBuildplan = $ship->getBuildplan(); |
46
|
|
|
$returnedmodules = []; |
47
|
|
|
|
48
|
|
|
$buildTime = $queueEntry->getBuildtime(); |
49
|
|
|
$finishDate = $queueEntry->getFinishDate(); |
50
|
|
|
$startDate = $finishDate - $buildTime; |
51
|
|
|
$currentTime = time(); |
52
|
|
|
$firstQuarter = $startDate + ($buildTime * 0.25); |
53
|
|
|
|
54
|
|
|
$withinFirstQuarter = $currentTime <= $firstQuarter; |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
if ($oldBuildplan != null && $newBuildplan != null) { |
58
|
|
|
foreach (SpacecraftModuleTypeEnum::getModuleSelectorOrder() as $moduleType) { |
59
|
|
|
$oldModules = $oldBuildplan->getModulesByType($moduleType)->toArray(); |
60
|
|
|
$newModules = $newBuildplan->getModulesByType($moduleType)->toArray(); |
61
|
|
|
|
62
|
|
|
/** @var array<Module> */ |
63
|
|
|
$addingModules = array_udiff($newModules, $oldModules, function (Module $a, Module $b): int { |
64
|
|
|
return $a->getId() - $b->getId(); |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
if ($withinFirstQuarter) { |
68
|
|
|
foreach ($addingModules as $module) { |
69
|
|
|
if ($module->getType() != SpacecraftModuleTypeEnum::HULL) { |
70
|
|
|
$returnedmodules[] = $module; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$txt = _("Auf der Kolonie " . $colony->getName() . " wurde die Umrüstung der " . $ship->getName() . " abgebrochen"); |
78
|
|
|
|
79
|
|
|
if ($returnedmodules !== []) { |
80
|
|
|
$msg = "\n\nDie folgenden Module wurden beim Abbruch der Umrüstung zurückgewonnen: \n"; |
81
|
|
|
|
82
|
|
|
foreach ($returnedmodules as $module) { |
83
|
|
|
$this->storageManager->upperStorage($colony, $module->getCommodity(), 1); |
84
|
|
|
$msg .= "- " . $module->getName() . "\n"; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$txt .= $msg; |
88
|
|
|
} else { |
89
|
|
|
$txt .= "\n\nEs konnten keine Module zurückgewonnen werden, da der Umrüstungsprozess bereits zu weit fortgeschritten war"; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->privateMessageSender->send( |
93
|
|
|
UserConstants::USER_NOONE, |
94
|
|
|
$colony->getUserId(), |
95
|
|
|
$txt, |
96
|
|
|
PrivateMessageFolderTypeEnum::SPECIAL_COLONY |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$this->setStateNoneAndSave($ship); |
100
|
|
|
$this->colonyShipQueueRepository->truncateByShip($ship->getId()); |
101
|
|
|
|
102
|
|
|
return true; |
103
|
|
|
} |
104
|
|
|
|
105
|
8 |
|
return false; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
private function setStateNoneAndSave(Ship $ship): void |
109
|
|
|
{ |
110
|
|
|
$ship->getCondition()->setState(SpacecraftStateEnum::NONE); |
111
|
|
|
$this->shipRepository->save($ship); |
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