|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\Transfer; |
|
6
|
|
|
|
|
7
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
|
8
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
9
|
|
|
|
|
10
|
|
|
class TransferInformation |
|
11
|
|
|
{ |
|
12
|
|
|
public function __construct(private TransferTypeEnum $currentType, private ColonyInterface|ShipInterface $from, private ColonyInterface|ShipInterface $to, private bool $isUnload, private bool $isFriend) {} |
|
13
|
|
|
|
|
14
|
|
|
public function isCommodityTransferPossible(bool $isOtherTypeRequired = true): bool |
|
15
|
|
|
{ |
|
16
|
|
|
return !($isOtherTypeRequired |
|
17
|
|
|
&& $this->currentType === TransferTypeEnum::COMMODITIES); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function isCrewTransferPossible(bool $isOtherTypeRequired = true): bool |
|
21
|
|
|
{ |
|
22
|
|
|
if ( |
|
23
|
|
|
$isOtherTypeRequired |
|
24
|
|
|
&& $this->currentType === TransferTypeEnum::CREW |
|
25
|
|
|
) { |
|
26
|
|
|
return false; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if ( |
|
30
|
|
|
$this->to instanceof ShipInterface |
|
31
|
|
|
&& $this->to->hasUplink() |
|
32
|
|
|
) { |
|
33
|
|
|
return true; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return $this->to->getUser() === $this->from->getUser(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function isTorpedoTransferPossible(bool $isOtherTypeRequired = true): bool |
|
40
|
|
|
{ |
|
41
|
|
|
if ( |
|
42
|
|
|
$isOtherTypeRequired |
|
43
|
|
|
&& $this->currentType === TransferTypeEnum::TORPEDOS |
|
44
|
|
|
) { |
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $this->from instanceof ShipInterface |
|
49
|
|
|
&& $this->to instanceof ShipInterface |
|
50
|
|
|
&& $this->from->isTorpedoStorageHealthy() |
|
51
|
|
|
&& (!$this->isUnload() || $this->from->getTorpedoCount() > 0) |
|
52
|
|
|
&& ($this->to->hasTorpedo() || $this->to->isTorpedoStorageHealthy()) |
|
53
|
|
|
&& ($this->isUnload() || $this->to->getTorpedoCount() > 0); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function isFriend(): bool |
|
57
|
|
|
{ |
|
58
|
|
|
if ( |
|
59
|
|
|
!$this->isFriend |
|
60
|
|
|
&& $this->from->getUser() !== $this->to->getUser() |
|
61
|
|
|
) { |
|
62
|
|
|
return false; |
|
63
|
|
|
} else { |
|
64
|
|
|
return true; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function isOtherGoodTransferPossible(): bool |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->isCommodityTransferPossible() |
|
71
|
|
|
|| $this->isCrewTransferPossible() |
|
72
|
|
|
|| $this->isTorpedoTransferPossible(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getTransferType(): TransferTypeEnum |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->currentType; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function isUnload(): bool |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->isUnload; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getTargetId(): int |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->to->getId(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function isColonyTarget(): bool |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->to instanceof ColonyInterface; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getSource(): ShipInterface|ColonyInterface |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->from; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function getTarget(): ShipInterface|ColonyInterface |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->to; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|