|
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\Index; |
|
14
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
|
15
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
|
16
|
|
|
use Doctrine\ORM\Mapping\OneToMany; |
|
17
|
|
|
use Doctrine\ORM\Mapping\OneToOne; |
|
18
|
|
|
use Doctrine\ORM\Mapping\OrderBy; |
|
19
|
|
|
use Doctrine\ORM\Mapping\Table; |
|
20
|
|
|
use Stu\Component\Faction\FactionEnum; |
|
21
|
|
|
use Stu\Component\Spacecraft\ModuleSpecialAbilityEnum; |
|
22
|
|
|
use Stu\Component\Spacecraft\SpacecraftModuleTypeEnum; |
|
23
|
|
|
use Stu\Component\Spacecraft\SpacecraftRumpRoleEnum; |
|
24
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
|
25
|
|
|
use Stu\Orm\Repository\ModuleRepository; |
|
26
|
|
|
|
|
27
|
|
|
#[Table(name: 'stu_modules')] |
|
28
|
|
|
#[Index(name: 'ship_rump_role_type_idx', columns: ['rumps_role_id', 'type'])] |
|
29
|
|
|
#[Entity(repositoryClass: ModuleRepository::class)] |
|
30
|
|
|
class Module |
|
31
|
|
|
{ |
|
32
|
|
|
#[Id] |
|
33
|
|
|
#[Column(type: 'integer')] |
|
34
|
|
|
#[GeneratedValue(strategy: 'IDENTITY')] |
|
35
|
|
|
private int $id; |
|
36
|
|
|
|
|
37
|
|
|
#[Column(type: 'string')] |
|
38
|
|
|
private string $name = ''; |
|
39
|
|
|
|
|
40
|
|
|
#[Column(type: 'smallint')] |
|
41
|
|
|
private int $level = 0; |
|
42
|
|
|
|
|
43
|
|
|
#[Column(type: 'smallint')] |
|
44
|
|
|
private int $upgrade_factor = 0; |
|
45
|
|
|
|
|
46
|
|
|
#[Column(type: 'smallint')] |
|
47
|
|
|
private int $default_factor = 0; |
|
48
|
|
|
|
|
49
|
|
|
#[Column(type: 'smallint')] |
|
50
|
|
|
private int $downgrade_factor = 0; |
|
51
|
|
|
|
|
52
|
|
|
#[Column(type: 'smallint')] |
|
53
|
|
|
private int $crew = 0; |
|
54
|
|
|
|
|
55
|
|
|
#[Column(type: 'integer', enumType: SpacecraftModuleTypeEnum::class)] |
|
56
|
|
|
private SpacecraftModuleTypeEnum $type = SpacecraftModuleTypeEnum::HULL; |
|
57
|
|
|
|
|
58
|
|
|
#[Column(type: 'integer', nullable: true)] |
|
59
|
|
|
private ?int $research_id = 0; |
|
60
|
|
|
|
|
61
|
|
|
#[Column(type: 'integer')] |
|
62
|
|
|
private int $commodity_id = 0; |
|
63
|
|
|
|
|
64
|
|
|
#[Column(type: 'boolean')] |
|
65
|
|
|
private bool $viewable = false; |
|
66
|
|
|
|
|
67
|
|
|
#[Column(type: 'integer', enumType: SpacecraftRumpRoleEnum::class, nullable: true)] |
|
68
|
|
|
private ?SpacecraftRumpRoleEnum $rumps_role_id = null; |
|
69
|
|
|
|
|
70
|
|
|
#[Column(type: 'smallint')] |
|
71
|
|
|
private int $ecost = 0; |
|
72
|
|
|
|
|
73
|
|
|
#[Column(type: 'integer', nullable: true, enumType: FactionEnum::class)] |
|
74
|
|
|
private ?FactionEnum $faction_id = null; |
|
75
|
|
|
|
|
76
|
|
|
#[Column(type: 'integer', enumType: SpacecraftSystemTypeEnum::class, nullable: true)] |
|
77
|
|
|
private ?SpacecraftSystemTypeEnum $system_type = null; |
|
78
|
|
|
|
|
79
|
|
|
#[Column(type: 'boolean', nullable: true)] |
|
80
|
|
|
private ?bool $is_npc = false; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var Research |
|
84
|
|
|
*/ |
|
85
|
|
|
#[ManyToOne(targetEntity: Research::class)] |
|
86
|
|
|
#[JoinColumn(name: 'research_id', nullable: false, referencedColumnName: 'id')] |
|
87
|
|
|
private $research; |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
#[ManyToOne(targetEntity: Commodity::class)] |
|
90
|
|
|
#[JoinColumn(name: 'commodity_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
|
91
|
|
|
private Commodity $commodity; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @var Faction |
|
95
|
|
|
*/ |
|
96
|
|
|
#[ManyToOne(targetEntity: Faction::class)] |
|
97
|
|
|
#[JoinColumn(name: 'faction_id', nullable: false, referencedColumnName: 'id')] |
|
98
|
|
|
private $faction; |
|
99
|
|
|
|
|
100
|
|
|
#[ManyToOne(targetEntity: ShipRumpRole::class)] |
|
101
|
|
|
#[JoinColumn(name: 'rumps_role_id', nullable: false, referencedColumnName: 'id')] |
|
102
|
|
|
private ShipRumpRole $shipRumpRole; |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @var ArrayCollection<int, ModuleSpecial> |
|
106
|
|
|
*/ |
|
107
|
|
|
#[OneToMany(targetEntity: ModuleSpecial::class, mappedBy: 'module', indexBy: 'special_id', fetch: 'EXTRA_LAZY')] |
|
108
|
|
|
#[OrderBy(['special_id' => 'ASC'])] |
|
109
|
|
|
private Collection $moduleSpecials; |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @var ArrayCollection<int, ModuleCost> |
|
113
|
|
|
*/ |
|
114
|
|
|
#[OneToMany(targetEntity: ModuleCost::class, mappedBy: 'module')] |
|
115
|
|
|
private Collection $buildingCosts; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @var ArrayCollection<int, TorpedoHull> |
|
119
|
|
|
*/ |
|
120
|
|
|
#[OneToMany(targetEntity: TorpedoHull::class, mappedBy: 'module', indexBy: 'torpedo_type')] |
|
121
|
|
|
#[OrderBy(['torpedo_type' => 'ASC'])] |
|
122
|
|
|
private Collection $torpedoHull; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @var ArrayCollection<int, WeaponShield> |
|
126
|
|
|
*/ |
|
127
|
|
|
#[OneToMany(targetEntity: WeaponShield::class, mappedBy: 'module', indexBy: 'weapon_id')] |
|
128
|
|
|
#[OrderBy(['weapon_id' => 'ASC'])] |
|
129
|
|
|
private Collection $weaponShield; |
|
130
|
|
|
|
|
131
|
|
|
#[OneToOne(targetEntity: Weapon::class, mappedBy: 'module')] |
|
132
|
|
|
private ?Weapon $weapon = null; |
|
133
|
|
|
|
|
134
|
|
|
public function __construct() |
|
135
|
|
|
{ |
|
136
|
|
|
$this->moduleSpecials = new ArrayCollection(); |
|
137
|
|
|
$this->buildingCosts = new ArrayCollection(); |
|
138
|
|
|
$this->torpedoHull = new ArrayCollection(); |
|
139
|
|
|
$this->weaponShield = new ArrayCollection(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
5 |
|
public function getId(): int |
|
143
|
|
|
{ |
|
144
|
5 |
|
return $this->id; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
8 |
|
public function getName(): string |
|
148
|
|
|
{ |
|
149
|
8 |
|
return $this->name; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function setName(string $name): Module |
|
153
|
|
|
{ |
|
154
|
|
|
$this->name = $name; |
|
155
|
|
|
|
|
156
|
|
|
return $this; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
6 |
|
public function getLevel(): int |
|
160
|
|
|
{ |
|
161
|
6 |
|
return $this->level; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function setLevel(int $level): Module |
|
165
|
|
|
{ |
|
166
|
|
|
$this->level = $level; |
|
167
|
|
|
|
|
168
|
|
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
3 |
|
public function getUpgradeFactor(): int |
|
172
|
|
|
{ |
|
173
|
3 |
|
return $this->upgrade_factor; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function setUpgradeFactor(int $upgradeFactor): Module |
|
177
|
|
|
{ |
|
178
|
|
|
$this->upgrade_factor = $upgradeFactor; |
|
179
|
|
|
|
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
5 |
|
public function getDefaultFactor(): int |
|
184
|
|
|
{ |
|
185
|
5 |
|
return $this->default_factor; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function setDefaultFactor(int $defaultFactor): Module |
|
189
|
|
|
{ |
|
190
|
|
|
$this->default_factor = $defaultFactor; |
|
191
|
|
|
|
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
5 |
|
public function getDowngradeFactor(): int |
|
196
|
|
|
{ |
|
197
|
5 |
|
return $this->downgrade_factor; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function setDowngradeFactor(int $downgradeFactor): Module |
|
201
|
|
|
{ |
|
202
|
|
|
$this->downgrade_factor = $downgradeFactor; |
|
203
|
|
|
|
|
204
|
|
|
return $this; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
3 |
|
public function getCrew(): int |
|
208
|
|
|
{ |
|
209
|
3 |
|
return $this->crew; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
3 |
|
public function getCrewByFactionAndRumpLvl(Faction $faction, SpacecraftRump $rump): int |
|
213
|
|
|
{ |
|
214
|
3 |
|
$result = $this->getCrew(); |
|
215
|
|
|
|
|
216
|
|
|
if ( |
|
217
|
3 |
|
$this->getFaction() !== null |
|
218
|
3 |
|
&& $this->getFaction()->getId() !== $faction->getId() |
|
219
|
|
|
) { |
|
220
|
3 |
|
$result += 1; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
3 |
|
if ($this->getLevel() > $rump->getBaseValues()->getModuleLevel()) { |
|
224
|
3 |
|
$result += 1; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
3 |
|
return $result; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
public function setCrew(int $crew): Module |
|
231
|
|
|
{ |
|
232
|
|
|
$this->crew = $crew; |
|
233
|
|
|
|
|
234
|
|
|
return $this; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
9 |
|
public function getType(): SpacecraftModuleTypeEnum |
|
238
|
|
|
{ |
|
239
|
9 |
|
return $this->type; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
public function setType(SpacecraftModuleTypeEnum $type): Module |
|
243
|
|
|
{ |
|
244
|
|
|
$this->type = $type; |
|
245
|
|
|
|
|
246
|
|
|
return $this; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
public function getResearchId(): ?int |
|
250
|
|
|
{ |
|
251
|
|
|
return $this->research_id; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
public function setResearchId(int $researchId): Module |
|
255
|
|
|
{ |
|
256
|
|
|
$this->research_id = $researchId; |
|
257
|
|
|
|
|
258
|
|
|
return $this; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
9 |
|
public function getCommodityId(): int |
|
262
|
|
|
{ |
|
263
|
9 |
|
return $this->commodity_id; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
public function setCommodityId(int $commodityId): Module |
|
267
|
|
|
{ |
|
268
|
|
|
$this->commodity_id = $commodityId; |
|
269
|
|
|
|
|
270
|
|
|
return $this; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
public function getViewable(): bool |
|
274
|
|
|
{ |
|
275
|
|
|
return $this->viewable; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
public function setViewable(bool $viewable): Module |
|
279
|
|
|
{ |
|
280
|
|
|
$this->viewable = $viewable; |
|
281
|
|
|
|
|
282
|
|
|
return $this; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
1 |
|
public function getShipRumpRoleId(): ?SpacecraftRumpRoleEnum |
|
286
|
|
|
{ |
|
287
|
1 |
|
return $this->rumps_role_id; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
1 |
|
public function getWeapon(): ?Weapon |
|
291
|
|
|
{ |
|
292
|
1 |
|
return $this->weapon; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
1 |
|
public function getEcost(): int |
|
296
|
|
|
{ |
|
297
|
1 |
|
return $this->ecost; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
public function setEcost(int $energyCosts): Module |
|
301
|
|
|
{ |
|
302
|
|
|
$this->ecost = $energyCosts; |
|
303
|
|
|
|
|
304
|
|
|
return $this; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
public function getFactionId(): ?FactionEnum |
|
308
|
|
|
{ |
|
309
|
|
|
return $this->faction_id; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
public function setFactionId(FactionEnum $factionId): ?Module |
|
313
|
|
|
{ |
|
314
|
|
|
$this->faction_id = $factionId; |
|
315
|
|
|
|
|
316
|
|
|
return $this; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
5 |
|
public function getSystemType(): ?SpacecraftSystemTypeEnum |
|
320
|
|
|
{ |
|
321
|
5 |
|
return $this->system_type; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @return Collection<int, ModuleSpecial> |
|
326
|
|
|
*/ |
|
327
|
3 |
|
public function getSpecials(): Collection |
|
328
|
|
|
{ |
|
329
|
3 |
|
return $this->moduleSpecials; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
public function hasSpecial(ModuleSpecialAbilityEnum $ability): bool |
|
333
|
|
|
{ |
|
334
|
|
|
return $this->moduleSpecials->containsKey($ability->value); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* @return Collection<int, ModuleCost> |
|
339
|
|
|
*/ |
|
340
|
1 |
|
public function getCost(): Collection |
|
341
|
|
|
{ |
|
342
|
1 |
|
return $this->buildingCosts; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
/** |
|
346
|
|
|
* @return array<int, ModuleCost> |
|
347
|
|
|
*/ |
|
348
|
1 |
|
public function getCostSorted(): array |
|
349
|
|
|
{ |
|
350
|
1 |
|
$array = $this->getCost()->getValues(); |
|
351
|
|
|
|
|
352
|
1 |
|
usort( |
|
353
|
1 |
|
$array, |
|
354
|
1 |
|
fn(ModuleCost $a, ModuleCost $b): int => $a->getCommodity()->getSort() <=> $b->getCommodity()->getSort() |
|
355
|
1 |
|
); |
|
356
|
|
|
|
|
357
|
1 |
|
return $array; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
1 |
|
public function getCommodity(): Commodity |
|
361
|
|
|
{ |
|
362
|
1 |
|
return $this->commodity; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
3 |
|
public function getDescription(): string |
|
366
|
|
|
{ |
|
367
|
3 |
|
return $this->getType()->getDescription(); |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* @return Collection<int, TorpedoHull> |
|
372
|
|
|
*/ |
|
373
|
3 |
|
public function getTorpedoHull(): Collection |
|
374
|
|
|
{ |
|
375
|
3 |
|
return $this->torpedoHull; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* @return Collection<int, WeaponShield> |
|
380
|
|
|
*/ |
|
381
|
4 |
|
public function getWeaponShield(): Collection |
|
382
|
|
|
{ |
|
383
|
4 |
|
return $this->weaponShield; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
3 |
|
public function getFaction(): ?Faction |
|
387
|
|
|
{ |
|
388
|
3 |
|
return $this->faction; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
3 |
|
public function getisNpc(): ?bool |
|
392
|
|
|
{ |
|
393
|
3 |
|
return $this->is_npc; |
|
394
|
|
|
} |
|
395
|
|
|
} |
|
396
|
|
|
|