|
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
|
|
|
|
|
17
|
|
|
class CommodityTransferStrategy implements TransferStrategyInterface |
|
18
|
|
|
{ |
|
19
|
1 |
|
public function __construct( |
|
20
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory, |
|
21
|
|
|
private StatusBarFactoryInterface $statusBarFactory |
|
22
|
1 |
|
) {} |
|
23
|
|
|
|
|
24
|
9 |
|
#[Override] |
|
25
|
|
|
public function setTemplateVariables( |
|
26
|
|
|
bool $isUnload, |
|
27
|
|
|
StorageEntityWrapperInterface $source, |
|
28
|
|
|
StorageEntityWrapperInterface $targetWrapper, |
|
29
|
|
|
GameControllerInterface $game |
|
30
|
|
|
): void { |
|
31
|
|
|
|
|
32
|
9 |
|
$target = $targetWrapper->get(); |
|
33
|
9 |
|
$beamableStorage = $isUnload ? $source->get()->getBeamableStorage() : $target->getBeamableStorage(); |
|
34
|
|
|
|
|
35
|
9 |
|
$game->setTemplateVar( |
|
36
|
9 |
|
'BEAMABLE_STORAGE', |
|
37
|
9 |
|
$beamableStorage |
|
38
|
9 |
|
); |
|
39
|
|
|
|
|
40
|
9 |
|
if ($target instanceof ColonyInterface) { |
|
41
|
2 |
|
$game->setTemplateVar( |
|
42
|
2 |
|
'SHOW_SHIELD_FREQUENCY', |
|
43
|
2 |
|
$this->colonyLibFactory->createColonyShieldingManager($target)->isShieldingEnabled() && $target->getUser() !== $source->getUser() |
|
44
|
2 |
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
9 |
|
$game->setTemplateVar('SOURCE_STORAGE_BAR', $this->createStorageBar($source)); |
|
48
|
9 |
|
$game->setTemplateVar('TARGET_STORAGE_BAR', $this->createStorageBar($targetWrapper)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
9 |
|
private function createStorageBar(StorageEntityWrapperInterface $entityWrapper): string |
|
52
|
|
|
{ |
|
53
|
9 |
|
return $this->statusBarFactory |
|
54
|
9 |
|
->createStatusBar() |
|
55
|
9 |
|
->setColor(StatusBarColorEnum::STATUSBAR_GREEN) |
|
56
|
9 |
|
->setLabel(_('Lager')) |
|
57
|
9 |
|
->setMaxValue($entityWrapper->get()->getMaxStorage()) |
|
58
|
9 |
|
->setValue($entityWrapper->get()->getStorageSum()) |
|
59
|
9 |
|
->render(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
#[Override] |
|
63
|
|
|
public function transfer( |
|
64
|
|
|
bool $isUnload, |
|
65
|
|
|
StorageEntityWrapperInterface $source, |
|
66
|
|
|
StorageEntityWrapperInterface $target, |
|
67
|
|
|
InformationInterface $information |
|
68
|
|
|
): void { |
|
69
|
|
|
|
|
70
|
|
|
$from = $isUnload ? $source : $target; |
|
71
|
|
|
if ($from->get()->getBeamableStorage()->isEmpty()) { |
|
72
|
|
|
$information->addInformation('Keine Waren zum Beamen vorhanden'); |
|
73
|
|
|
return; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$commodities = request::postArray('commodities'); |
|
77
|
|
|
$gcount = request::postArray('count'); |
|
78
|
|
|
if (count($commodities) == 0 || count($gcount) == 0) { |
|
79
|
|
|
$information->addInformation("Es wurden keine Waren zum Beamen ausgewählt"); |
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (!$target->canPenetrateShields($source->getUser(), $information)) { |
|
84
|
|
|
return; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$destination = $isUnload ? $target : $source; |
|
88
|
|
|
if ($destination->get()->getStorageSum() >= $destination->get()->getMaxStorage()) { |
|
89
|
|
|
$information->addInformationf('Der Lagerraum der %s ist voll', $destination->getName()); |
|
90
|
|
|
return; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$source->transfer($isUnload, $target, $information); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
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