|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Colony\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum; |
|
8
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
|
9
|
|
|
use Stu\Module\PlayerSetting\Lib\UserConstants; |
|
|
|
|
|
|
10
|
|
|
use Stu\Orm\Entity\Colony; |
|
11
|
|
|
use Stu\Orm\Entity\Fleet; |
|
12
|
|
|
use Stu\Orm\Repository\ColonyRepositoryInterface; |
|
13
|
|
|
use Stu\Orm\Repository\ColonySandboxRepositoryInterface; |
|
14
|
|
|
use Stu\Orm\Repository\ColonyShipQueueRepositoryInterface; |
|
15
|
|
|
use Stu\Orm\Repository\ColonyTerraformingRepositoryInterface; |
|
16
|
|
|
use Stu\Orm\Repository\CrewRepositoryInterface; |
|
17
|
|
|
use Stu\Orm\Repository\CrewTrainingRepositoryInterface; |
|
18
|
|
|
use Stu\Orm\Repository\PlanetFieldRepositoryInterface; |
|
19
|
|
|
use Stu\Orm\Repository\CrewAssignmentRepositoryInterface; |
|
20
|
|
|
use Stu\Orm\Repository\StorageRepositoryInterface; |
|
21
|
|
|
use Stu\Orm\Repository\UserRepositoryInterface; |
|
22
|
|
|
|
|
23
|
|
|
final class ColonyResetter implements ColonyResetterInterface |
|
24
|
|
|
{ |
|
25
|
2 |
|
public function __construct( |
|
26
|
|
|
private readonly ColonyRepositoryInterface $colonyRepository, |
|
27
|
|
|
private readonly UserRepositoryInterface $userRepository, |
|
28
|
|
|
private readonly StorageRepositoryInterface $storageRepository, |
|
29
|
|
|
private readonly ColonyTerraformingRepositoryInterface $colonyTerraformingRepository, |
|
30
|
|
|
private readonly ColonyShipQueueRepositoryInterface $colonyShipQueueRepository, |
|
31
|
|
|
private readonly PlanetFieldRepositoryInterface $planetFieldRepository, |
|
32
|
|
|
private readonly CrewRepositoryInterface $crewRepository, |
|
33
|
|
|
private readonly CrewTrainingRepositoryInterface $crewTrainingRepository, |
|
34
|
|
|
private readonly CrewAssignmentRepositoryInterface $shipCrewRepository, |
|
35
|
|
|
private readonly ColonySandboxRepositoryInterface $colonySandboxRepository, |
|
36
|
|
|
private readonly PrivateMessageSenderInterface $privateMessageSender |
|
37
|
2 |
|
) {} |
|
38
|
|
|
|
|
39
|
1 |
|
#[\Override] |
|
40
|
|
|
public function reset( |
|
41
|
|
|
Colony $colony, |
|
42
|
|
|
bool $sendMessage = true |
|
43
|
|
|
): void { |
|
44
|
1 |
|
$this->resetBlockers($colony, $sendMessage); |
|
45
|
1 |
|
$this->resetDefenders($colony, $sendMessage); |
|
46
|
1 |
|
$this->resetCrew($colony); |
|
47
|
1 |
|
$this->resetCrewTraining($colony); |
|
48
|
|
|
|
|
49
|
1 |
|
$colony |
|
50
|
1 |
|
->setUser($this->userRepository->getFallbackUser()) |
|
51
|
1 |
|
->setName('') |
|
52
|
1 |
|
->getChangeable() |
|
53
|
1 |
|
->setEps(0) |
|
54
|
1 |
|
->setMaxEps(0) |
|
55
|
1 |
|
->setMaxStorage(0) |
|
56
|
1 |
|
->setWorkers(0) |
|
57
|
1 |
|
->setWorkless(0) |
|
58
|
1 |
|
->setMaxBev(0) |
|
59
|
1 |
|
->setTorpedo(null) |
|
60
|
1 |
|
->setShieldFrequency(0) |
|
61
|
1 |
|
->setShields(0) |
|
62
|
1 |
|
->setImmigrationstate(true) |
|
63
|
1 |
|
->setPopulationlimit(0); |
|
64
|
|
|
|
|
65
|
1 |
|
$this->colonyRepository->save($colony); |
|
66
|
|
|
|
|
67
|
1 |
|
$this->storageRepository->truncateByColony($colony); |
|
68
|
|
|
|
|
69
|
1 |
|
foreach ($this->colonyTerraformingRepository->getByColony([$colony]) as $fieldTerraforming) { |
|
70
|
1 |
|
$this->colonyTerraformingRepository->delete($fieldTerraforming); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
$this->colonyShipQueueRepository->truncateByColony($colony); |
|
74
|
1 |
|
$this->planetFieldRepository->truncateByColony($colony); |
|
75
|
1 |
|
$this->colonySandboxRepository->truncateByColony($colony); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
private function resetBlockers(Colony $colony, bool $sendMessage = true): void |
|
79
|
|
|
{ |
|
80
|
1 |
|
foreach ($colony->getBlockers() as $blockerFleet) { |
|
81
|
1 |
|
if ($sendMessage) { |
|
82
|
|
|
$this->sendMessage($colony, $blockerFleet, false); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
1 |
|
$blockerFleet->setBlockedColony(null); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
1 |
|
$colony->getBlockers()->clear(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
private function resetDefenders(Colony $colony, bool $sendMessage = true): void |
|
92
|
|
|
{ |
|
93
|
1 |
|
foreach ($colony->getDefenders() as $defenderFleet) { |
|
94
|
1 |
|
if ($sendMessage) { |
|
95
|
|
|
$this->sendMessage($colony, $defenderFleet, true); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
1 |
|
$defenderFleet->setDefendedColony(null); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
$colony->getDefenders()->clear(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
1 |
|
private function resetCrew(Colony $colony): void |
|
105
|
|
|
{ |
|
106
|
1 |
|
$crewArray = []; |
|
107
|
1 |
|
foreach ($colony->getCrewAssignments() as $crewAssignment) { |
|
108
|
1 |
|
$crewArray[] = $crewAssignment->getCrew(); |
|
109
|
1 |
|
$crewAssignment->clearAssignment(); |
|
110
|
1 |
|
$this->shipCrewRepository->delete($crewAssignment); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
foreach ($crewArray as $crew) { |
|
114
|
1 |
|
$this->crewRepository->delete($crew); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
private function resetCrewTraining(Colony $colony): void |
|
119
|
|
|
{ |
|
120
|
1 |
|
$this->crewTrainingRepository->truncateByColony($colony); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
private function sendMessage(Colony $colony, Fleet $fleet, bool $isDefending): void |
|
124
|
|
|
{ |
|
125
|
|
|
$txt = sprintf( |
|
126
|
|
|
'Der Spieler %s hat die Kolonie %s in Sektor %d|%d (%s System) verlassen. Deine Flotte %s hat die %s beendet.', |
|
127
|
|
|
$colony->getUser()->getName(), |
|
128
|
|
|
$colony->getName(), |
|
129
|
|
|
$colony->getSx(), |
|
130
|
|
|
$colony->getSy(), |
|
131
|
|
|
$colony->getSystem()->getName(), |
|
132
|
|
|
$fleet->getName(), |
|
133
|
|
|
$isDefending ? 'Verteidigung' : 'Blockade' |
|
134
|
|
|
); |
|
135
|
|
|
|
|
136
|
|
|
$this->privateMessageSender->send( |
|
137
|
|
|
UserConstants::USER_NOONE, |
|
138
|
|
|
$fleet->getUserId(), |
|
139
|
|
|
$txt, |
|
140
|
|
|
PrivateMessageFolderTypeEnum::SPECIAL_SHIP |
|
141
|
|
|
); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
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