|
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\Colony; |
|
9
|
|
|
use Stu\Orm\Entity\Ship; |
|
10
|
|
|
use Stu\Orm\Entity\Spacecraft; |
|
11
|
|
|
|
|
12
|
|
|
class TransferInformation |
|
13
|
|
|
{ |
|
14
|
|
|
private EntityWithStorageInterface $source; |
|
15
|
|
|
private EntityWithStorageInterface $target; |
|
16
|
|
|
|
|
17
|
16 |
|
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
|
16 |
|
$this->source = $sourceWrapper->get(); |
|
25
|
16 |
|
$this->target = $targetWrapper->get(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
16 |
|
public function isCommodityTransferPossible(bool $isOtherTypeRequired = true): bool |
|
29
|
|
|
{ |
|
30
|
16 |
|
return !($isOtherTypeRequired |
|
31
|
16 |
|
&& $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 Spacecraft |
|
45
|
9 |
|
&& $this->target->hasUplink() |
|
|
|
|
|
|
46
|
|
|
) { |
|
47
|
|
|
return true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
9 |
|
return $this->target->getUser()?->getId() === $this->source->getUser()?->getId(); |
|
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 Spacecraft |
|
63
|
13 |
|
&& $this->target instanceof Spacecraft |
|
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
|
|
|
return $this->isFriend || $this->source->getUser()?->getId() === $this->target->getUser()?->getId(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
13 |
|
public function isOtherGoodTransferPossible(): bool |
|
76
|
|
|
{ |
|
77
|
13 |
|
return $this->isCommodityTransferPossible() |
|
78
|
13 |
|
|| $this->isCrewTransferPossible() |
|
79
|
13 |
|
|| $this->isTorpedoTransferPossible(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
16 |
|
public function getTransferType(): TransferTypeEnum |
|
83
|
|
|
{ |
|
84
|
16 |
|
return $this->currentType; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
16 |
|
public function getSourceType(): TransferEntityTypeEnum |
|
88
|
|
|
{ |
|
89
|
16 |
|
return $this->source->getTransferEntityType(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
16 |
|
public function getTargetType(): TransferEntityTypeEnum |
|
93
|
|
|
{ |
|
94
|
16 |
|
return $this->target->getTransferEntityType(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
13 |
|
public function isUnload(): bool |
|
98
|
|
|
{ |
|
99
|
13 |
|
return $this->isUnload; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
13 |
|
public function getSourceId(): int |
|
103
|
|
|
{ |
|
104
|
13 |
|
return $this->source->getId(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
13 |
|
public function getTargetId(): int |
|
108
|
|
|
{ |
|
109
|
13 |
|
return $this->target->getId(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
16 |
|
public function getSource(): EntityWithStorageInterface |
|
113
|
|
|
{ |
|
114
|
16 |
|
return $this->source; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
16 |
|
public function getTarget(): EntityWithStorageInterface |
|
118
|
|
|
{ |
|
119
|
16 |
|
return $this->target; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
16 |
|
public function getSourceWrapper(): StorageEntityWrapperInterface |
|
123
|
|
|
{ |
|
124
|
16 |
|
return $this->sourceWrapper; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
16 |
|
public function getTargetWrapper(): StorageEntityWrapperInterface |
|
128
|
|
|
{ |
|
129
|
16 |
|
return $this->targetWrapper; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
13 |
|
public function getBeamFactor(): int |
|
133
|
|
|
{ |
|
134
|
13 |
|
return $this->sourceWrapper->getBeamFactor(); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
13 |
|
public function isSourceAbove(): bool |
|
138
|
|
|
{ |
|
139
|
13 |
|
return $this->getSourceType() !== TransferEntityTypeEnum::COLONY; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
13 |
|
public function isUpIcon(): bool |
|
143
|
|
|
{ |
|
144
|
13 |
|
return ($this->getSource() instanceof Colony) === $this->isUnload(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
9 |
|
public function showFleetleaderActions(): bool |
|
148
|
|
|
{ |
|
149
|
9 |
|
$source = $this->getSource(); |
|
150
|
9 |
|
if (!$source instanceof Ship) { |
|
151
|
5 |
|
return false; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
4 |
|
$fleet = $source->getFleet(); |
|
155
|
|
|
|
|
156
|
4 |
|
return $fleet !== null |
|
157
|
4 |
|
&& $source->isFleetLeader() |
|
158
|
4 |
|
&& $fleet->getShipCount() > 1; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.