Passed
Push — dev ( 262e9d...837c0e )
by Nico
30:19
created

Ship::setDockedToId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

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