Passed
Push — master ( 1d5530...fba2a1 )
by Nico
56:37 queued 25:57
created

Ship::getSectorId()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 3
nop 0
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 20
rs 9.9332
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Ship::getHealthySystems() 0 10 3
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 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...
21
use RuntimeException;
22
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...
23
use Stu\Component\Ship\ShipAlertStateEnum;
24
use Stu\Component\Ship\ShipLSSModeEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Ship\ShipLSSModeEnum 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\Ship\ShipModuleTypeEnum;
26
use Stu\Component\Ship\ShipRumpEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Ship\ShipRumpEnum 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...
27
use Stu\Component\Ship\ShipStateEnum;
28
use Stu\Component\Ship\SpacecraftTypeEnum;
29
use Stu\Component\Ship\System\ShipSystemModeEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Ship\System\ShipSystemModeEnum 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...
30
use Stu\Component\Ship\System\ShipSystemTypeEnum;
31
use Stu\Component\Ship\System\Type\TorpedoStorageShipSystem;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Ship\Syste...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...
32
use Stu\Component\Ship\System\Type\TractorBeamShipSystem;
33
use Stu\Component\Station\StationUtility;
34
use Stu\Module\Control\GameControllerInterface;
35
use Stu\Module\Logging\LoggerUtilInterface;
36
use Stu\Module\Ship\Lib\Battle\FightLib;
37
use Stu\Orm\Repository\ShipRepository;
38
39
#[Table(name: 'stu_ships')]
40
#[Index(name: 'ship_fleet_idx', columns: ['fleets_id'])]
41
#[Index(name: 'ship_location_idx', columns: ['location_id'])]
42
#[Index(name: 'ship_rump_idx', columns: ['rumps_id'])]
43
#[Index(name: 'ship_web_idx', columns: ['holding_web_id'])]
44
#[Index(name: 'ship_user_idx', columns: ['user_id'])]
45
#[Index(name: 'ship_tractored_idx', columns: ['tractored_ship_id'])]
46
#[Index(name: 'ship_influence_area_idx', columns: ['influence_area_id'])]
47
#[Entity(repositoryClass: ShipRepository::class)]
48
class Ship implements ShipInterface
49
{
50
    #[Id]
51
    #[Column(type: 'integer')]
52
    #[GeneratedValue(strategy: 'IDENTITY')]
53
    private ?int $id = null;
54
55
    #[Column(type: 'integer')]
56
    private int $user_id = 0;
57
58
    #[Column(type: 'integer')]
59
    private int $rumps_id = 0;
0 ignored issues
show
introduced by
The private property $rumps_id is not used, and could be removed.
Loading history...
60
61
    #[Column(type: 'integer', nullable: true)]
62
    private ?int $plans_id = null;
0 ignored issues
show
introduced by
The private property $plans_id is not used, and could be removed.
Loading history...
63
64
    #[Column(type: 'integer', nullable: true)]
65
    private ?int $fleets_id = null;
66
67
    #[Column(type: 'smallint', length: 1)]
68
    private int $direction = 0;
69
70
    #[Column(type: 'string')]
71
    private string $name = '';
72
73
    #[Column(type: 'smallint', length: 1, enumType: ShipAlertStateEnum::class)]
74
    private ShipAlertStateEnum $alvl = ShipAlertStateEnum::ALERT_GREEN;
75
76
    #[Column(type: 'smallint', length: 1)]
77
    private int $lss_mode = ShipLSSModeEnum::LSS_NORMAL;
78
79
    #[Column(type: 'integer', length: 6)]
80
    private int $huelle = 0;
81
82
    #[Column(type: 'integer', length: 6)]
83
    private int $max_huelle = 0;
84
85
    #[Column(type: 'integer', length: 6)]
86
    private int $schilde = 0;
87
88
    #[Column(type: 'integer', length: 6)]
89
    private int $max_schilde = 0;
90
91
    #[Column(type: 'integer', nullable: true)]
92
    private ?int $tractored_ship_id = null;
93
94
    #[Column(type: 'integer', nullable: true)]
95
    private ?int $holding_web_id = null;
96
97
    #[Column(type: 'integer', nullable: true)]
98
    private ?int $dock = null;
99
100
    #[Column(type: 'integer')]
101
    private int $former_rumps_id = 0;
102
103
    #[Column(type: 'smallint', length: 1, enumType: SpacecraftTypeEnum::class)]
104
    private SpacecraftTypeEnum $type = SpacecraftTypeEnum::SPACECRAFT_TYPE_SHIP;
105
106
    #[Column(type: 'integer')]
107
    private int $database_id = 0;
108
109
    #[Column(type: 'boolean')]
110
    private bool $is_destroyed = false;
111
112
    #[Column(type: 'boolean')]
113
    private bool $disabled = false;
114
115
    #[Column(type: 'smallint', length: 3)]
116
    private int $hit_chance = 0;
117
118
    #[Column(type: 'smallint', length: 3)]
119
    private int $evade_chance = 0;
120
121
    #[Column(type: 'smallint', length: 4)]
122
    private int $base_damage = 0;
123
124
    #[Column(type: 'smallint', length: 3)]
125
    private int $sensor_range = 0;
126
127
    #[Column(type: 'integer')]
128
    private int $shield_regeneration_timer = 0;
129
130
    #[Column(type: 'smallint', enumType: ShipStateEnum::class)]
131
    private ShipStateEnum $state = ShipStateEnum::SHIP_STATE_NONE;
132
133
    #[Column(type: 'boolean')]
134
    private bool $is_fleet_leader = false;
135
136
    #[Column(type: 'integer')]
137
    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...
138
139
    #[Column(type: 'integer', nullable: true)]
140
    private ?int $influence_area_id = null;
0 ignored issues
show
introduced by
The private property $influence_area_id is not used, and could be removed.
Loading history...
141
142
    #[Column(type: 'boolean')]
143
    private bool $in_emergency = false;
144
145
    #[ManyToOne(targetEntity: 'Fleet', inversedBy: 'ships')]
146
    #[JoinColumn(name: 'fleets_id', referencedColumnName: 'id')]
147
    private ?FleetInterface $fleet = null;
148
149
    #[OneToOne(targetEntity: 'TradePost', mappedBy: 'ship')]
150
    private ?TradePostInterface $tradePost = null;
151
152
    #[ManyToOne(targetEntity: 'Ship', inversedBy: 'dockedShips')]
153
    #[JoinColumn(name: 'dock', referencedColumnName: 'id')]
154
    private ?ShipInterface $dockedTo = null;
155
156
    /**
157
     * @var ArrayCollection<int, ShipInterface>
158
     */
159
    #[OneToMany(targetEntity: 'Ship', mappedBy: 'dockedTo', indexBy: 'id')]
160
    #[OrderBy(['fleets_id' => 'DESC', 'is_fleet_leader' => 'DESC'])]
161
    private Collection $dockedShips;
162
163
    /**
164
     * @var ArrayCollection<int, DockingPrivilegeInterface>
165
     */
166
    #[OneToMany(targetEntity: 'DockingPrivilege', mappedBy: 'ship')]
167
    private Collection $dockingPrivileges;
168
169
    #[OneToOne(targetEntity: 'Ship')]
170
    #[JoinColumn(name: 'tractored_ship_id', referencedColumnName: 'id')]
171
    private ?ShipInterface $tractoredShip = null;
172
173
    #[OneToOne(targetEntity: 'Ship', mappedBy: 'tractoredShip')]
174
    private ?ShipInterface $tractoringShip = null;
175
176
    #[ManyToOne(targetEntity: 'TholianWeb')]
177
    #[JoinColumn(name: 'holding_web_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
178
    private ?TholianWebInterface $holdingWeb = null;
179
180
    #[ManyToOne(targetEntity: 'User')]
181
    #[JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
182
    private UserInterface $user;
183
184
    /**
185
     * @var ArrayCollection<int, ShipCrewInterface>
186
     */
187
    #[OneToMany(targetEntity: 'ShipCrew', mappedBy: 'ship', indexBy: 'id')]
188
    #[OrderBy(['id' => 'ASC'])]
189
    private Collection $crew;
190
191
    #[OneToOne(targetEntity: 'TorpedoStorage', mappedBy: 'ship')]
192
    private ?TorpedoStorageInterface $torpedoStorage = null;
193
194
    /**
195
     * @var ArrayCollection<int, ShipSystemInterface>
196
     */
197
    #[OneToMany(targetEntity: 'ShipSystem', mappedBy: 'ship', indexBy: 'system_type')]
198
    #[OrderBy(['system_type' => 'ASC'])]
199
    private Collection $systems;
200
201
    #[ManyToOne(targetEntity: 'ShipRump')]
202
    #[JoinColumn(name: 'rumps_id', referencedColumnName: 'id')]
203
    private ShipRumpInterface $rump;
204
205
    #[ManyToOne(targetEntity: 'ShipBuildplan')]
206
    #[JoinColumn(name: 'plans_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
207
    private ?ShipBuildplanInterface $buildplan = null;
208
209
    /**
210
     * @var ArrayCollection<int, StorageInterface>
211
     */
212
    #[OneToMany(targetEntity: 'Storage', mappedBy: 'ship', indexBy: 'commodity_id')]
213
    #[OrderBy(['commodity_id' => 'ASC'])]
214
    private Collection $storage;
215
216
    #[ManyToOne(targetEntity: 'Location')]
217
    #[JoinColumn(name: 'location_id', referencedColumnName: 'id')]
218
    private LocationInterface $location;
219
220
    #[ManyToOne(targetEntity: 'StarSystem')]
221
    #[JoinColumn(name: 'influence_area_id', referencedColumnName: 'id')]
222
    private ?StarSystemInterface $influenceArea = null;
223
224
    /**
225
     * @var ArrayCollection<int, ShipLogInterface>
226
     */
227
    #[OneToMany(targetEntity: 'ShipLog', mappedBy: 'ship', fetch: 'EXTRA_LAZY')]
228
    #[OrderBy(['id' => 'DESC'])]
229
    private Collection $logbook;
230
231
    #[OneToOne(targetEntity: 'ShipTakeover', mappedBy: 'source')]
232
    private ?ShipTakeoverInterface $takeoverActive = null;
233
234
    #[OneToOne(targetEntity: 'ShipTakeover', mappedBy: 'target')]
235
    private ?ShipTakeoverInterface $takeoverPassive = null;
236
237 3
    public function __construct()
238
    {
239 3
        $this->dockedShips = new ArrayCollection();
240 3
        $this->dockingPrivileges = new ArrayCollection();
241 3
        $this->crew = new ArrayCollection();
242 3
        $this->systems = new ArrayCollection();
243 3
        $this->storage = new ArrayCollection();
244 3
        $this->logbook = new ArrayCollection();
245
    }
246
247
    #[Override]
248
    public function getId(): int
249
    {
250
        if ($this->id === null) {
251
            throw new RuntimeException('entity not yet persisted');
252
        }
253
254
        return $this->id;
255
    }
256
257
    #[Override]
258
    public function getUserId(): int
259
    {
260
        return $this->user_id;
261
    }
262
263
    #[Override]
264
    public function getUserName(): string
265
    {
266
        return $this->getUser()->getName();
267
    }
268
269
    #[Override]
270
    public function getFleetId(): ?int
271
    {
272
        return $this->fleets_id;
273
    }
274
275
    #[Override]
276
    public function setFleetId(?int $fleetId): ShipInterface
277
    {
278
        $this->fleets_id = $fleetId;
279
        return $this;
280
    }
281
282
    #[Override]
283
    public function getSystemsId(): ?int
284
    {
285
        return $this->getSystem() !== null ? $this->getSystem()->getId() : null;
286
    }
287
288
    #[Override]
289
    public function getLayer(): ?LayerInterface
290
    {
291
        return $this->getLocation()->getLayer();
292
    }
293
294
    #[Override]
295
    public function getSx(): int
296
    {
297
        return $this->getStarsystemMap()->getSx();
298
    }
299
300
    #[Override]
301
    public function getSy(): int
302
    {
303
        return $this->getStarsystemMap()->getSy();
304
    }
305
306
    #[Override]
307
    public function getFlightDirection(): int
308
    {
309
        return $this->direction;
310
    }
311
312
    #[Override]
313
    public function setFlightDirection(int $direction): ShipInterface
314
    {
315
        $this->direction = $direction;
316
        return $this;
317
    }
318
319
    #[Override]
320
    public function getName(): string
321
    {
322
        return $this->name;
323
    }
324
325
    #[Override]
326
    public function setName(string $name): ShipInterface
327
    {
328
        $this->name = $name;
329
        return $this;
330
    }
331
332
    #[Override]
333
    public function getLSSmode(): int
334
    {
335
        return $this->lss_mode;
336
    }
337
338
    public function isLSSModeNormal(): bool
339
    {
340
        return $this->getLSSMode() === ShipLSSModeEnum::LSS_NORMAL;
341
    }
342
343
    public function isLSSModeBorder(): bool
344
    {
345
        return $this->getLSSMode() === ShipLSSModeEnum::LSS_BORDER;
346
    }
347
348
    #[Override]
349
    public function setLSSMode(int $lssMode): ShipInterface
350
    {
351
        $this->lss_mode = $lssMode;
352
        return $this;
353
    }
354
355
    #[Override]
356
    public function getAlertState(): ShipAlertStateEnum
357
    {
358
        return $this->alvl;
359
    }
360
361
    #[Override]
362
    public function setAlertState(ShipAlertStateEnum $state): ShipInterface
363
    {
364
        $this->alvl = $state;
365
        return $this;
366
    }
367
368
    #[Override]
369
    public function setAlertStateGreen(): ShipInterface
370
    {
371
        return $this->setAlertState(ShipAlertStateEnum::ALERT_GREEN);
372
    }
373
374
    #[Override]
375
    public function isSystemHealthy(ShipSystemTypeEnum $type): bool
376
    {
377
        if (!$this->hasShipSystem($type)) {
378
            return false;
379
        }
380
381
        return $this->getShipSystem($type)->getStatus() > 0;
382
    }
383
384
    #[Override]
385
    public function getSystemState(ShipSystemTypeEnum $type): bool
386
    {
387
        if (!$this->hasShipSystem($type)) {
388
            return false;
389
        }
390
391
        return $this->getShipSystem($type)->getMode() === ShipSystemModeEnum::MODE_ON
392
            || $this->getShipSystem($type)->getMode() === ShipSystemModeEnum::MODE_ALWAYS_ON;
393
    }
394
395
    #[Override]
396
    public function getImpulseState(): bool
397
    {
398
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_IMPULSEDRIVE);
399
    }
400
401
    #[Override]
402
    public function getWarpDriveState(): bool
403
    {
404
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_WARPDRIVE);
405
    }
406
407
    #[Override]
408
    public function isWarped(): bool
409
    {
410
        $tractoringShip = $this->getTractoringShip();
411
412
        if ($tractoringShip !== null) {
413
            return $tractoringShip->getWarpDriveState();
414
        }
415
416
        return $this->getWarpDriveState();
417
    }
418
419
    #[Override]
420
    public function getWebState(): bool
421
    {
422
        return $this->getHoldingWeb() !== null;
423
    }
424
425
    #[Override]
426
    public function getCloakState(): bool
427
    {
428
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_CLOAK);
429
    }
430
431
    #[Override]
432
    public function getTachyonState(): bool
433
    {
434
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_TACHYON_SCANNER);
435
    }
436
437
    #[Override]
438
    public function getSubspaceState(): bool
439
    {
440
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_SUBSPACE_SCANNER);
441
    }
442
443
    #[Override]
444
    public function getAstroState(): bool
445
    {
446
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_ASTRO_LABORATORY);
447
    }
448
449
    #[Override]
450
    public function getRPGModuleState(): bool
451
    {
452
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_RPG_MODULE);
453
    }
454
455
    #[Override]
456
    public function getConstructionHubState(): bool
457
    {
458
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_CONSTRUCTION_HUB);
459
    }
460
461
    #[Override]
462
    public function getHull(): int
463
    {
464
        return $this->huelle;
465
    }
466
467
    #[Override]
468
    public function setHuell(int $hull): ShipInterface
469
    {
470
        $this->huelle = $hull;
471
        return $this;
472
    }
473
474
    #[Override]
475
    public function getMaxHull(): int
476
    {
477
        return $this->max_huelle;
478
    }
479
480
    #[Override]
481
    public function setMaxHuell(int $maxHull): ShipInterface
482
    {
483
        $this->max_huelle = $maxHull;
484
        return $this;
485
    }
486
487
    #[Override]
488
    public function getShield(): int
489
    {
490
        return $this->schilde;
491
    }
492
493
    #[Override]
494
    public function setShield(int $schilde): ShipInterface
495
    {
496
        $this->schilde = $schilde;
497
        return $this;
498
    }
499
500
    /**
501
     * proportional to shield system status
502
     */
503
    #[Override]
504
    public function getMaxShield(bool $isTheoretical = false): int
505
    {
506
        if ($isTheoretical || !$this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_SHIELDS)) {
507
            return $this->max_schilde;
508
        }
509
510
        return (int) (ceil($this->max_schilde
511
            * $this->getShipSystem(ShipSystemTypeEnum::SYSTEM_SHIELDS)->getStatus() / 100));
512
    }
513
514
    #[Override]
515
    public function setMaxShield(int $maxShields): ShipInterface
516
    {
517
        $this->max_schilde = $maxShields;
518
        return $this;
519
    }
520
521
    #[Override]
522
    public function getHealthPercentage(): float
523
    {
524
        return ($this->getHull() + $this->getShield())
525
            / ($this->getMaxHull() + $this->getMaxShield(true)) * 100;
526
    }
527
528
    #[Override]
529
    public function getShieldState(): bool
530
    {
531
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_SHIELDS);
532
    }
533
534
    #[Override]
535
    public function getNbs(): bool
536
    {
537
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_NBS);
538
    }
539
540
    #[Override]
541
    public function getLss(): bool
542
    {
543
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_LSS);
544
    }
545
546
    #[Override]
547
    public function getPhaserState(): bool
548
    {
549
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_PHASER);
550
    }
551
552
    #[Override]
553
    public function isAlertGreen(): bool
554
    {
555
        return $this->getAlertState() === ShipAlertStateEnum::ALERT_GREEN;
556
    }
557
558
    #[Override]
559
    public function getTorpedoState(): bool
560
    {
561
        return $this->getSystemState(ShipSystemTypeEnum::SYSTEM_TORPEDO);
562
    }
563
564
    #[Override]
565
    public function getFormerRumpId(): int
566
    {
567
        return $this->former_rumps_id;
568
    }
569
570
    #[Override]
571
    public function setFormerRumpId(int $formerShipRumpId): ShipInterface
572
    {
573
        $this->former_rumps_id = $formerShipRumpId;
574
        return $this;
575
    }
576
577
    #[Override]
578
    public function getTorpedoCount(): int
579
    {
580
        if ($this->getTorpedoStorage() === null) {
581
            return 0;
582
        }
583
584
        return $this->getTorpedoStorage()->getStorage()->getAmount();
585
    }
586
587
    #[Override]
588
    public function isBase(): bool
589
    {
590
        return $this->type === SpacecraftTypeEnum::SPACECRAFT_TYPE_STATION;
591
    }
592
593
    #[Override]
594
    public function isTrumfield(): bool
595
    {
596
        return $this->getRump()->isTrumfield();
597
    }
598
599
    #[Override]
600
    public function isShuttle(): bool
601
    {
602
        return $this->getRump()->getCategoryId() === ShipRumpEnum::SHIP_CATEGORY_SHUTTLE;
603
    }
604
605
    #[Override]
606
    public function isConstruction(): bool
607
    {
608
        return $this->getRump()->getCategoryId() === ShipRumpEnum::SHIP_CATEGORY_CONSTRUCTION;
609
    }
610
611
    #[Override]
612
    public function getSpacecraftType(): SpacecraftTypeEnum
613
    {
614
        return $this->type;
615
    }
616
617
    #[Override]
618
    public function setSpacecraftType(SpacecraftTypeEnum $type): ShipInterface
619
    {
620
        $this->type = $type;
621
        return $this;
622
    }
623
624
    #[Override]
625
    public function getDatabaseId(): int
626
    {
627
        return $this->database_id;
628
    }
629
630
    #[Override]
631
    public function setDatabaseId(int $databaseEntryId): ShipInterface
632
    {
633
        $this->database_id = $databaseEntryId;
634
        return $this;
635
    }
636
637
    #[Override]
638
    public function isDestroyed(): bool
639
    {
640
        return $this->is_destroyed;
641
    }
642
643
    #[Override]
644
    public function setIsDestroyed(bool $isDestroyed): ShipInterface
645
    {
646
        $this->is_destroyed = $isDestroyed;
647
        return $this;
648
    }
649
650
    #[Override]
651
    public function isDisabled(): bool
652
    {
653
        return $this->disabled;
654
    }
655
656
    #[Override]
657
    public function setDisabled(bool $isDisabled): ShipInterface
658
    {
659
        $this->disabled = $isDisabled;
660
        return $this;
661
    }
662
663
664
665
    /**
666
     * proportional to computer system status
667
     */
668
    #[Override]
669
    public function getHitChance(): int
670
    {
671
        if (!$this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_COMPUTER)) {
672
            return $this->hit_chance;
673
        }
674
675
        return (int) (ceil($this->hit_chance
676
            * $this->getShipSystem(ShipSystemTypeEnum::SYSTEM_COMPUTER)->getStatus() / 100));
677
    }
678
679
    #[Override]
680
    public function setHitChance(int $hitChance): ShipInterface
681
    {
682
        $this->hit_chance = $hitChance;
683
        return $this;
684
    }
685
686
    /**
687
     * proportional to impulsedrive system status
688
     */
689
    #[Override]
690
    public function getEvadeChance(): int
691
    {
692
        if (!$this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_IMPULSEDRIVE)) {
693
            return $this->evade_chance;
694
        }
695
696
        return (int) (ceil($this->evade_chance
697
            * $this->getShipSystem(ShipSystemTypeEnum::SYSTEM_IMPULSEDRIVE)->getStatus() / 100));
698
    }
699
700
    #[Override]
701
    public function setEvadeChance(int $evadeChance): ShipInterface
702
    {
703
        $this->evade_chance = $evadeChance;
704
        return $this;
705
    }
706
707
    /**
708
     * proportional to energy weapon system status
709
     */
710
    #[Override]
711
    public function getBaseDamage(): int
712
    {
713
        if (!$this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_PHASER)) {
714
            return $this->base_damage;
715
        }
716
717
        return (int) (ceil($this->base_damage
718
            * $this->getShipSystem(ShipSystemTypeEnum::SYSTEM_PHASER)->getStatus() / 100));
719
    }
720
721
    #[Override]
722
    public function setBaseDamage(int $baseDamage): ShipInterface
723
    {
724
        $this->base_damage = $baseDamage;
725
        return $this;
726
    }
727
728
    /**
729
     * proportional to sensor system status
730
     */
731
    #[Override]
732
    public function getSensorRange(): int
733
    {
734
        if (!$this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_LSS)) {
735
            return $this->sensor_range;
736
        }
737
738
        return (int) (ceil($this->sensor_range
739
            * $this->getShipSystem(ShipSystemTypeEnum::SYSTEM_LSS)->getStatus() / 100));
740
    }
741
742
    #[Override]
743
    public function setSensorRange(int $sensorRange): ShipInterface
744
    {
745
        $this->sensor_range = $sensorRange;
746
        return $this;
747
    }
748
749
    /**
750
     * proportional to tractor beam system status
751
     */
752
    #[Override]
753
    public function getTractorPayload(): int
754
    {
755
        if (!$this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_TRACTOR_BEAM)) {
756
            return 0;
757
        }
758
759
        return (int) (ceil($this->getRump()->getTractorPayload()
760
            * $this->getShipSystem(ShipSystemTypeEnum::SYSTEM_TRACTOR_BEAM)->getStatus() / 100));
761
    }
762
763
    #[Override]
764
    public function getShieldRegenerationTimer(): int
765
    {
766
        return $this->shield_regeneration_timer;
767
    }
768
769
    #[Override]
770
    public function setShieldRegenerationTimer(int $shieldRegenerationTimer): ShipInterface
771
    {
772
        $this->shield_regeneration_timer = $shieldRegenerationTimer;
773
        return $this;
774
    }
775
776
    #[Override]
777
    public function getState(): ShipStateEnum
778
    {
779
        return $this->state;
780
    }
781
782
    #[Override]
783
    public function setState(ShipStateEnum $state): ShipInterface
784
    {
785
        $this->state = $state;
786
        return $this;
787
    }
788
789
    #[Override]
790
    public function getIsInEmergency(): bool
791
    {
792
        return $this->in_emergency;
793
    }
794
795
    #[Override]
796
    public function setIsInEmergency(bool $inEmergency): ShipInterface
797
    {
798
        $this->in_emergency = $inEmergency;
799
        return $this;
800
    }
801
802
    #[Override]
803
    public function isUnderRepair(): bool
804
    {
805
        return $this->getState() === ShipStateEnum::SHIP_STATE_REPAIR_ACTIVE
806
            || $this->getState() === ShipStateEnum::SHIP_STATE_REPAIR_PASSIVE;
807
    }
808
809
    #[Override]
810
    public function getIsFleetLeader(): bool
811
    {
812
        return $this->getFleet() !== null && $this->is_fleet_leader;
813
    }
814
815
    #[Override]
816
    public function setIsFleetLeader(bool $isFleetLeader): ShipInterface
817
    {
818
        $this->is_fleet_leader = $isFleetLeader;
819
        return $this;
820
    }
821
822
    #[Override]
823
    public function getCrewAssignments(): Collection
824
    {
825
        return $this->crew;
826
    }
827
828
    #[Override]
829
    public function getPosX(): int
830
    {
831
        return $this->location->getX();
832
    }
833
834
    #[Override]
835
    public function getPosY(): int
836
    {
837
        return $this->location->getY();
838
    }
839
840
    #[Override]
841
    public function getCrewCount(): int
842
    {
843
        return $this->getCrewAssignments()->count();
844
    }
845
846
    #[Override]
847
    public function getNeededCrewCount(): int
848
    {
849
        $buildplan = $this->getBuildplan();
850
        if ($buildplan === null) {
851
            return 0;
852
        }
853
854
        return $buildplan->getCrew();
855
    }
856
857
    #[Override]
858
    public function getExcessCrewCount(): int
859
    {
860
        return $this->getCrewCount() - $this->getNeededCrewCount();
861
    }
862
863
    #[Override]
864
    public function hasEnoughCrew(?GameControllerInterface $game = null): bool
865
    {
866
        $buildplan = $this->getBuildplan();
867
868
        if ($buildplan === null) {
869
            if ($game !== null) {
870
                $game->addInformation(_("Keine Crew vorhanden"));
871
            }
872
            return false;
873
        }
874
875
        $result = $buildplan->getCrew() <= 0
876
            || $this->getCrewCount() >= $buildplan->getCrew();
877
878
        if (!$result && $game !== null) {
879
            $game->addInformationf(
880
                _("Es werden %d Crewmitglieder benötigt"),
881
                $buildplan->getCrew()
882
            );
883
        }
884
885
        return $result;
886
    }
887
888
    #[Override]
889
    public function getFleet(): ?FleetInterface
890
    {
891
        return $this->fleet;
892
    }
893
894
    #[Override]
895
    public function setFleet(?FleetInterface $fleet): ShipInterface
896
    {
897
        $this->fleet = $fleet;
898
        return $this;
899
    }
900
901
    #[Override]
902
    public function isFleetLeader(): bool
903
    {
904
        return $this->getIsFleetLeader();
905
    }
906
907
    #[Override]
908
    public function getUser(): UserInterface
909
    {
910
        return $this->user;
911
    }
912
913
    #[Override]
914
    public function setUser(UserInterface $user): ShipInterface
915
    {
916
        $this->user = $user;
917
        return $this;
918
    }
919
920
    #[Override]
921
    public function getSystem(): ?StarSystemInterface
922
    {
923
        return $this->getStarsystemMap() !== null ? $this->getStarsystemMap()->getSystem() : null;
924
    }
925
926
    #[Override]
927
    public function getModules(): array
928
    {
929
        $modules = [];
930
931
        $buildplan = $this->getBuildplan();
932
        if ($buildplan === null) {
933
            return $modules;
934
        }
935
936
        foreach ($buildplan->getModules() as $obj) {
937
            $module = $obj->getModule();
938
            $index = $module->getType() === ShipModuleTypeEnum::SPECIAL ? $module->getId() : $module->getType()->value;
939
            $modules[$index] = $module;
940
        }
941
942
        if ($this->isBase()) {
943
            foreach ($this->getSystems() as $system) {
944
                $module = $system->getModule();
945
946
                if ($module !== null) {
947
                    $index = $module->getType() === ShipModuleTypeEnum::SPECIAL ? $module->getId() : $module->getType()->value;
948
                    $modules[$index] = $module;
949
                }
950
            }
951
        }
952
953
        return $modules;
954
    }
955
956
    #[Override]
957
    public function isDeflectorHealthy(): bool
958
    {
959
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_DEFLECTOR);
960
    }
961
962
    #[Override]
963
    public function isTroopQuartersHealthy(): bool
964
    {
965
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_TROOP_QUARTERS);
966
    }
967
968
    #[Override]
969
    public function isMatrixScannerHealthy(): bool
970
    {
971
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_MATRIX_SCANNER);
972
    }
973
974
    #[Override]
975
    public function isTorpedoStorageHealthy(): bool
976
    {
977
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_TORPEDO_STORAGE);
978
    }
979
980
    #[Override]
981
    public function isShuttleRampHealthy(): bool
982
    {
983
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_SHUTTLE_RAMP);
984
    }
985
986
    #[Override]
987
    public function isWebEmitterHealthy(): bool
988
    {
989
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_THOLIAN_WEB);
990
    }
991
992
    #[Override]
993
    public function isWarpAble(): bool
994
    {
995
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_WARPDRIVE);
996
    }
997
998
    #[Override]
999
    public function isTractoring(): bool
1000
    {
1001
        return $this->getTractoredShip() !== null;
1002
    }
1003
1004
    #[Override]
1005
    public function isTractored(): bool
1006
    {
1007
        return $this->getTractoringShip() !== null;
1008
    }
1009
1010
    #[Override]
1011
    public function isOverColony(): ?ColonyInterface
1012
    {
1013
        return $this->getStarsystemMap() !== null ? $this->getStarsystemMap()->getColony() : null;
1014
    }
1015
1016
    #[Override]
1017
    public function isOverSystem(): ?StarSystemInterface
1018
    {
1019
        if ($this->getSystem() !== null) {
1020
            return null;
1021
        }
1022
1023
        return $this->getMap()->getSystem();
1024
    }
1025
1026
    #[Override]
1027
    public function isWarpPossible(): bool
1028
    {
1029
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_WARPDRIVE) && $this->getSystem() === null;
1030
    }
1031
1032
    #[Override]
1033
    public function getTorpedo(): ?TorpedoTypeInterface
1034
    {
1035
        if ($this->getTorpedoStorage() === null) {
1036
            return null;
1037
        }
1038
1039
        return $this->getTorpedoStorage()->getTorpedo();
1040
    }
1041
1042
    #[Override]
1043
    public function getTorpedoStorage(): ?TorpedoStorageInterface
1044
    {
1045
        return $this->torpedoStorage;
1046
    }
1047
1048
    #[Override]
1049
    public function setTorpedoStorage(?TorpedoStorageInterface $torpedoStorage): ShipInterface
1050
    {
1051
        $this->torpedoStorage = $torpedoStorage;
1052
        return $this;
1053
    }
1054
1055
    #[Override]
1056
    public function getStorage(): Collection
1057
    {
1058
        return $this->storage;
1059
    }
1060
1061
    #[Override]
1062
    public function getLogbook(): Collection
1063
    {
1064
        return $this->logbook;
1065
    }
1066
1067
    #[Override]
1068
    public function getTakeoverActive(): ?ShipTakeoverInterface
1069
    {
1070
        return $this->takeoverActive;
1071
    }
1072
1073
    #[Override]
1074
    public function setTakeoverActive(?ShipTakeoverInterface $takeover): ShipInterface
1075
    {
1076
        $this->takeoverActive = $takeover;
1077
1078
        return $this;
1079
    }
1080
1081
    #[Override]
1082
    public function getTakeoverPassive(): ?ShipTakeoverInterface
1083
    {
1084
        return $this->takeoverPassive;
1085
    }
1086
1087
    #[Override]
1088
    public function setTakeoverPassive(?ShipTakeoverInterface $takeover): ShipInterface
1089
    {
1090
        $this->takeoverPassive = $takeover;
1091
1092
        return $this;
1093
    }
1094
1095
    #[Override]
1096
    public function getStorageSum(): int
1097
    {
1098
        return array_reduce(
1099
            $this->getStorage()->getValues(),
1100
            fn (int $sum, StorageInterface $storage): int => $sum + $storage->getAmount(),
1101
            0
1102
        );
1103
    }
1104
1105
    #[Override]
1106
    public function getMaxStorage(): int
1107
    {
1108
        return $this->getRump()->getStorage();
1109
    }
1110
1111
    #[Override]
1112
    public function getBeamableStorage(): array
1113
    {
1114
        return array_filter(
1115
            $this->getStorage()->getValues(),
1116
            fn (StorageInterface $storage): bool => $storage->getCommodity()->isBeamable() === true
1117
        );
1118
    }
1119
1120
    #[Override]
1121
    public function getTradePost(): ?TradePostInterface
1122
    {
1123
        return $this->tradePost;
1124
    }
1125
1126
    #[Override]
1127
    public function setTradePost(?TradePostInterface $tradePost): ShipInterface
1128
    {
1129
        $this->tradePost = $tradePost;
1130
1131
        return $this;
1132
    }
1133
1134 3
    #[Override]
1135
    public function getMap(): ?MapInterface
1136
    {
1137 3
        if ($this->location instanceof MapInterface) {
1138 1
            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\MapInterface|null.
Loading history...
1139
        }
1140 2
        if ($this->location instanceof StarSystemMapInterface) {
1141 2
            return $this->location->getSystem()->getMap();
0 ignored issues
show
Bug introduced by
The method getSystem() does not exist on Stu\Orm\Entity\LocationInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Stu\Orm\Entity\Location. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1141
            return $this->location->/** @scrutinizer ignore-call */ getSystem()->getMap();
Loading history...
1142
        }
1143
1144
        return null;
1145
    }
1146
1147
    #[Override]
1148
    public function getMapRegion(): ?MapRegionInterface
1149
    {
1150
        $systemMap = $this->getStarsystemMap();
1151
        if ($systemMap !== null) {
1152
            return null;
1153
        }
1154
1155
        $map = $this->getMap();
1156
        if ($map === null) {
1157
            return null;
1158
        }
1159
1160
        return $map->getMapRegion();
1161
    }
1162
1163 3
    #[Override]
1164
    public function setLocation(LocationInterface $location): ShipInterface
1165
    {
1166 3
        $this->location = $location;
1167
1168 3
        return $this;
1169
    }
1170
1171 3
    #[Override]
1172
    public function getStarsystemMap(): ?StarSystemMapInterface
1173
    {
1174 3
        if ($this->location instanceof StarSystemMapInterface) {
1175 2
            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\StarSystemMapInterface|null.
Loading history...
1176
        }
1177
1178 1
        return null;
1179
    }
1180
1181
    #[Override]
1182
    public function getLocation(): MapInterface|StarSystemMapInterface
1183
    {
1184
        if (
1185
            $this->location instanceof MapInterface
1186
            || $this->location instanceof StarSystemMapInterface
1187
        ) {
1188
            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...
1189
        }
1190
1191
        throw new RuntimeException('unknown type');
1192
    }
1193
1194
    #[Override]
1195
    public function getInfluenceArea(): ?StarSystemInterface
1196
    {
1197
        return $this->influenceArea;
1198
    }
1199
1200
    #[Override]
1201
    public function setInfluenceArea(?StarSystemInterface $influenceArea): ShipInterface
1202
    {
1203
        $this->influenceArea = $influenceArea;
1204
        return $this;
1205
    }
1206
1207
    #[Override]
1208
    public function getBeamFactor(): int
1209
    {
1210
        return $this->getRump()->getBeamFactor();
1211
    }
1212
1213
    #[Override]
1214
    public function getSectorString(): string
1215
    {
1216
        return $this->getCurrentMapField()->getSectorString();
1217
    }
1218
1219
    #[Override]
1220
    public function getBuildplan(): ?ShipBuildplanInterface
1221
    {
1222
        return $this->buildplan;
1223
    }
1224
1225
    #[Override]
1226
    public function setBuildplan(?ShipBuildplanInterface $shipBuildplan): ShipInterface
1227
    {
1228
        $this->buildplan = $shipBuildplan;
1229
        return $this;
1230
    }
1231
1232
    #[Override]
1233
    public function getSystems(): Collection
1234
    {
1235
        return $this->systems;
1236
    }
1237
1238
    #[Override]
1239
    public function hasShipSystem(ShipSystemTypeEnum $type): bool
1240
    {
1241
        return $this->getSystems()->containsKey($type->value);
1242
    }
1243
1244
    #[Override]
1245
    public function getShipSystem(ShipSystemTypeEnum $type): ShipSystemInterface
1246
    {
1247
        $system = $this->getSystems()->get($type->value);
1248
        if ($system === null) {
1249
            throw new RuntimeException(sprintf('system type %d does not exist on ship', $type->value));
1250
        }
1251
1252
        return $system;
1253
    }
1254
1255
    #[Override]
1256
    public function getHealthySystems(): array
1257
    {
1258
        $healthySystems = [];
1259
        foreach ($this->getSystems() as $system) {
1260
            if ($system->getStatus() > 0) {
1261
                $healthySystems[] = $system;
1262
            }
1263
        }
1264
        return $healthySystems;
1265
    }
1266
1267
    #[Override]
1268
    public function displayNbsActions(): bool
1269
    {
1270
        return !$this->getCloakState()
1271
            && !$this->isWarped();
1272
    }
1273
1274
    #[Override]
1275
    public function isTractorbeamPossible(): bool
1276
    {
1277
        return TractorBeamShipSystem::isTractorBeamPossible($this);
1278
    }
1279
1280
    #[Override]
1281
    public function isBoardingPossible(): bool
1282
    {
1283
        return FightLib::isBoardingPossible($this);
1284
    }
1285
1286
    #[Override]
1287
    public function isInterceptable(): bool
1288
    {
1289
        //TODO can tractored ships be intercepted?!
1290
        return $this->getWarpDriveState();
1291
    }
1292
1293
    #[Override]
1294
    public function dockedOnTradePost(): bool
1295
    {
1296
        return $this->getDockedTo() && $this->getDockedTo()->getTradePost() !== null;
1297
    }
1298
1299
    #[Override]
1300
    public function getDockPrivileges(): Collection
1301
    {
1302
        return $this->dockingPrivileges;
1303
    }
1304
1305
    #[Override]
1306
    public function getDockingSlotCount(): int
1307
    {
1308
        return ($this->getState() === ShipStateEnum::SHIP_STATE_UNDER_CONSTRUCTION)
1309
            || ($this->getState() === ShipStateEnum::SHIP_STATE_UNDER_SCRAPPING)
1310
            ? 50 : $this->getRump()->getDockingSlots();
1311
    }
1312
1313
    #[Override]
1314
    public function hasFreeDockingSlots(): bool
1315
    {
1316
        return $this->getDockingSlotCount() > $this->getDockedShipCount();
1317
    }
1318
1319
    #[Override]
1320
    public function getFreeDockingSlotCount(): int
1321
    {
1322
        return $this->getDockingSlotCount() - $this->getDockedShipCount();
1323
    }
1324
1325
    #[Override]
1326
    public function getDockedShipCount(): int
1327
    {
1328
        return $this->dockedShips->count();
1329
    }
1330
1331
    #[Override]
1332
    public function getTractoredShip(): ?ShipInterface
1333
    {
1334
        return $this->tractoredShip;
1335
    }
1336
1337
    #[Override]
1338
    public function setTractoredShip(?ShipInterface $ship): ShipInterface
1339
    {
1340
        $this->tractoredShip = $ship;
1341
        return $this;
1342
    }
1343
1344
    #[Override]
1345
    public function setTractoredShipId(?int $shipId): ShipInterface
1346
    {
1347
        $this->tractored_ship_id = $shipId;
1348
        return $this;
1349
    }
1350
1351
    #[Override]
1352
    public function getTractoringShip(): ?ShipInterface
1353
    {
1354
        return $this->tractoringShip;
1355
    }
1356
1357
    #[Override]
1358
    public function setTractoringShip(?ShipInterface $ship): ShipInterface
1359
    {
1360
        $this->tractoringShip = $ship;
1361
        return $this;
1362
    }
1363
1364
    #[Override]
1365
    public function getHoldingWeb(): ?TholianWebInterface
1366
    {
1367
        return $this->holdingWeb;
1368
    }
1369
1370
    #[Override]
1371
    public function setHoldingWeb(?TholianWebInterface $web): ShipInterface
1372
    {
1373
        $this->holdingWeb = $web;
1374
1375
        if ($web === null) {
1376
            $this->holding_web_id = null;
1377
        }
1378
1379
        return $this;
1380
    }
1381
1382
    #[Override]
1383
    public function getHoldingWebBackgroundStyle(): string
1384
    {
1385
        if ($this->getHoldingWeb() === null) {
1386
            return '';
1387
        }
1388
1389
        if ($this->getHoldingWeb()->isFinished()) {
1390
            $icon =  'web.png';
1391
        } else {
1392
            $closeTofinish = $this->getHoldingWeb()->getFinishedTime() - time() < TimeConstants::ONE_HOUR_IN_SECONDS;
1393
1394
            $icon = $closeTofinish ? 'web_u.png' : 'web_u2.png';
1395
        }
1396
1397
        return sprintf('src="assets/buttons/%s"; class="indexedGraphics" style="z-index: 5;"', $icon);
1398
    }
1399
1400
    public function getHoldingWebImageStyle(): string
1401
    {
1402
        if ($this->getHoldingWeb() === null) {
1403
            return '';
1404
        }
1405
1406
        if ($this->getHoldingWeb()->isFinished()) {
1407
            $icon =  'webfill.png';
1408
        } else {
1409
            $closeTofinish = $this->getHoldingWeb()->getFinishedTime() - time() < TimeConstants::ONE_HOUR_IN_SECONDS;
1410
1411
            $icon = $closeTofinish ? 'web_ufill.png' : 'web_ufill2.png';
1412
        }
1413
1414
        return $icon;
1415
    }
1416
1417
    #[Override]
1418
    public function getCurrentMapField(): StarSystemMapInterface|MapInterface
1419
    {
1420
        return $this->getStarsystemMap() ?? $this->getMap();
1421
    }
1422
1423
    private function getShieldRegenerationPercentage(): int
1424
    {
1425
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_SHIELDS) ? 10 : 0;
1426
    }
1427
1428
    #[Override]
1429
    public function getShieldRegenerationRate(): int
1430
    {
1431
        return (int) ceil(($this->getMaxShield() / 100) * $this->getShieldRegenerationPercentage());
1432
    }
1433
1434
    #[Override]
1435
    public function canIntercept(): bool
1436
    {
1437
        return $this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_WARPDRIVE)
1438
            && !$this->isTractored() && !$this->isTractoring();
1439
    }
1440
1441
    #[Override]
1442
    public function canMove(): bool
1443
    {
1444
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_WARPDRIVE)
1445
            || $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_IMPULSEDRIVE);
1446
    }
1447
1448
    #[Override]
1449
    public function hasActiveWeapon(): bool
1450
    {
1451
        return $this->getPhaserState() || $this->getTorpedoState();
1452
    }
1453
1454
    #[Override]
1455
    public function hasEscapePods(): bool
1456
    {
1457
        return $this->getRump()->isEscapePods() && $this->getCrewCount() > 0;
1458
    }
1459
1460
    #[Override]
1461
    public function getRepairRate(): int
1462
    {
1463
        // @todo
1464
        return 100;
1465
    }
1466
1467
    #[Override]
1468
    public function getRump(): ShipRumpInterface
1469
    {
1470
        return $this->rump;
1471
    }
1472
1473
    #[Override]
1474
    public function getRumpId(): int
1475
    {
1476
        return $this->getRump()->getId();
1477
    }
1478
1479
    #[Override]
1480
    public function getRumpName(): string
1481
    {
1482
        return $this->getRump()->getName();
1483
    }
1484
1485
    #[Override]
1486
    public function setRump(ShipRumpInterface $shipRump): ShipInterface
1487
    {
1488
        $this->rump = $shipRump;
1489
        return $this;
1490
    }
1491
1492
    #[Override]
1493
    public function hasPhaser(): bool
1494
    {
1495
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_PHASER);
1496
    }
1497
1498
    #[Override]
1499
    public function hasTorpedo(): bool
1500
    {
1501
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_TORPEDO);
1502
    }
1503
1504
    #[Override]
1505
    public function hasCloak(): bool
1506
    {
1507
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_CLOAK);
1508
    }
1509
1510
    #[Override]
1511
    public function hasTachyonScanner(): bool
1512
    {
1513
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_TACHYON_SCANNER);
1514
    }
1515
1516
    #[Override]
1517
    public function hasShuttleRamp(): bool
1518
    {
1519
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_SHUTTLE_RAMP);
1520
    }
1521
1522
    #[Override]
1523
    public function hasSubspaceScanner(): bool
1524
    {
1525
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_SUBSPACE_SCANNER);
1526
    }
1527
1528
    #[Override]
1529
    public function hasAstroLaboratory(): bool
1530
    {
1531
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_ASTRO_LABORATORY);
1532
    }
1533
1534
    #[Override]
1535
    public function hasWarpdrive(): bool
1536
    {
1537
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_WARPDRIVE);
1538
    }
1539
1540
    #[Override]
1541
    public function hasReactor(): bool
1542
    {
1543
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_WARPCORE) ||
1544
            $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_FUSION_REACTOR) ||
1545
            $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_SINGULARITY_REACTOR);
1546
    }
1547
1548
    #[Override]
1549
    public function hasRPGModule(): bool
1550
    {
1551
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_RPG_MODULE);
1552
    }
1553
1554
    #[Override]
1555
    public function hasNbsLss(): bool
1556
    {
1557
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_LSS);
1558
    }
1559
1560
    #[Override]
1561
    public function hasUplink(): bool
1562
    {
1563
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_UPLINK);
1564
    }
1565
1566
    #[Override]
1567
    public function hasTranswarp(): bool
1568
    {
1569
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_TRANSWARP_COIL);
1570
    }
1571
1572
    #[Override]
1573
    public function getTranswarpCooldown(): ?int
1574
    {
1575
        $cooldown = $this->getShipSystem(ShipSystemTypeEnum::SYSTEM_TRANSWARP_COIL)->getCooldown();
1576
1577
        return $cooldown > time() ? $cooldown : null;
1578
    }
1579
1580
    #[Override]
1581
    public function getMaxTorpedos(): int
1582
    {
1583
        return $this->getRump()->getBaseTorpedoStorage()
1584
            + ($this->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_TORPEDO_STORAGE)
1585
                ? TorpedoStorageShipSystem::TORPEDO_CAPACITY : 0);
1586
    }
1587
1588
    #[Override]
1589
    public function getDockedShips(): Collection
1590
    {
1591
        return $this->dockedShips;
1592
    }
1593
1594
    #[Override]
1595
    public function getDockedTo(): ?ShipInterface
1596
    {
1597
        return $this->dockedTo;
1598
    }
1599
1600
    #[Override]
1601
    public function setDockedTo(?ShipInterface $dockedTo): ShipInterface
1602
    {
1603
        $this->dockedTo = $dockedTo;
1604
        return $this;
1605
    }
1606
1607
    #[Override]
1608
    public function setDockedToId(?int $dockedToId): ShipInterface
1609
    {
1610
        $this->dock = $dockedToId;
1611
        return $this;
1612
    }
1613
1614
    #[Override]
1615
    public function hasFreeShuttleSpace(?LoggerUtilInterface $loggerUtil = null): bool
1616
    {
1617
        if ($loggerUtil !== null) {
1618
            $loggerUtil->log(sprintf('rumpShuttleSlots: %d', $this->getRump()->getShuttleSlots()));
1619
            $loggerUtil->log(sprintf('storedShuttleCount: %d', $this->getStoredShuttleCount()));
1620
        }
1621
        return $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_SHUTTLE_RAMP)
1622
            && $this->getRump()->getShuttleSlots() - $this->getStoredShuttleCount() > 0;
1623
    }
1624
1625
    #[Override]
1626
    public function getStoredShuttles(): array
1627
    {
1628
        $shuttles = [];
1629
1630
        foreach ($this->getStorage() as $stor) {
1631
            if ($stor->getCommodity()->isShuttle()) {
1632
                $shuttles[] = $stor->getCommodity();
1633
            }
1634
        }
1635
1636
        return $shuttles;
1637
    }
1638
1639
    #[Override]
1640
    public function getStoredShuttleCount(): int
1641
    {
1642
        $count = 0;
1643
1644
        foreach ($this->getStorage() as $stor) {
1645
            if ($stor->getCommodity()->isShuttle()) {
1646
                $count += $stor->getAmount();
1647
            }
1648
        }
1649
1650
        return $count;
1651
    }
1652
1653
    /**
1654
     * @return CommodityInterface[]
1655
     */
1656
    #[Override]
1657
    public function getStoredBuoy(): array
1658
    {
1659
        $buoy = [];
1660
1661
        foreach ($this->getStorage() as $stor) {
1662
            if ($stor->getCommodity()->isBouy()) {
1663
                $buoy[] = $stor->getCommodity();
1664
            }
1665
        }
1666
1667
        return $buoy;
1668
    }
1669
1670
1671
    #[Override]
1672
    public function hasStoredBuoy(): bool
1673
    {
1674
        return $this->getStoredBuoy() !== [];
1675
    }
1676
1677
1678
    #[Override]
1679
    public function getDockedWorkbeeCount(): int
1680
    {
1681
        $count = 0;
1682
1683
        foreach ($this->getDockedShips() as $ships) {
1684
            if ($ships->getRump()->getCategoryId() === ShipRumpEnum::SHIP_CATEGORY_SHUTTLE) {
1685
                $count += 1;
1686
            }
1687
        }
1688
1689
        return $count;
1690
    }
1691
1692
    #[Override]
1693
    public function canMan(): bool
1694
    {
1695
        $buildplan = $this->getBuildplan();
1696
1697
        return $buildplan !== null
1698
            && $buildplan->getCrew() > 0
1699
            && $this->hasShipSystem(ShipSystemTypeEnum::SYSTEM_LIFE_SUPPORT);
1700
    }
1701
1702
    #[Override]
1703
    public function canBuildConstruction(): bool
1704
    {
1705
        return StationUtility::canShipBuildConstruction($this);
1706
    }
1707
1708
    #[Override]
1709
    public function hasCrewmanOfUser(int $userId): bool
1710
    {
1711
        foreach ($this->getCrewAssignments() as $shipCrew) {
1712
            if ($shipCrew->getCrew()->getUser()->getId() === $userId) {
1713
                return true;
1714
            }
1715
        }
1716
1717
        return false;
1718
    }
1719
1720
    #[Override]
1721
    public function __toString(): string
1722
    {
1723
        if ($this->id !== null) {
1724
            return sprintf('id: %d, name: %s', $this->getId(), $this->getName());
1725
        }
1726
1727
        return $this->getName();
1728
    }
1729
1730
    #[Override]
1731
    public function getHullColorStyle(): string
1732
    {
1733
        return $this->getColorStyle($this->getHull(), $this->getMaxHull());
1734
    }
1735
1736
    private function getColorStyle(int $actual, int $max): string
1737
    {
1738
        // full
1739
        if ($actual === $max) {
1740
            return '';
1741
        }
1742
1743
        // less than 100% - green
1744
        if ($actual / $max > 0.75) {
1745
            return 'color: #19c100;';
1746
        }
1747
1748
        // less than 75% - yellow
1749
        if ($actual / $max > 0.50) {
1750
            return 'color: #f4e932;';
1751
        }
1752
1753
        // less than 50% - orange
1754
        if ($actual / $max > 0.25) {
1755
            return 'color: #f48b28;';
1756
        }
1757
1758
        // less than 25% - red
1759
        return 'color: #ff3c3c;';
1760
    }
1761
}
1762