1
|
|
|
<?php namespace Xaoc303\BattleCalc; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class Army |
5
|
|
|
* @package Xaoc303\BattleCalc |
6
|
|
|
*/ |
7
|
|
|
class Army |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var array |
11
|
|
|
*/ |
12
|
|
|
private $units; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* __construct |
16
|
|
|
* |
17
|
|
|
* @param array $input_units |
18
|
|
|
*/ |
19
|
|
|
public function __construct($input_units) |
20
|
|
|
{ |
21
|
|
|
$units = new Squad(); |
22
|
|
|
$this->setUnits($units->createArmy($input_units)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* setUnits |
27
|
|
|
* |
28
|
|
|
* @param array $units |
29
|
|
|
*/ |
30
|
|
|
public function setUnits($units) |
31
|
|
|
{ |
32
|
|
|
$this->units = $units; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* getUnits |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function getUnits() |
41
|
|
|
{ |
42
|
|
|
return $this->units; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* manCount |
47
|
|
|
* |
48
|
|
|
* @param integer $Inic |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
public function manCount(&$Inic) |
52
|
|
|
{ |
53
|
|
|
$units = $this->getUnits(); |
54
|
|
|
|
55
|
|
|
$ManCount = 0; |
56
|
|
|
$count = count($units); |
57
|
|
|
for ($i = 0; $i < $count; $i++) { |
58
|
|
|
$ManCount += $units[$i]['All']['ManCount']; |
59
|
|
|
if ($units[$i]['All']['Iniciative'] > $Inic && $units[$i]['All']['ManCount'] > 0) { |
60
|
|
|
$Inic = $units[$i]['All']['Iniciative']; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $ManCount; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* shadow |
69
|
|
|
* |
70
|
|
|
* @param Army $ArmyDet |
71
|
|
|
* @param integer $Round |
72
|
|
|
*/ |
73
|
|
|
public function shadow(Army &$ArmyDet, $Round) |
74
|
|
|
{ |
75
|
|
|
$unitsSh = $this->getUnits(); |
76
|
|
|
$unitsDet = $ArmyDet->getUnits(); |
77
|
|
|
|
78
|
|
|
// set shadow |
79
|
|
|
$count = count($unitsSh); |
80
|
|
|
for ($i = 0; $i < $count; $i++) { |
81
|
|
|
$unitsSh[$i]['All']['ManCountVisible'] = $unitsSh[$i]['All']['ManCount']; |
82
|
|
|
|
83
|
|
|
if ($unitsSh[$i]['All']['ManCount'] > 0) { |
84
|
|
|
$this->setShadow($unitsSh, $i, $count, $Round); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$ManCount = $this->getDetectorsCount($unitsDet); |
89
|
|
|
$this->unsetShadow($unitsSh, $ManCount); |
90
|
|
|
|
91
|
|
|
$this->setUnits($unitsSh); |
92
|
|
|
$ArmyDet->setUnits($unitsDet); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* setShadow |
97
|
|
|
* |
98
|
|
|
* @param array $unitsSh |
99
|
|
|
* @param int $i |
100
|
|
|
* @param int $units_count |
101
|
|
|
* @param int $Round |
102
|
|
|
*/ |
103
|
|
|
private function setShadow(&$unitsSh, &$i, &$units_count, $Round) |
104
|
|
|
{ |
105
|
|
|
switch ($unitsSh[$i]['Base']['ID']) { |
106
|
|
|
case 105: // Dark Templar |
107
|
|
|
case 109: // Observer |
108
|
|
|
$this->setShadowSquadAll($unitsSh, $i); |
109
|
|
|
break; |
110
|
|
|
|
111
|
|
|
case 114: // Arbiter |
112
|
|
|
$this->setShadowSquad114($unitsSh, $i, $units_count); |
113
|
|
|
break; |
114
|
|
|
|
115
|
|
|
case 204: // Ghost |
116
|
|
|
$this->setShadowSquadRound($unitsSh, $i, $Round); |
117
|
|
|
break; |
118
|
|
|
|
119
|
|
|
case 213: // Writh |
120
|
|
|
$this->setShadowSquadRound($unitsSh, $i, $Round); |
121
|
|
|
break; |
122
|
|
|
|
123
|
|
|
case 305: // Lurker |
124
|
|
|
$this->setShadowSquadAllHold($unitsSh, $i, $Round); |
125
|
|
|
break; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* setShadowSquadAll |
131
|
|
|
* |
132
|
|
|
* @param array $unitsSh |
133
|
|
|
* @param int $i |
134
|
|
|
*/ |
135
|
|
|
private function setShadowSquadAll(&$unitsSh, &$i) |
136
|
|
|
{ |
137
|
|
|
$unitsSh[$i]['All']['ManCountVisible'] = 0; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* setShadowSquad114 |
142
|
|
|
* |
143
|
|
|
* @param array $unitsSh |
144
|
|
|
* @param int $i |
145
|
|
|
* @param int $units_count |
146
|
|
|
*/ |
147
|
|
|
private function setShadowSquad114(&$unitsSh, &$i, &$units_count) |
148
|
|
|
{ |
149
|
|
|
$ManCount = $unitsSh[$i]['All']['MagicManCount'] * $unitsSh[$i]['All']['ManCount']; |
150
|
|
|
while ($ManCount > 0) { |
151
|
|
|
$ManCountExists = false; |
152
|
|
|
|
153
|
|
|
for ($i1 = 0; $i1 < $units_count; $i1++) { |
154
|
|
|
if ($i1 != $i && $unitsSh[$i1]['All']['ManCount'] > 0 && $unitsSh[$i1]['All']['ManCountVisible'] != 0) { |
155
|
|
|
$unitsSh[$i1]['All']['ManCountVisible']--; |
156
|
|
|
$ManCount--; |
157
|
|
|
$ManCountExists = true; |
158
|
|
|
if ($ManCount == 0) { |
159
|
|
|
$i1 = $units_count; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
if (!$ManCountExists) { |
165
|
|
|
$ManCount = 0; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
$i = $units_count; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* setShadowSquadRound |
173
|
|
|
* |
174
|
|
|
* @param array $unitsSh |
175
|
|
|
* @param int $i |
176
|
|
|
* @param int $Round |
177
|
|
|
*/ |
178
|
|
|
private function setShadowSquadRound(&$unitsSh, &$i, &$Round) |
179
|
|
|
{ |
180
|
|
|
if ($Round > $unitsSh[$i]['All']['Iniciative'] - 20) { |
181
|
|
|
$unitsSh[$i]['All']['ManCountVisible'] = 0; |
182
|
|
|
} else { |
183
|
|
|
$unitsSh[$i]['All']['ManCountVisible'] = $unitsSh[$i]['All']['ManCount']; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* setShadowSquadAllHold |
189
|
|
|
* |
190
|
|
|
* @param array $unitsSh |
191
|
|
|
* @param int $i |
192
|
|
|
* @param null|int $Round |
193
|
|
|
*/ |
194
|
|
|
private function setShadowSquadAllHold(&$unitsSh, &$i, $Round = null) |
195
|
|
|
{ |
196
|
|
|
if ($Round < $unitsSh[$i]['All']['Iniciative'] - 2) { |
197
|
|
|
$unitsSh[$i]['All']['ManCountVisible'] = 0; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* getDetectorsCount |
203
|
|
|
* |
204
|
|
|
* @param array $unitsDet |
205
|
|
|
* @return int |
206
|
|
|
*/ |
207
|
|
|
private function getDetectorsCount(&$unitsDet) |
208
|
|
|
{ |
209
|
|
|
$ManCount = 0; |
210
|
|
|
$count = count($unitsDet); |
211
|
|
|
for ($i = 0; $i < $count; $i++) { |
212
|
|
|
if (in_array($unitsDet[$i]['Base']['ID'], [109, 211, 309]) && $unitsDet[$i]['All']['ManCount'] > 0) { |
213
|
|
|
$ManCount += $unitsDet[$i]['All']['MagicManCount'] * $unitsDet[$i]['All']['ManCount']; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
return $ManCount; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* unsetShadow |
221
|
|
|
* |
222
|
|
|
* @param array $unitsSh |
223
|
|
|
* @param int $ManCount |
224
|
|
|
*/ |
225
|
|
|
private function unsetShadow(&$unitsSh, $ManCount) |
226
|
|
|
{ |
227
|
|
|
while ($ManCount > 0) { |
228
|
|
|
$ManCountExists = false; |
229
|
|
|
$count = count($unitsSh); |
230
|
|
|
for ($i = 0; $i < $count; $i++) { |
231
|
|
|
if ($unitsSh[$i]['All']['ManCount'] > 0 && $unitsSh[$i]['All']['ManCountVisible'] != $unitsSh[$i]['All']['ManCount']) { |
232
|
|
|
$unitsSh[$i]['All']['ManCountVisible']++; |
233
|
|
|
$ManCount--; |
234
|
|
|
$ManCountExists = true; |
235
|
|
|
if ($ManCount == 0) { |
236
|
|
|
$i = count($unitsSh); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
if (!$ManCountExists) { |
241
|
|
|
$ManCount = 0; |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* clear |
248
|
|
|
*/ |
249
|
|
|
public function clear() |
250
|
|
|
{ |
251
|
|
|
$units = $this->getUnits(); |
252
|
|
|
$count = count($units); |
253
|
|
|
for ($i = 0; $i < $count; $i++) { |
254
|
|
|
$units[$i]['All']['Color'] = 0; |
255
|
|
|
$units[$i]['All']['AttackTer'] = 0; |
256
|
|
|
$units[$i]['All']['AttackAir'] = 0; |
257
|
|
|
$units[$i]['All']['AttackMagicAll'] = 0; |
258
|
|
|
$units[$i]['All']['AttackMagicShield'] = 0; |
259
|
|
|
$units[$i]['All']['AttackMagicHP'] = 0; |
260
|
|
|
$units[$i]['All']['ManLock'] = 0; |
261
|
|
|
$units[$i]['All']['Magic'][0] = null; |
262
|
|
|
$units[$i]['All']['Magic'][1] = null; |
263
|
|
|
$units[$i]['All']['Magic'][2] = null; |
264
|
|
|
$units[$i]['All']['HealingLive'] = 0; |
265
|
|
|
$units[$i]['All']['HealingTech'] = 0; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
$this->setUnits($units); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* manCountVisible |
275
|
|
|
* |
276
|
|
|
* @param integer $unit_type |
277
|
|
|
* @return int |
278
|
|
|
*/ |
279
|
|
|
public function manCountVisible($unit_type) |
280
|
|
|
{ |
281
|
|
|
$units = $this->getUnits(); |
282
|
|
|
|
283
|
|
|
$ManCountVisible = 0; |
284
|
|
|
$count = count($units); |
285
|
|
|
for ($i = 0; $i < $count; $i++) { |
286
|
|
|
if ($units[$i]['All']['UT'] == $unit_type) { |
287
|
|
|
$ManCountVisible += $units[$i]['All']['ManCountVisible']; |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
return $ManCountVisible; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* attackNull |
295
|
|
|
* |
296
|
|
|
* @param integer $ManCountA |
297
|
|
|
*/ |
298
|
|
|
public function attackNull($ManCountA) |
299
|
|
|
{ |
300
|
|
|
$units = $this->getUnits(); |
301
|
|
|
|
302
|
|
|
$count = count($units); |
303
|
|
|
for ($i = 0; $i < $count; $i++) { |
304
|
|
|
if ($units[$i]['All']['ManCount'] > 0) { |
305
|
|
|
if ($units[$i]['All']['AttackAir'] > 0 && $units[$i]['All']['AttackTer'] && $ManCountA > 0) { |
306
|
|
|
$units[$i]['All']['AttackTer'] = 0; |
307
|
|
|
} else { |
308
|
|
|
$units[$i]['All']['AttackAir'] = 0; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
if ($units[$i]['All']['ManLock'] > 0) { |
312
|
|
|
$units[$i]['All']['AttackAir'] = $units[$i]['All']['AttackAir'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManLock']); |
313
|
|
|
$units[$i]['All']['AttackTer'] = $units[$i]['All']['AttackTer'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManLock']); |
314
|
|
|
$units[$i]['All']['AttackMagicAll'] = $units[$i]['All']['AttackMagicAll'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManLock']); |
315
|
|
|
$units[$i]['All']['AttackMagicShield'] = $units[$i]['All']['AttackMagicShield'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManLock']); |
316
|
|
|
$units[$i]['All']['AttackMagicHP'] = $units[$i]['All']['AttackMagicHP'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManLock']); |
317
|
|
|
} |
318
|
|
|
if ($units[$i]['All']['ManPhantom'] > 0) { |
319
|
|
|
$units[$i]['All']['AttackAir'] = $units[$i]['All']['AttackAir'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManPhantom']); |
320
|
|
|
$units[$i]['All']['AttackTer'] = $units[$i]['All']['AttackTer'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManPhantom']); |
321
|
|
|
$units[$i]['All']['AttackMagicAll'] = $units[$i]['All']['AttackMagicAll'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManPhantom']); |
322
|
|
|
$units[$i]['All']['AttackMagicShield'] = $units[$i]['All']['AttackMagicShield'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManPhantom']); |
323
|
|
|
$units[$i]['All']['AttackMagicHP'] = $units[$i]['All']['AttackMagicHP'] / $units[$i]['All']['ManCount'] * ($units[$i]['All']['ManCount'] - $units[$i]['All']['ManPhantom']); |
324
|
|
|
} |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
$this->setUnits($units); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* count |
333
|
|
|
* |
334
|
|
|
* @return int |
335
|
|
|
*/ |
336
|
|
|
public function count() |
337
|
|
|
{ |
338
|
|
|
$units = $this->getUnits(); |
339
|
|
|
|
340
|
|
|
$ManCount = 0; |
341
|
|
|
$count = count($units); |
342
|
|
|
for ($i = 0; $i < $count; $i++) { |
343
|
|
|
$ManCountTemp = $units[$i]['All']['ManCount']; |
344
|
|
|
$units[$i]['All']['ManCount'] = (int) ($units[$i]['All']['HP'] / $units[$i]['Base']['HP']); |
345
|
|
|
|
346
|
|
|
if ($units[$i]['All']['HP'] % $units[$i]['Base']['HP'] > 0) { |
347
|
|
|
$units[$i]['All']['ManCount']++; |
348
|
|
|
} |
349
|
|
|
if ($units[$i]['All']['ManPhantom'] > 0 && $ManCountTemp > $units[$i]['All']['ManCount']) { |
350
|
|
|
$units[$i]['All']['ManPhantom']--; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
$ManCount += $units[$i]['All']['ManCount']; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
$this->setUnits($units); |
357
|
|
|
return $ManCount; |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
|