|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Game\Lib\View\Provider; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use Stu\Component\Colony\ColonyTypeEnum; |
|
|
|
|
|
|
9
|
|
|
use Stu\Component\Communication\Kn\KnFactoryInterface; |
|
10
|
|
|
use Stu\Component\Communication\Kn\KnItemInterface; |
|
11
|
|
|
use Stu\Component\Crew\CrewCountRetrieverInterface; |
|
12
|
|
|
use Stu\Component\Game\GameEnum; |
|
|
|
|
|
|
13
|
|
|
use Stu\Component\Player\ColonyLimitCalculatorInterface; |
|
14
|
|
|
use Stu\Component\Player\CrewLimitCalculatorInterface; |
|
15
|
|
|
use Stu\Component\Player\Relation\PlayerRelationDeterminatorInterface; |
|
16
|
|
|
use Stu\Component\Player\Settings\UserSettingsProviderInterface; |
|
17
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
18
|
|
|
use Stu\Module\PlayerSetting\Lib\UserEnum; |
|
|
|
|
|
|
19
|
|
|
use Stu\Module\Spacecraft\Lib\EmergencyWrapper; |
|
20
|
|
|
use Stu\Orm\Entity\KnPostInterface; |
|
21
|
|
|
use Stu\Orm\Repository\AllianceBoardTopicRepositoryInterface; |
|
22
|
|
|
use Stu\Orm\Repository\ColonyShipQueueRepositoryInterface; |
|
23
|
|
|
use Stu\Orm\Repository\HistoryRepositoryInterface; |
|
24
|
|
|
use Stu\Orm\Repository\KnPostRepositoryInterface; |
|
25
|
|
|
use Stu\Orm\Repository\ShipyardShipQueueRepositoryInterface; |
|
26
|
|
|
use Stu\Orm\Repository\SpacecraftEmergencyRepositoryInterface; |
|
27
|
|
|
use Stu\Orm\Repository\UserProfileVisitorRepositoryInterface; |
|
28
|
|
|
use Stu\Orm\Repository\UserRepositoryInterface; |
|
29
|
|
|
|
|
30
|
|
|
final class MaindeskProvider implements ViewComponentProviderInterface |
|
31
|
|
|
{ |
|
32
|
1 |
|
public function __construct( |
|
33
|
|
|
private readonly HistoryRepositoryInterface $historyRepository, |
|
34
|
|
|
private readonly AllianceBoardTopicRepositoryInterface $allianceBoardTopicRepository, |
|
35
|
|
|
private readonly UserProfileVisitorRepositoryInterface $userProfileVisitorRepository, |
|
36
|
|
|
private readonly KnPostRepositoryInterface $knPostRepository, |
|
37
|
|
|
private readonly ColonyShipQueueRepositoryInterface $colonyShipQueueRepository, |
|
38
|
|
|
private readonly ShipyardShipQueueRepositoryInterface $shipyardShipQueueRepository, |
|
39
|
|
|
private readonly UserRepositoryInterface $userRepository, |
|
40
|
|
|
private readonly SpacecraftEmergencyRepositoryInterface $spacecraftEmergencyRepository, |
|
41
|
|
|
private readonly UserSettingsProviderInterface $userSettingsProvider, |
|
42
|
|
|
private readonly KnFactoryInterface $knFactory, |
|
43
|
|
|
private readonly ColonyLimitCalculatorInterface $colonyLimitCalculator, |
|
44
|
|
|
private readonly PlayerRelationDeterminatorInterface $playerRelationDeterminator, |
|
45
|
|
|
private readonly CrewLimitCalculatorInterface $crewLimitCalculator, |
|
46
|
|
|
private readonly CrewCountRetrieverInterface $crewCountRetriever |
|
47
|
1 |
|
) {} |
|
48
|
|
|
|
|
49
|
2 |
|
#[Override] |
|
50
|
|
|
public function setTemplateVariables(GameControllerInterface $game): void |
|
51
|
|
|
{ |
|
52
|
2 |
|
$user = $game->getUser(); |
|
53
|
2 |
|
$userId = $user->getId(); |
|
54
|
|
|
|
|
55
|
2 |
|
$game->setTemplateVar( |
|
56
|
2 |
|
'DISPLAY_FIRST_COLONY_DIALOGUE', |
|
57
|
2 |
|
$user->getState() === UserEnum::USER_STATE_UNCOLONIZED |
|
58
|
2 |
|
); |
|
59
|
|
|
|
|
60
|
2 |
|
$game->setTemplateVar( |
|
61
|
2 |
|
'DISPLAY_COLONIZATION_SHIP_DIALOGUE', |
|
62
|
2 |
|
$user->getState() === UserEnum::USER_STATE_COLONIZATION_SHIP |
|
63
|
2 |
|
); |
|
64
|
|
|
|
|
65
|
2 |
|
$newAmount = $this->knPostRepository->getAmountSince($user->getKnMark()); |
|
66
|
|
|
|
|
67
|
2 |
|
$game->setTemplateVar( |
|
68
|
2 |
|
'NEW_KN_POSTING_COUNT', |
|
69
|
2 |
|
$newAmount |
|
70
|
2 |
|
); |
|
71
|
2 |
|
$newKnPostings = $this->knPostRepository->getNewerThenMark($user->getKnMark()); |
|
72
|
2 |
|
if ($newKnPostings !== []) { |
|
73
|
2 |
|
$game->setTemplateVar('MARKED_KN_ID', $newKnPostings[0]->getId()); |
|
74
|
|
|
} |
|
75
|
2 |
|
$game->setTemplateVar( |
|
76
|
2 |
|
'NEW_KN_POSTINGS', |
|
77
|
2 |
|
array_map( |
|
78
|
2 |
|
function (KnPostInterface $knPost) use ($user, $newAmount): KnItemInterface { |
|
79
|
2 |
|
$newAmount--; |
|
80
|
2 |
|
$knItem = $this->knFactory->createKnItem( |
|
81
|
2 |
|
$knPost, |
|
82
|
2 |
|
$user |
|
83
|
2 |
|
); |
|
84
|
2 |
|
$knItem->setMark(((int)floor($newAmount / GameEnum::KN_PER_SITE)) * 6); |
|
85
|
2 |
|
return $knItem; |
|
86
|
2 |
|
}, |
|
87
|
2 |
|
$newKnPostings |
|
88
|
2 |
|
) |
|
89
|
2 |
|
); |
|
90
|
2 |
|
$game->setTemplateVar( |
|
91
|
2 |
|
'RECENT_PROFILE_VISITORS', |
|
92
|
2 |
|
$this->userProfileVisitorRepository->getRecent($userId) |
|
93
|
2 |
|
); |
|
94
|
2 |
|
$game->setTemplateVar( |
|
95
|
2 |
|
'RANDOM_ONLINE_USER', |
|
96
|
2 |
|
$this->userRepository->getOrderedByLastaction(35, $userId, time() - GameEnum::USER_ONLINE_PERIOD) |
|
97
|
2 |
|
); |
|
98
|
2 |
|
$game->setTemplateVar( |
|
99
|
2 |
|
'SHIP_BUILD_PROGRESS', |
|
100
|
2 |
|
[...$this->colonyShipQueueRepository->getByUserAndMode($userId, 1), ...$this->shipyardShipQueueRepository->getByUser($userId)] |
|
101
|
2 |
|
); |
|
102
|
2 |
|
$game->setTemplateVar( |
|
103
|
2 |
|
'SHIP_RETROFIT_PROGRESS', |
|
104
|
2 |
|
[...$this->colonyShipQueueRepository->getByUserAndMode($userId, 2)] |
|
105
|
2 |
|
); |
|
106
|
|
|
|
|
107
|
2 |
|
$alliance = $user->getAlliance(); |
|
108
|
2 |
|
if ($alliance !== null) { |
|
109
|
2 |
|
$game->setTemplateVar('ALLIANCE', true); |
|
110
|
|
|
|
|
111
|
2 |
|
$game->setTemplateVar( |
|
112
|
2 |
|
'RECENT_ALLIANCE_BOARD_TOPICS', |
|
113
|
2 |
|
$this->allianceBoardTopicRepository->getRecentByAlliance($alliance->getId()) |
|
114
|
2 |
|
); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
if ($this->userSettingsProvider->isShowPirateHistoryEntrys($user)) { |
|
118
|
|
|
$game->setTemplateVar('RECENT_HISTORY', $this->historyRepository->getRecent()); |
|
119
|
|
|
} else { |
|
120
|
2 |
|
$game->setTemplateVar('RECENT_HISTORY', $this->historyRepository->getRecentWithoutPirate()); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
//emergencies |
|
124
|
2 |
|
$this->setPotentialEmergencies($game); |
|
125
|
|
|
|
|
126
|
|
|
//planet |
|
127
|
2 |
|
$game->setTemplateVar('PLANET_LIMIT', $this->colonyLimitCalculator->getColonyLimitWithType($user, ColonyTypeEnum::COLONY_TYPE_PLANET)); |
|
128
|
2 |
|
$game->setTemplateVar('PLANET_COUNT', $this->colonyLimitCalculator->getColonyCountWithType($user, ColonyTypeEnum::COLONY_TYPE_PLANET)); |
|
129
|
|
|
|
|
130
|
|
|
//moon |
|
131
|
2 |
|
$game->setTemplateVar('MOON_LIMIT', $this->colonyLimitCalculator->getColonyLimitWithType($user, ColonyTypeEnum::COLONY_TYPE_MOON)); |
|
132
|
2 |
|
$game->setTemplateVar('MOON_COUNT', $this->colonyLimitCalculator->getColonyCountWithType($user, ColonyTypeEnum::COLONY_TYPE_MOON)); |
|
133
|
|
|
|
|
134
|
|
|
//asteroid |
|
135
|
2 |
|
$game->setTemplateVar('ASTEROID_LIMIT', $this->colonyLimitCalculator->getColonyLimitWithType($user, ColonyTypeEnum::COLONY_TYPE_ASTEROID)); |
|
136
|
2 |
|
$game->setTemplateVar('ASTEROID_COUNT', $this->colonyLimitCalculator->getColonyCountWithType($user, ColonyTypeEnum::COLONY_TYPE_ASTEROID)); |
|
137
|
|
|
|
|
138
|
2 |
|
$game->setTemplateVar( |
|
139
|
2 |
|
'CREW_LIMIT', |
|
140
|
2 |
|
$this->crewLimitCalculator->getGlobalCrewLimit($user) |
|
141
|
2 |
|
); |
|
142
|
|
|
|
|
143
|
|
|
// crew count |
|
144
|
2 |
|
$game->setTemplateVar( |
|
145
|
2 |
|
'CREW_COUNT_SHIPS', |
|
146
|
2 |
|
$this->crewCountRetriever->getAssignedToShipsCount($user) |
|
147
|
2 |
|
); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
2 |
|
private function setPotentialEmergencies(GameControllerInterface $game): void |
|
151
|
|
|
{ |
|
152
|
2 |
|
$emergencies = $this->spacecraftEmergencyRepository->getActive(); |
|
153
|
|
|
|
|
154
|
2 |
|
if ($emergencies === []) { |
|
155
|
2 |
|
return; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
$emergencyWrappers = []; |
|
159
|
|
|
|
|
160
|
|
|
foreach ($emergencies as $emergency) { |
|
161
|
|
|
$emergencyWrappers[] = new EmergencyWrapper($this->playerRelationDeterminator, $emergency, $game->getUser()); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
$game->setTemplateVar('EMERGENCYWRAPPERS', $emergencyWrappers); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
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