|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Fight Controller |
|
5
|
|
|
* |
|
6
|
|
|
* @author Noé Zufferey |
|
7
|
|
|
* @copyright Expansion - le jeu |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arès |
|
10
|
|
|
* @update 14.02.14 |
|
11
|
|
|
*/ |
|
12
|
|
|
namespace Asylamba\Modules\Ares\Manager; |
|
13
|
|
|
|
|
14
|
|
|
use Asylamba\Classes\Library\DataAnalysis; |
|
15
|
|
|
use Asylamba\Classes\Library\Utils; |
|
16
|
|
|
use Asylamba\Modules\Ares\Model\LiveReport; |
|
17
|
|
|
use Asylamba\Modules\Athena\Resource\ShipResource; |
|
18
|
|
|
|
|
19
|
|
|
class FightManager { |
|
20
|
|
|
/** @var CommanderManager **/ |
|
21
|
|
|
protected $commanderManager; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param \Asylamba\Modules\Ares\Manager\CommanderManager $commanderManager |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(CommanderManager $commanderManager) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->commanderManager = $commanderManager; |
|
29
|
|
|
self::$currentLine = 3; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
private $isAFight = FALSE; |
|
33
|
|
|
|
|
34
|
|
|
# ATTRIBUT STATIC DE LIGNE COURANTE |
|
35
|
|
|
|
|
36
|
|
|
private static $currentLine = 0; |
|
37
|
|
|
|
|
38
|
|
|
private static $AFighterBonus = array(1, 1, 1, 1); |
|
39
|
|
|
private static $ACorvetteBonus = array(1, 1, 1, 1); |
|
40
|
|
|
private static $AFrigateBonus = array(1, 1, 1, 1); |
|
41
|
|
|
private static $ADestroyerBonus = array(1, 1, 1, 1); |
|
42
|
|
|
|
|
43
|
|
|
private static $DFighterBonus = array(1, 1, 1, 1); |
|
44
|
|
|
private static $DCorvetteBonus = array(1, 1, 1, 1); |
|
45
|
|
|
private static $DFrigateBonus = array(1, 1, 1, 1); |
|
46
|
|
|
private static $DDestroyerBonus = array(1, 1, 1, 1); |
|
47
|
|
|
|
|
48
|
|
|
public function setFightControl($isAFight = false) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->isAFight = $isAFight; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
# GETTER |
|
54
|
|
|
|
|
55
|
|
|
public static function getCurrentLine() { |
|
56
|
|
|
return self::$currentLine; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public static function getAFighterBonus($i) { |
|
60
|
|
|
return self::$AFighterBonus[$i]; |
|
61
|
|
|
} |
|
62
|
|
|
public static function getACorvetteBonus($i) { |
|
63
|
|
|
return self::$ACorvetteBonus[$i]; |
|
64
|
|
|
} |
|
65
|
|
|
public static function getAFrigateBonus($i) { |
|
66
|
|
|
return self::$AFrigateBonus[$i]; |
|
67
|
|
|
} |
|
68
|
|
|
public static function getADestroyerBonus($i) { |
|
69
|
|
|
return self::$ADestroyerBonus[$i]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public static function getDFighterBonus($i) { |
|
73
|
|
|
return self::$DFighterBonus[$i]; |
|
74
|
|
|
} |
|
75
|
|
|
public static function getDCorvetteBonus($i) { |
|
76
|
|
|
return self::$DCorvetteBonus[$i]; |
|
77
|
|
|
} |
|
78
|
|
|
public static function getDFrigateBonus($i) { |
|
79
|
|
|
return self::$DFrigateBonus[$i]; |
|
80
|
|
|
} |
|
81
|
|
|
public static function getDDestroyerBonus($i) { |
|
82
|
|
|
return self::$DDestroyerBonus[$i]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
// SETTER |
|
88
|
|
|
|
|
89
|
|
|
public function setPlayerBonus($ABonus, $DBonus) { |
|
90
|
|
|
if (isset($ABonus['global'])) { |
|
91
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
92
|
|
|
self::$AFighterBonus[$i] += $ABonus['global'][$i]; |
|
93
|
|
|
self::$ACorvetteBonus[$i] += $ABonus['global'][$i]; |
|
94
|
|
|
self::$AFrigateBonus[$i] += $ABonus['global'][$i]; |
|
95
|
|
|
self::$ADestroyerBonus[$i] += $ABonus['global'][$i]; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if (isset($ABonus['fighter'])) { |
|
100
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
101
|
|
|
self::$AFighterBonus[$i] += $ABonus['fighter'][$i]; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
if (isset($ABonus['corvette'])) { |
|
106
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
107
|
|
|
self::$ACorvetteBonus[$i] += $ABonus['corvette'][$i]; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (isset($ABonus['frigate'])) { |
|
112
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
113
|
|
|
self::$AFrigateBonus[$i] += $ABonus['frigate'][$i]; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
if (isset($ABonus['destroyer'])) { |
|
118
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
119
|
|
|
self::$ADestroyerBonus[$i] += $ABonus['destroyer'][$i]; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
if (isset($DBonus['global'])) { |
|
124
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
125
|
|
|
self::$DFighterBonus[$i] += $DBonus['global'][$i]; |
|
126
|
|
|
self::$DCorvetteBonus[$i] += $DBonus['global'][$i]; |
|
127
|
|
|
self::$DFrigateBonus[$i] += $DBonus['global'][$i]; |
|
128
|
|
|
self::$DDestroyerBonus[$i] += $DBonus['global'][$i]; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
if (isset($DBonus['fighter'])) { |
|
133
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
134
|
|
|
self::$DFighterBonus[$i] += $DBonus['fighter'][$i]; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
if (isset($DBonus['corvette'])) { |
|
139
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
140
|
|
|
self::$DCorvetteBonus[$i] += $DBonus['corvette'][$i]; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
if (isset($DBonus['frigate'])) { |
|
145
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
146
|
|
|
self::$DFrigateBonus[$i] += $DBonus['frigate'][$i]; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if (isset($DBonus['destroyer'])) { |
|
151
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
152
|
|
|
self::$DDestroyerBonus[$i] += $DBonus['destroyer'][$i]; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function setEnvironmentBonus($ABonus, $DBonus) { |
|
159
|
|
|
if (isset($ABonus['global'])) { |
|
160
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
161
|
|
|
self::$AFighterBonus[$i] += $ABonus['global'][$i]; |
|
162
|
|
|
self::$ACorvetteBonus[$i] += $ABonus['global'][$i]; |
|
163
|
|
|
self::$AFrigateBonus[$i] += $ABonus['global'][$i]; |
|
164
|
|
|
self::$ADestroyerBonus[$i] += $ABonus['global'][$i]; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
if (isset($ABonus['fighter'])) { |
|
169
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
170
|
|
|
self::$AFighterBonus[$i] += $ABonus['fighter'][$i]; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
if (isset($ABonus['corvette'])) { |
|
175
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
176
|
|
|
self::$ACorvetteBonus[$i] += $ABonus['corvette'][$i]; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
if (isset($ABonus['frigate'])) { |
|
181
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
182
|
|
|
self::$AFrigateBonus[$i] += $ABonus['frigate'][$i]; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if (isset($ABonus['destroyer'])) { |
|
187
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
188
|
|
|
self::$ADestroyerBonus[$i] += $ABonus['destroyer'][$i]; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
if (isset($DBonus['global'])) { |
|
193
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
194
|
|
|
self::$DFighterBonus[$i] += $DBonus['global'][$i]; |
|
195
|
|
|
self::$DCorvetteBonus[$i] += $DBonus['global'][$i]; |
|
196
|
|
|
self::$DFrigateBonus[$i] += $DBonus['global'][$i]; |
|
197
|
|
|
self::$DDestroyerBonus[$i] += $DBonus['global'][$i]; |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
if (isset($DBonus['fighter'])) { |
|
202
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
203
|
|
|
self::$DFighterBonus[$i] += $DBonus['fighter'][$i]; |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
if (isset($DBonus['corvette'])) { |
|
208
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
209
|
|
|
self::$DCorvetteBonus[$i] += $DBonus['corvette'][$i]; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
if (isset($DBonus['frigate'])) { |
|
214
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
215
|
|
|
self::$DFrigateBonus[$i] += $DBonus['frigate'][$i]; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
if (isset($DBonus['destroyer'])) { |
|
220
|
|
|
for($i = 0; $i < 4; $i++) { |
|
|
|
|
|
|
221
|
|
|
self::$DDestroyerBonus[$i] += $DBonus['destroyer'][$i]; |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* DEMARE LE COMBAT ENTRE DEUX COMMANDANT |
|
228
|
|
|
* COMPTE L'ARMEE D |
|
229
|
|
|
* si 0 vaisseaux |
|
230
|
|
|
* A gagne |
|
231
|
|
|
* SINON COMBAT |
|
232
|
|
|
* COMPTE L'ARMEE A |
|
233
|
|
|
* si 0 vaisseaux |
|
234
|
|
|
* D gagne |
|
235
|
|
|
* SINON COMBAT |
|
236
|
|
|
*/ |
|
237
|
|
|
|
|
238
|
|
|
public function startFight($commanderA, $playerA, $commanderD, $playerD = NULL) { |
|
239
|
|
|
$commanderA->setIsAttacker(TRUE); |
|
240
|
|
|
$commanderD->setIsAttacker(FALSE); |
|
241
|
|
|
|
|
242
|
|
|
$commanderA->setPevInBegin(); |
|
243
|
|
|
$commanderD->setPevInBegin(); |
|
244
|
|
|
|
|
245
|
|
|
LiveReport::$rPlayerAttacker = $commanderA->rPlayer; |
|
246
|
|
|
LiveReport::$rPlayerDefender = $commanderD->rPlayer; |
|
247
|
|
|
|
|
248
|
|
|
LiveReport::$avatarA = $commanderA->avatar; |
|
249
|
|
|
LiveReport::$avatarD = $commanderD->avatar; |
|
250
|
|
|
LiveReport::$nameA = $commanderA->name; |
|
251
|
|
|
LiveReport::$nameD = $commanderD->name; |
|
252
|
|
|
LiveReport::$levelA = $commanderA->level; |
|
253
|
|
|
LiveReport::$levelD = $commanderD->level; |
|
254
|
|
|
LiveReport::$experienceA = $commanderA->experience; |
|
255
|
|
|
LiveReport::$experienceD = $commanderD->experience; |
|
256
|
|
|
LiveReport::$palmaresA = $commanderA->palmares; |
|
257
|
|
|
LiveReport::$palmaresD = $commanderD->palmares; |
|
258
|
|
|
|
|
259
|
|
|
$shipsA = $commanderA->getNbrShipByType(); |
|
260
|
|
|
$shipsD = $commanderD->getNbrShipByType(); |
|
261
|
|
|
$weight = 0; |
|
262
|
|
|
|
|
263
|
|
|
for ($i = 0; $i < count($shipsA); $i++) { |
|
|
|
|
|
|
264
|
|
|
$weight += DataAnalysis::resourceToStdUnit(ShipResource::getInfo($i, 'resourcePrice') * $shipsA[$i]); |
|
265
|
|
|
$weight += DataAnalysis::resourceToStdUnit(ShipResource::getInfo($i, 'resourcePrice') * $shipsD[$i]); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
LiveReport::$importance = $weight; |
|
269
|
|
|
|
|
270
|
|
|
$i = 0; |
|
271
|
|
|
foreach ($commanderA->armyInBegin AS $s) { |
|
|
|
|
|
|
272
|
|
|
LiveReport::$squadrons[] = array(0, $i, 0, 0, $commanderA->id, $s[0], $s[1], $s[2], $s[3], $s[4], $s[5], $s[6], $s[7], $s[8], $s[9], $s[10], $s[11]); |
|
273
|
|
|
$i++; |
|
274
|
|
|
} |
|
275
|
|
|
$i = 0; |
|
276
|
|
|
foreach ($commanderD->armyInBegin AS $s) { |
|
|
|
|
|
|
277
|
|
|
LiveReport::$squadrons[] = array(0, $i, 0, 0, $commanderD->id, $s[0], $s[1], $s[2], $s[3], $s[4], $s[5], $s[6], $s[7], $s[8], $s[9], $s[10], $s[11]); |
|
278
|
|
|
$i++; |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
while(1) { |
|
|
|
|
|
|
282
|
|
|
if (LiveReport::$round == 1000) { |
|
283
|
|
|
break; |
|
284
|
|
|
} |
|
285
|
|
|
$nbrShipsD = 0; |
|
286
|
|
|
$nbrShipsA = 0; |
|
287
|
|
|
|
|
288
|
|
|
foreach ($commanderA->getArmy() as $squadronA) { |
|
289
|
|
|
$nbrShipsA += $squadronA->getNbrShips(); |
|
290
|
|
|
} |
|
291
|
|
|
if ($nbrShipsA == 0) { |
|
292
|
|
|
$this->commanderManager->resultOfFight($commanderD, TRUE, $commanderA); |
|
293
|
|
|
$this->commanderManager->resultOfFight($commanderA, FALSE, $commanderD); |
|
294
|
|
|
$commanderA->setStatement(3); |
|
295
|
|
|
$commanderD->setDDeath(Utils::now()); |
|
296
|
|
|
LiveReport::$rPlayerWinner = $commanderD->rPlayer; |
|
297
|
|
|
|
|
298
|
|
|
if ($commanderD->rPlayer != ID_GAIA) { |
|
299
|
|
|
$playerD->increaseVictory(1); |
|
300
|
|
|
$playerA->increaseDefeat(1); |
|
301
|
|
|
} else{ |
|
|
|
|
|
|
302
|
|
|
$playerA->increaseDefeat(1); |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
break; |
|
306
|
|
|
} else { |
|
307
|
|
|
$commanderA = $this->commanderManager->engage($commanderD, $commanderA); |
|
308
|
|
|
LiveReport::$halfround++; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
foreach ($commanderD->getArmy() as $squadronD) { |
|
312
|
|
|
$nbrShipsD += $squadronD->getNbrShips(); |
|
313
|
|
|
} |
|
314
|
|
|
if($nbrShipsD == 0) { |
|
|
|
|
|
|
315
|
|
|
$this->commanderManager->resultOfFight($commanderA, TRUE, $commanderD); |
|
316
|
|
|
$this->commanderManager->resultOfFight($commanderD, FALSE, $commanderA); |
|
317
|
|
|
$commanderD->setStatement(3); |
|
318
|
|
|
$commanderD->setDDeath(Utils::now()); |
|
319
|
|
|
LiveReport::$rPlayerWinner = $commanderA->rPlayer; |
|
320
|
|
|
|
|
321
|
|
|
if ($commanderD->rPlayer != ID_GAIA) { |
|
322
|
|
|
$playerA->increaseVictory(1); |
|
323
|
|
|
$playerD->increaseDefeat(1); |
|
324
|
|
|
} else { |
|
325
|
|
|
$playerA->increaseVictory(1); |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
break; |
|
329
|
|
|
} else { |
|
330
|
|
|
$commanderD = $this->commanderManager->engage($commanderA, $commanderD); |
|
331
|
|
|
LiveReport::$halfround++; |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
LiveReport::$round++; |
|
335
|
|
|
self::$currentLine++; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
$i = 0; |
|
339
|
|
|
foreach ($commanderA->armyAtEnd AS $s) { |
|
|
|
|
|
|
340
|
|
|
LiveReport::$squadrons[] = array(0, $i, 0, -1, $commanderA->id, $s[0], $s[1], $s[2], $s[3], $s[4], $s[5], $s[6], $s[7], $s[8], $s[9], $s[10], $s[11]); |
|
341
|
|
|
$i++; |
|
342
|
|
|
} |
|
343
|
|
|
$i = 0; |
|
344
|
|
|
foreach ($commanderD->armyAtEnd AS $s) { |
|
|
|
|
|
|
345
|
|
|
LiveReport::$squadrons[] = array(0, $i, 0, -1, $commanderD->id, $s[0], $s[1], $s[2], $s[3], $s[4], $s[5], $s[6], $s[7], $s[8], $s[9], $s[10], $s[11]); |
|
346
|
|
|
$i++; |
|
347
|
|
|
} |
|
348
|
|
|
return array($commanderA, $commanderD); |
|
349
|
|
|
} |
|
350
|
|
|
} |