1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Lib\Transfer; |
6
|
|
|
|
7
|
|
|
use Stu\Lib\Transfer\Wrapper\StorageEntityWrapperInterface; |
8
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
9
|
|
|
use Stu\Orm\Entity\ShipInterface; |
10
|
|
|
use Stu\Orm\Entity\SpacecraftInterface; |
11
|
|
|
|
12
|
|
|
class TransferInformation |
13
|
|
|
{ |
14
|
|
|
private EntityWithStorageInterface $source; |
15
|
|
|
private EntityWithStorageInterface $target; |
16
|
|
|
|
17
|
13 |
|
public function __construct( |
18
|
|
|
private TransferTypeEnum $currentType, |
19
|
|
|
private StorageEntityWrapperInterface $sourceWrapper, |
20
|
|
|
private StorageEntityWrapperInterface $targetWrapper, |
21
|
|
|
private bool $isUnload, |
22
|
|
|
private bool $isFriend |
23
|
|
|
) { |
24
|
13 |
|
$this->source = $sourceWrapper->get(); |
25
|
13 |
|
$this->target = $targetWrapper->get(); |
26
|
|
|
} |
27
|
|
|
|
28
|
13 |
|
public function isCommodityTransferPossible(bool $isOtherTypeRequired = true): bool |
29
|
|
|
{ |
30
|
13 |
|
return !($isOtherTypeRequired |
31
|
13 |
|
&& $this->currentType === TransferTypeEnum::COMMODITIES); |
32
|
|
|
} |
33
|
|
|
|
34
|
13 |
|
public function isCrewTransferPossible(bool $isOtherTypeRequired = true): bool |
35
|
|
|
{ |
36
|
|
|
if ( |
37
|
13 |
|
$isOtherTypeRequired |
38
|
13 |
|
&& $this->currentType === TransferTypeEnum::CREW |
39
|
|
|
) { |
40
|
4 |
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ( |
44
|
9 |
|
$this->target instanceof SpacecraftInterface |
45
|
9 |
|
&& $this->target->hasUplink() |
|
|
|
|
46
|
|
|
) { |
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
9 |
|
return $this->target->getUser() === $this->source->getUser(); |
51
|
|
|
} |
52
|
|
|
|
53
|
13 |
|
public function isTorpedoTransferPossible(bool $isOtherTypeRequired = true): bool |
54
|
|
|
{ |
55
|
|
|
if ( |
56
|
13 |
|
$isOtherTypeRequired |
57
|
13 |
|
&& $this->currentType === TransferTypeEnum::TORPEDOS |
58
|
|
|
) { |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
13 |
|
return $this->source instanceof SpacecraftInterface |
63
|
13 |
|
&& $this->target instanceof SpacecraftInterface |
64
|
13 |
|
&& $this->source->isTorpedoStorageHealthy() |
|
|
|
|
65
|
13 |
|
&& (!$this->isUnload() || $this->source->getTorpedoCount() > 0) |
|
|
|
|
66
|
13 |
|
&& ($this->target->hasTorpedo() || $this->target->isTorpedoStorageHealthy()) |
|
|
|
|
67
|
13 |
|
&& ($this->isUnload() || $this->target->getTorpedoCount() > 0); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function isFriend(): bool |
71
|
|
|
{ |
72
|
|
|
if ( |
73
|
|
|
!$this->isFriend |
74
|
|
|
&& $this->source->getUser() !== $this->target->getUser() |
75
|
|
|
) { |
76
|
|
|
return false; |
77
|
|
|
} else { |
78
|
|
|
return true; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
13 |
|
public function isOtherGoodTransferPossible(): bool |
83
|
|
|
{ |
84
|
13 |
|
return $this->isCommodityTransferPossible() |
85
|
13 |
|
|| $this->isCrewTransferPossible() |
86
|
13 |
|
|| $this->isTorpedoTransferPossible(); |
87
|
|
|
} |
88
|
|
|
|
89
|
13 |
|
public function getTransferType(): TransferTypeEnum |
90
|
|
|
{ |
91
|
13 |
|
return $this->currentType; |
92
|
|
|
} |
93
|
|
|
|
94
|
13 |
|
public function getSourceType(): TransferEntityTypeEnum |
95
|
|
|
{ |
96
|
13 |
|
return $this->source->getTransferEntityType(); |
97
|
|
|
} |
98
|
|
|
|
99
|
13 |
|
public function getTargetType(): TransferEntityTypeEnum |
100
|
|
|
{ |
101
|
13 |
|
return $this->target->getTransferEntityType(); |
102
|
|
|
} |
103
|
|
|
|
104
|
13 |
|
public function isUnload(): bool |
105
|
|
|
{ |
106
|
13 |
|
return $this->isUnload; |
107
|
|
|
} |
108
|
|
|
|
109
|
13 |
|
public function getSourceId(): int |
110
|
|
|
{ |
111
|
13 |
|
return $this->source->getId(); |
112
|
|
|
} |
113
|
|
|
|
114
|
13 |
|
public function getTargetId(): int |
115
|
|
|
{ |
116
|
13 |
|
return $this->target->getId(); |
117
|
|
|
} |
118
|
|
|
|
119
|
13 |
|
public function getSource(): EntityWithStorageInterface |
120
|
|
|
{ |
121
|
13 |
|
return $this->source; |
122
|
|
|
} |
123
|
|
|
|
124
|
13 |
|
public function getTarget(): EntityWithStorageInterface |
125
|
|
|
{ |
126
|
13 |
|
return $this->target; |
127
|
|
|
} |
128
|
|
|
|
129
|
13 |
|
public function getSourceWrapper(): StorageEntityWrapperInterface |
130
|
|
|
{ |
131
|
13 |
|
return $this->sourceWrapper; |
132
|
|
|
} |
133
|
|
|
|
134
|
13 |
|
public function getTargetWrapper(): StorageEntityWrapperInterface |
135
|
|
|
{ |
136
|
13 |
|
return $this->targetWrapper; |
137
|
|
|
} |
138
|
|
|
|
139
|
13 |
|
public function getBeamFactor(): int |
140
|
|
|
{ |
141
|
13 |
|
return $this->sourceWrapper->getBeamFactor(); |
142
|
|
|
} |
143
|
|
|
|
144
|
13 |
|
public function isSourceAbove(): bool |
145
|
|
|
{ |
146
|
13 |
|
return $this->getSourceType() !== TransferEntityTypeEnum::COLONY; |
147
|
|
|
} |
148
|
|
|
|
149
|
13 |
|
public function isUpIcon(): bool |
150
|
|
|
{ |
151
|
13 |
|
return ($this->getSource() instanceof ColonyInterface) === $this->isUnload(); |
152
|
|
|
} |
153
|
|
|
|
154
|
9 |
|
public function showFleetleaderActions(): bool |
155
|
|
|
{ |
156
|
9 |
|
$source = $this->getSource(); |
157
|
9 |
|
if (!$source instanceof ShipInterface) { |
158
|
5 |
|
return false; |
159
|
|
|
} |
160
|
|
|
|
161
|
4 |
|
$fleet = $source->getFleet(); |
162
|
|
|
|
163
|
4 |
|
return $fleet !== null |
164
|
4 |
|
&& $source->isFleetLeader() |
165
|
4 |
|
&& $fleet->getShipCount() > 1; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|