Passed
Push — dev ( c12b3a...6ad196 )
by Janko
24:31 queued 10:07
created

Spacecraft::getSpacecraftSystem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
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\DiscriminatorColumn;
11
use Doctrine\ORM\Mapping\DiscriminatorMap;
12
use Doctrine\ORM\Mapping\Entity;
13
use Doctrine\ORM\Mapping\GeneratedValue;
14
use Doctrine\ORM\Mapping\Id;
15
use Doctrine\ORM\Mapping\InheritanceType;
16
use Doctrine\ORM\Mapping\JoinColumn;
17
use Doctrine\ORM\Mapping\ManyToOne;
18
use Doctrine\ORM\Mapping\OneToMany;
19
use Doctrine\ORM\Mapping\OneToOne;
20
use Doctrine\ORM\Mapping\OrderBy;
21
use Doctrine\ORM\Mapping\Table;
22
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use RuntimeException;
24
use Stu\Component\Game\TimeConstants;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Game\TimeConstants was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Stu\Component\Map\DirectionEnum;
26
use Stu\Component\Spacecraft\SpacecraftAlertStateEnum;
27
use Stu\Component\Spacecraft\SpacecraftModuleTypeEnum;
28
use Stu\Component\Spacecraft\SpacecraftRumpEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Spacecraft\SpacecraftRumpEnum was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Stu\Component\Spacecraft\SpacecraftStateEnum;
30
use Stu\Component\Spacecraft\SpacecraftLssModeEnum;
31
use Stu\Component\Spacecraft\SpacecraftTypeEnum;
32
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
33
use Stu\Component\Spacecraft\System\Type\TorpedoStorageShipSystem;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Spacecraft...orpedoStorageShipSystem was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
use Stu\Component\Spacecraft\Trait\HasSpacecraftSystemTrait;
35
use Stu\Component\Spacecraft\Trait\SpacecraftCrewTrait;
36
use Stu\Component\Spacecraft\Trait\SpacecraftEvadeChanceTrait;
37
use Stu\Component\Spacecraft\Trait\SpacecraftHitChanceTrait;
38
use Stu\Component\Spacecraft\Trait\SpacecraftInteractionTrait;
39
use Stu\Component\Spacecraft\Trait\SpacecraftLocationTrait;
40
use Stu\Component\Spacecraft\Trait\SpacecraftShieldsTrait;
41
use Stu\Component\Spacecraft\Trait\SpacecraftStorageTrait;
42
use Stu\Component\Spacecraft\Trait\SpacecraftSystemHealthTrait;
43
use Stu\Component\Spacecraft\Trait\SpacecraftSystemStateTrait;
44
use Stu\Orm\Repository\SpacecraftRepository;
45
46
#[Table(name: 'stu_spacecraft')]
47
#[Entity(repositoryClass: SpacecraftRepository::class)]
48
#[InheritanceType('JOINED')]
49
#[DiscriminatorColumn(name: 'type', type: 'string')]
50
#[DiscriminatorMap([
51
    SpacecraftTypeEnum::SHIP->value => Ship::class,
52
    SpacecraftTypeEnum::STATION->value => Station::class,
53
    SpacecraftTypeEnum::THOLIAN_WEB->value => TholianWeb::class
54
])]
55
abstract class Spacecraft implements SpacecraftInterface
56
{
57
    use SpacecraftSystemStateTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...cecraftSystemStateTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
58
    use HasSpacecraftSystemTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...asSpacecraftSystemTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
59
    use SpacecraftSystemHealthTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...ecraftSystemHealthTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
60
    use SpacecraftShieldsTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...\SpacecraftShieldsTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
61
    use SpacecraftHitChanceTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...pacecraftHitChanceTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
62
    use SpacecraftEvadeChanceTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...cecraftEvadeChanceTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
63
    use SpacecraftCrewTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft\Trait\SpacecraftCrewTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
64
    use SpacecraftLocationTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...SpacecraftLocationTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
65
    use SpacecraftStorageTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...\SpacecraftStorageTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
66
    use SpacecraftInteractionTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...cecraftInteractionTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
67
68
    #[Id]
69
    #[Column(type: 'integer')]
70
    #[GeneratedValue(strategy: 'IDENTITY')]
71
    private ?int $id = null;
72
73
    #[Column(type: 'integer')]
74
    private int $user_id = 0;
75
76
    #[Column(type: 'integer')]
77
    private int $rump_id = 0;
0 ignored issues
show
introduced by
The private property $rump_id is not used, and could be removed.
Loading history...
78
79
    #[Column(type: 'integer', nullable: true)]
80
    private ?int $plan_id = null;
0 ignored issues
show
introduced by
The private property $plan_id is not used, and could be removed.
Loading history...
81
82
    #[Column(type: 'smallint', length: 1, enumType: DirectionEnum::class, nullable: true)]
83
    private ?DirectionEnum $direction = null;
84
85
    #[Column(type: 'string')]
86
    private string $name = '';
87
88
    #[Column(type: 'smallint', length: 1, enumType: SpacecraftAlertStateEnum::class)]
89
    private SpacecraftAlertStateEnum $alvl = SpacecraftAlertStateEnum::ALERT_GREEN;
90
91
    #[Column(type: 'smallint', length: 1, enumType: SpacecraftLssModeEnum::class)]
92
    private SpacecraftLssModeEnum $lss_mode = SpacecraftLssModeEnum::NORMAL;
93
94
    #[Column(type: 'integer', length: 6)]
95
    private int $huelle = 0;
96
97
    #[Column(type: 'integer', length: 6)]
98
    private int $max_huelle = 0;
99
100
    #[Column(type: 'integer', length: 6)]
101
    private int $schilde = 0;
102
103
    #[Column(type: 'integer', length: 6)]
104
    private int $max_schilde = 0;
105
106
    #[Column(type: 'integer', nullable: true)]
107
    private ?int $tractored_ship_id = null;
0 ignored issues
show
introduced by
The private property $tractored_ship_id is not used, and could be removed.
Loading history...
108
109
    #[Column(type: 'integer', nullable: true)]
110
    private ?int $holding_web_id = null;
0 ignored issues
show
introduced by
The private property $holding_web_id is not used, and could be removed.
Loading history...
111
112
    #[Column(type: 'integer', nullable: true)]
113
    private ?int $database_id = null;
114
115
    private bool $is_destroyed = false;
116
117
    #[Column(type: 'boolean')]
118
    private bool $disabled = false;
119
120
    #[Column(type: 'smallint', length: 3)]
121
    private int $hit_chance = 0;
122
123
    #[Column(type: 'smallint', length: 3)]
124
    private int $evade_chance = 0;
125
126
    #[Column(type: 'smallint', length: 4)]
127
    private int $base_damage = 0;
128
129
    #[Column(type: 'smallint', enumType: SpacecraftStateEnum::class)]
130
    private SpacecraftStateEnum $state = SpacecraftStateEnum::NONE;
131
132
    #[Column(type: 'integer')]
133
    private int $location_id = 0;
0 ignored issues
show
introduced by
The private property $location_id is not used, and could be removed.
Loading history...
134
135
    #[Column(type: 'boolean')]
136
    private bool $in_emergency = false;
137
138
    #[OneToOne(targetEntity: 'Ship')]
139
    #[JoinColumn(name: 'tractored_ship_id', referencedColumnName: 'id')]
140
    private ?ShipInterface $tractoredShip = null;
141
142
    #[ManyToOne(targetEntity: 'TholianWeb')]
143
    #[JoinColumn(name: 'holding_web_id', referencedColumnName: 'id')]
144
    private ?TholianWebInterface $holdingWeb = null;
145
146
    #[ManyToOne(targetEntity: 'User')]
147
    #[JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
148
    private UserInterface $user;
149
150
    /**
151
     * @var ArrayCollection<int, CrewAssignmentInterface>
152
     */
153
    #[OneToMany(targetEntity: 'CrewAssignment', mappedBy: 'spacecraft', indexBy: 'id')]
154
    #[OrderBy(['id' => 'ASC'])]
155
    private Collection $crew;
156
157
    #[OneToOne(targetEntity: 'TorpedoStorage', mappedBy: 'spacecraft')]
158
    private ?TorpedoStorageInterface $torpedoStorage = null;
159
160
    /**
161
     * @var ArrayCollection<int, SpacecraftSystemInterface>
162
     */
163
    #[OneToMany(targetEntity: 'SpacecraftSystem', mappedBy: 'spacecraft', indexBy: 'system_type')]
164
    #[OrderBy(['system_type' => 'ASC'])]
165
    private Collection $systems;
166
167
    #[ManyToOne(targetEntity: 'SpacecraftRump')]
168
    #[JoinColumn(name: 'rump_id', referencedColumnName: 'id')]
169
    private SpacecraftRumpInterface $rump;
170
171
    #[ManyToOne(targetEntity: 'SpacecraftBuildplan')]
172
    #[JoinColumn(name: 'plan_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
173
    private ?SpacecraftBuildplanInterface $buildplan = null;
174
175
    /**
176
     * @var ArrayCollection<int, StorageInterface>
177
     */
178
    #[OneToMany(targetEntity: 'Storage', mappedBy: 'spacecraft', indexBy: 'commodity_id')]
179
    #[OrderBy(['commodity_id' => 'ASC'])]
180
    private Collection $storage;
181
182
    #[ManyToOne(targetEntity: 'Location')]
183
    #[JoinColumn(name: 'location_id', referencedColumnName: 'id')]
184
    private LocationInterface $location;
185
186
    /**
187
     * @var ArrayCollection<int, ShipLogInterface>
188
     */
189
    #[OneToMany(targetEntity: 'ShipLog', mappedBy: 'spacecraft', fetch: 'EXTRA_LAZY')]
190
    #[OrderBy(['id' => 'DESC'])]
191
    private Collection $logbook;
192
193
    #[OneToOne(targetEntity: 'ShipTakeover', mappedBy: 'source')]
194
    private ?ShipTakeoverInterface $takeoverActive = null;
195
196
    #[OneToOne(targetEntity: 'ShipTakeover', mappedBy: 'target')]
197
    private ?ShipTakeoverInterface $takeoverPassive = null;
198
199 3
    public function __construct()
200
    {
201 3
        $this->crew = new ArrayCollection();
202 3
        $this->systems = new ArrayCollection();
203 3
        $this->storage = new ArrayCollection();
204 3
        $this->logbook = new ArrayCollection();
205
    }
206
207 43
    #[Override]
208
    public function getId(): int
209
    {
210 43
        if ($this->id === null) {
211
            throw new RuntimeException(sprintf('entity "%s" not yet persisted', $this->getName()));
212
        }
213
214 43
        return $this->id;
215
    }
216
217 1
    #[Override]
218
    public function getUserId(): int
219
    {
220 1
        return $this->user_id;
221
    }
222
223 7
    #[Override]
224
    public function getUserName(): string
225
    {
226 7
        return $this->getUser()->getName();
227
    }
228
229
    #[Override]
230
    public function getSystemsId(): ?int
231
    {
232
        return $this->getSystem() !== null ? $this->getSystem()->getId() : null;
233
    }
234
235
    #[Override]
236
    public function getFlightDirection(): ?DirectionEnum
237
    {
238
        return $this->direction;
239
    }
240
241
    #[Override]
242
    public function setFlightDirection(DirectionEnum $direction): SpacecraftInterface
243
    {
244
        $this->direction = $direction;
245
        return $this;
246
    }
247
248 35
    #[Override]
249
    public function getName(): string
250
    {
251 35
        return $this->name;
252
    }
253
254
    #[Override]
255
    public function setName(string $name): SpacecraftInterface
256
    {
257
        $this->name = $name;
258
        return $this;
259
    }
260
261 2
    #[Override]
262
    public function getLssMode(): SpacecraftLssModeEnum
263
    {
264 2
        return $this->lss_mode;
265
    }
266
267
    #[Override]
268
    public function setLssMode(SpacecraftLssModeEnum $lssMode): SpacecraftInterface
269
    {
270
        $this->lss_mode = $lssMode;
271
        return $this;
272
    }
273
274 6
    #[Override]
275
    public function getAlertState(): SpacecraftAlertStateEnum
276
    {
277 6
        return $this->alvl;
278
    }
279
280
    #[Override]
281
    public function setAlertState(SpacecraftAlertStateEnum $state): SpacecraftInterface
282
    {
283
        $this->alvl = $state;
284
        return $this;
285
    }
286
287
    #[Override]
288
    public function setAlertStateGreen(): SpacecraftInterface
289
    {
290
        return $this->setAlertState(SpacecraftAlertStateEnum::ALERT_GREEN);
291
    }
292
293 2
    #[Override]
294
    public function isWarped(): bool
295
    {
296 2
        return $this->getWarpDriveState();
297
    }
298
299 4
    #[Override]
300
    public function isHeldByTholianWeb(): bool
301
    {
302 4
        return $this->getHoldingWeb() !== null;
303
    }
304
305 15
    #[Override]
306
    public function getHull(): int
307
    {
308 15
        return $this->huelle;
309
    }
310
311
    #[Override]
312
    public function setHuell(int $hull): SpacecraftInterface
313
    {
314
        $this->huelle = $hull;
315
        return $this;
316
    }
317
318 15
    #[Override]
319
    public function getMaxHull(): int
320
    {
321 15
        return $this->max_huelle;
322
    }
323
324
    #[Override]
325
    public function setMaxHuell(int $maxHull): SpacecraftInterface
326
    {
327
        $this->max_huelle = $maxHull;
328
        return $this;
329
    }
330
331 9
    #[Override]
332
    public function getShield(): int
333
    {
334 9
        return $this->schilde;
335
    }
336
337
    #[Override]
338
    public function setShield(int $schilde): SpacecraftInterface
339
    {
340
        $this->schilde = $schilde;
341
        return $this;
342
    }
343
344
    #[Override]
345
    public function setMaxShield(int $maxShields): SpacecraftInterface
346
    {
347
        $this->max_schilde = $maxShields;
348
        return $this;
349
    }
350
351
    #[Override]
352
    public function getHealthPercentage(): float
353
    {
354
        return ($this->getHull() + $this->getShield())
355
            / ($this->getMaxHull() + $this->getMaxShield(true)) * 100;
356
    }
357
358 1
    #[Override]
359
    public function isAlertGreen(): bool
360
    {
361 1
        return $this->getAlertState() === SpacecraftAlertStateEnum::ALERT_GREEN;
362
    }
363
364
    #[Override]
365
    public function getTorpedoCount(): int
366
    {
367
        if ($this->getTorpedoStorage() === null) {
368
            return 0;
369
        }
370
371
        return $this->getTorpedoStorage()->getStorage()->getAmount();
372
    }
373
374 7
    #[Override]
375
    public function isStation(): bool
376
    {
377 7
        return $this instanceof StationInterface;
378
    }
379
380 1
    #[Override]
381
    public function isShuttle(): bool
382
    {
383 1
        return $this->getRump()->getCategoryId() === SpacecraftRumpEnum::SHIP_CATEGORY_SHUTTLE;
384
    }
385
386 2
    #[Override]
387
    public function isConstruction(): bool
388
    {
389 2
        return $this->getRump()->getCategoryId() === SpacecraftRumpEnum::SHIP_CATEGORY_CONSTRUCTION;
390
    }
391
392 1
    #[Override]
393
    public function getDatabaseId(): ?int
394
    {
395 1
        return $this->database_id;
396
    }
397
398
    #[Override]
399
    public function setDatabaseId(?int $databaseEntryId): SpacecraftInterface
400
    {
401
        $this->database_id = $databaseEntryId;
402
        return $this;
403
    }
404
405 2
    #[Override]
406
    public function isDestroyed(): bool
407
    {
408 2
        return $this->is_destroyed;
409
    }
410
411
    #[Override]
412
    public function setIsDestroyed(bool $isDestroyed): SpacecraftInterface
413
    {
414
        $this->is_destroyed = $isDestroyed;
415
        return $this;
416
    }
417
418
    #[Override]
419
    public function isDisabled(): bool
420
    {
421
        return $this->disabled;
422
    }
423
424
    #[Override]
425
    public function setDisabled(bool $isDisabled): SpacecraftInterface
426
    {
427
        $this->disabled = $isDisabled;
428
        return $this;
429
    }
430
431
    #[Override]
432
    public function setHitChance(int $hitChance): SpacecraftInterface
433
    {
434
        $this->hit_chance = $hitChance;
435
        return $this;
436
    }
437
438
    #[Override]
439
    public function setEvadeChance(int $evadeChance): SpacecraftInterface
440
    {
441
        $this->evade_chance = $evadeChance;
442
        return $this;
443
    }
444
445
    /**
446
     * proportional to energy weapon system status
447
     */
448 1
    #[Override]
449
    public function getBaseDamage(): int
450
    {
451 1
        if (!$this->hasSpacecraftSystem(SpacecraftSystemTypeEnum::PHASER)) {
452
            return $this->base_damage;
453
        }
454
455 1
        return (int) (ceil($this->base_damage
456 1
            * $this->getSpacecraftSystem(SpacecraftSystemTypeEnum::PHASER)->getStatus() / 100));
457
    }
458
459
    #[Override]
460
    public function setBaseDamage(int $baseDamage): SpacecraftInterface
461
    {
462
        $this->base_damage = $baseDamage;
463
        return $this;
464
    }
465
466
    /**
467
     * proportional to tractor beam system status
468
     */
469 1
    #[Override]
470
    public function getTractorPayload(): int
471
    {
472 1
        if (!$this->hasSpacecraftSystem(SpacecraftSystemTypeEnum::TRACTOR_BEAM)) {
473
            return 0;
474
        }
475
476 1
        return (int) (ceil($this->getRump()->getTractorPayload()
477 1
            * $this->getSpacecraftSystem(SpacecraftSystemTypeEnum::TRACTOR_BEAM)->getStatus() / 100));
478
    }
479
480 5
    #[Override]
481
    public function getState(): SpacecraftStateEnum
482
    {
483 5
        return $this->state;
484
    }
485
486
    #[Override]
487
    public function setState(SpacecraftStateEnum $state): SpacecraftInterface
488
    {
489
        $this->state = $state;
490
        return $this;
491
    }
492
493 1
    #[Override]
494
    public function isInEmergency(): bool
495
    {
496 1
        return $this->in_emergency;
497
    }
498
499
    #[Override]
500
    public function setIsInEmergency(bool $inEmergency): SpacecraftInterface
501
    {
502
        $this->in_emergency = $inEmergency;
503
        return $this;
504
    }
505
506
    #[Override]
507
    public function isUnderRepair(): bool
508
    {
509
        return $this->getState() === SpacecraftStateEnum::REPAIR_ACTIVE
510
            || $this->getState() === SpacecraftStateEnum::REPAIR_PASSIVE;
511
    }
512
513 13
    #[Override]
514
    public function getCrewAssignments(): Collection
515
    {
516 13
        return $this->crew;
517
    }
518
519 47
    #[Override]
520
    public function getUser(): UserInterface
521
    {
522 47
        return $this->user;
523
    }
524
525
    #[Override]
526
    public function setUser(UserInterface $user): SpacecraftInterface
527
    {
528
        $this->user = $user;
529
        return $this;
530
    }
531
532 2
    #[Override]
533
    public function getModules(): array
534
    {
535 2
        $modules = [];
536
537 2
        $buildplan = $this->getBuildplan();
538 2
        if ($buildplan === null) {
539
            return $modules;
540
        }
541
542 2
        foreach ($buildplan->getModulesOrdered() as $obj) {
543 2
            $module = $obj->getModule();
544 2
            $index = $module->getType() === SpacecraftModuleTypeEnum::SPECIAL ? $module->getId() : $module->getType()->value;
545 2
            $modules[$index] = $module;
546
        }
547
548 2
        return $modules;
549
    }
550
551 1
    #[Override]
552
    public function isTractoring(): bool
553
    {
554 1
        return $this->getTractoredShip() !== null;
555
    }
556
557 1
    #[Override]
558
    public function isWarpPossible(): bool
559
    {
560 1
        return $this->hasSpacecraftSystem(SpacecraftSystemTypeEnum::WARPDRIVE) && $this->getSystem() === null;
561
    }
562
563 3
    #[Override]
564
    public function getTorpedo(): ?TorpedoTypeInterface
565
    {
566 3
        if ($this->getTorpedoStorage() === null) {
567 3
            return null;
568
        }
569
570
        return $this->getTorpedoStorage()->getTorpedo();
571
    }
572
573 3
    #[Override]
574
    public function getTorpedoStorage(): ?TorpedoStorageInterface
575
    {
576 3
        return $this->torpedoStorage;
577
    }
578
579
    #[Override]
580
    public function setTorpedoStorage(?TorpedoStorageInterface $torpedoStorage): SpacecraftInterface
581
    {
582
        $this->torpedoStorage = $torpedoStorage;
583
        return $this;
584
    }
585
586 15
    #[Override]
587
    public function getStorage(): Collection
588
    {
589 15
        return $this->storage;
590
    }
591
592 39
    #[Override]
593
    public function getLocation(): MapInterface|StarSystemMapInterface
594
    {
595
        if (
596 39
            $this->location instanceof MapInterface
597 39
            || $this->location instanceof StarSystemMapInterface
598
        ) {
599 39
            return $this->location;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->location returns the type Stu\Orm\Entity\LocationInterface which includes types incompatible with the type-hinted return Stu\Orm\Entity\MapInterf...\StarSystemMapInterface.
Loading history...
600
        }
601
602
        throw new RuntimeException('unknown type');
603
    }
604
605 1
    #[Override]
606
    public function getLogbook(): Collection
607
    {
608 1
        return $this->logbook;
609
    }
610
611 4
    #[Override]
612
    public function getTakeoverActive(): ?ShipTakeoverInterface
613
    {
614 4
        return $this->takeoverActive;
615
    }
616
617
    #[Override]
618
    public function setTakeoverActive(?ShipTakeoverInterface $takeover): SpacecraftInterface
619
    {
620
        $this->takeoverActive = $takeover;
621
622
        return $this;
623
    }
624
625 4
    #[Override]
626
    public function getTakeoverPassive(): ?ShipTakeoverInterface
627
    {
628 4
        return $this->takeoverPassive;
629
    }
630
631
    #[Override]
632
    public function setTakeoverPassive(?ShipTakeoverInterface $takeover): SpacecraftInterface
633
    {
634
        $this->takeoverPassive = $takeover;
635
636
        return $this;
637
    }
638
639 3
    #[Override]
640
    public function setLocation(LocationInterface $location): SpacecraftInterface
641
    {
642 3
        $this->location = $location;
643
644 3
        return $this;
645
    }
646
647 11
    #[Override]
648
    public function getBeamFactor(): int
649
    {
650 11
        return $this->getRump()->getBeamFactor();
651
    }
652
653 13
    #[Override]
654
    public function getBuildplan(): ?SpacecraftBuildplanInterface
655
    {
656 13
        return $this->buildplan;
657
    }
658
659
    #[Override]
660
    public function setBuildplan(?SpacecraftBuildplanInterface $spacecraftBuildplan): SpacecraftInterface
661
    {
662
        $this->buildplan = $spacecraftBuildplan;
663
        return $this;
664
    }
665
666 39
    #[Override]
667
    public function getSystems(): Collection
668
    {
669 39
        return $this->systems;
670
    }
671
672 1
    #[Override]
673
    public function displayNbsActions(): bool
674
    {
675 1
        return !$this->isCloaked()
676 1
            && !$this->isWarped();
677
    }
678
679 2
    #[Override]
680
    public function getTractoredShip(): ?ShipInterface
681
    {
682 2
        return $this->tractoredShip;
683
    }
684
685
    #[Override]
686
    public function setTractoredShip(?ShipInterface $ship): SpacecraftInterface
687
    {
688
        $this->tractoredShip = $ship;
689
        return $this;
690
    }
691
692 8
    #[Override]
693
    public function getHoldingWeb(): ?TholianWebInterface
694
    {
695 8
        return $this->holdingWeb;
696
    }
697
698
    #[Override]
699
    public function setHoldingWeb(?TholianWebInterface $web): SpacecraftInterface
700
    {
701
        $this->holdingWeb = $web;
702
703
        return $this;
704
    }
705
706 4
    #[Override]
707
    public function getHoldingWebBackgroundStyle(): string
708
    {
709 4
        if ($this->getHoldingWeb() === null) {
710 4
            return '';
711
        }
712
713
        if ($this->getHoldingWeb()->isFinished()) {
714
            $icon =  'web.png';
715
        } else {
716
            $closeTofinish = $this->getHoldingWeb()->getFinishedTime() - time() < TimeConstants::ONE_HOUR_IN_SECONDS;
717
718
            $icon = $closeTofinish ? 'web_u.png' : 'web_u2.png';
719
        }
720
721
        return sprintf('src="assets/buttons/%s"; class="indexedGraphics" style="z-index: 5;"', $icon);
722
    }
723
724
    public function getHoldingWebImageStyle(): string
725
    {
726
        if ($this->getHoldingWeb() === null) {
727
            return '';
728
        }
729
730
        if ($this->getHoldingWeb()->isFinished()) {
731
            $icon =  'webfill.png';
732
        } else {
733
            $closeTofinish = $this->getHoldingWeb()->getFinishedTime() - time() < TimeConstants::ONE_HOUR_IN_SECONDS;
734
735
            $icon = $closeTofinish ? 'web_ufill.png' : 'web_ufill2.png';
736
        }
737
738
        return $icon;
739
    }
740
741
    #[Override]
742
    public function hasEscapePods(): bool
743
    {
744
        return $this->getRump()->isEscapePods() && $this->getCrewCount() > 0;
745
    }
746
747 1
    #[Override]
748
    public function getRepairRate(): int
749
    {
750
        // @todo
751 1
        return 100;
752
    }
753
754 36
    #[Override]
755
    public function getRump(): SpacecraftRumpInterface
756
    {
757 36
        return $this->rump;
758
    }
759
760 19
    #[Override]
761
    public function getRumpId(): int
762
    {
763 19
        return $this->getRump()->getId();
764
    }
765
766 19
    #[Override]
767
    public function getRumpName(): string
768
    {
769 19
        return $this->getRump()->getName();
770
    }
771
772
    #[Override]
773
    public function setRump(SpacecraftRumpInterface $shipRump): SpacecraftInterface
774
    {
775
        $this->rump = $shipRump;
776
        return $this;
777
    }
778
779 3
    #[Override]
780
    public function getMaxTorpedos(): int
781
    {
782 3
        return $this->getRump()->getBaseTorpedoStorage()
783 3
            + ($this->isSystemHealthy(SpacecraftSystemTypeEnum::TORPEDO_STORAGE)
784 3
                ? TorpedoStorageShipSystem::TORPEDO_CAPACITY : 0);
785
    }
786
787 2
    #[Override]
788
    public function getHref(): string
789
    {
790 2
        $moduleView = $this->getType()->getModuleView();
791 2
        if ($moduleView === null) {
792
            return '';
793
        }
794
795 2
        return sprintf(
796 2
            '%s?%s=1&id=%d',
797 2
            $moduleView->getPhpPage(),
798 2
            $this->getType()->getViewIdentifier(),
799 2
            $this->getId()
800 2
        );
801
    }
802
803
    #[Override]
804
    public function __toString(): string
805
    {
806
        if ($this->id !== null) {
807
            return sprintf(
808
                "id: %d, name: %s,\nhull: %d/%d, shields %d/%d,\nevadeChance: %d, hitChance: %d, baseDamage: %d",
809
                $this->getId(),
810
                $this->getName(),
811
                $this->huelle,
812
                $this->max_huelle,
813
                $this->schilde,
814
                $this->max_schilde,
815
                $this->evade_chance,
816
                $this->hit_chance,
817
                $this->base_damage
818
            );
819
        }
820
821
        return $this->getName();
822
    }
823
824 4
    #[Override]
825
    public function getHullColorStyle(): string
826
    {
827 4
        return $this->getColorStyle($this->getHull(), $this->getMaxHull());
828
    }
829
830 4
    private function getColorStyle(int $actual, int $max): string
831
    {
832
        // full
833 4
        if ($actual === $max) {
834 3
            return '';
835
        }
836
837
        // less than 100% - green
838 1
        if ($actual / $max > 0.75) {
839 1
            return 'color: #19c100;';
840
        }
841
842
        // less than 75% - yellow
843
        if ($actual / $max > 0.50) {
844
            return 'color: #f4e932;';
845
        }
846
847
        // less than 50% - orange
848
        if ($actual / $max > 0.25) {
849
            return 'color: #f48b28;';
850
        }
851
852
        // less than 25% - red
853
        return 'color: #ff3c3c;';
854
    }
855
}
856