|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\ModuleScreen; |
|
6
|
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
use Stu\Component\Ship\ShipModuleTypeEnum; |
|
9
|
|
|
use Stu\Module\Ship\Lib\ModuleValueCalculator; |
|
10
|
|
|
use Stu\Module\Ship\Lib\ModuleValueCalculatorInterface; |
|
11
|
|
|
use Stu\Module\ShipModule\ModuleTypeDescriptionMapper; |
|
12
|
|
|
use Stu\Module\Tal\TalPageInterface; |
|
13
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
|
14
|
|
|
use Stu\Orm\Entity\ShipBuildplanInterface; |
|
15
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
16
|
|
|
use Stu\Orm\Entity\ShipRumpInterface; |
|
17
|
|
|
use Stu\Orm\Entity\ShipRumpModuleLevelInterface; |
|
18
|
|
|
use Stu\Orm\Repository\ModuleRepositoryInterface; |
|
19
|
|
|
use Stu\Orm\Repository\ShipRumpModuleLevelRepositoryInterface; |
|
20
|
|
|
use Stu\Orm\Repository\WeaponShieldRepositoryInterface; |
|
21
|
|
|
|
|
22
|
|
|
class ModuleSelector implements ModuleSelectorInterface |
|
23
|
|
|
{ |
|
24
|
|
|
private const MACRO = 'html/modulescreen.xhtml/moduleselector'; |
|
25
|
|
|
private const TEMPLATE = 'html/ajaxempty.xhtml'; |
|
26
|
|
|
|
|
27
|
|
|
/** @var ModuleSelectorWrapperInterface[] */ |
|
28
|
|
|
private $moduleSelectorWrappers; |
|
29
|
|
|
private int $moduleType; |
|
30
|
|
|
private ShipRumpInterface $rump; |
|
31
|
|
|
private int $userId; |
|
32
|
|
|
private ?ColonyInterface $colony; |
|
33
|
|
|
private ?ShipInterface $station; |
|
34
|
|
|
private ?ShipBuildplanInterface $buildplan; |
|
35
|
|
|
private ?WeaponShieldRepositoryInterface $weaponshield; |
|
36
|
|
|
|
|
37
|
|
|
private ModuleRepositoryInterface $moduleRepository; |
|
38
|
|
|
|
|
39
|
|
|
private ShipRumpModuleLevelRepositoryInterface $shipRumpModuleLevelRepository; |
|
40
|
|
|
|
|
41
|
|
|
private TalPageInterface $talPage; |
|
42
|
|
|
|
|
43
|
|
|
public function __construct( |
|
44
|
|
|
ModuleRepositoryInterface $moduleRepository, |
|
45
|
|
|
?WeaponShieldRepositoryInterface $weaponshield, |
|
46
|
|
|
ShipRumpModuleLevelRepositoryInterface $shipRumpModuleLevelRepository, |
|
47
|
|
|
TalPageInterface $talPage, |
|
48
|
|
|
int $moduleType, |
|
49
|
|
|
?ColonyInterface $colony, |
|
50
|
|
|
?ShipInterface $station, |
|
51
|
|
|
ShipRumpInterface $rump, |
|
52
|
|
|
int $userId, |
|
53
|
|
|
?ShipBuildplanInterface $buildplan = null |
|
54
|
|
|
) { |
|
55
|
|
|
$this->weaponshield = $weaponshield; |
|
56
|
|
|
$this->moduleType = $moduleType; |
|
57
|
|
|
$this->rump = $rump; |
|
58
|
|
|
$this->userId = $userId; |
|
59
|
|
|
$this->colony = $colony; |
|
60
|
|
|
$this->station = $station; |
|
61
|
|
|
$this->buildplan = $buildplan; |
|
62
|
|
|
$this->moduleRepository = $moduleRepository; |
|
63
|
|
|
$this->shipRumpModuleLevelRepository = $shipRumpModuleLevelRepository; |
|
64
|
|
|
$this->talPage = $talPage; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function allowMultiple(): bool |
|
68
|
|
|
{ |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getMacro(): string |
|
73
|
|
|
{ |
|
74
|
|
|
return self::MACRO; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function render(): string |
|
78
|
|
|
{ |
|
79
|
|
|
$this->talPage->setTemplate(self::TEMPLATE); |
|
80
|
|
|
$this->talPage->setVar('THIS', $this); |
|
81
|
|
|
return $this->talPage->parse(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getModuleType(): int |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->moduleType; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function allowEmptySlot(): bool |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->getModuleLevels()->{'getModuleMandatory' . $this->getModuleType()}() == ShipModuleTypeEnum::MODULE_OPTIONAL; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getModuleDescription(): string |
|
95
|
|
|
{ |
|
96
|
|
|
return ModuleTypeDescriptionMapper::getDescription($this->getModuleType()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getUserId(): int |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->userId; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function getRump(): ShipRumpInterface |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->rump; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getFactionbyWeapon($module): ?WeaponShieldRepositoryInterface |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->weaponshield->getFactionByModule($module); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
private function getShipRumpRoleId(): int |
|
115
|
|
|
{ |
|
116
|
|
|
$shipRumpRole = $this->getRump()->getShipRumpRole(); |
|
117
|
|
|
|
|
118
|
|
|
if ($shipRumpRole === null) { |
|
119
|
|
|
throw new InvalidArgumentException('invalid rump without rump role'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return $shipRumpRole->getId(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function getAvailableModules(): array |
|
126
|
|
|
{ |
|
127
|
|
|
if ($this->moduleSelectorWrappers === null) { |
|
128
|
|
|
$this->moduleSelectorWrappers = []; |
|
129
|
|
|
$modules = []; |
|
130
|
|
|
if ($this->getModuleType() == ShipModuleTypeEnum::MODULE_TYPE_SPECIAL) { |
|
131
|
|
|
if ($this->getColony() !== null) { |
|
132
|
|
|
$modules = $this->moduleRepository->getBySpecialTypeColonyAndRump( |
|
133
|
|
|
$this->getColony()->getId(), |
|
134
|
|
|
$this->getModuleType(), |
|
135
|
|
|
$this->getRump()->getId(), |
|
136
|
|
|
$this->getShipRumpRoleId() |
|
137
|
|
|
); |
|
138
|
|
|
} elseif ($this->station !== null) { |
|
139
|
|
|
$modules = $this->moduleRepository->getBySpecialTypeShipAndRump( |
|
140
|
|
|
$this->station->getId(), |
|
141
|
|
|
$this->getModuleType(), |
|
142
|
|
|
$this->getRump()->getId(), |
|
143
|
|
|
$this->getShipRumpRoleId() |
|
144
|
|
|
); |
|
145
|
|
|
} |
|
146
|
|
|
} else { |
|
147
|
|
|
if ($this->getColony() !== null) { |
|
148
|
|
|
$mod_level = $this->shipRumpModuleLevelRepository->getByShipRump( |
|
149
|
|
|
$this->getRump()->getId() |
|
150
|
|
|
); |
|
151
|
|
|
|
|
152
|
|
|
$min_level = $mod_level->{'getModuleLevel' . $this->getModuleType() . 'Min'}(); |
|
153
|
|
|
$max_level = $mod_level->{'getModuleLevel' . $this->getModuleType() . 'Max'}(); |
|
154
|
|
|
|
|
155
|
|
|
$modules = $this->moduleRepository->getByTypeColonyAndLevel( |
|
156
|
|
|
$this->getColony()->getId(), |
|
157
|
|
|
$this->getModuleType(), |
|
158
|
|
|
$this->getShipRumpRoleId(), |
|
159
|
|
|
range($min_level, $max_level) |
|
160
|
|
|
); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
foreach ($modules as $obj) { |
|
164
|
|
|
$this->moduleSelectorWrappers[$obj->getId()] = new ModuleSelectorWrapper($obj, $this->getBuildplan()); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
return $this->moduleSelectorWrappers; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function hasModuleSelected(): ModuleSelectWrapper |
|
171
|
|
|
{ |
|
172
|
|
|
return new ModuleSelectWrapper($this->buildplan); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function getColony(): ?ColonyInterface |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->colony; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function getBuildplan(): ?ShipBuildplanInterface |
|
181
|
|
|
{ |
|
182
|
|
|
return $this->buildplan; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function getModuleLevelClass(ShipRumpInterface $rump, ModuleSelectorWrapperInterface $module): string |
|
186
|
|
|
{ |
|
187
|
|
|
$moduleLevels = $this->getModuleLevels(); |
|
188
|
|
|
|
|
189
|
|
|
if ($moduleLevels->{'getModuleLevel' . $module->getModule()->getType()}() > $module->getModule()->getLevel()) { |
|
190
|
|
|
return 'module_positive'; |
|
191
|
|
|
} |
|
192
|
|
|
if ($moduleLevels->{'getModuleLevel' . $module->getModule()->getType()}() < $module->getModule()->getLevel()) { |
|
193
|
|
|
return 'module_negative'; |
|
194
|
|
|
} |
|
195
|
|
|
return ''; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function getModuleValueCalculator(): ModuleValueCalculatorInterface |
|
199
|
|
|
{ |
|
200
|
|
|
return new ModuleValueCalculator(); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function getModuleLevels(): ?ShipRumpModuleLevelInterface |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->shipRumpModuleLevelRepository->getByShipRump($this->rump->getId()); |
|
206
|
|
|
} |
|
207
|
|
|
} |