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