|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Colony\View\ShowModuleFab; |
|
6
|
|
|
|
|
7
|
|
|
use request; |
|
8
|
|
|
use Stu\Component\Colony\ColonyMenuEnum; |
|
9
|
|
|
use Stu\Component\Ship\ShipModuleTypeEnum; |
|
10
|
|
|
use Stu\Module\Colony\Lib\ColonyLoaderInterface; |
|
11
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
12
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
|
13
|
|
|
use Stu\Orm\Repository\BuildingFunctionRepositoryInterface; |
|
14
|
|
|
use Stu\Orm\Repository\ModuleBuildingFunctionRepositoryInterface; |
|
15
|
|
|
use Stu\Orm\Repository\ModuleQueueRepositoryInterface; |
|
16
|
|
|
use Stu\Orm\Repository\ShipRumpRepositoryInterface; |
|
17
|
|
|
use Stu\Orm\Repository\ShipRumpModuleLevelRepositoryInterface; |
|
18
|
|
|
use Stu\Orm\Repository\ShipBuildplanRepositoryInterface; |
|
19
|
|
|
use Stu\Orm\Repository\BuildplanModuleRepositoryInterface; |
|
20
|
|
|
|
|
21
|
|
|
final class ShowModuleFab implements ViewControllerInterface |
|
22
|
|
|
{ |
|
23
|
|
|
public const VIEW_IDENTIFIER = 'SHOW_MODULEFAB'; |
|
24
|
|
|
|
|
25
|
|
|
private ColonyLoaderInterface $colonyLoader; |
|
26
|
|
|
private ShowModuleFabRequestInterface $showModuleFabRequest; |
|
27
|
|
|
private ModuleBuildingFunctionRepositoryInterface $moduleBuildingFunctionRepository; |
|
28
|
|
|
private BuildingFunctionRepositoryInterface $buildingFunctionRepository; |
|
29
|
|
|
private ModuleQueueRepositoryInterface $moduleQueueRepository; |
|
30
|
|
|
private ShipRumpRepositoryInterface $shipRumpRepository; |
|
31
|
|
|
private ShipRumpModuleLevelRepositoryInterface $shipRumpModuleLevelRepository; |
|
32
|
|
|
private ShipBuildplanRepositoryInterface $shipBuildplanRepository; |
|
33
|
|
|
private BuildplanModuleRepositoryInterface $buildplanModuleRepository; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct( |
|
36
|
|
|
ColonyLoaderInterface $colonyLoader, |
|
37
|
|
|
ShowModuleFabRequestInterface $showModuleFabRequest, |
|
38
|
|
|
ModuleBuildingFunctionRepositoryInterface $moduleBuildingFunctionRepository, |
|
39
|
|
|
BuildingFunctionRepositoryInterface $buildingFunctionRepository, |
|
40
|
|
|
ModuleQueueRepositoryInterface $moduleQueueRepository, |
|
41
|
|
|
ShipRumpRepositoryInterface $shipRumpRepository, |
|
42
|
|
|
ShipRumpModuleLevelRepositoryInterface $shipRumpModuleLevelRepository, |
|
43
|
|
|
ShipBuildplanRepositoryInterface $shipBuildplanRepository, |
|
44
|
|
|
BuildplanModuleRepositoryInterface $buildplanModuleRepository |
|
45
|
|
|
) { |
|
46
|
|
|
$this->colonyLoader = $colonyLoader; |
|
47
|
|
|
$this->showModuleFabRequest = $showModuleFabRequest; |
|
48
|
|
|
$this->moduleBuildingFunctionRepository = $moduleBuildingFunctionRepository; |
|
49
|
|
|
$this->buildingFunctionRepository = $buildingFunctionRepository; |
|
50
|
|
|
$this->moduleQueueRepository = $moduleQueueRepository; |
|
51
|
|
|
$this->shipRumpRepository = $shipRumpRepository; |
|
52
|
|
|
$this->shipRumpModuleLevelRepository = $shipRumpModuleLevelRepository; |
|
53
|
|
|
$this->shipBuildplanRepository = $shipBuildplanRepository; |
|
54
|
|
|
$this->buildplanModuleRepository = $buildplanModuleRepository; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function handle(GameControllerInterface $game): void |
|
58
|
|
|
{ |
|
59
|
|
|
$userId = $game->getUser()->getId(); |
|
60
|
|
|
|
|
61
|
|
|
$colony = $this->colonyLoader->loadWithOwnerValidation( |
|
62
|
|
|
$this->showModuleFabRequest->getColonyId(), |
|
63
|
|
|
$userId, |
|
64
|
|
|
false |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$func = $this->buildingFunctionRepository->find(request::getIntFatal('func')); |
|
68
|
|
|
$modules = $this->moduleBuildingFunctionRepository->getByBuildingFunctionAndUser( |
|
69
|
|
|
$func->getFunction(), |
|
70
|
|
|
$userId |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
$sortedModules = []; |
|
74
|
|
|
foreach ($modules as $module) { |
|
75
|
|
|
$moduleType = $module->getModule()->getType()->value; |
|
76
|
|
|
$moduleLevel = $module->getModule()->getLevel(); |
|
77
|
|
|
if (!isset($sortedModules[$moduleType])) { |
|
78
|
|
|
$sortedModules[$moduleType] = []; |
|
79
|
|
|
} |
|
80
|
|
|
if (!isset($sortedModules[$moduleType][$moduleLevel])) { |
|
81
|
|
|
$sortedModules[$moduleType][$moduleLevel] = []; |
|
82
|
|
|
} |
|
83
|
|
|
$sortedModules[$moduleType][$moduleLevel][] = new ModuleFabricationListItemTal( |
|
84
|
|
|
$this->moduleQueueRepository, |
|
85
|
|
|
$module->getModule(), |
|
86
|
|
|
$colony |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$shipRumps = $this->shipRumpRepository->getBuildableByUser($userId); |
|
91
|
|
|
|
|
92
|
|
|
$moduleTypes = []; |
|
93
|
|
|
foreach (ShipModuleTypeEnum::cases() as $moduleType) { |
|
94
|
|
|
$moduleTypes[$moduleType->value] = [ |
|
95
|
|
|
'name' => $moduleType->getDescription(), |
|
96
|
|
|
'image' => "/assets/buttons/modul_screen_{$moduleType->value}.png" |
|
97
|
|
|
]; |
|
98
|
|
|
} |
|
99
|
|
|
$rumpModules = []; |
|
100
|
|
|
$rumpModules[0] = $sortedModules; |
|
101
|
|
|
foreach ($shipRumps as $rump) { |
|
102
|
|
|
$rumpId = $rump->getId(); |
|
103
|
|
|
$rumpModules[$rumpId] = []; |
|
104
|
|
|
|
|
105
|
|
|
foreach ($sortedModules as $type => $levels) { |
|
106
|
|
|
$mod_level = $this->shipRumpModuleLevelRepository->getByShipRump($rumpId); |
|
107
|
|
|
|
|
108
|
|
|
if ($type === ShipModuleTypeEnum::SPECIAL->value) { |
|
109
|
|
|
foreach ($levels as $level => $modules) { |
|
110
|
|
|
if (!isset($rumpModules[$rumpId][$type])) { |
|
111
|
|
|
$rumpModules[$rumpId][$type] = []; |
|
112
|
|
|
} |
|
113
|
|
|
$rumpModules[$rumpId][$type][$level] = $modules; |
|
114
|
|
|
} |
|
115
|
|
|
} else { |
|
116
|
|
|
$min_level_method = 'getModuleLevel' . $type . 'Min'; |
|
117
|
|
|
$max_level_method = 'getModuleLevel' . $type . 'Max'; |
|
118
|
|
|
|
|
119
|
|
|
if ($mod_level !== null && method_exists($mod_level, $min_level_method) && method_exists($mod_level, $max_level_method)) { |
|
120
|
|
|
$min_level = $mod_level->$min_level_method(); |
|
121
|
|
|
$max_level = $mod_level->$max_level_method(); |
|
122
|
|
|
|
|
123
|
|
|
foreach ($levels as $level => $modules) { |
|
124
|
|
|
if ($level >= $min_level && $level <= $max_level) { |
|
125
|
|
|
if (!isset($rumpModules[$rumpId][$type])) { |
|
126
|
|
|
$rumpModules[$rumpId][$type] = []; |
|
127
|
|
|
} |
|
128
|
|
|
$rumpModules[$rumpId][$type][$level] = $modules; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$buildplans = []; |
|
137
|
|
|
$buildplanModules = []; |
|
138
|
|
|
foreach ($shipRumps as $rump) { |
|
139
|
|
|
$rumpId = $rump->getId(); |
|
140
|
|
|
$buildplans[$rumpId] = $this->shipBuildplanRepository->getByUserAndRump($userId, $rumpId); |
|
141
|
|
|
|
|
142
|
|
|
foreach ($buildplans[$rumpId] as $buildplan) { |
|
143
|
|
|
$buildplanId = $buildplan->getId(); |
|
144
|
|
|
$buildplanModules[$buildplanId] = []; |
|
145
|
|
|
|
|
146
|
|
|
foreach ($this->buildplanModuleRepository->getByBuildplan($buildplanId) as $buildplanModule) { |
|
147
|
|
|
$moduleType = $buildplanModule->getModuleType()->value; |
|
148
|
|
|
$moduleLevel = $buildplanModule->getModule()->getLevel(); |
|
149
|
|
|
$moduleId = $buildplanModule->getModule()->getId(); |
|
150
|
|
|
|
|
151
|
|
|
if (!isset($buildplanModules[$buildplanId][$moduleType])) { |
|
152
|
|
|
$buildplanModules[$buildplanId][$moduleType] = []; |
|
153
|
|
|
} |
|
154
|
|
|
if (!isset($buildplanModules[$buildplanId][$moduleType][$moduleLevel])) { |
|
155
|
|
|
$buildplanModules[$buildplanId][$moduleType][$moduleLevel] = []; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
if (isset($sortedModules[$moduleType][$moduleLevel])) { |
|
159
|
|
|
foreach ($sortedModules[$moduleType][$moduleLevel] as $module) { |
|
160
|
|
|
if ($module->getModuleId() === $moduleId) { |
|
161
|
|
|
$buildplanModules[$buildplanId][$moduleType][$moduleLevel][] = $module; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
foreach ($buildplanModules as $buildplanId => $modulesByType) { |
|
171
|
|
|
foreach ($modulesByType as $type => $levels) { |
|
172
|
|
|
foreach ($levels as $level => $modules) { |
|
173
|
|
|
if (empty($modules)) { |
|
174
|
|
|
unset($buildplanModules[$buildplanId][$type][$level]); |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
if (empty($buildplanModules[$buildplanId][$type])) { |
|
178
|
|
|
unset($buildplanModules[$buildplanId][$type]); |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
if (empty($buildplanModules[$buildplanId])) { |
|
182
|
|
|
unset($buildplanModules[$buildplanId]); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
$combinedModules = []; |
|
187
|
|
|
$combinedModules[0] = [ |
|
188
|
|
|
'no_buildplan' => $sortedModules, |
|
189
|
|
|
'buildplans' => [] |
|
190
|
|
|
]; |
|
191
|
|
|
foreach ($shipRumps as $rump) { |
|
192
|
|
|
$rumpId = $rump->getId(); |
|
193
|
|
|
$combinedModules[$rumpId] = [ |
|
194
|
|
|
'no_buildplan' => $rumpModules[$rumpId] ?? [], |
|
195
|
|
|
'buildplans' => [] |
|
196
|
|
|
]; |
|
197
|
|
|
|
|
198
|
|
|
if (isset($buildplans[$rumpId])) { |
|
199
|
|
|
foreach ($buildplans[$rumpId] as $buildplan) { |
|
200
|
|
|
$buildplanId = $buildplan->getId(); |
|
201
|
|
|
if (isset($buildplanModules[$buildplanId])) { |
|
202
|
|
|
$combinedModules[$rumpId]['buildplans'][$buildplanId] = $buildplanModules[$buildplanId]; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
$game->showMacro(ColonyMenuEnum::MENU_MODULEFAB->getTemplate()); |
|
209
|
|
|
$game->setTemplateVar('CURRENT_MENU', ColonyMenuEnum::MENU_MODULEFAB); |
|
210
|
|
|
|
|
211
|
|
|
$game->setTemplateVar('HOST', $colony); |
|
212
|
|
|
$game->setTemplateVar('FUNC', $func); |
|
213
|
|
|
$game->setTemplateVar('SORTED_MODULES', $sortedModules); |
|
214
|
|
|
$game->setTemplateVar('SHIP_RUMPS', $shipRumps); |
|
215
|
|
|
$game->setTemplateVar('MODULE_TYPES', $moduleTypes); |
|
216
|
|
|
$game->setTemplateVar('RUMP_MODULES', $rumpModules); |
|
217
|
|
|
$game->setTemplateVar('BUILDPLANS', $buildplans); |
|
218
|
|
|
$game->setTemplateVar('BUILDPLAN_MODULES', $buildplanModules); |
|
219
|
|
|
$game->setTemplateVar('COMBINED_MODULES', $combinedModules); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|