|
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\Index; |
|
12
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
|
13
|
|
|
use Doctrine\ORM\Mapping\OneToMany; |
|
14
|
|
|
use Doctrine\ORM\Mapping\OneToOne; |
|
15
|
|
|
use Doctrine\ORM\Mapping\OrderBy; |
|
16
|
|
|
use Doctrine\ORM\Mapping\Table; |
|
17
|
|
|
use Stu\Component\Spacecraft\SpacecraftRumpCategoryEnum; |
|
18
|
|
|
use Stu\Component\Spacecraft\SpacecraftStateEnum; |
|
19
|
|
|
use Stu\Component\Spacecraft\SpacecraftTypeEnum; |
|
20
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
|
21
|
|
|
use Stu\Lib\Transfer\TransferEntityTypeEnum; |
|
22
|
|
|
use Stu\Orm\Repository\StationRepository; |
|
23
|
|
|
|
|
24
|
|
|
#[Table(name: 'stu_station')] |
|
25
|
|
|
#[Index(name: 'station_influence_area_idx', columns: ['influence_area_id'])] |
|
26
|
|
|
#[Entity(repositoryClass: StationRepository::class)] |
|
27
|
|
|
class Station extends Spacecraft |
|
28
|
|
|
{ |
|
29
|
|
|
#[Column(type: 'integer', nullable: true)] |
|
30
|
|
|
private ?int $influence_area_id = null; |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
#[OneToOne(targetEntity: TradePost::class, mappedBy: 'station')] |
|
33
|
|
|
private ?TradePost $tradePost = null; |
|
34
|
|
|
|
|
35
|
|
|
#[OneToOne(targetEntity: ConstructionProgress::class, mappedBy: 'station')] |
|
36
|
|
|
private ?ConstructionProgress $constructionProgress = null; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var ArrayCollection<int, Ship> |
|
40
|
|
|
*/ |
|
41
|
|
|
#[OneToMany(targetEntity: Ship::class, mappedBy: 'dockedTo', indexBy: 'id')] |
|
42
|
|
|
#[OrderBy(['fleet_id' => 'DESC', 'is_fleet_leader' => 'DESC'])] |
|
43
|
|
|
private Collection $dockedShips; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var ArrayCollection<int, DockingPrivilege> |
|
47
|
|
|
*/ |
|
48
|
|
|
#[OneToMany(targetEntity: DockingPrivilege::class, mappedBy: 'station')] |
|
49
|
|
|
#[OrderBy(['privilege_mode' => 'DESC'])] |
|
50
|
|
|
private Collection $dockingPrivileges; |
|
51
|
|
|
|
|
52
|
|
|
#[OneToOne(targetEntity: StarSystem::class)] |
|
53
|
|
|
#[JoinColumn(name: 'influence_area_id', referencedColumnName: 'id')] |
|
54
|
|
|
private ?StarSystem $influenceArea = null; |
|
55
|
|
|
|
|
56
|
1 |
|
public function __construct() |
|
57
|
|
|
{ |
|
58
|
1 |
|
parent::__construct(); |
|
59
|
1 |
|
$this->dockedShips = new ArrayCollection(); |
|
60
|
1 |
|
$this->dockingPrivileges = new ArrayCollection(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
8 |
|
#[\Override] |
|
64
|
|
|
public function getType(): SpacecraftTypeEnum |
|
65
|
|
|
{ |
|
66
|
8 |
|
return SpacecraftTypeEnum::STATION; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
#[\Override] |
|
70
|
|
|
public function getFleet(): ?Fleet |
|
71
|
|
|
{ |
|
72
|
2 |
|
return null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
5 |
|
public function getTradePost(): ?TradePost |
|
76
|
|
|
{ |
|
77
|
5 |
|
return $this->tradePost; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function setTradePost(?TradePost $tradePost): Station |
|
81
|
|
|
{ |
|
82
|
|
|
$this->tradePost = $tradePost; |
|
83
|
|
|
|
|
84
|
|
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getInfluenceArea(): ?StarSystem |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->influenceArea; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function setInfluenceArea(?StarSystem $influenceArea): Station |
|
93
|
|
|
{ |
|
94
|
|
|
$this->influenceArea = $influenceArea; |
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
1 |
|
public function getConstructionProgress(): ?ConstructionProgress |
|
99
|
|
|
{ |
|
100
|
1 |
|
return $this->constructionProgress; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function resetConstructionProgress(): Station |
|
104
|
|
|
{ |
|
105
|
|
|
$this->constructionProgress = null; |
|
106
|
|
|
|
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
1 |
|
#[\Override] |
|
111
|
|
|
public function getModules(): array |
|
112
|
|
|
{ |
|
113
|
1 |
|
$constructionProgress = $this->getConstructionProgress(); |
|
114
|
1 |
|
if ($constructionProgress === null) { |
|
115
|
|
|
return []; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
$parentModules = parent::getModules(); |
|
119
|
1 |
|
$parentModuleIds = array_map(fn(Module $module): int => $module->getId(), $parentModules); |
|
120
|
|
|
|
|
121
|
1 |
|
$specialModules = $constructionProgress |
|
122
|
1 |
|
->getSpecialModules() |
|
123
|
1 |
|
->filter(fn(ConstructionProgressModule $progressModule): bool => !in_array( |
|
124
|
1 |
|
$progressModule->getModule()->getId(), |
|
125
|
1 |
|
$parentModuleIds |
|
126
|
1 |
|
)) |
|
127
|
1 |
|
->map(fn(ConstructionProgressModule $progressModule): Module => $progressModule->getModule()) |
|
128
|
1 |
|
->toArray(); |
|
129
|
|
|
|
|
130
|
1 |
|
return $parentModules + $specialModules; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return Collection<int, DockingPrivilege> |
|
135
|
|
|
*/ |
|
136
|
2 |
|
public function getDockPrivileges(): Collection |
|
137
|
|
|
{ |
|
138
|
2 |
|
return $this->dockingPrivileges; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
2 |
|
public function getDockingSlotCount(): int |
|
142
|
|
|
{ |
|
143
|
2 |
|
$state = $this->getCondition()->getState(); |
|
144
|
|
|
|
|
145
|
2 |
|
return $state === SpacecraftStateEnum::UNDER_CONSTRUCTION |
|
146
|
2 |
|
|| $state === SpacecraftStateEnum::UNDER_SCRAPPING |
|
147
|
|
|
? 50 |
|
148
|
2 |
|
: $this->getRump()->getDockingSlots(); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function hasFreeDockingSlots(): bool |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->getDockingSlotCount() > $this->getDockedShipCount(); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
1 |
|
public function getFreeDockingSlotCount(): int |
|
157
|
|
|
{ |
|
158
|
1 |
|
return $this->getDockingSlotCount() - $this->getDockedShipCount(); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
4 |
|
public function getDockedShipCount(): int |
|
162
|
|
|
{ |
|
163
|
4 |
|
return $this->dockedShips->count(); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return Collection<int, Ship> |
|
168
|
|
|
*/ |
|
169
|
11 |
|
public function getDockedShips(): Collection |
|
170
|
|
|
{ |
|
171
|
11 |
|
return $this->dockedShips; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function getDockedWorkbeeCount(): int |
|
175
|
|
|
{ |
|
176
|
|
|
$count = 0; |
|
177
|
|
|
|
|
178
|
|
|
foreach ($this->getDockedShips() as $ships) { |
|
179
|
|
|
if ($ships->getRump()->getCategoryId() === SpacecraftRumpCategoryEnum::SHUTTLE) { |
|
180
|
|
|
$count += 1; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
return $count; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function getConstructionHubState(): bool |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->getSystemState(SpacecraftSystemTypeEnum::CONSTRUCTION_HUB); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
1 |
|
public function isAggregationSystemHealthy(): bool |
|
193
|
|
|
{ |
|
194
|
1 |
|
return $this->isSystemHealthy(SpacecraftSystemTypeEnum::AGGREGATION_SYSTEM); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
13 |
|
#[\Override] |
|
198
|
|
|
public function getTransferEntityType(): TransferEntityTypeEnum |
|
199
|
|
|
{ |
|
200
|
13 |
|
return TransferEntityTypeEnum::STATION; |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|