1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Lib\Transfer\Wrapper; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use request; |
9
|
|
|
use Stu\Lib\Information\InformationInterface; |
10
|
|
|
use Stu\Lib\Information\InformationWrapper; |
11
|
|
|
use Stu\Lib\Transfer\CommodityTransferInterface; |
12
|
|
|
use Stu\Lib\Transfer\EntityWithStorageInterface; |
13
|
|
|
use Stu\Lib\Transfer\Storage\StorageManagerInterface; |
14
|
|
|
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface; |
15
|
|
|
use Stu\Module\Spacecraft\Lib\Crew\TroopTransferUtilityInterface; |
16
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
17
|
|
|
use Stu\Orm\Entity\LocationInterface; |
18
|
|
|
use Stu\Orm\Entity\TorpedoTypeInterface; |
19
|
|
|
use Stu\Orm\Entity\UserInterface; |
20
|
|
|
|
21
|
|
|
class ColonyStorageEntityWrapper implements StorageEntityWrapperInterface |
22
|
|
|
{ |
23
|
4 |
|
public function __construct( |
24
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory, |
25
|
|
|
private CommodityTransferInterface $commodityTransfer, |
26
|
|
|
private StorageManagerInterface $storageManager, |
27
|
|
|
private TroopTransferUtilityInterface $troopTransferUtility, |
28
|
|
|
private ColonyInterface $colony |
29
|
4 |
|
) {} |
30
|
|
|
|
31
|
|
|
// GENERAL |
32
|
4 |
|
#[Override] |
33
|
|
|
public function get(): EntityWithStorageInterface |
34
|
|
|
{ |
35
|
4 |
|
return $this->colony; |
36
|
|
|
} |
37
|
|
|
|
38
|
4 |
|
#[Override] |
39
|
|
|
public function getUser(): UserInterface |
40
|
|
|
{ |
41
|
4 |
|
return $this->colony->getUser(); |
42
|
|
|
} |
43
|
|
|
|
44
|
2 |
|
#[Override] |
45
|
|
|
public function getName(): string |
46
|
|
|
{ |
47
|
2 |
|
return sprintf('Kolonie %s', $this->colony->getName()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
#[Override] |
51
|
|
|
public function getLocation(): LocationInterface |
52
|
|
|
{ |
53
|
|
|
return $this->colony->getLocation(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
#[Override] |
57
|
|
|
public function canPenetrateShields(UserInterface $user, InformationInterface $information): bool |
58
|
|
|
{ |
59
|
|
|
if ( |
60
|
|
|
$this->colony->getUser() !== $user |
61
|
|
|
&& $this->colonyLibFactory->createColonyShieldingManager($this->colony)->isShieldingEnabled() |
62
|
|
|
&& $this->colony->getShieldFrequency() |
|
|
|
|
63
|
|
|
) { |
64
|
|
|
$frequency = request::postInt('frequency'); |
65
|
|
|
if ($frequency !== $this->colony->getShieldFrequency()) { |
66
|
|
|
$information->addInformation("Die Schildfrequenz ist nicht korrekt"); |
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return true; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// COMMODITIES |
75
|
2 |
|
public function getBeamFactor(): int |
76
|
|
|
{ |
77
|
2 |
|
return $this->colony->getBeamFactor(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
#[Override] |
81
|
|
|
public function transfer( |
82
|
|
|
bool $isUnload, |
83
|
|
|
StorageEntityWrapperInterface $target, |
84
|
|
|
InformationInterface $information |
85
|
|
|
): void { |
86
|
|
|
|
87
|
|
|
$transferTarget = $isUnload ? $target->get() : $this->colony; |
88
|
|
|
if ($transferTarget->getMaxStorage() <= $transferTarget->getStorageSum()) { |
89
|
|
|
$information->addInformationf('%s: Der Lagerraum ist voll', $target->getName()); |
90
|
|
|
return; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$commodities = request::postArray('commodities'); |
94
|
|
|
$gcount = request::postArray('count'); |
95
|
|
|
|
96
|
|
|
$storage = $isUnload ? $this->colony->getStorage() : $target->get()->getBeamableStorage(); |
97
|
|
|
if ($storage->isEmpty()) { |
98
|
|
|
$information->addInformation("Keine Waren zum Beamen vorhanden"); |
99
|
|
|
return; |
100
|
|
|
} |
101
|
|
|
if (count($commodities) == 0 || count($gcount) == 0) { |
102
|
|
|
$information->addInformation("Es wurden keine Waren zum Beamen ausgewählt"); |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$informations = new InformationWrapper(); |
107
|
|
|
|
108
|
|
|
foreach ($commodities as $key => $value) { |
109
|
|
|
$commodityId = (int) $value; |
110
|
|
|
|
111
|
|
|
if (!array_key_exists($key, $gcount)) { |
112
|
|
|
continue; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$this->commodityTransfer->transferCommodity( |
116
|
|
|
$commodityId, |
117
|
|
|
$gcount[$key], |
118
|
|
|
$this->colony, |
119
|
|
|
$isUnload ? $this->colony : $target->get(), |
120
|
|
|
$transferTarget, |
121
|
|
|
$information |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
if (!$informations->isEmpty()) { |
126
|
|
|
$informations->addInformationArray( |
127
|
|
|
[sprintf( |
128
|
|
|
_('Die Kolonie %s hat folgende Waren zur %s transferiert'), |
129
|
|
|
$this->colony->getName(), |
130
|
|
|
$target->getName() |
131
|
|
|
)], |
132
|
|
|
true |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
// CREW |
138
|
|
|
#[Override] |
139
|
|
|
public function getMaxTransferrableCrew(bool $isTarget, UserInterface $user): int |
140
|
|
|
{ |
141
|
|
|
return $this->troopTransferUtility->ownCrewOnTarget($user, $this->colony); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
#[Override] |
145
|
|
|
public function getFreeCrewSpace(UserInterface $user): int |
146
|
|
|
{ |
147
|
|
|
if ($user !== $this->colony->getUser()) { |
148
|
|
|
return 0; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $this->colonyLibFactory |
152
|
|
|
->createColonyPopulationCalculator($this->colony) |
153
|
|
|
->getFreeAssignmentCount(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
#[Override] |
157
|
|
|
public function checkCrewStorage(int $amount, bool $isUnload, InformationInterface $information): bool |
158
|
|
|
{ |
159
|
|
|
return true; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
#[Override] |
163
|
|
|
public function acceptsCrewFrom(int $amount, UserInterface $user, InformationInterface $information): bool |
164
|
|
|
{ |
165
|
|
|
return $this->colony->getUser() === $user; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
#[Override] |
169
|
|
|
public function postCrewTransfer(int $foreignCrewChangeAmount, StorageEntityWrapperInterface $other, InformationInterface $information): void {} |
170
|
|
|
|
171
|
|
|
// TORPEDOS |
172
|
|
|
|
173
|
|
|
#[Override] |
174
|
|
|
public function getTorpedo(): ?TorpedoTypeInterface |
175
|
|
|
{ |
176
|
|
|
return null; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
#[Override] |
180
|
|
|
public function getTorpedoCount(): int |
181
|
|
|
{ |
182
|
|
|
return 0; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
#[Override] |
186
|
|
|
public function getMaxTorpedos(): int |
187
|
|
|
{ |
188
|
|
|
return $this->colony->getMaxStorage() - $this->colony->getStorageSum(); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
#[Override] |
192
|
|
|
public function canTransferTorpedos(InformationInterface $information): bool |
193
|
|
|
{ |
194
|
|
|
return true; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
#[Override] |
198
|
|
|
public function canStoreTorpedoType(TorpedoTypeInterface $torpedoType, InformationInterface $information): bool |
199
|
|
|
{ |
200
|
|
|
return true; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
#[Override] |
204
|
|
|
public function changeTorpedo(int $changeAmount, TorpedoTypeInterface $type): void |
205
|
|
|
{ |
206
|
|
|
if ($changeAmount > 0) { |
207
|
|
|
$this->storageManager->upperStorage( |
208
|
|
|
$this->colony, |
209
|
|
|
$type->getCommodity(), |
210
|
|
|
$changeAmount |
211
|
|
|
); |
212
|
|
|
} else { |
213
|
|
|
$this->storageManager->lowerStorage( |
214
|
|
|
$this->colony, |
215
|
|
|
$type->getCommodity(), |
216
|
|
|
$changeAmount |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|
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