|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use Doctrine\Common\Collections\Collection; |
|
9
|
|
|
use Doctrine\ORM\Mapping\Column; |
|
10
|
|
|
use Doctrine\ORM\Mapping\Entity; |
|
11
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
|
12
|
|
|
use Doctrine\ORM\Mapping\Id; |
|
13
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
|
14
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
|
15
|
|
|
use Doctrine\ORM\Mapping\OneToMany; |
|
16
|
|
|
use Doctrine\ORM\Mapping\OneToOne; |
|
17
|
|
|
use Doctrine\ORM\Mapping\OrderBy; |
|
18
|
|
|
use Doctrine\ORM\Mapping\Table; |
|
19
|
|
|
use LogicException; |
|
20
|
|
|
use Stu\Component\Colony\ColonyMenuEnum; |
|
21
|
|
|
use Stu\Component\Colony\Trait\ColonyRotationTrait; |
|
22
|
|
|
use Stu\Component\Game\ModuleEnum; |
|
23
|
|
|
use Stu\Lib\Colony\PlanetFieldHostInterface; |
|
24
|
|
|
use Stu\Lib\Colony\PlanetFieldHostTypeEnum; |
|
25
|
|
|
use Stu\Lib\Interaction\EntityWithInteractionCheckInterface; |
|
26
|
|
|
use Stu\Lib\Map\EntityWithLocationInterface; |
|
27
|
|
|
use Stu\Lib\Transfer\CommodityTransfer; |
|
28
|
|
|
use Stu\Lib\Transfer\EntityWithStorageInterface; |
|
29
|
|
|
use Stu\Lib\Transfer\TransferEntityTypeEnum; |
|
30
|
|
|
use Stu\Module\Colony\View\ShowColony\ShowColony; |
|
31
|
|
|
use Stu\Module\PlayerSetting\Lib\UserConstants; |
|
|
|
|
|
|
32
|
|
|
use Stu\Module\Spacecraft\Lib\Crew\EntityWithCrewAssignmentsInterface; |
|
33
|
|
|
use Stu\Orm\Repository\ColonyRepository; |
|
34
|
|
|
|
|
35
|
|
|
#[Table(name: 'stu_colony')] |
|
36
|
|
|
#[Entity(repositoryClass: ColonyRepository::class)] |
|
37
|
|
|
class Colony implements |
|
38
|
|
|
PlanetFieldHostInterface, |
|
39
|
|
|
EntityWithStorageInterface, |
|
40
|
|
|
EntityWithLocationInterface, |
|
41
|
|
|
EntityWithCrewAssignmentsInterface, |
|
42
|
|
|
EntityWithInteractionCheckInterface |
|
43
|
|
|
{ |
|
44
|
|
|
use ColonyRotationTrait; |
|
45
|
|
|
|
|
46
|
|
|
#[Id] |
|
47
|
|
|
#[Column(type: 'integer')] |
|
48
|
|
|
#[GeneratedValue(strategy: 'IDENTITY')] |
|
49
|
|
|
private int $id; |
|
50
|
|
|
|
|
51
|
|
|
#[OneToOne(targetEntity: ColonyChangeable::class, mappedBy: 'colony', fetch: 'EAGER', cascade: ['all'])] |
|
52
|
|
|
private ?ColonyChangeable $changeable; |
|
53
|
|
|
|
|
54
|
|
|
#[Column(type: 'integer')] |
|
55
|
|
|
private int $colonies_classes_id = 0; |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
#[Column(type: 'integer')] |
|
58
|
|
|
private int $user_id = 0; |
|
59
|
|
|
|
|
60
|
|
|
#[Column(type: 'string')] |
|
61
|
|
|
private string $name = ''; |
|
62
|
|
|
|
|
63
|
|
|
#[Column(type: 'string', length: 100)] |
|
64
|
|
|
private string $planet_name = ''; |
|
65
|
|
|
|
|
66
|
|
|
#[Column(type: 'text', nullable: true)] |
|
67
|
|
|
private ?string $mask = null; |
|
68
|
|
|
|
|
69
|
|
|
#[Column(type: 'integer', nullable: true)] |
|
70
|
|
|
private ?int $database_id = null; |
|
71
|
|
|
|
|
72
|
|
|
#[Column(type: 'integer', length: 3)] |
|
73
|
|
|
private int $rotation_factor = 1; |
|
74
|
|
|
|
|
75
|
|
|
#[Column(type: 'integer', length: 2)] |
|
76
|
|
|
private int $surface_width = 0; |
|
77
|
|
|
|
|
78
|
|
|
#[ManyToOne(targetEntity: ColonyClass::class)] |
|
79
|
|
|
#[JoinColumn(name: 'colonies_classes_id', nullable: false, referencedColumnName: 'id')] |
|
80
|
|
|
private ColonyClass $colonyClass; |
|
81
|
|
|
|
|
82
|
|
|
#[OneToOne(targetEntity: StarSystemMap::class, inversedBy: 'colony')] |
|
83
|
|
|
#[JoinColumn(name: 'starsystem_map_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
|
84
|
|
|
private StarSystemMap $starsystem_map; |
|
85
|
|
|
|
|
86
|
|
|
#[ManyToOne(targetEntity: User::class)] |
|
87
|
|
|
#[JoinColumn(name: 'user_id', nullable: false, referencedColumnName: 'id')] |
|
88
|
|
|
private User $user; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var ArrayCollection<int, PlanetField> |
|
92
|
|
|
*/ |
|
93
|
|
|
#[OneToMany( |
|
94
|
|
|
targetEntity: PlanetField::class, |
|
95
|
|
|
mappedBy: 'colony', |
|
96
|
|
|
indexBy: 'field_id', |
|
97
|
|
|
fetch: 'EXTRA_LAZY' |
|
98
|
|
|
)] |
|
99
|
|
|
#[OrderBy(['field_id' => 'ASC'])] |
|
100
|
|
|
private Collection $planetFields; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @var ArrayCollection<int, Storage> |
|
104
|
|
|
*/ |
|
105
|
|
|
#[OneToMany(targetEntity: Storage::class, mappedBy: 'colony', indexBy: 'commodity_id')] |
|
106
|
|
|
#[OrderBy(['commodity_id' => 'ASC'])] |
|
107
|
|
|
private Collection $storage; |
|
108
|
|
|
|
|
109
|
|
|
#[OneToOne(targetEntity: DatabaseEntry::class)] |
|
110
|
|
|
#[JoinColumn(name: 'database_id', referencedColumnName: 'id')] |
|
111
|
|
|
private ?DatabaseEntry $databaseEntry; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @var ArrayCollection<int, Fleet> |
|
115
|
|
|
*/ |
|
116
|
|
|
#[OneToMany(targetEntity: Fleet::class, mappedBy: 'defendedColony')] |
|
117
|
|
|
private Collection $defenders; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @var ArrayCollection<int, Fleet> |
|
121
|
|
|
*/ |
|
122
|
|
|
#[OneToMany(targetEntity: Fleet::class, mappedBy: 'blockedColony')] |
|
123
|
|
|
private Collection $blockers; |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @var ArrayCollection<int, CrewAssignment> |
|
127
|
|
|
*/ |
|
128
|
|
|
#[OneToMany(targetEntity: CrewAssignment::class, mappedBy: 'colony')] |
|
129
|
|
|
private Collection $crewAssignments; |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @var ArrayCollection<int, CrewTraining> |
|
133
|
|
|
*/ |
|
134
|
|
|
#[OneToMany(targetEntity: CrewTraining::class, mappedBy: 'colony')] |
|
135
|
|
|
private Collection $crewTrainings; |
|
136
|
|
|
|
|
137
|
|
|
/** @var array<int, int> */ |
|
138
|
|
|
private array $twilightZones = []; |
|
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
public function __construct() |
|
141
|
|
|
{ |
|
142
|
|
|
$this->planetFields = new ArrayCollection(); |
|
143
|
|
|
$this->storage = new ArrayCollection(); |
|
144
|
|
|
$this->defenders = new ArrayCollection(); |
|
145
|
|
|
$this->blockers = new ArrayCollection(); |
|
146
|
|
|
$this->crewAssignments = new ArrayCollection(); |
|
147
|
|
|
$this->crewTrainings = new ArrayCollection(); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
64 |
|
#[\Override] |
|
151
|
|
|
public function getId(): int |
|
152
|
|
|
{ |
|
153
|
64 |
|
return $this->id; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
36 |
|
public function getChangeable(): ColonyChangeable |
|
157
|
|
|
{ |
|
158
|
36 |
|
return $this->changeable ?? throw new LogicException('Colony has no changeable'); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function setChangeable(ColonyChangeable $changeable): Colony |
|
162
|
|
|
{ |
|
163
|
|
|
$this->changeable = $changeable; |
|
164
|
|
|
|
|
165
|
|
|
return $this; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
77 |
|
public function getUserId(): int |
|
169
|
|
|
{ |
|
170
|
77 |
|
return $this->user_id; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
8 |
|
public function getSx(): int |
|
174
|
|
|
{ |
|
175
|
8 |
|
return $this->getStarsystemMap()->getSx(); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
8 |
|
public function getSy(): int |
|
179
|
|
|
{ |
|
180
|
8 |
|
return $this->getStarsystemMap()->getSy(); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
18 |
|
#[\Override] |
|
184
|
|
|
public function getName(): string |
|
185
|
|
|
{ |
|
186
|
18 |
|
return $this->name; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function setName(string $name): Colony |
|
190
|
|
|
{ |
|
191
|
|
|
$this->name = $name; |
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
4 |
|
public function getPlanetName(): string |
|
196
|
|
|
{ |
|
197
|
4 |
|
return $this->planet_name; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function setPlanetName(string $planet_name): Colony |
|
201
|
|
|
{ |
|
202
|
|
|
$this->planet_name = $planet_name; |
|
203
|
|
|
return $this; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
2 |
|
public function getMask(): ?string |
|
207
|
|
|
{ |
|
208
|
2 |
|
return $this->mask; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
public function setMask(?string $mask): Colony |
|
212
|
|
|
{ |
|
213
|
|
|
$this->mask = $mask; |
|
214
|
|
|
return $this; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
public function getDatabaseId(): ?int |
|
218
|
|
|
{ |
|
219
|
|
|
return $this->database_id; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
public function setDatabaseEntry(?DatabaseEntry $entry): Colony |
|
223
|
|
|
{ |
|
224
|
|
|
$this->databaseEntry = $entry; |
|
225
|
|
|
return $this; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
5 |
|
public function getRotationFactor(): int |
|
229
|
|
|
{ |
|
230
|
5 |
|
return $this->rotation_factor; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
public function setRotationFactor(int $rotationFactor): Colony |
|
234
|
|
|
{ |
|
235
|
|
|
$this->rotation_factor = $rotationFactor; |
|
236
|
|
|
|
|
237
|
|
|
return $this; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
7 |
|
public function getSurfaceWidth(): int |
|
241
|
|
|
{ |
|
242
|
7 |
|
return $this->surface_width; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
public function setSurfaceWidth(int $surfaceWidth): Colony |
|
246
|
|
|
{ |
|
247
|
|
|
$this->surface_width = $surfaceWidth; |
|
248
|
|
|
return $this; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
30 |
|
#[\Override] |
|
252
|
|
|
public function getColonyClass(): ColonyClass |
|
253
|
|
|
{ |
|
254
|
30 |
|
return $this->colonyClass; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
public function setColonyClass(ColonyClass $colonyClass): Colony |
|
258
|
|
|
{ |
|
259
|
|
|
$this->colonyClass = $colonyClass; |
|
260
|
|
|
return $this; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
11 |
|
#[\Override] |
|
264
|
|
|
public function getStorageSum(): int |
|
265
|
|
|
{ |
|
266
|
11 |
|
return array_reduce( |
|
267
|
11 |
|
$this->getStorage()->getValues(), |
|
268
|
11 |
|
fn(int $sum, Storage $storage): int => $sum + $storage->getAmount(), |
|
269
|
11 |
|
0 |
|
270
|
11 |
|
); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
19 |
|
public function getStarsystemMap(): StarSystemMap |
|
274
|
|
|
{ |
|
275
|
19 |
|
return $this->starsystem_map; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
11 |
|
#[\Override] |
|
279
|
|
|
public function getLocation(): Map|StarSystemMap |
|
280
|
|
|
{ |
|
281
|
11 |
|
return $this->getStarsystemMap(); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
public function setStarsystemMap(StarSystemMap $systemMap): Colony |
|
285
|
|
|
{ |
|
286
|
|
|
$this->starsystem_map = $systemMap; |
|
287
|
|
|
|
|
288
|
|
|
return $this; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
9 |
|
public function getSystem(): StarSystem |
|
292
|
|
|
{ |
|
293
|
9 |
|
return $this->getStarsystemMap()->getSystem(); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
2 |
|
public function getBeamFactor(): int |
|
297
|
|
|
{ |
|
298
|
2 |
|
return 10; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
7 |
|
#[\Override] |
|
302
|
|
|
public function getPlanetFields(): Collection |
|
303
|
|
|
{ |
|
304
|
7 |
|
return $this->planetFields; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
2 |
|
#[\Override] |
|
308
|
|
|
public function getBeamableStorage(): Collection |
|
309
|
|
|
{ |
|
310
|
2 |
|
return CommodityTransfer::excludeNonBeamable($this->storage); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
19 |
|
#[\Override] |
|
314
|
|
|
public function getStorage(): Collection |
|
315
|
|
|
{ |
|
316
|
19 |
|
return $this->storage; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
1 |
|
public function isDefended(): bool |
|
320
|
|
|
{ |
|
321
|
1 |
|
return !$this->getDefenders()->isEmpty(); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @return Collection<int, Fleet> |
|
326
|
|
|
*/ |
|
327
|
2 |
|
public function getDefenders(): Collection |
|
328
|
|
|
{ |
|
329
|
2 |
|
return $this->defenders; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
1 |
|
public function isBlocked(): bool |
|
333
|
|
|
{ |
|
334
|
1 |
|
return !$this->getBlockers()->isEmpty(); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* @return Collection<int, Fleet> |
|
339
|
|
|
*/ |
|
340
|
1 |
|
public function getBlockers(): Collection |
|
341
|
|
|
{ |
|
342
|
1 |
|
return $this->blockers; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
#[\Override] |
|
346
|
|
|
public function getCrewAssignments(): Collection |
|
347
|
|
|
{ |
|
348
|
|
|
return $this->crewAssignments; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
5 |
|
public function getCrewAssignmentAmount(): int |
|
352
|
|
|
{ |
|
353
|
5 |
|
return $this->crewAssignments->count(); |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
1 |
|
public function getCrewTrainingAmount(): int |
|
357
|
|
|
{ |
|
358
|
1 |
|
return $this->crewTrainings->count(); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
6 |
|
public function isFree(): bool |
|
362
|
|
|
{ |
|
363
|
6 |
|
return $this->getUserId() === UserConstants::USER_NOONE; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
22 |
|
#[\Override] |
|
367
|
|
|
public function getUser(): User |
|
368
|
|
|
{ |
|
369
|
22 |
|
return $this->user; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
public function setUser(User $user): Colony |
|
373
|
|
|
{ |
|
374
|
|
|
$this->user = $user; |
|
375
|
|
|
return $this; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
17 |
|
#[\Override] |
|
379
|
|
|
public function getWorkers(): int |
|
380
|
|
|
{ |
|
381
|
17 |
|
return $this->getChangeable()->getWorkers(); |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
5 |
|
public function getWorkless(): int |
|
385
|
|
|
{ |
|
386
|
5 |
|
return $this->getChangeable()->getWorkless(); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
4 |
|
public function getMaxBev(): int |
|
390
|
|
|
{ |
|
391
|
4 |
|
return $this->getChangeable()->getMaxBev(); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
9 |
|
#[\Override] |
|
395
|
|
|
public function getMaxEps(): int |
|
396
|
|
|
{ |
|
397
|
9 |
|
return $this->getChangeable()->getMaxEps(); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
12 |
|
#[\Override] |
|
401
|
|
|
public function getMaxStorage(): int |
|
402
|
|
|
{ |
|
403
|
12 |
|
return $this->getChangeable()->getMaxStorage(); |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
15 |
|
#[\Override] |
|
407
|
|
|
public function getPopulation(): int |
|
408
|
|
|
{ |
|
409
|
15 |
|
return $this->getChangeable()->getPopulation(); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
2 |
|
public function getSectorString(): string |
|
413
|
|
|
{ |
|
414
|
2 |
|
return $this->getStarsystemMap()->getSectorString(); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
#[\Override] |
|
418
|
|
|
public function isColony(): bool |
|
419
|
|
|
{ |
|
420
|
|
|
return true; |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
47 |
|
#[\Override] |
|
424
|
|
|
public function getHostType(): PlanetFieldHostTypeEnum |
|
425
|
|
|
{ |
|
426
|
47 |
|
return PlanetFieldHostTypeEnum::COLONY; |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
3 |
|
#[\Override] |
|
430
|
|
|
public function getDefaultViewIdentifier(): string |
|
431
|
|
|
{ |
|
432
|
3 |
|
return ShowColony::VIEW_IDENTIFIER; |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
1 |
|
#[\Override] |
|
436
|
|
|
public function isMenuAllowed(ColonyMenuEnum $menu): bool |
|
437
|
|
|
{ |
|
438
|
1 |
|
return true; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
4 |
|
#[\Override] |
|
442
|
|
|
public function getTransferEntityType(): TransferEntityTypeEnum |
|
443
|
|
|
{ |
|
444
|
4 |
|
return TransferEntityTypeEnum::COLONY; |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
#[\Override] |
|
448
|
|
|
public function getHref(): string |
|
449
|
|
|
{ |
|
450
|
|
|
return sprintf( |
|
451
|
|
|
'%s?%s=1&id=%d', |
|
452
|
|
|
ModuleEnum::COLONY->getPhpPage(), |
|
453
|
|
|
ShowColony::VIEW_IDENTIFIER, |
|
454
|
|
|
$this->getId() |
|
455
|
|
|
); |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
#[\Override] |
|
459
|
|
|
public function getComponentParameters(): string |
|
460
|
|
|
{ |
|
461
|
|
|
return sprintf( |
|
462
|
|
|
'&hosttype=%d&id=%d', |
|
463
|
|
|
$this->getHostType()->value, |
|
464
|
|
|
$this->getId() |
|
465
|
|
|
); |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
|
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