1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Asylamba\Modules\Atlas\Manager; |
4
|
|
|
|
5
|
|
|
use Asylamba\Classes\Entity\EntityManager; |
6
|
|
|
|
7
|
|
|
use Asylamba\Modules\Demeter\Manager\ColorManager; |
8
|
|
|
use Asylamba\Modules\Hermes\Manager\ConversationManager; |
9
|
|
|
use Asylamba\Modules\Hermes\Manager\ConversationMessageManager; |
10
|
|
|
|
11
|
|
|
use Asylamba\Modules\Atlas\Routine\DailyRoutine; |
12
|
|
|
use Asylamba\Modules\Atlas\Routine\PlayerRoutine; |
13
|
|
|
use Asylamba\Modules\Atlas\Routine\FactionRoutine; |
14
|
|
|
|
15
|
|
|
use Asylamba\Modules\Hermes\Model\ConversationUser; |
16
|
|
|
use Asylamba\Modules\Hermes\Model\ConversationMessage; |
17
|
|
|
use Asylamba\Modules\Demeter\Resource\ColorResource; |
18
|
|
|
use Asylamba\Modules\Athena\Helper\OrbitalBaseHelper; |
19
|
|
|
use Asylamba\Modules\Zeus\Manager\PlayerManager; |
20
|
|
|
|
21
|
|
|
use Asylamba\Modules\Zeus\Model\Player; |
22
|
|
|
use Asylamba\Modules\Atlas\Model\PlayerRanking; |
23
|
|
|
use Asylamba\Modules\Atlas\Model\FactionRanking; |
24
|
|
|
use Asylamba\Modules\Atlas\Model\Ranking; |
25
|
|
|
use Asylamba\Modules\Gaia\Model\Sector; |
26
|
|
|
|
27
|
|
|
use Asylamba\Classes\Exception\ErrorException; |
28
|
|
|
|
29
|
|
|
use Asylamba\Classes\Library\Utils; |
30
|
|
|
|
31
|
|
|
class RankingManager |
32
|
|
|
{ |
33
|
|
|
/** @var EntityManager **/ |
34
|
|
|
protected $entityManager; |
35
|
|
|
/** @var PlayerRankingManager **/ |
36
|
|
|
protected $playerRankingManager; |
37
|
|
|
/** @var FactionRankingManager **/ |
38
|
|
|
protected $factionRankingManager; |
39
|
|
|
/** @var ColorManager **/ |
40
|
|
|
protected $colorManager; |
41
|
|
|
/** @var ConversationManager **/ |
42
|
|
|
protected $conversationManager; |
43
|
|
|
/** @var ConversationMessageManager **/ |
44
|
|
|
protected $conversationMessageManager; |
45
|
|
|
/** @var PlayerManager **/ |
46
|
|
|
protected $playerManager; |
47
|
|
|
/** @var OrbitalBaseHelper **/ |
48
|
|
|
protected $orbitalBaseHelper; |
49
|
|
|
/** @var FactionRoutine **/ |
50
|
|
|
protected $factionRoutine; |
51
|
|
|
/** @var PlayerRoutine **/ |
52
|
|
|
protected $playerRoutine; |
53
|
|
|
/** @var DailyRoutine **/ |
54
|
|
|
protected $dailyRoutine; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param EntityManager $entityManager |
58
|
|
|
* @param PlayerRankingManager $playerRankingManager |
59
|
|
|
* @param FactionRankingManager $factionRankingManager |
60
|
|
|
* @param ColorManager $colorManager |
61
|
|
|
* @param ConversationManager $conversationManager |
62
|
|
|
* @param ConversationMessageManager $conversationMessageManager |
63
|
|
|
* @param PlayerManager $playerManager |
64
|
|
|
* @param OrbitalBaseHelper $orbitalBaseHelper |
65
|
|
|
*/ |
66
|
|
|
public function __construct( |
67
|
|
|
EntityManager $entityManager, |
68
|
|
|
PlayerRankingManager $playerRankingManager, |
69
|
|
|
FactionRankingManager $factionRankingManager, |
70
|
|
|
ColorManager $colorManager, |
71
|
|
|
ConversationManager $conversationManager, |
72
|
|
|
ConversationMessageManager $conversationMessageManager, |
73
|
|
|
PlayerManager $playerManager, |
74
|
|
|
OrbitalBaseHelper $orbitalBaseHelper |
75
|
|
|
) |
76
|
|
|
{ |
|
|
|
|
77
|
|
|
$this->entityManager = $entityManager; |
78
|
|
|
$this->playerRankingManager = $playerRankingManager; |
79
|
|
|
$this->factionRankingManager = $factionRankingManager; |
80
|
|
|
$this->colorManager = $colorManager; |
81
|
|
|
$this->conversationManager = $conversationManager; |
82
|
|
|
$this->conversationMessageManager = $conversationMessageManager; |
83
|
|
|
$this->playerManager = $playerManager; |
84
|
|
|
$this->orbitalBaseHelper = $orbitalBaseHelper; |
85
|
|
|
|
86
|
|
|
$this->dailyRoutine = new DailyRoutine(); |
87
|
|
|
$this->playerRoutine = new PlayerRoutine(); |
88
|
|
|
$this->factionRoutine = new FactionRoutine(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function processPlayersRanking() |
92
|
|
|
{ |
93
|
|
|
if ($this->entityManager->getRepository(Ranking::class)->hasBeenAlreadyProcessed(true, false) === true) { |
|
|
|
|
94
|
|
|
return; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$players = $this->playerManager->getByStatements([Player::ACTIVE, Player::INACTIVE, Player::HOLIDAY]); |
98
|
|
|
|
99
|
|
|
$playerRankingRepository = $this->entityManager->getRepository(PlayerRanking::class); |
100
|
|
|
|
101
|
|
|
$ranking = $this->createRanking(true, false); |
102
|
|
|
|
103
|
|
|
$this->playerRoutine->execute( |
104
|
|
|
$players, |
105
|
|
|
$playerRankingRepository->getPlayersResources(), |
106
|
|
|
$playerRankingRepository->getPlayersResourcesData(), |
107
|
|
|
$playerRankingRepository->getPlayersGeneralData(), |
108
|
|
|
$playerRankingRepository->getPlayersArmiesData(), |
109
|
|
|
$playerRankingRepository->getPlayersPlanetData(), |
110
|
|
|
$playerRankingRepository->getPlayersTradeRoutes(), |
111
|
|
|
$playerRankingRepository->getPlayersLinkedTradeRoutes(), |
112
|
|
|
$playerRankingRepository->getAttackersButcherRanking(), |
113
|
|
|
$playerRankingRepository->getDefendersButcherRanking(), |
114
|
|
|
$this->orbitalBaseHelper |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
$S_PRM1 = $this->playerRankingManager->getCurrentSession(); |
118
|
|
|
$this->playerRankingManager->newSession(); |
119
|
|
|
$this->playerRankingManager->loadLastContext(); |
120
|
|
|
|
121
|
|
|
$this->playerRoutine->processResults($ranking, $players, $this->playerRankingManager, $playerRankingRepository); |
|
|
|
|
122
|
|
|
|
123
|
|
|
$this->playerRankingManager->changeSession($S_PRM1); |
124
|
|
|
|
125
|
|
|
$this->entityManager->flush(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function processFactionsRanking() |
129
|
|
|
{ |
130
|
|
|
if ($this->entityManager->getRepository(Ranking::class)->hasBeenAlreadyProcessed(false, true) === true) { |
|
|
|
|
131
|
|
|
return; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$factions = $this->colorManager->getInGameFactions(); |
135
|
|
|
$playerRankingRepository = $this->entityManager->getRepository(PlayerRanking::class); |
136
|
|
|
$factionRankingRepository = $this->entityManager->getRepository(FactionRanking::class); |
137
|
|
|
$sectors = $this->entityManager->getRepository(Sector::class)->getAll(); |
|
|
|
|
138
|
|
|
|
139
|
|
|
$ranking = $this->createRanking(false, true); |
140
|
|
|
|
141
|
|
|
foreach ($factions as $faction) { |
142
|
|
|
$routesIncome = $factionRankingRepository->getRoutesIncome($faction); |
143
|
|
|
$playerRankings = $playerRankingRepository->getFactionPlayerRankings($faction); |
144
|
|
|
|
145
|
|
|
$this->factionRoutine->execute($faction, $playerRankings, $routesIncome, $sectors); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$S_FRM1 = $this->factionRankingManager->getCurrentSession(); |
149
|
|
|
$this->factionRankingManager->newSession(); |
150
|
|
|
$this->factionRankingManager->loadLastContext(); |
151
|
|
|
|
152
|
|
|
$winningFactionId = $this->factionRoutine->processResults($ranking, $factions, $this->factionRankingManager); |
153
|
|
|
|
154
|
|
|
$this->factionRankingManager->changeSession($S_FRM1); |
155
|
|
|
|
156
|
|
|
if ($winningFactionId !== null) { |
157
|
|
|
$this->processWinningFaction($winningFactionId); |
158
|
|
|
} |
159
|
|
|
$this->entityManager->flush(); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
protected function processWinningFaction($factionId) |
163
|
|
|
{ |
164
|
|
|
$faction = $this->colorManager->get($factionId); |
165
|
|
|
$faction->isWinner = Color::WIN; |
166
|
|
|
|
167
|
|
|
# envoyer un message de Jean-Mi |
168
|
|
|
$winnerName = ColorResource::getInfo($faction->id, 'officialName'); |
169
|
|
|
$content = 'Salut,<br /><br />La victoire vient d\'être remportée par : <br /><strong>' . $winnerName . '</strong><br />'; |
170
|
|
|
$content .= 'Cette faction a atteint les ' . POINTS_TO_WIN . ' points, la partie est donc terminée.<br /><br />Bravo et un grand merci à tous les participants !'; |
171
|
|
|
|
172
|
|
|
$S_CVM1 = $this->conversationManager->getCurrentSession(); |
173
|
|
|
$this->conversationManager->newSession(); |
174
|
|
|
$this->conversationManager->load( |
175
|
|
|
['cu.rPlayer' => ID_JEANMI] |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
if ($this->conversationManager->size() == 1) { |
179
|
|
|
$conv = $this->conversationManager->get(); |
180
|
|
|
|
181
|
|
|
$conv->messages++; |
182
|
|
|
$conv->dLastMessage = Utils::now(); |
183
|
|
|
|
184
|
|
|
# désarchiver tous les users |
185
|
|
|
$users = $conv->players; |
186
|
|
|
foreach ($users as $user) { |
187
|
|
|
$user->convStatement = ConversationUser::CS_DISPLAY; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
# création du message |
191
|
|
|
$message = new ConversationMessage(); |
192
|
|
|
|
193
|
|
|
$message->rConversation = $conv->id; |
194
|
|
|
$message->rPlayer = ID_JEANMI; |
195
|
|
|
$message->type = ConversationMessage::TY_STD; |
196
|
|
|
$message->content = $content; |
|
|
|
|
197
|
|
|
$message->dCreation = Utils::now(); |
|
|
|
|
198
|
|
|
$message->dLastModification = NULL; |
199
|
|
|
|
200
|
|
|
$this->conversationMessageManager->add($message); |
201
|
|
|
} else { |
202
|
|
|
throw new ErrorException('La conversation n\'existe pas ou ne vous appartient pas.'); |
203
|
|
|
} |
204
|
|
|
$this->conversationManager->changeSession($S_CVM1); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
protected function createRanking($isPlayer, $isFaction) |
208
|
|
|
{ |
209
|
|
|
$ranking = |
210
|
|
|
(new Ranking()) |
211
|
|
|
->setIsPlayer($isPlayer) |
212
|
|
|
->setIsFaction($isFaction) |
213
|
|
|
->setCreatedAt(Utils::now()) |
214
|
|
|
; |
215
|
|
|
$this->entityManager->persist($ranking); |
216
|
|
|
$this->entityManager->flush($ranking); |
217
|
|
|
return $ranking; |
218
|
|
|
} |
219
|
|
|
} |