|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PlayerManager |
|
5
|
|
|
* |
|
6
|
|
|
* @author Gil Clavien |
|
7
|
|
|
* @copyright Expansion - le jeu |
|
8
|
|
|
* |
|
9
|
|
|
* @package Zeus |
|
10
|
|
|
* @version 20.05.13 |
|
11
|
|
|
**/ |
|
12
|
|
|
namespace Asylamba\Modules\Zeus\Manager; |
|
13
|
|
|
|
|
14
|
|
|
use Asylamba\Classes\Library\Utils; |
|
15
|
|
|
use Asylamba\Classes\Entity\EntityManager; |
|
16
|
|
|
use Asylamba\Classes\Library\Session\SessionWrapper; |
|
17
|
|
|
|
|
18
|
|
|
use Asylamba\Modules\Zeus\Model\Player; |
|
19
|
|
|
use Asylamba\Modules\Zeus\Model\PlayerBonus; |
|
20
|
|
|
use Asylamba\Modules\Promethee\Model\Technology; |
|
21
|
|
|
use Asylamba\Modules\Athena\Model\OrbitalBase; |
|
22
|
|
|
use Asylamba\Modules\Hermes\Model\Notification; |
|
23
|
|
|
use Asylamba\Modules\Ares\Model\Commander; |
|
24
|
|
|
use Asylamba\Modules\Athena\Model\Transaction; |
|
25
|
|
|
|
|
26
|
|
|
use Asylamba\Modules\Demeter\Manager\ColorManager; |
|
27
|
|
|
use Asylamba\Modules\Ares\Manager\CommanderManager; |
|
28
|
|
|
use Asylamba\Modules\Gaia\Manager\GalaxyColorManager; |
|
29
|
|
|
use Asylamba\Modules\Gaia\Manager\SectorManager; |
|
30
|
|
|
use Asylamba\Modules\Gaia\Manager\PlaceManager; |
|
31
|
|
|
use Asylamba\Modules\Athena\Manager\OrbitalBaseManager; |
|
32
|
|
|
use Asylamba\Modules\Hermes\Manager\NotificationManager; |
|
33
|
|
|
use Asylamba\Modules\Promethee\Manager\ResearchManager; |
|
34
|
|
|
use Asylamba\Modules\Athena\Manager\TransactionManager; |
|
35
|
|
|
use Asylamba\Modules\Athena\Manager\CommercialRouteManager; |
|
36
|
|
|
use Asylamba\Modules\Promethee\Manager\TechnologyManager; |
|
37
|
|
|
use Asylamba\Modules\Athena\Resource\ShipResource; |
|
38
|
|
|
use Asylamba\Modules\Demeter\Model\Color; |
|
39
|
|
|
|
|
40
|
|
|
use Asylamba\Classes\Worker\API; |
|
41
|
|
|
|
|
42
|
|
|
use Asylamba\Classes\Library\Game; |
|
43
|
|
|
use Asylamba\Classes\Container\ArrayList; |
|
44
|
|
|
|
|
45
|
|
|
use Asylamba\Classes\Exception\ErrorException; |
|
46
|
|
|
|
|
47
|
|
|
class PlayerManager { |
|
48
|
|
|
/** @var EntityManager **/ |
|
49
|
|
|
protected $entityManager; |
|
50
|
|
|
/** @var GalaxyColorManager **/ |
|
51
|
|
|
protected $galaxyColorManager; |
|
52
|
|
|
/** @var SectorManager */ |
|
53
|
|
|
protected $sectorManager; |
|
54
|
|
|
/** @var NotificationManager **/ |
|
55
|
|
|
protected $notificationManager; |
|
56
|
|
|
/** @var OrbitalBaseManager **/ |
|
57
|
|
|
protected $orbitalBaseManager; |
|
58
|
|
|
/** @var PlaceManager **/ |
|
59
|
|
|
protected $placeManager; |
|
60
|
|
|
/** @var CommanderManager **/ |
|
61
|
|
|
protected $commanderManager; |
|
62
|
|
|
/** @var ColorManager **/ |
|
63
|
|
|
protected $colorManager; |
|
64
|
|
|
/** @var ResearchManager **/ |
|
65
|
|
|
protected $researchManager; |
|
66
|
|
|
/** @var TransactionManager **/ |
|
67
|
|
|
protected $transactionManager; |
|
68
|
|
|
/** @var CommercialRouteManager **/ |
|
69
|
|
|
protected $commercialRouteManager; |
|
70
|
|
|
/** @var TechnologyManager **/ |
|
71
|
|
|
protected $technologyManager; |
|
72
|
|
|
/** @var PlayerBonusManager **/ |
|
73
|
|
|
protected $playerBonusManager; |
|
74
|
|
|
/** @var SessionWrapper **/ |
|
75
|
|
|
protected $sessionWrapper; |
|
76
|
|
|
/** @var API **/ |
|
77
|
|
|
protected $api; |
|
78
|
|
|
/** @var int **/ |
|
79
|
|
|
protected $playerBaseLevel; |
|
80
|
|
|
/** @var int **/ |
|
81
|
|
|
protected $playerTaxCoeff; |
|
82
|
|
|
/** @var string **/ |
|
83
|
|
|
protected $serverId; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param EntityManager $entityManager |
|
87
|
|
|
* @param GalaxyColorManager $galaxyColorManager |
|
88
|
|
|
* @param SectorManager $sectorManager |
|
89
|
|
|
* @param NotificationManager $notificationManager |
|
90
|
|
|
* @param OrbitalBaseManager $orbitalBaseManager |
|
91
|
|
|
* @param PlaceManager $placeManager |
|
92
|
|
|
* @param CommanderManager $commanderManager |
|
93
|
|
|
* @param ColorManager $colorManager |
|
94
|
|
|
* @param ResearchManager $researchManager |
|
95
|
|
|
* @param TransactionManager $transactionManager |
|
96
|
|
|
* @param CommercialRouteManager $commercialRouteManager |
|
97
|
|
|
* @param TechnologyManager $technologyManager |
|
98
|
|
|
* @param PlayerBonusManager $playerBonusManager |
|
99
|
|
|
* @param SessionWrapper $session |
|
100
|
|
|
* @param API $api |
|
101
|
|
|
* @param int $playerBaseLevel |
|
102
|
|
|
* @param int $playerTaxCoeff |
|
103
|
|
|
* @param string $serverId |
|
104
|
|
|
*/ |
|
105
|
|
|
public function __construct( |
|
106
|
|
|
EntityManager $entityManager, |
|
107
|
|
|
GalaxyColorManager $galaxyColorManager, |
|
108
|
|
|
SectorManager $sectorManager, |
|
109
|
|
|
NotificationManager $notificationManager, |
|
110
|
|
|
OrbitalBaseManager $orbitalBaseManager, |
|
111
|
|
|
PlaceManager $placeManager, |
|
112
|
|
|
CommanderManager $commanderManager, |
|
113
|
|
|
ColorManager $colorManager, |
|
114
|
|
|
ResearchManager $researchManager, |
|
115
|
|
|
TransactionManager $transactionManager, |
|
116
|
|
|
CommercialRouteManager $commercialRouteManager, |
|
117
|
|
|
TechnologyManager $technologyManager, |
|
118
|
|
|
PlayerBonusManager $playerBonusManager, |
|
119
|
|
|
SessionWrapper $session, |
|
120
|
|
|
API $api, |
|
121
|
|
|
$playerBaseLevel, |
|
122
|
|
|
$playerTaxCoeff, |
|
123
|
|
|
$serverId |
|
124
|
|
|
) |
|
125
|
|
|
{ |
|
|
|
|
|
|
126
|
|
|
$this->entityManager = $entityManager; |
|
127
|
|
|
$this->galaxyColorManager = $galaxyColorManager; |
|
128
|
|
|
$this->sectorManager = $sectorManager; |
|
129
|
|
|
$this->notificationManager = $notificationManager; |
|
130
|
|
|
$this->orbitalBaseManager = $orbitalBaseManager; |
|
131
|
|
|
$this->placeManager = $placeManager; |
|
132
|
|
|
$this->commanderManager = $commanderManager; |
|
133
|
|
|
$this->colorManager = $colorManager; |
|
134
|
|
|
$this->researchManager = $researchManager; |
|
135
|
|
|
$this->transactionManager = $transactionManager; |
|
136
|
|
|
$this->commercialRouteManager = $commercialRouteManager; |
|
137
|
|
|
$this->technologyManager = $technologyManager; |
|
138
|
|
|
$this->playerBonusManager = $playerBonusManager; |
|
139
|
|
|
$this->sessionWrapper = $session; |
|
140
|
|
|
$this->api = $api; |
|
141
|
|
|
$this->playerBaseLevel = $playerBaseLevel; |
|
142
|
|
|
$this->playerTaxCoeff = $playerTaxCoeff; |
|
143
|
|
|
$this->serverId = $serverId; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param int $playerId |
|
148
|
|
|
* @return Player |
|
149
|
|
|
*/ |
|
150
|
|
|
public function get($playerId) |
|
151
|
|
|
{ |
|
152
|
|
|
if(($player = $this->entityManager->getRepository(Player::class)->get($playerId)) !== null) { |
|
|
|
|
|
|
153
|
|
|
if ($this->sessionWrapper->get('playerId') === $player->id) { |
|
154
|
|
|
$player->synchronized = true; |
|
155
|
|
|
} |
|
156
|
|
|
$this->fill($player); |
|
157
|
|
|
} |
|
158
|
|
|
return $player; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @param string $name |
|
163
|
|
|
* @return Player |
|
164
|
|
|
*/ |
|
165
|
|
|
public function getByName($name) |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->entityManager->getRepository(PLayer::class)->getByName($name); |
|
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param string $bindKey |
|
172
|
|
|
* @return Player |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getByBindKey($bindKey) |
|
175
|
|
|
{ |
|
176
|
|
|
if(($player = $this->entityManager->getRepository(Player::class)->getByBindKey($bindKey)) !== null) { |
|
|
|
|
|
|
177
|
|
|
if ($this->sessionWrapper->get('playerId') === $player->id) { |
|
178
|
|
|
$player->synchronized = true; |
|
179
|
|
|
} |
|
180
|
|
|
$this->fill($player); |
|
181
|
|
|
} |
|
182
|
|
|
return $player; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @param int $id |
|
187
|
|
|
* @return array |
|
188
|
|
|
*/ |
|
189
|
|
|
public function getGodSons($id) |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->entityManager->getRepository(Player::class)->getGodSons($id); |
|
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @param array $ids |
|
196
|
|
|
* @param array $statements |
|
197
|
|
|
*/ |
|
198
|
|
|
public function getByIdsAndStatements($ids, $statements) |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->entityManager->getRepository(Player::class)->getByIdsAndStatements($ids, $statements); |
|
|
|
|
|
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @param array $statements |
|
205
|
|
|
* @return array |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getByStatements($statements) |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->entityManager->getRepository(Player::class)->getByStatements($statements); |
|
|
|
|
|
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @return int |
|
214
|
|
|
*/ |
|
215
|
|
|
public function countActivePlayers() |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->entityManager->getRepository(Player::class)->countActivePlayers(); |
|
|
|
|
|
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @return int |
|
222
|
|
|
*/ |
|
223
|
|
|
public function countAllPlayers() |
|
224
|
|
|
{ |
|
225
|
|
|
return $this->entityManager->getRepository(Player::class)->countAllPlayers(); |
|
|
|
|
|
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @param int $factionId |
|
230
|
|
|
* @param array $statements |
|
231
|
|
|
* @return array |
|
232
|
|
|
*/ |
|
233
|
|
|
public function countByFactionAndStatements($factionId, $statements) |
|
234
|
|
|
{ |
|
235
|
|
|
return $this->entityManager->getRepository(Player::class)->countByFactionAndStatements($factionId, $statements); |
|
|
|
|
|
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @param int $factionId |
|
240
|
|
|
* @return array |
|
241
|
|
|
*/ |
|
242
|
|
|
public function getFactionPlayers($factionId) |
|
243
|
|
|
{ |
|
244
|
|
|
return $this->entityManager->getRepository(Player::class)->getFactionPlayers($factionId); |
|
|
|
|
|
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @param int $factionId |
|
249
|
|
|
* @return array |
|
250
|
|
|
*/ |
|
251
|
|
|
public function getFactionPlayersByRanking($factionId) |
|
252
|
|
|
{ |
|
253
|
|
|
return $this->entityManager->getRepository(Player::class)->getFactionPlayersByRanking($factionId); |
|
|
|
|
|
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @param int $factionId |
|
258
|
|
|
* @return array |
|
259
|
|
|
*/ |
|
260
|
|
|
public function getFactionPlayersByName($factionId) |
|
261
|
|
|
{ |
|
262
|
|
|
return $this->entityManager->getRepository(Player::class)->getFactionPlayersByName($factionId); |
|
|
|
|
|
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* @param int $factionId |
|
267
|
|
|
* @return Player |
|
268
|
|
|
*/ |
|
269
|
|
|
public function getFactionAccount($factionId) |
|
270
|
|
|
{ |
|
271
|
|
|
return $this->entityManager->getRepository(Player::class)->getFactionAccount($factionId); |
|
|
|
|
|
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* @param int $factionId |
|
276
|
|
|
* @return array |
|
277
|
|
|
*/ |
|
278
|
|
|
public function getLastFactionPlayers($factionId) |
|
279
|
|
|
{ |
|
280
|
|
|
return $this->entityManager->getRepository(Player::class)->getLastFactionPlayers($factionId); |
|
|
|
|
|
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @param int $factionId |
|
285
|
|
|
* @return array |
|
286
|
|
|
*/ |
|
287
|
|
|
public function getParliamentMembers($factionId) |
|
288
|
|
|
{ |
|
289
|
|
|
return $this->entityManager->getRepository(Player::class)->getParliamentMembers($factionId); |
|
|
|
|
|
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* @param int $factionId |
|
294
|
|
|
* @param int $status |
|
295
|
|
|
* @return Player |
|
296
|
|
|
*/ |
|
297
|
|
|
public function getGovernmentMember($factionId, $status) |
|
298
|
|
|
{ |
|
299
|
|
|
return $this->entityManager->getRepository(Player::class)->getGovernmentMember($factionId, $status); |
|
|
|
|
|
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* @param int $factionId |
|
304
|
|
|
* @return array |
|
305
|
|
|
*/ |
|
306
|
|
|
public function getGovernmentMembers($factionId) |
|
307
|
|
|
{ |
|
308
|
|
|
return $this->entityManager->getRepository(PLayer::class)->getGovernmentMembers($factionId); |
|
|
|
|
|
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* @param int $factionId |
|
313
|
|
|
* @return Player |
|
314
|
|
|
*/ |
|
315
|
|
|
public function getFactionLeader($factionId) |
|
316
|
|
|
{ |
|
317
|
|
|
if (($leader = $this->entityManager->getRepository(Player::class)->getFactionLeader($factionId)) !== null) { |
|
|
|
|
|
|
318
|
|
|
$this->fill($leader); |
|
319
|
|
|
} |
|
320
|
|
|
return $leader; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
public function getActivePlayers() |
|
324
|
|
|
{ |
|
325
|
|
|
return $this->entityManager->getRepository(Player::class)->getActivePlayers(); |
|
|
|
|
|
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
public function search($search) { |
|
329
|
|
|
return $this->entityManager->getRepository(Player::class)->search($search); |
|
|
|
|
|
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
protected function fill(Player $player) { |
|
333
|
|
|
if ($this->isSynchronized($player)) { |
|
334
|
|
|
$this->saveSessionData($player); |
|
335
|
|
|
} |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
public function isSynchronized(Player $player) |
|
339
|
|
|
{ |
|
340
|
|
|
return ($player->getId() === $this->sessionWrapper->get('playerId')); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* @param Player $player |
|
345
|
|
|
*/ |
|
346
|
|
|
public function saveSessionData(Player $player) |
|
347
|
|
|
{ |
|
348
|
|
|
if(!$this->sessionWrapper->exist('playerInfo')) { |
|
|
|
|
|
|
349
|
|
|
$this->sessionWrapper->add('playerInfo', new ArrayList()); |
|
350
|
|
|
} |
|
351
|
|
|
$this->sessionWrapper->get('playerInfo')->add('color', $player->getRColor()); |
|
352
|
|
|
$this->sessionWrapper->get('playerInfo')->add('name', $player->getName()); |
|
353
|
|
|
$this->sessionWrapper->get('playerInfo')->add('avatar', $player->getAvatar()); |
|
354
|
|
|
$this->sessionWrapper->get('playerInfo')->add('credit', $player->getCredit()); |
|
355
|
|
|
$this->sessionWrapper->get('playerInfo')->add('experience', $player->getExperience()); |
|
356
|
|
|
$this->sessionWrapper->get('playerInfo')->add('level', $player->getLevel()); |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
public function add(Player $player) { |
|
360
|
|
|
$this->entityManager->persist($player); |
|
361
|
|
|
$this->entityManager->flush($player); |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
public function kill($playerId) { |
|
365
|
|
|
$player = $this->get($playerId); |
|
366
|
|
|
|
|
367
|
|
|
# API call |
|
368
|
|
|
$this->api->playerIsDead($player->bind, $this->serverId); |
|
369
|
|
|
|
|
370
|
|
|
# check if there is no other player with the same dead-name |
|
371
|
|
|
$futureName = '† ' . $player->name . ' '; |
|
372
|
|
|
while(TRUE) { |
|
|
|
|
|
|
373
|
|
|
if (($otherPlayer = $this->getByName($futureName)) === null) { |
|
374
|
|
|
break; |
|
375
|
|
|
} |
|
376
|
|
|
# on ajoute un 'I' à chaque fois |
|
377
|
|
|
$futureName .= 'I'; |
|
378
|
|
|
$this->entityManager->clear($otherPlayer); |
|
379
|
|
|
} |
|
380
|
|
|
# deadify the player |
|
381
|
|
|
$player->name = $futureName; |
|
382
|
|
|
$player->statement = Player::DEAD; |
|
383
|
|
|
$player->bind = NULL; |
|
384
|
|
|
$player->rColor = 0; |
|
385
|
|
|
|
|
386
|
|
|
$this->entityManager->flush(); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
public function reborn($playerId) { |
|
390
|
|
|
$player = $this->get($playerId); |
|
391
|
|
|
|
|
392
|
|
|
# sector choice |
|
393
|
|
|
$sectors = $this->sectorManager->getFactionSectors($player->rColor); |
|
394
|
|
|
|
|
395
|
|
|
$placeFound = FALSE; |
|
396
|
|
|
$placeId = NULL; |
|
397
|
|
|
foreach ($sectors as $sector) { |
|
398
|
|
|
# place choice |
|
399
|
|
|
$qr = $this->entityManager->getConnection()->prepare('SELECT p.id FROM place AS p |
|
400
|
|
|
INNER JOIN system AS sy ON p.rSystem = sy.id |
|
401
|
|
|
INNER JOIN sector AS se ON sy.rSector = se.id |
|
402
|
|
|
WHERE p.typeOfPlace = 1 |
|
403
|
|
|
AND se.id = ? |
|
404
|
|
|
AND p.rPlayer IS NULL |
|
405
|
|
|
ORDER BY p.population ASC |
|
406
|
|
|
LIMIT 0, 30' |
|
407
|
|
|
); |
|
408
|
|
|
$qr->execute(array($sector->id)); |
|
409
|
|
|
$aw = $qr->fetchAll(); |
|
410
|
|
|
if ($aw !== NULL) { |
|
411
|
|
|
$placeFound = TRUE; |
|
412
|
|
|
$placeId = $aw[rand(0, (count($aw) - 1))]['id']; |
|
413
|
|
|
break; |
|
414
|
|
|
} |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
if ($placeFound) { |
|
|
|
|
|
|
418
|
|
|
|
|
419
|
|
|
# reinitialize some values of the player |
|
420
|
|
|
$player->iUniversity = 1000; |
|
421
|
|
|
$player->partNaturalSciences = 25; |
|
422
|
|
|
$player->partLifeSciences = 25; |
|
423
|
|
|
$player->partSocialPoliticalSciences = 25; |
|
424
|
|
|
$player->partInformaticEngineering = 25; |
|
425
|
|
|
$player->statement = Player::ACTIVE; |
|
426
|
|
|
$player->factionPoint = 0; |
|
427
|
|
|
|
|
428
|
|
|
$technos = $this->technologyManager->getPlayerTechnology($player->id); |
|
429
|
|
|
$levelAE = $technos->getTechnology(Technology::BASE_QUANTITY); |
|
430
|
|
|
if ($levelAE != 0) { |
|
431
|
|
|
$this->technologyManager->deleteByRPlayer($player->id, Technology::BASE_QUANTITY); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
# attribute new base and place to player |
|
435
|
|
|
$ob = new OrbitalBase(); |
|
436
|
|
|
|
|
437
|
|
|
$ob->setRPlace($placeId); |
|
438
|
|
|
|
|
439
|
|
|
$ob->setRPlayer($player->id); |
|
440
|
|
|
$ob->setName("Colonie"); |
|
441
|
|
|
|
|
442
|
|
|
$ob->setLevelGenerator(1); |
|
443
|
|
|
$ob->setLevelRefinery(1); |
|
444
|
|
|
$ob->setLevelDock1(0); |
|
445
|
|
|
$ob->setLevelDock2(0); |
|
446
|
|
|
$ob->setLevelDock3(0); |
|
447
|
|
|
$ob->setLevelTechnosphere(0); |
|
448
|
|
|
$ob->setLevelCommercialPlateforme(0); |
|
449
|
|
|
$ob->setLevelStorage(1); |
|
450
|
|
|
$ob->setLevelRecycling(0); |
|
451
|
|
|
$ob->setLevelSpatioport(0); |
|
452
|
|
|
$ob->setResourcesStorage(1000); |
|
453
|
|
|
|
|
454
|
|
|
$this->orbitalBaseManager->updatePoints($ob); |
|
455
|
|
|
|
|
456
|
|
|
# initialisation des investissement |
|
457
|
|
|
$ob->setISchool(500); |
|
458
|
|
|
$ob->setIAntiSpy(500); |
|
459
|
|
|
|
|
460
|
|
|
# ajout de la base |
|
461
|
|
|
$ob->uOrbitalBase = Utils::now(); |
|
462
|
|
|
$ob->dCreation = Utils::now(); |
|
463
|
|
|
$this->orbitalBaseManager->add($ob); |
|
464
|
|
|
|
|
465
|
|
|
$this->placeManager->turnAsSpawnPlace($placeId, $player->getId()); |
|
466
|
|
|
|
|
467
|
|
|
# envoi d'une notif |
|
468
|
|
|
$notif = new Notification(); |
|
469
|
|
|
$notif->setRPlayer($player->id); |
|
470
|
|
|
$notif->setTitle('Nouvelle Colonie'); |
|
471
|
|
|
$notif->addBeg() |
|
472
|
|
|
->addTxt('Vous vous êtes malheureusement fait prendre votre dernière planète. Une nouvelle colonie vous a été attribuée') |
|
473
|
|
|
->addEnd(); |
|
474
|
|
|
$this->notificationManager->add($notif); |
|
475
|
|
|
$this->entityManager->flush(); |
|
476
|
|
|
} else { |
|
477
|
|
|
# si on ne trouve pas de lieu pour le faire poper ou si la faction n'a plus de secteur, le joueur meurt |
|
478
|
|
|
$this->kill($player); |
|
479
|
|
|
} |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
public function updatePlayersCredits() |
|
483
|
|
|
{ |
|
484
|
|
|
$players = $this->getActivePlayers(); |
|
485
|
|
|
$factions = $this->colorManager->getAll(); |
|
486
|
|
|
$S_RSM1 = $this->researchManager->getCurrentSession(); |
|
487
|
|
|
$now = Utils::now(); |
|
488
|
|
|
$repository = $this->entityManager->getRepository(Player::class); |
|
489
|
|
|
$this->entityManager->beginTransaction(); |
|
490
|
|
|
|
|
491
|
|
|
foreach ($players as $player) { |
|
492
|
|
|
# update time |
|
493
|
|
|
$hours = Utils::intervalDates($now, $player->uPlayer); |
|
494
|
|
|
$nbHours = count($hours); |
|
495
|
|
|
if ($nbHours === 0) { |
|
496
|
|
|
continue; |
|
497
|
|
|
} |
|
498
|
|
|
$player->uPlayer = $now; |
|
499
|
|
|
# load the bonus |
|
500
|
|
|
$playerBonus = $this->playerBonusManager->getBonusByPlayer($player); |
|
501
|
|
|
$this->playerBonusManager->load($playerBonus); |
|
502
|
|
|
|
|
503
|
|
|
# load the researches |
|
504
|
|
|
$S_RSM1 = $this->researchManager->getCurrentSession(); |
|
505
|
|
|
$this->researchManager->newSession(); |
|
506
|
|
|
$this->researchManager->load(array('rPlayer' => $player->id)); |
|
507
|
|
|
|
|
508
|
|
|
$bases = $this->orbitalBaseManager->getPlayerBases($player->id); |
|
509
|
|
|
$commanders = $this->commanderManager->getPlayerCommanders( |
|
510
|
|
|
$player->id, |
|
511
|
|
|
[Commander::AFFECTED, Commander::MOVING], |
|
512
|
|
|
['c.experience' => 'DESC', 'c.statement' => 'ASC'] |
|
513
|
|
|
); |
|
514
|
|
|
$researchSession = $this->researchManager->getCurrentSession(); |
|
515
|
|
|
$transactions = $this->transactionManager->getPlayerPropositions($player->id, Transaction::TYP_SHIP); |
|
516
|
|
|
|
|
517
|
|
|
$initialCredits = $player->credit; |
|
518
|
|
|
|
|
519
|
|
|
for ($i = 0; $i < $nbHours; $i++) { |
|
520
|
|
|
$this->uCredit( |
|
521
|
|
|
$player, |
|
522
|
|
|
$bases, |
|
523
|
|
|
$playerBonus, |
|
524
|
|
|
$commanders, |
|
525
|
|
|
$researchSession, |
|
526
|
|
|
$factions, |
|
527
|
|
|
$transactions |
|
528
|
|
|
); |
|
529
|
|
|
} |
|
530
|
|
|
$repository->updatePlayerCredits( |
|
|
|
|
|
|
531
|
|
|
$player, |
|
532
|
|
|
abs($initialCredits - $player->credit), |
|
533
|
|
|
($initialCredits > $player->credit) ? '-' : '+' |
|
534
|
|
|
); |
|
535
|
|
|
$this->entityManager->clear($player); |
|
536
|
|
|
} |
|
537
|
|
|
$this->researchManager->changeSession($S_RSM1); |
|
538
|
|
|
$this->entityManager->flush(Color::class); |
|
539
|
|
|
$this->entityManager->commit(); |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
public function uCredit(Player $player, $playerBases, $playerBonus, $commanders, $rsmSession, &$factions, $transactions) { |
|
543
|
|
|
|
|
544
|
|
|
$popTax = 0; $nationTax = 0; |
|
|
|
|
|
|
545
|
|
|
$credits = $player->credit; |
|
546
|
|
|
$schoolInvests = 0; $antiSpyInvests = 0; |
|
|
|
|
|
|
547
|
|
|
|
|
548
|
|
|
$totalGain = 0; |
|
549
|
|
|
|
|
550
|
|
|
# university investments |
|
551
|
|
|
$uniInvests = $player->iUniversity; |
|
552
|
|
|
$naturalTech = ($player->iUniversity * $player->partNaturalSciences / 100); |
|
553
|
|
|
$lifeTech = ($player->iUniversity * $player->partLifeSciences / 100); |
|
554
|
|
|
$socialTech = ($player->iUniversity * $player->partSocialPoliticalSciences / 100); |
|
555
|
|
|
$informaticTech = ($player->iUniversity * $player->partInformaticEngineering / 100); |
|
556
|
|
|
|
|
557
|
|
|
foreach ($playerBases as $base) { |
|
558
|
|
|
$popTax = Game::getTaxFromPopulation($base->getPlanetPopulation(), $base->typeOfBase, $this->playerTaxCoeff); |
|
559
|
|
|
$popTax += $popTax * $playerBonus->bonus->get(PlayerBonus::POPULATION_TAX) / 100; |
|
560
|
|
|
$nationTax = $base->tax * $popTax / 100; |
|
561
|
|
|
|
|
562
|
|
|
# revenu des routes commerciales |
|
563
|
|
|
$routesIncome = $this->commercialRouteManager->getBaseIncome($base); |
|
564
|
|
|
$routesIncome += $routesIncome * $playerBonus->bonus->get(PlayerBonus::COMMERCIAL_INCOME) / 100; |
|
565
|
|
|
|
|
566
|
|
|
$credits += ($popTax - $nationTax + $routesIncome); |
|
567
|
|
|
$totalGain += $popTax - $nationTax + $routesIncome; |
|
568
|
|
|
|
|
569
|
|
|
# investments |
|
570
|
|
|
$schoolInvests += $base->getISchool(); |
|
571
|
|
|
$antiSpyInvests += $base->getIAntiSpy(); |
|
572
|
|
|
|
|
573
|
|
|
# paiement à l'alliance |
|
574
|
|
|
if ($player->rColor != 0) { |
|
575
|
|
|
foreach ($factions as $faction) { |
|
576
|
|
|
if ($faction->id == $base->sectorColor) { |
|
577
|
|
|
$faction->increaseCredit($nationTax); |
|
578
|
|
|
break; |
|
579
|
|
|
} |
|
580
|
|
|
} |
|
581
|
|
|
} |
|
582
|
|
|
} |
|
583
|
|
|
# si la balance de crédit est positive |
|
584
|
|
|
$totalInvests = $uniInvests + $schoolInvests + $antiSpyInvests; |
|
585
|
|
|
if ($credits >= $totalInvests) { |
|
586
|
|
|
$credits -= $totalInvests; |
|
587
|
|
|
$newCredit = $credits; |
|
588
|
|
|
} else { # si elle est négative |
|
589
|
|
|
$n = new Notification(); |
|
590
|
|
|
$n->setRPlayer($player->id); |
|
591
|
|
|
$n->setTitle('Caisses vides'); |
|
592
|
|
|
$n->addBeg()->addTxt('Domaine')->addSep(); |
|
593
|
|
|
$n->addTxt('Vous ne disposez pas d\'assez de crédits.')->addBrk()->addTxt('Les impôts que vous percevez ne suffisent plus à payer vos investissements.'); |
|
594
|
|
|
|
|
595
|
|
|
if ($totalInvests - $uniInvests <= $totalGain) { |
|
596
|
|
|
# we can decrease only the uni investments |
|
597
|
|
|
$newIUniversity = $totalGain - $schoolInvests - $antiSpyInvests; |
|
598
|
|
|
|
|
599
|
|
|
$player->iUniversity = $newIUniversity; |
|
|
|
|
|
|
600
|
|
|
$credits -= ($newIUniversity + $schoolInvests + $antiSpyInvests); |
|
601
|
|
|
|
|
602
|
|
|
# recompute the real amount for each research |
|
603
|
|
|
$naturalTech = ($player->iUniversity * $player->partNaturalSciences / 100); |
|
604
|
|
|
$lifeTech = ($player->iUniversity * $player->partLifeSciences / 100); |
|
605
|
|
|
$socialTech = ($player->iUniversity * $player->partSocialPoliticalSciences / 100); |
|
606
|
|
|
$informaticTech = ($player->iUniversity * $player->partInformaticEngineering / 100); |
|
607
|
|
|
|
|
608
|
|
|
$n->addBrk()->addTxt(' Vos investissements dans l\'université ont été modifiés afin qu\'aux prochaines relèves vous puissiez payer. Attention, cette situation ne vous apporte pas de crédits.'); |
|
609
|
|
|
} else { |
|
610
|
|
|
# we have to decrease the other investments too |
|
611
|
|
|
# investments in university to 0 |
|
612
|
|
|
$player->iUniversity = 0; |
|
613
|
|
|
# then we decrease the other investments with a ratio |
|
614
|
|
|
$ratioDifference = floor($totalGain / ($schoolInvests + $antiSpyInvests) * 100); |
|
615
|
|
|
|
|
616
|
|
|
$naturalTech = 0; $lifeTech = 0; $socialTech = 0; $informaticTech = 0; |
|
|
|
|
|
|
617
|
|
|
|
|
618
|
|
|
foreach ($playerBases as $orbitalBase) { |
|
619
|
|
|
$newISchool = ceil($orbitalBase->getISchool() * $ratioDifference / 100); |
|
620
|
|
|
$newIAntiSpy = ceil($orbitalBase->getIAntiSpy() * $ratioDifference / 100); |
|
621
|
|
|
|
|
622
|
|
|
$orbitalBase->setISchool($newISchool); |
|
623
|
|
|
$orbitalBase->setIAntiSpy($newIAntiSpy); |
|
624
|
|
|
|
|
625
|
|
|
$credits -= ($newISchool + $newIAntiSpy); |
|
626
|
|
|
|
|
627
|
|
|
$naturalTech += ($newISchool * $player->partNaturalSciences / 100); |
|
628
|
|
|
$lifeTech += ($newISchool * $player->partLifeSciences / 100); |
|
629
|
|
|
$socialTech += ($newISchool * $player->partSocialPoliticalSciences / 100); |
|
630
|
|
|
$informaticTech += ($newISchool * $player->partInformaticEngineering / 100); |
|
631
|
|
|
} |
|
632
|
|
|
$n->addTxt(' Seuls ')->addStg($ratioDifference . '%')->addTxt(' des crédits d\'investissements peuvent être honorés.')->addBrk(); |
|
633
|
|
|
$n->addTxt(' Vos investissements dans l\'université ont été mis à zéro et les autres diminués de façon pondérée afin qu\'aux prochaines relèves vous puissiez payer. Attention, cette situation ne vous apporte pas de crédits.'); |
|
634
|
|
|
} |
|
635
|
|
|
|
|
636
|
|
|
$n->addSep()->addLnk('financial', 'vers les finances →'); |
|
637
|
|
|
$n->addEnd(); |
|
638
|
|
|
|
|
639
|
|
|
$this->notificationManager->add($n); |
|
640
|
|
|
|
|
641
|
|
|
$newCredit = $credits; |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
# payer les commandants |
|
645
|
|
|
$nbOfComNotPaid = 0; |
|
646
|
|
|
$comList = new ArrayList(); |
|
647
|
|
|
foreach ($commanders as $commander) { |
|
648
|
|
|
if (!in_array($commander->getStatement(), [Commander::AFFECTED, Commander::MOVING])) { |
|
649
|
|
|
continue; |
|
650
|
|
|
} |
|
651
|
|
|
if ($newCredit >= (Commander::LVLINCOMECOMMANDER * $commander->getLevel())) { |
|
652
|
|
|
$newCredit -= (Commander::LVLINCOMECOMMANDER * $commander->getLevel()); |
|
653
|
|
|
continue; |
|
654
|
|
|
} |
|
655
|
|
|
# on remet les vaisseaux dans les hangars |
|
656
|
|
|
$this->commanderManager->emptySquadrons($commander); |
|
657
|
|
|
|
|
658
|
|
|
# on vend le commandant |
|
659
|
|
|
$commander->setStatement(Commander::ONSALE); |
|
660
|
|
|
$commander->setRPlayer(ID_GAIA); |
|
661
|
|
|
|
|
662
|
|
|
# TODO : vendre le commandant au marché |
|
663
|
|
|
# (ou alors le mettre en statement COM_DESERT et supprimer ses escadrilles) |
|
664
|
|
|
|
|
665
|
|
|
$comList->add($nbOfComNotPaid, $commander->getName()); |
|
666
|
|
|
$nbOfComNotPaid++; |
|
667
|
|
|
$this->entityManager->flush($commander); |
|
668
|
|
|
} |
|
669
|
|
|
# si au moins un commandant n'a pas pu être payé --> envoyer une notif |
|
670
|
|
|
if ($nbOfComNotPaid) { |
|
671
|
|
|
$n = new Notification(); |
|
672
|
|
|
$n->setRPlayer($player->id); |
|
673
|
|
|
$n->setTitle('Commandant impayé'); |
|
674
|
|
|
|
|
675
|
|
|
$n->addBeg()->addTxt('Domaine')->addSep(); |
|
676
|
|
|
if ($nbOfComNotPaid == 1) { |
|
677
|
|
|
$n->addTxt('Vous n\'avez pas assez de crédits pour payer votre commandant ' . $comList->get(0) . '. Celui-ci a donc déserté ! '); |
|
678
|
|
|
$n->addBrk()->addTxt('Il est allé proposer ses services sur le marché. Si vous voulez le récupérer, vous pouvez vous y rendre et le racheter.'); |
|
679
|
|
|
} else { |
|
680
|
|
|
$n->addTxt('Vous n\'avez pas assez de crédits pour payer certains de vos commandants. Ils ont donc déserté ! ')->addBrk(); |
|
681
|
|
|
$n->addTxt('Voici la liste de ces commandants : '); |
|
682
|
|
|
for ($i = 0; $i < $comList->size() - 2; $i++) { |
|
683
|
|
|
$n->addTxt($comList->get($i) . ', '); |
|
684
|
|
|
} |
|
685
|
|
|
$n->addTxt($comList->get($comList->size() - 2) . ' et ' . $comList->get($comList->size() - 1) . '.'); |
|
686
|
|
|
$n->addBrk()->addTxt('Ils sont tous allés proposer leurs services sur le marché. Si vous voulez les récupérer, vous pouvez vous y rendre et les racheter.'); |
|
687
|
|
|
} |
|
688
|
|
|
$n->addEnd(); |
|
689
|
|
|
$this->notificationManager->add($n); |
|
690
|
|
|
} |
|
691
|
|
|
|
|
692
|
|
|
# payer l'entretien des vaisseaux |
|
693
|
|
|
# vaisseaux en vente |
|
694
|
|
|
$transactionTotalCost = 0; |
|
695
|
|
|
$nbTransactions = count($transactions); |
|
696
|
|
|
for ($i = ($nbTransactions - 1); $i >= 0; $i--) { |
|
697
|
|
|
$transaction = $transactions[$i]; |
|
698
|
|
|
$transactionTotalCost += ShipResource::getInfo($transaction->identifier, 'cost') * ShipResource::COST_REDUCTION * $transaction->quantity; |
|
699
|
|
|
} |
|
700
|
|
|
if ($newCredit >= $transactionTotalCost) { |
|
701
|
|
|
$newCredit -= $transactionTotalCost; |
|
702
|
|
|
} else { |
|
703
|
|
|
$newCredit = 0; |
|
704
|
|
|
} |
|
705
|
|
|
# vaisseaux affectés |
|
706
|
|
|
foreach ($commanders as $commander) { |
|
707
|
|
|
$ships = $commander->getNbrShipByType(); |
|
708
|
|
|
$cost = Game::getFleetCost($ships, TRUE); |
|
709
|
|
|
|
|
710
|
|
|
if ($newCredit >= $cost) { |
|
711
|
|
|
$newCredit -= $cost; |
|
712
|
|
|
continue; |
|
713
|
|
|
} |
|
714
|
|
|
# on vend le commandant car on n'arrive pas à payer la flotte (trash hein) |
|
715
|
|
|
$commander->setStatement(Commander::ONSALE); |
|
716
|
|
|
$commander->setRPlayer(ID_GAIA); |
|
717
|
|
|
|
|
718
|
|
|
$n = new Notification(); |
|
719
|
|
|
$n->setRPlayer($player->id); |
|
720
|
|
|
$n->setTitle('Flotte impayée'); |
|
721
|
|
|
$n->addBeg()->addTxt('Domaine')->addSep(); |
|
722
|
|
|
$n->addTxt('Vous n\'avez pas assez de crédits pour payer l\'entretien de la flotte de votre officier ' . $commander->name . '. Celui-ci a donc déserté ! ... avec la flotte, désolé.'); |
|
723
|
|
|
$n->addEnd(); |
|
724
|
|
|
$this->notificationManager->add($n); |
|
725
|
|
|
$this->entityManager->flush($commander); |
|
726
|
|
|
} |
|
727
|
|
|
# vaisseaux sur la planète |
|
728
|
|
|
foreach ($playerBases as $base) { |
|
729
|
|
|
$cost = Game::getFleetCost($base->shipStorage, FALSE); |
|
730
|
|
|
|
|
731
|
|
|
if ($newCredit >= $cost) { |
|
732
|
|
|
$newCredit -= $cost; |
|
733
|
|
|
} else { |
|
734
|
|
|
# n'arrive pas à tous les payer ! |
|
735
|
|
|
for ($j = ShipResource::SHIP_QUANTITY-1; $j >= 0; $j--) { |
|
736
|
|
|
if ($base->shipStorage[$j] > 0) { |
|
737
|
|
|
$unitCost = ShipResource::getInfo($j, 'cost'); |
|
738
|
|
|
|
|
739
|
|
|
$possibleMaintenable = floor($newCredit / $unitCost); |
|
740
|
|
|
if ($possibleMaintenable > $base->shipStorage[$j]) { |
|
741
|
|
|
$possibleMaintenable = $base->shipStorage[$j]; |
|
742
|
|
|
} |
|
743
|
|
|
$newCredit -= $possibleMaintenable * $unitCost; |
|
744
|
|
|
|
|
745
|
|
|
$toKill = $base->shipStorage[$j] - $possibleMaintenable; |
|
746
|
|
|
if ($toKill > 0) { |
|
747
|
|
|
$this->orbitalBaseManager->removeShipFromDock($base, $j, $toKill); |
|
748
|
|
|
|
|
749
|
|
|
$n = new Notification(); |
|
750
|
|
|
$n->setRPlayer($player->id); |
|
751
|
|
|
$n->setTitle('Entretien vaisseau impayé'); |
|
752
|
|
|
|
|
753
|
|
|
$n->addBeg()->addTxt('Domaine')->addSep(); |
|
754
|
|
|
if ($toKill == 1) { |
|
755
|
|
|
$n->addTxt('Vous n\'avez pas assez de crédits pour payer l\'entretien d\'un(e) ' . ShipResource::getInfo($j, 'codeName') . ' sur ' . $base->name . '. Ce vaisseau part donc à la casse ! '); |
|
756
|
|
|
} else { |
|
757
|
|
|
$n->addTxt('Vous n\'avez pas assez de crédits pour payer l\'entretien de ' . $toKill . ' ' . ShipResource::getInfo($j, 'codeName') . 's sur ' . $base->name . '. Ces vaisseaux partent donc à la casse ! '); |
|
758
|
|
|
} |
|
759
|
|
|
$n->addEnd(); |
|
760
|
|
|
$this->notificationManager->add($n); |
|
761
|
|
|
} |
|
762
|
|
|
} |
|
763
|
|
|
} |
|
764
|
|
|
} |
|
765
|
|
|
} |
|
766
|
|
|
|
|
767
|
|
|
# faire les recherches |
|
768
|
|
|
$S_RSM1 = $this->researchManager->getCurrentSession(); |
|
769
|
|
|
$this->researchManager->changeSession($rsmSession); |
|
770
|
|
|
if ($this->researchManager->size() == 1) { |
|
771
|
|
|
# add the bonus |
|
772
|
|
|
$naturalTech += $naturalTech * $playerBonus->bonus->get(PlayerBonus::UNI_INVEST) / 100; |
|
773
|
|
|
$lifeTech += $lifeTech * $playerBonus->bonus->get(PlayerBonus::UNI_INVEST) / 100; |
|
774
|
|
|
$socialTech += $socialTech * $playerBonus->bonus->get(PlayerBonus::UNI_INVEST) / 100; |
|
775
|
|
|
$informaticTech += $informaticTech * $playerBonus->bonus->get(PlayerBonus::UNI_INVEST) / 100; |
|
776
|
|
|
|
|
777
|
|
|
$tech = $this->researchManager->get(); |
|
778
|
|
|
$this->researchManager->update($tech, $player->id, $naturalTech, $lifeTech, $socialTech, $informaticTech); |
|
779
|
|
|
} else { |
|
780
|
|
|
throw new ErrorException('une erreur est survenue lors de la mise à jour des investissements de recherche pour le joueur ' . $player->id . '.'); |
|
781
|
|
|
} |
|
782
|
|
|
$this->researchManager->changeSession($S_RSM1); |
|
783
|
|
|
|
|
784
|
|
|
$player->credit = $newCredit; |
|
|
|
|
|
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
// OBJECT METHOD |
|
788
|
|
|
public function increaseCredit(Player $player, $credit) { |
|
789
|
|
|
$player->credit += abs($credit); |
|
790
|
|
|
|
|
791
|
|
|
$this->entityManager->getRepository(Player::class)->updatePlayerCredits($player, abs($credit), '+'); |
|
|
|
|
|
|
792
|
|
|
} |
|
793
|
|
|
|
|
794
|
|
|
public function decreaseCredit(Player $player, $credit) { |
|
795
|
|
|
$credits = |
|
796
|
|
|
(abs($credit) > $player->credit) |
|
797
|
|
|
? 0 |
|
798
|
|
|
: abs($credit) |
|
799
|
|
|
; |
|
800
|
|
|
$player->credit += $credits; |
|
801
|
|
|
$this->entityManager->getRepository(Player::class)->updatePlayerCredits($player, $credits, '-'); |
|
|
|
|
|
|
802
|
|
|
} |
|
803
|
|
|
|
|
804
|
|
|
public function increaseExperience(Player $player, $exp) { |
|
805
|
|
|
$exp = round($exp); |
|
806
|
|
|
$player->experience += $exp; |
|
807
|
|
|
if ($player->isSynchronized()) { |
|
808
|
|
|
$this->sessionWrapper->get('playerInfo')->add('experience', $player->experience); |
|
809
|
|
|
} |
|
810
|
|
|
$nextLevel = $this->playerBaseLevel * pow(2, ($player->level - 1)); |
|
811
|
|
|
if ($player->experience >= $nextLevel) { |
|
812
|
|
|
$player->level++; |
|
813
|
|
|
if ($player->isSynchronized()) { |
|
814
|
|
|
$this->sessionWrapper->get('playerInfo')->add('level', $player->level); |
|
815
|
|
|
} |
|
816
|
|
|
$n = new Notification(); |
|
817
|
|
|
$n->setTitle('Niveau supérieur'); |
|
818
|
|
|
$n->setRPlayer($player->id); |
|
819
|
|
|
$n->addBeg()->addTxt('Félicitations, vous gagnez un niveau, vous êtes ')->addStg('niveau ' . $player->level)->addTxt('.'); |
|
820
|
|
|
if ($player->level == 2) { |
|
821
|
|
|
$n->addSep()->addTxt('Attention, à partir de maintenant vous ne bénéficiez plus de la protection des nouveaux arrivants, n\'importe quel joueur peut désormais piller votre planète. '); |
|
822
|
|
|
$n->addTxt('Pensez donc à développer vos flottes pour vous défendre.'); |
|
823
|
|
|
} |
|
824
|
|
|
if ($player->level == 4) { |
|
825
|
|
|
$n->addSep()->addTxt('Attention, à partir de maintenant un joueur adverse peut conquérir votre planète ! Si vous n\'en avez plus, le jeu est terminé pour vous. '); |
|
826
|
|
|
$n->addTxt('Pensez donc à étendre votre royaume en colonisant d\'autres planètes.'); |
|
827
|
|
|
} |
|
828
|
|
|
$n->addEnd(); |
|
829
|
|
|
|
|
830
|
|
|
$this->notificationManager->add($n); |
|
831
|
|
|
|
|
832
|
|
|
# parrainage : au niveau 3, le parrain gagne 1M crédits |
|
833
|
|
|
if ($player->level == 3 AND $player->rGodfather != NULL) { |
|
|
|
|
|
|
834
|
|
|
# add 1'000'000 credits to the godfather |
|
835
|
|
|
if (($godFather = $this->get($player->rGodfather)) !== null) { |
|
836
|
|
|
$this->increaseCredit($godFather, 1000000); |
|
837
|
|
|
|
|
838
|
|
|
# send a message to the godfather |
|
839
|
|
|
$n = new Notification(); |
|
840
|
|
|
$n->setRPlayer($player->rGodfather); |
|
841
|
|
|
$n->setTitle('Récompense de parrainage'); |
|
842
|
|
|
$n->addBeg()->addTxt('Un de vos filleuls a atteint le niveau 3. '); |
|
843
|
|
|
$n->addTxt('Il s\'agit de '); |
|
844
|
|
|
$n->addLnk('embassy/player-' . $player->getId(), '"' . $player->name . '"')->addTxt('.'); |
|
845
|
|
|
$n->addBrk()->addTxt('Vous venez de gagner 1\'000\'000 crédits. N\'hésitez pas à parrainer d\'autres personnes pour gagner encore plus.'); |
|
846
|
|
|
$n->addEnd(); |
|
847
|
|
|
|
|
848
|
|
|
$this->entityManager->flush($godFather); |
|
849
|
|
|
$this->notificationManager->add($n); |
|
850
|
|
|
} |
|
851
|
|
|
} |
|
852
|
|
|
} |
|
853
|
|
|
$this->entityManager->flush($player); |
|
854
|
|
|
} |
|
855
|
|
|
|
|
856
|
|
|
/** |
|
857
|
|
|
* @param int $playerId |
|
858
|
|
|
* @param int $investment |
|
859
|
|
|
*/ |
|
860
|
|
|
public function updateUniversityInvestment($playerId, $investment) |
|
861
|
|
|
{ |
|
862
|
|
|
$this->entityManager->getRepository(Player::class)->updateUniversityInvestment($playerId, $investment); |
|
|
|
|
|
|
863
|
|
|
} |
|
864
|
|
|
} |