|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\ModuleScreen; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use Stu\Component\Ship\ShipModuleTypeEnum; |
|
9
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
|
10
|
|
|
use Stu\Orm\Entity\ModuleInterface; |
|
11
|
|
|
use Stu\Orm\Entity\ShipBuildplanInterface; |
|
12
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
13
|
|
|
use Stu\Orm\Entity\ShipRumpInterface; |
|
14
|
|
|
use Stu\Orm\Entity\ShipRumpModuleLevelInterface; |
|
15
|
|
|
use Stu\Orm\Entity\StorageInterface; |
|
16
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
17
|
|
|
use Stu\Orm\Repository\ModuleRepositoryInterface; |
|
18
|
|
|
|
|
19
|
|
|
final class ModuleSelectorEntry implements ModuleSelectorEntryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
private ModuleSelectorInterface $moduleSelector, |
|
24
|
|
|
private ModuleInterface $module, |
|
25
|
|
|
private ShipRumpInterface $rump, |
|
26
|
|
|
private ShipRumpModuleLevelInterface $shipRumpModuleLevel, |
|
27
|
|
|
private ColonyInterface|ShipInterface $host, |
|
28
|
|
|
private UserInterface $user, |
|
29
|
|
|
private ModuleRepositoryInterface $moduleRepository, |
|
30
|
|
|
private ?ShipBuildplanInterface $buildplan = null |
|
31
|
|
|
) {} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
#[Override] |
|
35
|
|
|
public function isChosen(): bool |
|
36
|
|
|
{ |
|
37
|
|
|
if ($this->isDisabled()) { |
|
38
|
|
|
return false; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ($this->buildplan !== null) { |
|
42
|
|
|
if ($this->module->getType() === ShipModuleTypeEnum::SPECIAL) { |
|
43
|
|
|
$allModulesWithSameName = $this->moduleRepository->findBy(['name' => $this->module->getName()]); |
|
44
|
|
|
|
|
45
|
|
|
$modules = $this->buildplan->getModules(); |
|
46
|
|
|
foreach ($modules as $buildplanModule) { |
|
47
|
|
|
foreach ($allModulesWithSameName as $moduleWithSameName) { |
|
48
|
|
|
if ($buildplanModule->getModule()->getName() === $moduleWithSameName->getName()) { |
|
49
|
|
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} else { |
|
54
|
|
|
$modulesByType = $this->buildplan->getModulesByType($this->module->getType()); |
|
55
|
|
|
foreach ($modulesByType as $buildplanModule) { |
|
56
|
|
|
if ($buildplanModule->getModule()->getId() === $this->module->getId()) { |
|
57
|
|
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
#[Override] |
|
69
|
|
|
public function isDisabled(): bool |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getStoredAmount() < 1; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
#[Override] |
|
75
|
|
|
public function getStoredAmount(): int |
|
76
|
|
|
{ |
|
77
|
|
|
/** @var StorageInterface|null */ |
|
78
|
|
|
$storage = $this->host->getStorage()->get($this->module->getCommodityId()); |
|
79
|
|
|
|
|
80
|
|
|
if ($storage === null) { |
|
81
|
|
|
return 0; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $storage->getAmount(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
#[Override] |
|
88
|
|
|
public function getModule(): ModuleInterface |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->module; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
#[Override] |
|
94
|
|
|
public function getNeededCrew(): int |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->module->getCrewByFactionAndRumpLvl($this->user->getFaction(), $this->rump); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
#[Override] |
|
100
|
|
|
public function getValue(): int |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->module |
|
103
|
|
|
->getType() |
|
104
|
|
|
->getModuleRumpWrapperCallable()($this->rump, $this->buildplan) |
|
105
|
|
|
->getValue($this->module); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
#[Override] |
|
109
|
|
|
public function getSecondvalue(): ?int |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->module |
|
112
|
|
|
->getType() |
|
113
|
|
|
->getModuleRumpWrapperCallable()($this->rump, $this->buildplan) |
|
114
|
|
|
->getSecondValue($this->module); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
#[Override] |
|
118
|
|
|
public function getModuleLevelClass(): string |
|
119
|
|
|
{ |
|
120
|
|
|
$moduleLevels = $this->shipRumpModuleLevel; |
|
121
|
|
|
$module = $this->module; |
|
122
|
|
|
|
|
123
|
|
|
if ($moduleLevels->{'getModuleLevel' . $module->getType()->value}() > $module->getLevel()) { |
|
124
|
|
|
return 'module_positive'; |
|
125
|
|
|
} |
|
126
|
|
|
if ($moduleLevels->{'getModuleLevel' . $module->getType()->value}() < $module->getLevel()) { |
|
127
|
|
|
return 'module_negative'; |
|
128
|
|
|
} |
|
129
|
|
|
return ''; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
#[Override] |
|
133
|
|
|
public function getAddonValues(): array |
|
134
|
|
|
{ |
|
135
|
|
|
$addon = $this->moduleSelector->getAddon(); |
|
136
|
|
|
if ($addon === null) { |
|
137
|
|
|
return []; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $addon->getModificators($this->module); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
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