1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\Column; |
8
|
|
|
use Doctrine\ORM\Mapping\Entity; |
9
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
10
|
|
|
use Doctrine\ORM\Mapping\Id; |
11
|
|
|
use Doctrine\ORM\Mapping\Index; |
12
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
13
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
14
|
|
|
use Doctrine\ORM\Mapping\Table; |
15
|
|
|
use Override; |
|
|
|
|
16
|
|
|
use Stu\Component\Spacecraft\ModuleSpecialAbilityEnum; |
17
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemModeEnum; |
18
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
19
|
|
|
use Stu\Orm\Repository\SpacecraftSystemRepository; |
20
|
|
|
|
21
|
|
|
#[Table(name: 'stu_spacecraft_system')] |
22
|
|
|
#[Index(name: 'spacecraft_system_status_idx', columns: ['status'])] |
23
|
|
|
#[Index(name: 'spacecraft_system_type_idx', columns: ['system_type'])] |
24
|
|
|
#[Index(name: 'spacecraft_system_mode_idx', columns: ['mode'])] |
25
|
|
|
#[Entity(repositoryClass: SpacecraftSystemRepository::class)] |
26
|
|
|
class SpacecraftSystem implements SpacecraftSystemInterface |
27
|
|
|
{ |
28
|
|
|
#[Id] |
29
|
|
|
#[Column(type: 'integer')] |
30
|
|
|
#[GeneratedValue(strategy: 'IDENTITY')] |
31
|
|
|
private int $id; |
32
|
|
|
|
33
|
|
|
#[Column(type: 'integer')] |
34
|
|
|
private int $spacecraft_id = 0; |
|
|
|
|
35
|
|
|
|
36
|
|
|
#[Column(type: 'smallint', enumType: SpacecraftSystemTypeEnum::class)] |
37
|
|
|
private SpacecraftSystemTypeEnum $system_type = SpacecraftSystemTypeEnum::HULL; |
38
|
|
|
|
39
|
|
|
#[Column(type: 'integer', nullable: true)] |
40
|
|
|
private ?int $module_id = 0; |
41
|
|
|
|
42
|
|
|
#[Column(type: 'smallint')] |
43
|
|
|
private int $status = 0; |
44
|
|
|
|
45
|
|
|
#[Column(type: 'smallint', enumType: SpacecraftSystemModeEnum::class)] |
46
|
|
|
private SpacecraftSystemModeEnum $mode = SpacecraftSystemModeEnum::MODE_OFF; |
47
|
|
|
|
48
|
|
|
#[Column(type: 'integer', nullable: true)] |
49
|
|
|
private ?int $cooldown = null; |
50
|
|
|
|
51
|
|
|
#[Column(type: 'text', nullable: true)] |
52
|
|
|
private ?string $data = null; |
53
|
|
|
|
54
|
|
|
#[ManyToOne(targetEntity: 'Module')] |
55
|
|
|
#[JoinColumn(name: 'module_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
56
|
|
|
private ?ModuleInterface $module = null; |
57
|
|
|
|
58
|
|
|
#[ManyToOne(targetEntity: 'Spacecraft')] |
59
|
|
|
#[JoinColumn(name: 'spacecraft_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
60
|
|
|
private SpacecraftInterface $spacecraft; |
61
|
|
|
|
62
|
|
|
#[Override] |
63
|
|
|
public function getId(): int |
64
|
|
|
{ |
65
|
|
|
return $this->id; |
66
|
|
|
} |
67
|
|
|
|
68
|
4 |
|
#[Override] |
69
|
|
|
public function getSystemType(): SpacecraftSystemTypeEnum |
70
|
|
|
{ |
71
|
4 |
|
return $this->system_type; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
#[Override] |
75
|
|
|
public function setSystemType(SpacecraftSystemTypeEnum $type): SpacecraftSystemInterface |
76
|
|
|
{ |
77
|
|
|
$this->system_type = $type; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
#[Override] |
83
|
|
|
public function getModuleId(): ?int |
84
|
|
|
{ |
85
|
|
|
return $this->module_id; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
#[Override] |
89
|
|
|
public function setModuleId(int $moduleId): SpacecraftSystemInterface |
90
|
|
|
{ |
91
|
|
|
$this->module_id = $moduleId; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
13 |
|
#[Override] |
97
|
|
|
public function getStatus(): int |
98
|
|
|
{ |
99
|
13 |
|
return $this->status; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
#[Override] |
103
|
|
|
public function setStatus(int $status): SpacecraftSystemInterface |
104
|
|
|
{ |
105
|
|
|
$this->status = $status; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
7 |
|
#[Override] |
111
|
|
|
public function isHealthy(): bool |
112
|
|
|
{ |
113
|
7 |
|
return $this->getStatus() > 0; |
114
|
|
|
} |
115
|
|
|
|
116
|
2 |
|
#[Override] |
117
|
|
|
public function getName(): string |
118
|
|
|
{ |
119
|
2 |
|
return $this->getSystemType()->getDescription(); |
120
|
|
|
} |
121
|
|
|
|
122
|
2 |
|
#[Override] |
123
|
|
|
public function getCssClass(): string |
124
|
|
|
{ |
125
|
2 |
|
if ($this->getStatus() < 1) { |
126
|
|
|
return _("sysStatus0"); |
127
|
2 |
|
} elseif ($this->getStatus() < 26) { |
128
|
|
|
return _("sysStatus1to25"); |
129
|
2 |
|
} elseif ($this->getStatus() < 51) { |
130
|
|
|
return _("sysStatus26to50"); |
131
|
2 |
|
} elseif ($this->getStatus() < 76) { |
132
|
|
|
return _("sysStatus51to75"); |
133
|
|
|
} else { |
134
|
2 |
|
return _("sysStatus76to100"); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
12 |
|
#[Override] |
139
|
|
|
public function getMode(): SpacecraftSystemModeEnum |
140
|
|
|
{ |
141
|
12 |
|
return $this->mode; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
#[Override] |
145
|
|
|
public function setMode(SpacecraftSystemModeEnum $mode): SpacecraftSystemInterface |
146
|
|
|
{ |
147
|
|
|
$this->mode = $mode; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
2 |
|
#[Override] |
153
|
|
|
public function getCooldown(): ?int |
154
|
|
|
{ |
155
|
2 |
|
return $this->cooldown > time() ? $this->cooldown : null; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
#[Override] |
159
|
|
|
public function setCooldown(int $cooldown): SpacecraftSystemInterface |
160
|
|
|
{ |
161
|
|
|
$this->cooldown = $cooldown; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
1 |
|
#[Override] |
167
|
|
|
public function getModule(): ?ModuleInterface |
168
|
|
|
{ |
169
|
1 |
|
return $this->module; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
#[Override] |
173
|
|
|
public function setModule(ModuleInterface $module): SpacecraftSystemInterface |
174
|
|
|
{ |
175
|
|
|
$this->module = $module; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
#[Override] |
181
|
|
|
public function getSpacecraft(): SpacecraftInterface |
182
|
|
|
{ |
183
|
|
|
return $this->spacecraft; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
#[Override] |
187
|
|
|
public function setSpacecraft(SpacecraftInterface $spacecraft): SpacecraftSystemInterface |
188
|
|
|
{ |
189
|
|
|
$this->spacecraft = $spacecraft; |
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
12 |
|
#[Override] |
194
|
|
|
public function getData(): ?string |
195
|
|
|
{ |
196
|
12 |
|
return $this->data; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
#[Override] |
200
|
|
|
public function setData(string $data): SpacecraftSystemInterface |
201
|
|
|
{ |
202
|
|
|
$this->data = $data; |
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
#[Override] |
207
|
|
|
public function determineSystemLevel(): int |
208
|
|
|
{ |
209
|
|
|
$module = $this->getModule(); |
210
|
|
|
|
211
|
|
|
if ($module !== null && $module->getLevel() > 0) { |
212
|
|
|
return $module->getLevel(); |
213
|
|
|
} else { |
214
|
|
|
return max(1, $this->getSpacecraft()->getRump()->getModuleLevel() - 1); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
#[Override] |
219
|
|
|
public function hasSpecial(ModuleSpecialAbilityEnum $ability): bool |
220
|
|
|
{ |
221
|
|
|
return $this->module !== null |
222
|
|
|
? $this->module->hasSpecial($ability) |
223
|
|
|
: false; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
#[Override] |
227
|
|
|
public function __toString(): string |
228
|
|
|
{ |
229
|
|
|
return sprintf( |
230
|
|
|
'"%s": %s', |
231
|
|
|
$this->system_type->name, |
|
|
|
|
232
|
|
|
$this->data ?? 'null' |
233
|
|
|
); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
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