|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\View\ShowAggregationSystem; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
8
|
|
|
use request; |
|
9
|
|
|
use Stu\Exception\SanityCheckException; |
|
10
|
|
|
use Stu\Component\Faction\FactionEnum; |
|
11
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
12
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
|
13
|
|
|
use Stu\Module\Commodity\CommodityTypeEnum; |
|
14
|
|
|
use Stu\Module\Ship\Lib\ShipLoaderInterface; |
|
15
|
|
|
use Stu\Orm\Repository\CommodityRepositoryInterface; |
|
16
|
|
|
use Stu\Orm\Repository\BuildingCommodityRepositoryInterface; |
|
17
|
|
|
use Stu\Component\Ship\System\ShipSystemTypeEnum; |
|
18
|
|
|
|
|
19
|
|
|
final class ShowAggregationSystem implements ViewControllerInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public const string VIEW_IDENTIFIER = 'SHOW_AGGREGATION_SYSTEM_AJAX'; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
public function __construct( |
|
24
|
|
|
private ShipLoaderInterface $shipLoader, |
|
25
|
|
|
private CommodityRepositoryInterface $commodityRepository, |
|
26
|
|
|
private BuildingCommodityRepositoryInterface $buildingCommodityRepository |
|
27
|
|
|
) {} |
|
28
|
|
|
|
|
29
|
|
|
#[Override] |
|
30
|
|
|
public function handle(GameControllerInterface $game): void |
|
31
|
|
|
{ |
|
32
|
|
|
$user = $game->getUser(); |
|
33
|
|
|
$userId = $user->getId(); |
|
34
|
|
|
|
|
35
|
|
|
$ship = $this->shipLoader->getByIdAndUser( |
|
36
|
|
|
request::indInt('id'), |
|
37
|
|
|
$userId, |
|
38
|
|
|
false, |
|
39
|
|
|
false |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$wrapper = $this->shipLoader->getWrapperByIdAndUser( |
|
43
|
|
|
request::indInt('id'), |
|
44
|
|
|
$userId, |
|
45
|
|
|
false, |
|
46
|
|
|
false |
|
47
|
|
|
); |
|
48
|
|
|
$module = $ship->getShipSystem(ShipSystemTypeEnum::SYSTEM_AGGREGATION_SYSTEM)->getModule(); |
|
49
|
|
|
|
|
50
|
|
|
$game->setPageTitle(_('Aggregationssystem')); |
|
51
|
|
|
$game->setMacroInAjaxWindow('html/ship/aggregationsystem.twig'); |
|
52
|
|
|
|
|
53
|
|
|
$game->setTemplateVar('WRAPPER', $wrapper); |
|
54
|
|
|
|
|
55
|
|
|
$aggregationsystem = $wrapper->getAggregationSystemSystemData(); |
|
56
|
|
|
if ($aggregationsystem === null) { |
|
57
|
|
|
throw new SanityCheckException('no aggregation system installed', null, self::VIEW_IDENTIFIER); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$commodities = CommodityTypeEnum::COMMODITY_CONVERSIONS; |
|
61
|
|
|
$mode1Commodities = array_filter($commodities, fn($entry): bool => $entry[4] === 1); |
|
62
|
|
|
$mode2Commodities = array_filter($commodities, fn($entry): bool => $entry[4] === 2); |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$mode1Commodities = array_map(fn($entry): array => [ |
|
66
|
|
|
$this->commodityRepository->find($entry[0]), |
|
67
|
|
|
$this->commodityRepository->find($entry[1]), |
|
68
|
|
|
$entry[2], |
|
69
|
|
|
$entry[3] |
|
70
|
|
|
], $mode1Commodities); |
|
71
|
|
|
|
|
72
|
|
|
$mode2Commodities = array_map(fn($entry): array => [ |
|
73
|
|
|
$this->commodityRepository->find($entry[0]), |
|
74
|
|
|
$this->commodityRepository->find($entry[1]), |
|
75
|
|
|
$entry[2], |
|
76
|
|
|
$entry[3] |
|
77
|
|
|
], $mode2Commodities); |
|
78
|
|
|
|
|
79
|
|
|
if ($module && $module->getFactionId() == FactionEnum::FACTION_FERENGI) { |
|
80
|
|
|
foreach ($mode1Commodities as &$entry) { |
|
81
|
|
|
$entry[2] *= 2; |
|
82
|
|
|
$entry[3] *= 2; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
foreach ($mode2Commodities as &$entry) { |
|
86
|
|
|
$entry[2] *= 2; |
|
87
|
|
|
$entry[3] *= 2; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
$mode1Commodities = array_filter($mode1Commodities, function ($entry) use ($userId): bool { |
|
93
|
|
|
return $entry[1] !== null && $this->buildingCommodityRepository->canProduceCommodity($userId, $entry[1]->getId()); |
|
94
|
|
|
}); |
|
95
|
|
|
|
|
96
|
|
|
$mode2Commodities = array_filter($mode2Commodities, function ($entry) use ($userId): bool { |
|
97
|
|
|
return $entry[1] !== null && $this->buildingCommodityRepository->canProduceCommodity($userId, $entry[1]->getId()); |
|
98
|
|
|
}); |
|
99
|
|
|
|
|
100
|
|
|
$chosencommodity = $aggregationsystem->getCommodityId(); |
|
101
|
|
|
$game->setTemplateVar('MODE1_COMMODITIES', $mode1Commodities); |
|
102
|
|
|
$game->setTemplateVar('MODE2_COMMODITIES', $mode2Commodities); |
|
103
|
|
|
$game->setTemplateVar('CHOSENCOMMODITY', $chosencommodity); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|