|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\Transfer\Strategy; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use request; |
|
9
|
|
|
use Stu\Lib\Information\InformationInterface; |
|
10
|
|
|
use Stu\Lib\Transfer\Wrapper\StorageEntityWrapperInterface; |
|
11
|
|
|
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface; |
|
12
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
13
|
|
|
use Stu\Module\Template\StatusBarColorEnum; |
|
|
|
|
|
|
14
|
|
|
use Stu\Module\Template\StatusBarFactoryInterface; |
|
15
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
|
16
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
17
|
|
|
|
|
18
|
|
|
class CommodityTransferStrategy implements TransferStrategyInterface |
|
19
|
|
|
{ |
|
20
|
1 |
|
public function __construct( |
|
21
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory, |
|
22
|
|
|
private StatusBarFactoryInterface $statusBarFactory |
|
23
|
1 |
|
) {} |
|
24
|
|
|
|
|
25
|
9 |
|
#[Override] |
|
26
|
|
|
public function setTemplateVariables( |
|
27
|
|
|
bool $isUnload, |
|
28
|
|
|
StorageEntityWrapperInterface $source, |
|
29
|
|
|
StorageEntityWrapperInterface $targetWrapper, |
|
30
|
|
|
GameControllerInterface $game |
|
31
|
|
|
): void { |
|
32
|
|
|
|
|
33
|
9 |
|
$target = $targetWrapper->get(); |
|
34
|
9 |
|
$beamableStorage = $isUnload ? $source->get()->getBeamableStorage() : $target->getBeamableStorage(); |
|
35
|
|
|
|
|
36
|
9 |
|
$game->setTemplateVar( |
|
37
|
9 |
|
'BEAMABLE_STORAGE', |
|
38
|
9 |
|
$beamableStorage |
|
39
|
9 |
|
); |
|
40
|
|
|
|
|
41
|
9 |
|
if ($target instanceof ColonyInterface) { |
|
42
|
2 |
|
$game->setTemplateVar( |
|
43
|
2 |
|
'SHOW_SHIELD_FREQUENCY', |
|
44
|
2 |
|
$this->colonyLibFactory->createColonyShieldingManager($target)->isShieldingEnabled() && $target->getUser() !== $source->getUser() |
|
45
|
2 |
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
9 |
|
$game->setTemplateVar('SOURCE_STORAGE_BAR', $this->createStorageBar($source)); |
|
49
|
9 |
|
$game->setTemplateVar('TARGET_STORAGE_BAR', $this->createStorageBar($targetWrapper)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
9 |
|
private function createStorageBar(StorageEntityWrapperInterface $entityWrapper): string |
|
53
|
|
|
{ |
|
54
|
9 |
|
return $this->statusBarFactory |
|
55
|
9 |
|
->createStatusBar() |
|
56
|
9 |
|
->setColor(StatusBarColorEnum::STATUSBAR_GREEN) |
|
57
|
9 |
|
->setLabel(_('Lager')) |
|
58
|
9 |
|
->setMaxValue($entityWrapper->get()->getMaxStorage()) |
|
59
|
9 |
|
->setValue($entityWrapper->get()->getStorageSum()) |
|
60
|
9 |
|
->render(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
#[Override] |
|
64
|
|
|
public function transfer( |
|
65
|
|
|
bool $isUnload, |
|
66
|
|
|
StorageEntityWrapperInterface $source, |
|
67
|
|
|
StorageEntityWrapperInterface $target, |
|
68
|
|
|
InformationInterface $information |
|
69
|
|
|
): void { |
|
70
|
|
|
|
|
71
|
|
|
$from = $isUnload ? $source : $target; |
|
72
|
|
|
if ($from->get()->getBeamableStorage()->isEmpty()) { |
|
73
|
|
|
$information->addInformation('Keine Waren zum Beamen vorhanden'); |
|
74
|
|
|
return; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$commodities = request::postArray('commodities'); |
|
78
|
|
|
$gcount = request::postArray('count'); |
|
79
|
|
|
if (count($commodities) == 0 || count($gcount) == 0) { |
|
80
|
|
|
$information->addInformation("Es wurden keine Waren zum Beamen ausgewählt"); |
|
81
|
|
|
return; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if ($this->shieldsAreBlocking($target, $source->getUser(), $information)) { |
|
85
|
|
|
return; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$destination = $isUnload ? $target : $source; |
|
89
|
|
|
if ($destination->get()->getStorageSum() >= $destination->get()->getMaxStorage()) { |
|
90
|
|
|
$information->addInformationf('Der Lagerraum der %s ist voll', $destination->getName()); |
|
91
|
|
|
return; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$source->transfer($isUnload, $target, $information); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
private function shieldsAreBlocking(StorageEntityWrapperInterface $targetWrapper, UserInterface $user, InformationInterface $information): bool |
|
98
|
|
|
{ |
|
99
|
|
|
$target = $targetWrapper->get(); |
|
100
|
|
|
|
|
101
|
|
|
if ( |
|
102
|
|
|
$target instanceof ColonyInterface |
|
103
|
|
|
&& $target->getUser() !== $user |
|
104
|
|
|
&& $this->colonyLibFactory->createColonyShieldingManager($target)->isShieldingEnabled() |
|
105
|
|
|
&& $target->getShieldFrequency() |
|
|
|
|
|
|
106
|
|
|
) { |
|
107
|
|
|
$frequency = request::postInt('frequency'); |
|
108
|
|
|
if ($frequency !== $target->getShieldFrequency()) { |
|
109
|
|
|
$information->addInformation("Die Schildfrequenz ist nicht korrekt"); |
|
110
|
|
|
return true; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return false; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths