1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Commander Manager |
5
|
|
|
* |
6
|
|
|
* @author Noé Zufferey |
7
|
|
|
* @copyright Expansion - le jeu |
8
|
|
|
* |
9
|
|
|
* @package Arès |
10
|
|
|
* @update 20.05.13 |
11
|
|
|
*/ |
12
|
|
|
// !! lors d'un load, mettre c. avant les attribut where |
13
|
|
|
|
14
|
|
|
namespace Asylamba\Modules\Ares\Manager; |
15
|
|
|
|
16
|
|
|
use Asylamba\Classes\Entity\EntityManager; |
17
|
|
|
use Asylamba\Classes\Library\Utils; |
18
|
|
|
use Asylamba\Classes\Library\Game; |
19
|
|
|
use Asylamba\Modules\Athena\Manager\OrbitalBaseManager; |
20
|
|
|
use Asylamba\Modules\Zeus\Manager\PlayerManager; |
21
|
|
|
use Asylamba\Modules\Zeus\Manager\PlayerBonusManager; |
22
|
|
|
use Asylamba\Modules\Gaia\Manager\PlaceManager; |
23
|
|
|
use Asylamba\Modules\Demeter\Manager\ColorManager; |
24
|
|
|
use Asylamba\Modules\Hermes\Manager\NotificationManager; |
25
|
|
|
use Asylamba\Classes\Container\ArrayList; |
26
|
|
|
|
27
|
|
|
use Asylamba\Classes\Worker\EventDispatcher; |
28
|
|
|
|
29
|
|
|
use Asylamba\Modules\Athena\Model\OrbitalBase; |
30
|
|
|
use Asylamba\Modules\Gaia\Model\Place; |
31
|
|
|
use Asylamba\Modules\Ares\Model\Report; |
32
|
|
|
use Asylamba\Modules\Ares\Model\LiveReport; |
33
|
|
|
use Asylamba\Modules\Zeus\Model\PlayerBonus; |
34
|
|
|
use Asylamba\Modules\Ares\Model\Commander; |
35
|
|
|
use Asylamba\Modules\Gaia\Resource\SquadronResource; |
36
|
|
|
use Asylamba\Modules\Demeter\Model\Color; |
37
|
|
|
|
38
|
|
|
use Asylamba\Classes\Scheduler\RealTimeActionScheduler; |
39
|
|
|
|
40
|
|
|
use Asylamba\Modules\Gaia\Event\PlaceOwnerChangeEvent; |
41
|
|
|
|
42
|
|
|
class CommanderManager |
43
|
|
|
{ |
44
|
|
|
/** @var EntityManager **/ |
45
|
|
|
protected $entityManager; |
46
|
|
|
/** @var FightManager **/ |
47
|
|
|
protected $fightManager; |
48
|
|
|
/** @var ReportManager **/ |
49
|
|
|
protected $reportManager; |
50
|
|
|
/** @var OrbitalBaseManager **/ |
51
|
|
|
protected $orbitalBaseManager; |
52
|
|
|
/** @var PlayerManager **/ |
53
|
|
|
protected $playerManager; |
54
|
|
|
/** @var PlayerBonusManager **/ |
55
|
|
|
protected $playerBonusManager; |
56
|
|
|
/** @var PlaceManager **/ |
57
|
|
|
protected $placeManager; |
58
|
|
|
/** @var ColorManager **/ |
59
|
|
|
protected $colorManager; |
60
|
|
|
/** @var NotificationManager **/ |
61
|
|
|
protected $notificationManager; |
62
|
|
|
/** @var RealTimeActionScheduler **/ |
63
|
|
|
protected $realtimeActionScheduler; |
64
|
|
|
/** @var EventDispatcher **/ |
65
|
|
|
protected $eventDispatcher; |
66
|
|
|
/** @var int **/ |
67
|
|
|
protected $commanderBaseLevel; |
68
|
|
|
|
69
|
|
|
protected $actions = [ |
70
|
|
|
Commander::MOVE => 'uChangeBase', |
71
|
|
|
Commander::LOOT => 'uLoot', |
72
|
|
|
Commander::COLO => 'uConquer', |
73
|
|
|
Commander::BACK => 'uReturnBase' |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param EntityManager $entityManager |
78
|
|
|
* @param FightManager $fightManager |
79
|
|
|
* @param ReportManager $reportManager |
80
|
|
|
* @param OrbitalBaseManager $orbitalBaseManager |
81
|
|
|
* @param PlayerManager $playerManager |
82
|
|
|
* @param PlayerBonusManager $playerBonusManager |
83
|
|
|
* @param PlaceManager $placeManager |
84
|
|
|
* @param ColorManager $colorManager |
85
|
|
|
* @param NotificationManager $notificationManager |
86
|
|
|
* @param RealTimeActionScheduler $realtimeActionScheduler |
87
|
|
|
* @param EventDispatcher $eventDispatcher |
88
|
|
|
* @param int $commanderBaseLevel |
89
|
|
|
*/ |
90
|
|
|
public function __construct( |
91
|
|
|
EntityManager $entityManager, |
92
|
|
|
FightManager $fightManager, |
93
|
|
|
ReportManager $reportManager, |
94
|
|
|
OrbitalBaseManager $orbitalBaseManager, |
95
|
|
|
PlayerManager $playerManager, |
96
|
|
|
PlayerBonusManager $playerBonusManager, |
97
|
|
|
PlaceManager $placeManager, |
98
|
|
|
ColorManager $colorManager, |
99
|
|
|
NotificationManager $notificationManager, |
100
|
|
|
RealTimeActionScheduler $realtimeActionScheduler, |
101
|
|
|
EventDispatcher $eventDispatcher, |
102
|
|
|
$commanderBaseLevel |
103
|
|
|
) { |
104
|
|
|
$this->entityManager = $entityManager; |
105
|
|
|
$this->fightManager = $fightManager; |
106
|
|
|
$this->reportManager = $reportManager; |
107
|
|
|
$this->orbitalBaseManager = $orbitalBaseManager; |
108
|
|
|
$this->playerManager = $playerManager; |
109
|
|
|
$this->playerBonusManager = $playerBonusManager; |
110
|
|
|
$this->placeManager = $placeManager; |
111
|
|
|
$this->colorManager = $colorManager; |
112
|
|
|
$this->notificationManager = $notificationManager; |
113
|
|
|
$this->realtimeActionScheduler = $realtimeActionScheduler; |
114
|
|
|
$this->eventDispatcher = $eventDispatcher; |
115
|
|
|
$this->commanderBaseLevel = $commanderBaseLevel; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param integer $id |
120
|
|
|
* @return Commander |
121
|
|
|
*/ |
122
|
|
|
public function get($id) |
123
|
|
|
{ |
124
|
|
|
return $this->entityManager->getRepository(Commander::class)->get($id); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param integer $orbitalBaseId |
129
|
|
|
* @param array $statements |
130
|
|
|
* @return array |
131
|
|
|
*/ |
132
|
|
|
public function getBaseCommanders($orbitalBaseId, $statements = [], $orderBy = []) |
133
|
|
|
{ |
134
|
|
|
return $this->entityManager->getRepository(Commander::class)->getBaseCommanders($orbitalBaseId, $statements, $orderBy); |
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param int $playerId |
139
|
|
|
* @param array $statements |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
public function getPlayerCommanders($playerId, $statements = [], $orderBy = []) |
143
|
|
|
{ |
144
|
|
|
return $this->entityManager->getRepository(Commander::class)->getPlayerCommanders($playerId, $statements, $orderBy); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
|
|
public function getMovingCommanders() |
151
|
|
|
{ |
152
|
|
|
return $this->entityManager->getRepository(Commander::class)->getMovingCommanders(); |
|
|
|
|
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param array $ids |
157
|
|
|
* @return array |
158
|
|
|
*/ |
159
|
|
|
public function getCommandersByIds($ids) |
160
|
|
|
{ |
161
|
|
|
return $this->entityManager->getRepository(Commander::class)->getCommandersByIds($ids); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param int $orbitalBaseId |
166
|
|
|
* @param int $line |
167
|
|
|
* @return array |
168
|
|
|
*/ |
169
|
|
|
public function getCommandersByLine($orbitalBaseId, $line) |
170
|
|
|
{ |
171
|
|
|
return $this->entityManager->getRepository(Commander::class)->getCommandersByLine($orbitalBaseId, $line); |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param int $playerId |
176
|
|
|
* @return array |
177
|
|
|
*/ |
178
|
|
|
public function getIncomingAttacks($playerId) |
179
|
|
|
{ |
180
|
|
|
return $this->entityManager->getRepository(Commander::class)->getIncomingAttacks($playerId); |
|
|
|
|
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param int $playerId |
185
|
|
|
* @return array |
186
|
|
|
*/ |
187
|
|
|
public function getVisibleIncomingAttacks($playerId) |
188
|
|
|
{ |
189
|
|
|
$attackingCommanders = $this->getIncomingAttacks($playerId) ; |
190
|
|
|
$incomingCommanders = [] ; |
191
|
|
|
|
192
|
|
|
foreach ($attackingCommanders as $commander) { |
193
|
|
|
# va chercher les heures auxquelles il rentre dans les cercles d'espionnage |
194
|
|
|
$startPlace = $this->placeManager->get($commander->getRBase()); |
195
|
|
|
$destinationPlace = $this->placeManager->get($commander->getRPlaceDestination()); |
196
|
|
|
$times = Game::getAntiSpyEntryTime($startPlace, $destinationPlace, $commander->getArrivalDate()); |
197
|
|
|
|
198
|
|
|
if (strtotime(Utils::now()) >= strtotime($times[0])) { |
199
|
|
|
# ajout de l'événement |
200
|
|
|
$incomingCommanders[] = $commander; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
return $incomingCommanders; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param int $playerId |
208
|
|
|
* @return array |
209
|
|
|
*/ |
210
|
|
|
public function getOutcomingAttacks($playerId) |
211
|
|
|
{ |
212
|
|
|
return $this->entityManager->getRepository(Commander::class)->getOutcomingAttacks($playerId); |
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param array $place |
217
|
|
|
* @return array |
218
|
|
|
*/ |
219
|
|
|
public function getIncomingCommanders($place) |
220
|
|
|
{ |
221
|
|
|
return $this->entityManager->getRepository(Commander::class)->getIncomingCommanders($place); |
|
|
|
|
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function scheduleMovements() |
225
|
|
|
{ |
226
|
|
|
$commanders = $this->getMovingCommanders(); |
227
|
|
|
foreach ($commanders as $commander) { |
228
|
|
|
$this->realtimeActionScheduler->schedule( |
229
|
|
|
'ares.commander_manager', |
230
|
|
|
$this->actions[$commander->getTravelType()], |
231
|
|
|
$commander, |
232
|
|
|
$commander->dArrival, |
233
|
|
|
[ |
234
|
|
|
'class' => Place::class, |
235
|
|
|
'id' => $commander->getRPlaceDestination() |
236
|
|
|
] |
237
|
|
|
); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @param int $orbitalBaseId |
243
|
|
|
* @param int $line |
244
|
|
|
* @return int |
245
|
|
|
*/ |
246
|
|
|
public function countCommandersByLine($orbitalBaseId, $line) |
247
|
|
|
{ |
248
|
|
|
return $this->entityManager->getRepository(Commander::class)->countCommandersByLine($orbitalBaseId, $line); |
|
|
|
|
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
public function setEarnedExperience(Commander $commander, Commander $enemyCommander) { |
252
|
|
|
$commander->setArmy(); |
253
|
|
|
$finalOwnPev = 0; |
254
|
|
|
|
255
|
|
|
foreach ($commander->army as $squadron) { |
256
|
|
|
foreach ($squadron->getSquadron() as $ship) { |
257
|
|
|
$finalOwnPev += $ship->getPev(); |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
$importance = (($finalOwnPev + 1) * ($enemyCommander->getPevInBegin())) / |
261
|
|
|
((($commander->pevInBegin + 1) * (($enemyCommander->getLevel() + 1) / |
262
|
|
|
($commander->level + 1)))); |
263
|
|
|
|
264
|
|
|
$commander->earnedExperience = $importance * Commander::COEFFEARNEDEXP; |
|
|
|
|
265
|
|
|
if($commander->winner) { |
|
|
|
|
266
|
|
|
LiveReport::$importance = $importance; |
|
|
|
|
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
if ($commander->rPlayer > 0) { |
270
|
|
|
$exp = round($commander->earnedExperience / Commander::COEFFEXPPLAYER); |
271
|
|
|
$this->playerManager->increaseExperience($this->playerManager->get($commander->rPlayer), $exp); |
272
|
|
|
|
273
|
|
|
if ($enemyCommander->isAttacker == TRUE) { |
274
|
|
|
LiveReport::$expPlayerD = $exp; |
|
|
|
|
275
|
|
|
} else { |
276
|
|
|
LiveReport::$expPlayerA = $exp; |
|
|
|
|
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
public function setBonus(Commander $commander) { |
282
|
|
|
$commander->setArmy(); |
283
|
|
|
$playerBonus = new PlayerBonus($commander->rPlayer); |
|
|
|
|
284
|
|
|
$playerBonus->load(); |
|
|
|
|
285
|
|
|
|
286
|
|
|
foreach ($commander->army as $squadron) { |
287
|
|
|
foreach ($squadron->squadron as $ship) { |
288
|
|
|
$ship->setBonus($playerBonus->bonus); |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
public function upExperience(Commander $commander, $earnedExperience) { |
294
|
|
|
$commander->experience += $earnedExperience; |
295
|
|
|
$initialLevel = $commander->getLevel(); |
296
|
|
|
|
297
|
|
|
while ($commander->experience >= $this->experienceToLevelUp($commander)) { |
298
|
|
|
$commander->setLevel($commander->getLevel() + 1); |
299
|
|
|
} |
300
|
|
|
$this->entityManager->getRepository(Commander::class)->updateExperience( |
|
|
|
|
301
|
|
|
$commander, |
302
|
|
|
$earnedExperience, |
303
|
|
|
$commander->getLevel() - $initialLevel |
304
|
|
|
); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
public function nbLevelUp($level, $newExperience) { |
308
|
|
|
$oLevel = $level; |
309
|
|
|
$nLevel = $level; |
310
|
|
|
while (1) { |
311
|
|
|
if ($newExperience >= (pow(2, $nLevel) * $this->commanderBaseLevel)) { |
312
|
|
|
$nLevel++; |
313
|
|
|
} else { |
314
|
|
|
break; |
315
|
|
|
} |
316
|
|
|
} |
317
|
|
|
return $nLevel - $oLevel; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
public function experienceToLevelUp(Commander $commander) { |
321
|
|
|
return pow(2, $commander->level) * $this->commanderBaseLevel; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
public function emptySquadrons(Commander $commander) { |
325
|
|
|
if (($orbitalBase = $this->orbitalBaseManager->get($commander->rBase)) === null) { |
326
|
|
|
return; |
327
|
|
|
} |
328
|
|
|
$nbSquadrons = count($commander->squadronsIds); |
329
|
|
|
for ($i = 0; $i < $nbSquadrons; ++$i) { |
330
|
|
|
for ($j = 0; $j < 12; $j++) { |
331
|
|
|
$orbitalBase->setShipStorage($j, $orbitalBase->getShipStorage($j) + $commander->getSquadron($i)->getNbrShipByType($j)); |
332
|
|
|
} |
333
|
|
|
$commander->getSquadron($i)->emptySquadron(); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
public function uExperienceInSchool() |
338
|
|
|
{ |
339
|
|
|
$now = Utils::now(); |
340
|
|
|
$commanders = $this->entityManager->getRepository(Commander::class)->getAllByStatements([Commander::INSCHOOL]); |
|
|
|
|
341
|
|
|
$this->entityManager->beginTransaction(); |
342
|
|
|
|
343
|
|
|
foreach ($commanders as $commander) { |
344
|
|
|
// If the commander was updated recently, we skip him |
345
|
|
|
if (Utils::interval($commander->uCommander, $now, 'h') === 0) { |
346
|
|
|
continue; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
$nbrHours = Utils::intervalDates($now, $commander->uCommander); |
350
|
|
|
$commander->uCommander = $now; |
351
|
|
|
$orbitalBase = $this->orbitalBaseManager->get($commander->rBase); |
352
|
|
|
|
353
|
|
|
$playerBonus = $this->playerBonusManager->getBonusByPlayer($this->playerManager->get($commander->rPlayer)); |
354
|
|
|
$this->playerBonusManager->load($playerBonus); |
355
|
|
|
$playerBonus = $playerBonus->bonus; |
356
|
|
|
foreach ($nbrHours as $hour) { |
357
|
|
|
$invest = $orbitalBase->iSchool; |
358
|
|
|
$invest += $invest * $playerBonus->get(PlayerBonus::COMMANDER_INVEST) / 100; |
359
|
|
|
|
360
|
|
|
# xp gagnée |
361
|
|
|
$earnedExperience = $invest / Commander::COEFFSCHOOL; |
362
|
|
|
$earnedExperience += (rand(0, 1) == 1) |
363
|
|
|
? rand(0, $earnedExperience / 20) |
364
|
|
|
: -(rand(0, $earnedExperience / 20)); |
365
|
|
|
$earnedExperience = round($earnedExperience); |
366
|
|
|
$earnedExperience = ($earnedExperience < 0) |
367
|
|
|
? 0 : $earnedExperience; |
368
|
|
|
|
369
|
|
|
$this->upExperience($commander, $earnedExperience); |
370
|
|
|
} |
371
|
|
|
} |
372
|
|
|
$this->entityManager->commit(); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
public function move(Commander $commander, $rDestinationPlace, $rStartPlace, $travelType, $travelLength, $duration) { |
376
|
|
|
$commander->rDestinationPlace = $rDestinationPlace; |
377
|
|
|
$commander->rStartPlace = $rStartPlace; |
378
|
|
|
$commander->travelType = $travelType; |
379
|
|
|
$commander->travelLength = $travelLength; |
380
|
|
|
$commander->statement = Commander::MOVING; |
381
|
|
|
|
382
|
|
|
$commander->dStart = ($travelType != 3) ? Utils::now() : $commander->dArrival; |
383
|
|
|
$commander->destinationPlaceName = ($travelType != 3) ? $commander->destinationPlaceName : $commander->startPlaceName; |
384
|
|
|
$commander->startPlaceName = ($travelType != 3) ? $commander->oBName : $commander->destinationPlaceName; |
385
|
|
|
$date = new \DateTime($commander->dStart); |
386
|
|
|
$date->modify('+' . $duration . 'second'); |
387
|
|
|
$commander->dArrival = $date->format('Y-m-d H:i:s'); |
388
|
|
|
|
389
|
|
|
$this->realtimeActionScheduler->schedule( |
390
|
|
|
'ares.commander_manager', |
391
|
|
|
$this->actions[$travelType], |
392
|
|
|
$commander, |
|
|
|
|
393
|
|
|
$commander->dArrival, |
394
|
|
|
[ |
395
|
|
|
'class' => Place::class, |
396
|
|
|
'id' => $commander->getRPlaceDestination() |
397
|
|
|
] |
398
|
|
|
); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
public function resultOfFight(Commander $commander, $isWinner, $enemyCommander) { |
402
|
|
|
if ($isWinner == TRUE) { |
403
|
|
|
$this->setEarnedExperience($commander, $enemyCommander); |
404
|
|
|
$commander->earnedExperience = round($commander->earnedExperience); |
|
|
|
|
405
|
|
|
LiveReport::$expCom = $commander->earnedExperience; |
|
|
|
|
406
|
|
|
|
407
|
|
|
$commander->winner = TRUE; |
408
|
|
|
$commander->palmares++; |
409
|
|
|
$commander->setArmyAtEnd(); |
410
|
|
|
$this->upExperience($commander, $commander->earnedExperience); |
411
|
|
|
$commander->hasChanged = TRUE; |
|
|
|
|
412
|
|
|
} else { |
413
|
|
|
/** @TOVERIFY **/ |
414
|
|
|
$this->setEarnedExperience($commander, $commander, $enemyCommander); |
|
|
|
|
415
|
|
|
$commander->earnedExperience = round($commander->earnedExperience); |
416
|
|
|
|
417
|
|
|
$commander->winner = FALSE; |
418
|
|
|
$commander->setArmyAtEnd(); |
419
|
|
|
$this->upExperience($commander, $commander->earnedExperience); |
420
|
|
|
$commander->hasChanged = TRUE; |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
# ENGAGE UN COMBAT ENTRE CHAQUE SQUADRON CONTRE UN COMMANDANT |
425
|
|
|
public function engage(Commander $commander, $enemyCommander) { |
426
|
|
|
$commander->setArmy(); |
427
|
|
|
|
428
|
|
|
for ($i = 0; $i < count($commander->squadronsIds); $i++) { |
|
|
|
|
429
|
|
|
$commander->getSquadron($i)->relId = 0; |
430
|
|
|
} |
431
|
|
|
$idSquadron = 0; |
432
|
|
|
foreach ($commander->army as $squadron) { |
433
|
|
|
if ($squadron->getNbrShips() != 0 AND $squadron->getLineCoord() * 3 <= FightManager::getCurrentLine()) { |
|
|
|
|
434
|
|
|
$enemyCommander = $squadron->engage($enemyCommander, $idSquadron, $commander->id, $commander->name, $commander); |
435
|
|
|
} |
436
|
|
|
$idSquadron++; |
437
|
|
|
} |
438
|
|
|
return $enemyCommander; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
public function getPosition(Commander $commander, $x1, $y1, $x2, $y2) { |
442
|
|
|
$x = $x1; |
443
|
|
|
$y = $y1; |
444
|
|
|
if ($commander->statement == Commander::MOVING) { |
445
|
|
|
$parcouredTime = Utils::interval($commander->dStart, Utils::now(), 's'); |
446
|
|
|
$totalTime = Utils::interval($commander->dStart, $commander->dArrival, 's'); |
447
|
|
|
$progression = $parcouredTime / $totalTime; |
448
|
|
|
|
449
|
|
|
$x = $x1 + $progression * ($x2-$x1); |
450
|
|
|
$y = $y1 + $progression * ($y2-$y1); |
451
|
|
|
} |
452
|
|
|
return array($x, $y); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
public function getEventInfo(Commander $commander) { |
456
|
|
|
$info = new ArrayList(); |
457
|
|
|
$info->add('id', $commander->id); |
458
|
|
|
$info->add('name', $commander->name); |
459
|
|
|
$info->add('avatar', $commander->avatar); |
460
|
|
|
$info->add('level', $commander->level); |
461
|
|
|
|
462
|
|
|
$info->add('dStart', $commander->dStart); |
463
|
|
|
$info->add('rStart', $commander->rStartPlace); |
464
|
|
|
$info->add('nStart', $commander->startPlaceName); |
465
|
|
|
$info->add('dArrival', $commander->dArrival); |
466
|
|
|
$info->add('rArrival', $commander->rDestinationPlace); |
467
|
|
|
$info->add('nArrival', $commander->destinationPlaceName); |
468
|
|
|
|
469
|
|
|
$info->add('travelType', $commander->travelType); |
470
|
|
|
$info->add('resources', $commander->resources); |
471
|
|
|
|
472
|
|
|
return $info; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Fleet moving |
477
|
|
|
* |
478
|
|
|
* @param int $commanderId |
479
|
|
|
*/ |
480
|
|
|
public function uChangeBase($commanderId) { |
481
|
|
|
$commander = $this->get($commanderId); |
482
|
|
|
$place = $this->placeManager->get($commander->rDestinationPlace); |
483
|
|
|
$place->commanders = $this->getBaseCommanders($place->id); |
484
|
|
|
$commanderPlace = $this->placeManager->get($commander->rBase); |
485
|
|
|
$player = $this->playerManager->get($commander->rPlayer); |
486
|
|
|
$playerBonus = $this->playerBonusManager->getBonusByPlayer($player); |
487
|
|
|
$this->playerBonusManager->load($playerBonus); |
488
|
|
|
# si la place et la flotte ont la même couleur |
489
|
|
|
# on pose la flotte si il y a assez de place |
490
|
|
|
# sinon on met la flotte dans les hangars |
491
|
|
|
if ($place->playerColor !== $commander->playerColor or $place->typeOfBase !== Place::TYP_ORBITALBASE) { |
492
|
|
|
# retour forcé |
493
|
|
|
$this->comeBack($place, $commander, $commanderPlace, $playerBonus); |
494
|
|
|
$this->placeManager->sendNotif($place, Place::CHANGELOST, $commander); |
495
|
|
|
$this->entityManager->flush(); |
496
|
|
|
return; |
497
|
|
|
} |
498
|
|
|
$maxCom = |
499
|
|
|
($place->typeOfOrbitalBase == OrbitalBase::TYP_MILITARY || $place->typeOfOrbitalBase == OrbitalBase::TYP_CAPITAL) |
500
|
|
|
? OrbitalBase::MAXCOMMANDERMILITARY |
501
|
|
|
: OrbitalBase::MAXCOMMANDERSTANDARD |
502
|
|
|
; |
503
|
|
|
|
504
|
|
|
# si place a assez de case libre : |
505
|
|
|
if (count($place->commanders) < $maxCom) { |
506
|
|
|
$comLine2 = 0; |
507
|
|
|
|
508
|
|
|
foreach ($place->commanders as $com) { |
509
|
|
|
if ($com->line == 2) { |
510
|
|
|
$comLine2++; |
511
|
|
|
} |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
if ($maxCom == OrbitalBase::MAXCOMMANDERMILITARY) { |
515
|
|
|
if ($comLine2 < 2) { |
516
|
|
|
$commander->line = 2; |
517
|
|
|
} else { |
518
|
|
|
$commander->line = 1; |
519
|
|
|
} |
520
|
|
|
} else { |
521
|
|
|
if ($comLine2 < 1) { |
522
|
|
|
$commander->line = 2; |
523
|
|
|
} else { |
524
|
|
|
$commander->line = 1; |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
# changer rBase commander |
529
|
|
|
$commander->rBase = $place->id; |
530
|
|
|
$this->endTravel($commander, Commander::AFFECTED); |
531
|
|
|
|
532
|
|
|
# ajouter à la place le commandant |
533
|
|
|
$place->commanders[] = $commander; |
534
|
|
|
|
535
|
|
|
# envoi de notif |
536
|
|
|
$this->placeManager->sendNotif($place, Place::CHANGESUCCESS, $commander); |
537
|
|
|
} else { |
538
|
|
|
# changer rBase commander |
539
|
|
|
$commander->rBase = $place->id; |
540
|
|
|
$this->endTravel($commander, Commander::RESERVE); |
541
|
|
|
|
542
|
|
|
$this->emptySquadrons($commander); |
543
|
|
|
|
544
|
|
|
# envoi de notif |
545
|
|
|
$this->placeManager->sendNotif($place, Place::CHANGEFAIL, $commander); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
# modifier le rPlayer (ne se modifie pas si c'est le même) |
549
|
|
|
$commander->rPlayer = $place->rPlayer; |
550
|
|
|
|
551
|
|
|
# instance de la place d'envoie + suppr commandant de ses flottes |
552
|
|
|
# enlever à rBase le commandant |
553
|
|
|
for ($i = 0; $i < count($commanderPlace->commanders); $i++) { |
|
|
|
|
554
|
|
|
if ($commanderPlace->commanders[$i]->id == $commander->id) { |
555
|
|
|
unset($commanderPlace->commanders[$i]); |
556
|
|
|
$commanderPlace->commanders = array_merge($commanderPlace->commanders); |
557
|
|
|
} |
558
|
|
|
} |
559
|
|
|
$this->entityManager->flush(); |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
# pillage |
563
|
|
|
public function uLoot($commanderId) { |
564
|
|
|
$commander = $this->get($commanderId); |
565
|
|
|
$place = $this->placeManager->get($commander->rDestinationPlace); |
566
|
|
|
$place->commanders = $this->getBaseCommanders($place->id); |
567
|
|
|
$placePlayer = $this->playerManager->get($place->rPlayer); |
568
|
|
|
$placeBase = $this->orbitalBaseManager->get($place->id); |
569
|
|
|
$commanderPlace = $this->placeManager->get($commander->rBase); |
570
|
|
|
$commanderPlayer = $this->playerManager->get($commander->rPlayer); |
571
|
|
|
$commanderColor = $this->colorManager->get($commanderPlayer->rColor); |
572
|
|
|
$playerBonus = $this->playerBonusManager->getBonusByPlayer($commanderPlayer); |
573
|
|
|
$this->playerBonusManager->load($playerBonus); |
574
|
|
|
LiveReport::$type = Commander::LOOT; |
575
|
|
|
LiveReport::$dFight = $commander->dArrival; |
576
|
|
|
|
577
|
|
|
# si la planète est vide |
578
|
|
|
if ($place->rPlayer == NULL) { |
579
|
|
|
LiveReport::$isLegal = Report::LEGAL; |
580
|
|
|
|
581
|
|
|
# planète vide : faire un combat |
582
|
|
|
$this->startFight($place, $commander, $commanderPlayer); |
583
|
|
|
|
584
|
|
|
# victoire |
585
|
|
|
if ($commander->getStatement() != Commander::DEAD) { |
586
|
|
|
# piller la planète |
587
|
|
|
$this->lootAnEmptyPlace($place, $commander, $playerBonus); |
588
|
|
|
# création du rapport de combat |
589
|
|
|
$report = $this->createReport($place); |
590
|
|
|
|
591
|
|
|
# réduction de la force de la planète |
592
|
|
|
$percentage = (($report->pevAtEndD + 1) / ($report->pevInBeginD + 1)) * 100; |
593
|
|
|
$place->danger = round(($percentage * $place->danger) / 100); |
|
|
|
|
594
|
|
|
|
595
|
|
|
$this->comeBack($place, $commander, $commanderPlace, $playerBonus); |
596
|
|
|
$this->placeManager->sendNotif($place, Place::LOOTEMPTYSSUCCESS, $commander, $report->id); |
|
|
|
|
597
|
|
|
} else { |
598
|
|
|
# si il est mort |
599
|
|
|
# enlever le commandant de la session |
600
|
|
|
for ($i = 0; $i < count($commanderPlace->commanders); $i++) { |
|
|
|
|
601
|
|
|
if ($commanderPlace->commanders[$i]->getId() == $commander->getId()) { |
602
|
|
|
unset($commanderPlace->commanders[$i]); |
603
|
|
|
$commanderPlace->commanders = array_merge($commanderPlace->commanders); |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
# création du rapport de combat |
608
|
|
|
$report = $this->createReport($place); |
609
|
|
|
$this->placeManager->sendNotif($place, Place::LOOTEMPTYFAIL, $commander, $report->id); |
|
|
|
|
610
|
|
|
|
611
|
|
|
# réduction de la force de la planète |
612
|
|
|
$percentage = (($report->pevAtEndD + 1) / ($report->pevInBeginD + 1)) * 100; |
613
|
|
|
$place->danger = round(($percentage * $place->danger) / 100); |
614
|
|
|
} |
615
|
|
|
# si il y a une base d'un joueur |
616
|
|
|
} else { |
617
|
|
|
if ($commanderColor->colorLink[$place->playerColor] == Color::ALLY || $commanderColor->colorLink[$place->playerColor] == Color::PEACE) { |
618
|
|
|
LiveReport::$isLegal = Report::ILLEGAL; |
619
|
|
|
} else { |
620
|
|
|
LiveReport::$isLegal = Report::LEGAL; |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
# planète à joueur : si $this->rColor != commandant->rColor |
624
|
|
|
# si il peut l'attaquer |
625
|
|
|
if (($place->playerColor != $commander->getPlayerColor() && $place->playerLevel > 1 && $commanderColor->colorLink[$place->playerColor] != Color::ALLY) || ($place->playerColor == 0)) { |
626
|
|
|
$dCommanders = array(); |
627
|
|
|
foreach ($place->commanders as $dCommander) { |
628
|
|
|
if ($dCommander->statement == Commander::AFFECTED && $dCommander->line == 1) { |
629
|
|
|
$dCommanders[] = $dCommander; |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
# il y a des commandants en défense : faire un combat avec un des commandants |
634
|
|
|
if (count($dCommanders) != 0) { |
635
|
|
|
$aleaNbr = rand(0, count($dCommanders) - 1); |
636
|
|
|
$this->startFight($place, $commander, $commanderPlayer, $dCommanders[$aleaNbr], $placePlayer, TRUE); |
637
|
|
|
|
638
|
|
|
# victoire |
639
|
|
|
if ($commander->getStatement() != Commander::DEAD) { |
640
|
|
|
# piller la planète |
641
|
|
|
$this->lootAPlayerPlace($commander, $playerBonus, $placeBase); |
642
|
|
|
$this->comeBack($place, $commander, $commanderPlace, $playerBonus); |
643
|
|
|
|
644
|
|
|
# suppression des commandants |
645
|
|
|
unset($place->commanders[$aleaNbr]); |
646
|
|
|
$place->commanders = array_merge($place->commanders); |
647
|
|
|
|
648
|
|
|
# création du rapport |
649
|
|
|
$report = $this->createReport($place); |
650
|
|
|
|
651
|
|
|
$this->placeManager->sendNotif($place, Place::LOOTPLAYERWHITBATTLESUCCESS, $commander, $report->id); |
|
|
|
|
652
|
|
|
|
653
|
|
|
# défaite |
654
|
|
|
} else { |
655
|
|
|
# enlever le commandant de la session |
656
|
|
|
for ($i = 0; $i < count($commanderPlace->commanders); $i++) { |
|
|
|
|
657
|
|
|
if ($commanderPlace->commanders[$i]->getId() == $commander->getId()) { |
658
|
|
|
unset($commanderPlace->commanders[$i]); |
659
|
|
|
$commanderPlace->commanders = array_merge($commanderPlace->commanders); |
660
|
|
|
} |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
# création du rapport |
664
|
|
|
$report = $this->createReport($place); |
665
|
|
|
|
666
|
|
|
# mise à jour des flottes du commandant défenseur |
667
|
|
|
for ($j = 0; $j < count($dCommanders[$aleaNbr]->armyAtEnd); $j++) { |
|
|
|
|
668
|
|
|
for ($i = 0; $i < 12; $i++) { |
669
|
|
|
$dCommanders[$aleaNbr]->armyInBegin[$j][$i] = $dCommanders[$aleaNbr]->armyAtEnd[$j][$i]; |
670
|
|
|
} |
671
|
|
|
} |
672
|
|
|
|
673
|
|
|
$this->placeManager->sendNotif($place, Place::LOOTPLAYERWHITBATTLEFAIL, $commander, $report->id); |
|
|
|
|
674
|
|
|
} |
675
|
|
|
} else { |
676
|
|
|
$this->lootAPlayerPlace($commander, $playerBonus, $placeBase); |
677
|
|
|
$this->comeBack($place, $commander, $commanderPlace, $playerBonus); |
678
|
|
|
$this->placeManager->sendNotif($place, Place::LOOTPLAYERWHITOUTBATTLESUCCESS, $commander); |
679
|
|
|
} |
680
|
|
|
|
|
|
|
|
681
|
|
|
} else { |
682
|
|
|
# si c'est la même couleur |
683
|
|
|
if ($place->rPlayer == $commander->rPlayer) { |
684
|
|
|
# si c'est une de nos planètes |
685
|
|
|
# on tente de se poser |
686
|
|
|
$this->uChangeBase($commander->id); |
687
|
|
|
} else { |
688
|
|
|
# si c'est une base alliée |
689
|
|
|
# on repart |
690
|
|
|
$this->comeBack($place, $commander, $commanderPlace, $playerBonus); |
691
|
|
|
$this->placeManager->sendNotif($place, Place::CHANGELOST, $commander); |
692
|
|
|
} |
693
|
|
|
} |
694
|
|
|
} |
695
|
|
|
$this->entityManager->flush(); |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
# conquest |
699
|
|
|
public function uConquer($commanderId) { |
700
|
|
|
$commander = $this->get($commanderId); |
701
|
|
|
$place = $this->placeManager->get($commander->rDestinationPlace); |
702
|
|
|
$place->commanders = $this->getBaseCommanders($place->id); |
703
|
|
|
$placePlayer = $this->playerManager->get($place->rPlayer); |
704
|
|
|
$placeBase = $this->orbitalBaseManager->get($place->id); |
705
|
|
|
$commanderPlace = $this->placeManager->get($commander->rBase); |
706
|
|
|
$commanderPlayer = $this->playerManager->get($commander->rPlayer); |
707
|
|
|
$commanderColor = $this->colorManager->get($commanderPlayer->rColor); |
708
|
|
|
$baseCommanders = $this->getBaseCommanders($place->getId()); |
709
|
|
|
$playerBonus = $this->playerBonusManager->getBonusByPlayer($commanderPlayer); |
710
|
|
|
$this->playerBonusManager->load($playerBonus); |
711
|
|
|
# conquete |
712
|
|
|
if ($place->rPlayer != NULL) { |
713
|
|
|
if (($place->playerColor != $commander->getPlayerColor() && $place->playerLevel > 3 && $commanderColor->colorLink[$place->playerColor] != Color::ALLY) || ($place->playerColor == 0)) { |
714
|
|
|
$tempCom = array(); |
715
|
|
|
|
716
|
|
|
for ($i = 0; $i < count($place->commanders); $i++) { |
|
|
|
|
717
|
|
|
if ($place->commanders[$i]->line <= 1) { |
718
|
|
|
$tempCom[] = $place->commanders[$i]; |
719
|
|
|
} |
720
|
|
|
} |
721
|
|
|
for ($i = 0; $i < count($place->commanders); $i++) { |
|
|
|
|
722
|
|
|
if ($place->commanders[$i]->line >= 2) { |
723
|
|
|
$tempCom[] = $place->commanders[$i]; |
724
|
|
|
} |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
$place->commanders = $tempCom; |
728
|
|
|
|
729
|
|
|
$nbrBattle = 0; |
730
|
|
|
$reportIds = array(); |
731
|
|
|
$reportArray = array(); |
732
|
|
|
|
733
|
|
|
while ($nbrBattle < count($place->commanders)) { |
734
|
|
|
if ($place->commanders[$nbrBattle]->statement == Commander::AFFECTED) { |
735
|
|
|
LiveReport::$type = Commander::COLO; |
736
|
|
|
LiveReport::$dFight = $commander->dArrival; |
737
|
|
|
|
738
|
|
|
if ($commanderColor->colorLink[$place->playerColor] == Color::ALLY || $commanderColor->colorLink[$place->playerColor] == Color::PEACE) { |
739
|
|
|
LiveReport::$isLegal = Report::ILLEGAL; |
740
|
|
|
} else { |
741
|
|
|
LiveReport::$isLegal = Report::LEGAL; |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
$this->startFight($place, $commander, $commanderPlayer, $place->commanders[$nbrBattle], $placePlayer, TRUE); |
745
|
|
|
|
746
|
|
|
$report = $this->createReport($place); |
747
|
|
|
$reportArray[] = $report; |
748
|
|
|
$reportIds[] = $report->id; |
749
|
|
|
# PATCH DEGUEU POUR LES MUTLIS-COMBATS |
750
|
|
|
$this->entityManager->clear($report); |
751
|
|
|
$reports = $this->reportManager->getByAttackerAndPlace($commander->rPlayer, $place->id, $commander->dArrival); |
752
|
|
|
foreach($reports as $r) { |
|
|
|
|
753
|
|
|
if ($r->id == $report->id) { |
754
|
|
|
continue; |
755
|
|
|
} |
756
|
|
|
$r->statementAttacker = Report::DELETED; |
757
|
|
|
$r->statementDefender = Report::DELETED; |
758
|
|
|
} |
759
|
|
|
$this->entityManager->flush(Report::class); |
760
|
|
|
$this->entityManager->clear(Report::class); |
761
|
|
|
######################################## |
762
|
|
|
|
763
|
|
|
# mettre à jour armyInBegin si prochain combat pour prochain rapport |
764
|
|
|
for ($j = 0; $j < count($commander->armyAtEnd); $j++) { |
|
|
|
|
765
|
|
|
for ($i = 0; $i < 12; $i++) { |
766
|
|
|
$commander->armyInBegin[$j][$i] = $commander->armyAtEnd[$j][$i]; |
767
|
|
|
} |
768
|
|
|
} |
769
|
|
|
for ($j = 0; $j < count($place->commanders[$nbrBattle]->armyAtEnd); $j++) { |
|
|
|
|
770
|
|
|
for ($i = 0; $i < 12; $i++) { |
771
|
|
|
$place->commanders[$nbrBattle]->armyInBegin[$j][$i] = $place->commanders[$nbrBattle]->armyAtEnd[$j][$i]; |
772
|
|
|
} |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
$nbrBattle++; |
776
|
|
|
# mort du commandant |
777
|
|
|
# arrêt des combats |
778
|
|
|
if ($commander->getStatement() == Commander::DEAD) { |
779
|
|
|
break; |
780
|
|
|
} |
781
|
|
|
} else { |
782
|
|
|
$nbrBattle++; |
783
|
|
|
} |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
# victoire |
787
|
|
|
if ($commander->getStatement() != Commander::DEAD) { |
788
|
|
|
if ($nbrBattle == 0) { |
789
|
|
|
$this->placeManager->sendNotif($place, Place::CONQUERPLAYERWHITOUTBATTLESUCCESS, $commander, NULL); |
790
|
|
|
} else { |
791
|
|
|
$this->placeManager->sendNotifForConquest($place, Place::CONQUERPLAYERWHITBATTLESUCCESS, $commander, $reportIds); |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
|
795
|
|
|
#attribuer le joueur à la place |
796
|
|
|
$place->commanders = array(); |
797
|
|
|
$place->playerColor = $commander->playerColor; |
798
|
|
|
$place->rPlayer = $commander->rPlayer; |
799
|
|
|
|
800
|
|
|
# changer l'appartenance de la base (et de la place) |
801
|
|
|
$this->orbitalBaseManager->changeOwnerById($place->id, $placeBase, $commander->getRPlayer(), $baseCommanders); |
802
|
|
|
$place->commanders[] = $commander; |
803
|
|
|
|
804
|
|
|
$commander->rBase = $place->id; |
805
|
|
|
$this->endTravel($commander, Commander::AFFECTED); |
806
|
|
|
$commander->line = 2; |
807
|
|
|
|
808
|
|
|
$this->eventDispatcher->dispatch(new PlaceOwnerChangeEvent($place)); |
809
|
|
|
|
810
|
|
|
# PATCH DEGUEU POUR LES MUTLIS-COMBATS |
811
|
|
|
$this->notificationManager->patchForMultiCombats($commander->rPlayer, $place->rPlayer, $commander->dArrival); |
812
|
|
|
# défaite |
813
|
|
|
} else { |
814
|
|
|
for ($i = 0; $i < count($place->commanders); $i++) { |
|
|
|
|
815
|
|
|
if ($place->commanders[$i]->statement == Commander::DEAD) { |
816
|
|
|
unset($place->commanders[$i]); |
817
|
|
|
$place->commanders = array_merge($place->commanders); |
818
|
|
|
} |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
$this->placeManager->sendNotifForConquest($place, Place::CONQUERPLAYERWHITBATTLEFAIL, $commander, $reportIds); |
822
|
|
|
} |
823
|
|
|
|
|
|
|
|
824
|
|
|
} else { |
825
|
|
|
# si c'est la même couleur |
826
|
|
|
if ($place->rPlayer == $commander->rPlayer) { |
827
|
|
|
# si c'est une de nos planètes |
828
|
|
|
# on tente de se poser |
829
|
|
|
$this->uChangeBase($commander->id); |
830
|
|
|
} else { |
831
|
|
|
# si c'est une base alliée |
832
|
|
|
# on repart |
833
|
|
|
$this->comeBack($place, $commander, $commanderPlace, $playerBonus); |
834
|
|
|
$this->placeManager->sendNotif($place, Place::CHANGELOST, $commander); |
835
|
|
|
} |
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
# colonisation |
839
|
|
|
} else { |
840
|
|
|
# faire un combat |
841
|
|
|
LiveReport::$type = Commander::COLO; |
842
|
|
|
LiveReport::$dFight = $commander->dArrival; |
843
|
|
|
LiveReport::$isLegal = Report::LEGAL; |
844
|
|
|
|
845
|
|
|
$this->startFight($place, $commander, $commanderPlayer); |
846
|
|
|
|
847
|
|
|
# victoire |
848
|
|
|
if ($commander->getStatement() !== Commander::DEAD) { |
849
|
|
|
# attribuer le rPlayer à la Place ! |
850
|
|
|
$place->rPlayer = $commander->rPlayer; |
851
|
|
|
$place->commanders[] = $commander; |
852
|
|
|
$place->playerColor = $commander->playerColor; |
853
|
|
|
$place->typeOfBase = 4; |
854
|
|
|
|
855
|
|
|
# créer une base |
856
|
|
|
$ob = new OrbitalBase(); |
857
|
|
|
$ob->rPlace = $place->id; |
858
|
|
|
$ob->setRPlayer($commander->getRPlayer()); |
859
|
|
|
$ob->setName('colonie'); |
860
|
|
|
$ob->iSchool = 500; |
861
|
|
|
$ob->iAntiSpy = 500; |
862
|
|
|
$ob->resourcesStorage = 2000; |
863
|
|
|
$ob->uOrbitalBase = Utils::now(); |
864
|
|
|
$ob->dCreation = Utils::now(); |
865
|
|
|
$this->orbitalBaseManager->updatePoints($ob); |
866
|
|
|
|
867
|
|
|
$this->orbitalBaseManager->add($ob); |
868
|
|
|
|
869
|
|
|
# attibuer le commander à la place |
870
|
|
|
$commander->rBase = $place->id; |
871
|
|
|
$this->endTravel($commander, Commander::AFFECTED); |
872
|
|
|
$commander->line = 2; |
873
|
|
|
|
874
|
|
|
# création du rapport |
875
|
|
|
$report = $this->createReport($place); |
876
|
|
|
|
877
|
|
|
$place->danger = 0; |
878
|
|
|
|
879
|
|
|
$this->placeManager->sendNotif($place, Place::CONQUEREMPTYSSUCCESS, $commander, $report->id); |
880
|
|
|
|
881
|
|
|
$this->eventDispatcher->dispatch(new PlaceOwnerChangeEvent($place)); |
882
|
|
|
|
883
|
|
|
# défaite |
884
|
|
|
} else { |
885
|
|
|
# création du rapport |
886
|
|
|
$report = $this->createReport($place); |
887
|
|
|
|
888
|
|
|
# mise à jour du danger |
889
|
|
|
$percentage = (($report->pevAtEndD + 1) / ($report->pevInBeginD + 1)) * 100; |
890
|
|
|
$place->danger = round(($percentage * $place->danger) / 100); |
|
|
|
|
891
|
|
|
|
892
|
|
|
$this->placeManager->sendNotif($place, Place::CONQUEREMPTYFAIL, $commander); |
893
|
|
|
|
894
|
|
|
# enlever le commandant de la place |
895
|
|
|
foreach ($commanderPlace->commanders as $placeCommander) { |
896
|
|
|
if ($placeCommander->getId() == $commander->getId()) { |
897
|
|
|
unset($placeCommander); |
898
|
|
|
$commanderPlace->commanders = array_merge($commanderPlace->commanders); |
899
|
|
|
} |
900
|
|
|
} |
901
|
|
|
} |
902
|
|
|
} |
903
|
|
|
$this->entityManager->flush(Commander::class); |
904
|
|
|
$this->entityManager->flush($place); |
905
|
|
|
} |
906
|
|
|
|
907
|
|
|
/** |
908
|
|
|
* @param int $commanderId |
909
|
|
|
*/ |
910
|
|
|
public function uReturnBase($commanderId) { |
911
|
|
|
$commander = $this->get($commanderId); |
912
|
|
|
$place = $this->placeManager->get($commander->rDestinationPlace); |
913
|
|
|
$commanderBase = $this->orbitalBaseManager->get($commander->rBase); |
914
|
|
|
|
915
|
|
|
$this->endTravel($commander, Commander::AFFECTED); |
916
|
|
|
|
917
|
|
|
$this->placeManager->sendNotif($place, Place::COMEBACK, $commander); |
918
|
|
|
|
919
|
|
|
if ($commander->resources > 0) { |
920
|
|
|
$this->orbitalBaseManager->increaseResources($commanderBase, $commander->resources, TRUE); |
921
|
|
|
$commander->resources = 0; |
922
|
|
|
} |
923
|
|
|
$this->entityManager->flush($commander); |
924
|
|
|
} |
925
|
|
|
|
926
|
|
|
/** |
927
|
|
|
* @param Commander $commander |
928
|
|
|
* @param string $statement |
929
|
|
|
*/ |
930
|
|
|
public function endTravel(Commander $commander, $statement) |
931
|
|
|
{ |
932
|
|
|
$commander->travelType = null; |
933
|
|
|
$commander->travelLength = null; |
934
|
|
|
$commander->dStart = null; |
935
|
|
|
$commander->dArrival = null; |
936
|
|
|
$commander->rStartPlace = null; |
937
|
|
|
$commander->rDestinationPlace = null; |
938
|
|
|
$commander->statement = $statement; |
939
|
|
|
} |
940
|
|
|
|
941
|
|
|
# HELPER |
942
|
|
|
|
943
|
|
|
# comeBack |
944
|
|
|
public function comeBack(Place $place, $commander, $commanderPlace, $playerBonus) { |
945
|
|
|
$length = Game::getDistance($place->getXSystem(), $commanderPlace->getXSystem(), $place->getYSystem(), $commanderPlace->getYSystem()); |
946
|
|
|
$duration = Game::getTimeToTravel($commanderPlace, $place, $playerBonus->bonus); |
947
|
|
|
|
948
|
|
|
$this->move($commander, $commander->rBase, $place->id, Commander::BACK, $length, $duration); |
949
|
|
|
} |
950
|
|
|
|
951
|
|
|
private function lootAnEmptyPlace(Place $place, $commander, $playerBonus) { |
952
|
|
|
$bonus = $playerBonus->bonus->get(PlayerBonus::SHIP_CONTAINER); |
953
|
|
|
|
954
|
|
|
$storage = $commander->getPevToLoot() * Commander::COEFFLOOT; |
955
|
|
|
$storage += round($storage * ((2 * $bonus) / 100)); |
956
|
|
|
|
957
|
|
|
$resourcesLooted = 0; |
|
|
|
|
958
|
|
|
$resourcesLooted = ($storage > $place->resources) ? $place->resources : $storage; |
959
|
|
|
|
960
|
|
|
$place->resources -= $resourcesLooted; |
961
|
|
|
$commander->resources = $resourcesLooted; |
962
|
|
|
|
963
|
|
|
LiveReport::$resources = $resourcesLooted; |
|
|
|
|
964
|
|
|
} |
965
|
|
|
|
966
|
|
|
private function lootAPlayerPlace($commander, $playerBonus, $placeBase) { |
967
|
|
|
$bonus = $playerBonus->bonus->get(PlayerBonus::SHIP_CONTAINER); |
968
|
|
|
|
969
|
|
|
$resourcesToLoot = $placeBase->getResourcesStorage() - Commander::LIMITTOLOOT; |
970
|
|
|
|
971
|
|
|
$storage = $commander->getPevToLoot() * Commander::COEFFLOOT; |
972
|
|
|
$storage += round($storage * ((2 * $bonus) / 100)); |
973
|
|
|
|
974
|
|
|
$resourcesLooted = 0; |
|
|
|
|
975
|
|
|
$resourcesLooted = ($storage > $resourcesToLoot) ? $resourcesToLoot : $storage; |
976
|
|
|
|
977
|
|
|
if ($resourcesLooted > 0) { |
978
|
|
|
$this->orbitalBaseManager->decreaseResources($placeBase, $resourcesLooted); |
979
|
|
|
$commander->resources = $resourcesLooted; |
980
|
|
|
|
981
|
|
|
LiveReport::$resources = $resourcesLooted; |
|
|
|
|
982
|
|
|
} |
983
|
|
|
} |
984
|
|
|
|
985
|
|
|
private function startFight(Place $place, $commander, $player, $enemyCommander = NULL, $enemyPlayer = NULL, $pvp = FALSE) { |
986
|
|
|
if ($pvp == TRUE) { |
|
|
|
|
987
|
|
|
$commander->setArmy(); |
988
|
|
|
$enemyCommander->setArmy(); |
989
|
|
|
|
990
|
|
|
$this->fightManager->startFight($commander, $player, $enemyCommander, $enemyPlayer); |
991
|
|
|
} else { |
992
|
|
|
$commander->setArmy(); |
993
|
|
|
$computerCommander = $this->createVirtualCommander($place); |
994
|
|
|
|
995
|
|
|
$this->fightManager->startFight($commander, $player, $computerCommander); |
996
|
|
|
} |
997
|
|
|
} |
998
|
|
|
|
999
|
|
|
private function createReport(Place $place) { |
1000
|
|
|
$report = new Report(); |
1001
|
|
|
|
1002
|
|
|
$report->rPlayerAttacker = LiveReport::$rPlayerAttacker; |
1003
|
|
|
$report->rPlayerDefender = LiveReport::$rPlayerDefender; |
1004
|
|
|
$report->rPlayerWinner = LiveReport::$rPlayerWinner; |
1005
|
|
|
$report->avatarA = LiveReport::$avatarA; |
1006
|
|
|
$report->avatarD = LiveReport::$avatarD; |
1007
|
|
|
$report->nameA = LiveReport::$nameA; |
1008
|
|
|
$report->nameD = LiveReport::$nameD; |
1009
|
|
|
$report->levelA = LiveReport::$levelA; |
1010
|
|
|
$report->levelD = LiveReport::$levelD; |
1011
|
|
|
$report->experienceA = LiveReport::$experienceA; |
1012
|
|
|
$report->experienceD = LiveReport::$experienceD; |
1013
|
|
|
$report->palmaresA = LiveReport::$palmaresA; |
1014
|
|
|
$report->palmaresD = LiveReport::$palmaresD; |
1015
|
|
|
$report->resources = LiveReport::$resources; |
1016
|
|
|
$report->expCom = LiveReport::$expCom; |
1017
|
|
|
$report->expPlayerA = LiveReport::$expPlayerA; |
1018
|
|
|
$report->expPlayerD = LiveReport::$expPlayerD; |
1019
|
|
|
$report->rPlace = $place->id; |
1020
|
|
|
$report->type = LiveReport::$type; |
1021
|
|
|
$report->round = LiveReport::$round; |
1022
|
|
|
$report->importance = LiveReport::$importance; |
1023
|
|
|
$report->squadrons = LiveReport::$squadrons; |
1024
|
|
|
$report->dFight = LiveReport::$dFight; |
1025
|
|
|
$report->isLegal = LiveReport::$isLegal; |
1026
|
|
|
$report->placeName = ($place->baseName == '') ? 'planète rebelle' : $place->baseName; |
1027
|
|
|
$report->setArmies(); |
1028
|
|
|
$report->setPev(); |
1029
|
|
|
|
1030
|
|
|
$this->reportManager->add($report); |
1031
|
|
|
LiveReport::clear(); |
1032
|
|
|
|
1033
|
|
|
return $report; |
1034
|
|
|
} |
1035
|
|
|
|
1036
|
|
|
/** |
1037
|
|
|
* @param Place $place |
1038
|
|
|
* @return Commander |
1039
|
|
|
*/ |
1040
|
|
|
public function createVirtualCommander(Place $place) { |
1041
|
|
|
$vCommander = new Commander(); |
1042
|
|
|
$vCommander->id = 'Null'; |
|
|
|
|
1043
|
|
|
$vCommander->rPlayer = ID_GAIA; |
1044
|
|
|
$vCommander->name = 'rebelle'; |
1045
|
|
|
$vCommander->avatar = 't3-c4'; |
1046
|
|
|
$vCommander->sexe = 1; |
1047
|
|
|
$vCommander->age = 42; |
1048
|
|
|
$vCommander->statement = 1; |
1049
|
|
|
$vCommander->level = ceil((((($place->maxDanger / (Place::DANGERMAX / Place::LEVELMAXVCOMMANDER))) * 9) + ($place->population / (Place::POPMAX / Place::LEVELMAXVCOMMANDER))) / 10); |
|
|
|
|
1050
|
|
|
|
1051
|
|
|
$nbrsquadron = ceil($vCommander->level * (($place->danger + 1) / ($place->maxDanger + 1))); |
1052
|
|
|
|
1053
|
|
|
$army = array(); |
1054
|
|
|
$squadronsIds = array(); |
1055
|
|
|
|
1056
|
|
|
for ($i = 0; $i < $nbrsquadron; $i++) { |
1057
|
|
|
$aleaNbr = ($place->coefHistory * $place->coefResources * $place->position * $i) % SquadronResource::size(); |
1058
|
|
|
$army[] = SquadronResource::get($vCommander->level, $aleaNbr); |
1059
|
|
|
$squadronsIds[] = 0; |
1060
|
|
|
} |
1061
|
|
|
|
1062
|
|
|
for ($i = $vCommander->level - 1; $i >= $nbrsquadron; $i--) { |
1063
|
|
|
$army[$i] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Utils::now()); |
1064
|
|
|
$squadronsIds[] = 0; |
1065
|
|
|
} |
1066
|
|
|
|
1067
|
|
|
$vCommander->setSquadronsIds($squadronsIds); |
1068
|
|
|
$vCommander->setArmyInBegin($army); |
1069
|
|
|
$vCommander->setArmy(); |
1070
|
|
|
$vCommander->setPevInBegin(); |
1071
|
|
|
|
1072
|
|
|
return $vCommander; |
1073
|
|
|
} |
1074
|
|
|
} |
1075
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: