|
1
|
|
|
<?php namespace Xaoc303\BattleCalc; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class ArmyDamage |
|
5
|
|
|
* @package Xaoc303\BattleCalc |
|
6
|
|
|
*/ |
|
7
|
|
|
class ArmyDamage |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var array |
|
11
|
|
|
*/ |
|
12
|
|
|
private $unitsAtt; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
private $unitsDef; |
|
18
|
|
|
|
|
19
|
|
|
private $DamageTer = 0; |
|
20
|
|
|
private $DamageAir = 0; |
|
21
|
|
|
private $DamageMagicAll = 0; |
|
22
|
|
|
private $DamageMagicShield = 0; |
|
23
|
|
|
private $DamageMagicHP = 0; |
|
24
|
|
|
|
|
25
|
|
|
private $ManCountT_Def = 0; |
|
26
|
|
|
private $ManCountA_Def = 0; |
|
27
|
|
|
|
|
28
|
|
|
private $HealingLive = 0; |
|
29
|
|
|
private $HealingTech = 0; |
|
30
|
|
|
|
|
31
|
|
|
private $ManDamageT = 0; |
|
32
|
|
|
private $ManDamageA = 0; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* run |
|
36
|
|
|
* |
|
37
|
|
|
* @param Army $armyAtt |
|
38
|
|
|
* @param Army $armyDef |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function run(Army &$armyAtt, Army &$armyDef) |
|
41
|
|
|
{ |
|
42
|
|
|
$class = new ArmyDamage(); |
|
43
|
|
|
|
|
44
|
|
|
$class->unitsAtt = $armyAtt->getUnits(); |
|
45
|
|
|
$class->unitsDef = $armyDef->getUnits(); |
|
46
|
|
|
|
|
47
|
|
|
$class->damage(); |
|
48
|
|
|
|
|
49
|
|
|
$armyAtt->setUnits($class->unitsAtt); |
|
50
|
|
|
$armyDef->setUnits($class->unitsDef); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* damage |
|
55
|
|
|
*/ |
|
56
|
|
|
private function damage() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->damageSum(); |
|
59
|
|
|
$this->damageManCount(); |
|
60
|
|
|
$this->damageHealing(); |
|
61
|
|
|
|
|
62
|
|
|
$this->setManDamageT(); |
|
63
|
|
|
$this->setManDamageA(); |
|
64
|
|
|
|
|
65
|
|
|
$count = count($this->unitsDef); |
|
66
|
|
|
for ($i = 0; $i < $count; $i++) { |
|
67
|
|
|
if ($this->unitsDef[$i]['All']['ManCountVisible'] > 0 || $this->DamageMagicAll > 0 || $this->DamageMagicShield > 0 || $this->DamageMagicHP > 0) { |
|
68
|
|
|
$this->damageSquad($i); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function setManDamageT() |
|
74
|
|
|
{ |
|
75
|
|
|
if ($this->DamageTer == 0 || $this->ManCountT_Def == 0) { |
|
76
|
|
|
$this->ManDamageT = 0; |
|
77
|
|
|
} |
|
78
|
|
|
if ($this->DamageTer > 0 && $this->ManCountT_Def > 0) { |
|
79
|
|
|
$this->ManDamageT = $this->DamageTer / $this->ManCountT_Def; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
private function setManDamageA() |
|
84
|
|
|
{ |
|
85
|
|
|
if ($this->DamageAir == 0 || $this->ManCountA_Def == 0) { |
|
86
|
|
|
$this->ManDamageA = 0; |
|
87
|
|
|
} |
|
88
|
|
|
if ($this->DamageAir > 0 && $this->ManCountA_Def > 0) { |
|
89
|
|
|
$this->ManDamageA = $this->DamageAir / $this->ManCountA_Def; |
|
90
|
|
|
} // среднее на каждгого. воздух |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* damageSum |
|
95
|
|
|
*/ |
|
96
|
|
|
private function damageSum() |
|
97
|
|
|
{ |
|
98
|
|
|
$count = count($this->unitsAtt); |
|
99
|
|
|
for ($i = 0; $i < $count; $i++) { |
|
100
|
|
|
$this->DamageTer += $this->unitsAtt[$i]['All']['AttackTer']; |
|
101
|
|
|
$this->DamageAir += $this->unitsAtt[$i]['All']['AttackAir']; |
|
102
|
|
|
$this->DamageMagicAll += $this->unitsAtt[$i]['All']['AttackMagicAll']; |
|
103
|
|
|
$this->DamageMagicShield += $this->unitsAtt[$i]['All']['AttackMagicShield']; |
|
104
|
|
|
$this->DamageMagicHP += $this->unitsAtt[$i]['All']['AttackMagicHP']; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* damageManCount |
|
110
|
|
|
*/ |
|
111
|
|
|
private function damageManCount() |
|
112
|
|
|
{ |
|
113
|
|
|
$count = count($this->unitsDef); |
|
114
|
|
|
for ($i = 0; $i < $count; $i++) { |
|
115
|
|
|
if ($this->unitsDef[$i]['All']['UT'] == 0) { |
|
116
|
|
|
$this->ManCountT_Def += $this->unitsDef[$i]['All']['ManCountVisible']; |
|
117
|
|
|
} |
|
118
|
|
|
if ($this->unitsDef[$i]['All']['UT'] == 1) { |
|
119
|
|
|
$this->ManCountA_Def += $this->unitsDef[$i]['All']['ManCountVisible']; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* damageHealing |
|
126
|
|
|
*/ |
|
127
|
|
|
private function damageHealing() |
|
128
|
|
|
{ |
|
129
|
|
|
$count = count($this->unitsDef); |
|
130
|
|
|
for ($i = 0; $i < $count; $i++) { |
|
131
|
|
|
$this->HealingLive += $this->unitsDef[$i]['All']['HealingLive']; |
|
132
|
|
|
$this->HealingTech += $this->unitsDef[$i]['All']['HealingTech']; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
private function damageSquad(&$i) |
|
137
|
|
|
{ |
|
138
|
|
|
$unitsDef = $this->unitsDef; |
|
139
|
|
|
$ManDamageAll = 0; |
|
140
|
|
|
$ManDamageShield = 0; |
|
141
|
|
|
$ManDamageHP = 0; |
|
142
|
|
|
if ($unitsDef[$i]['All']['ManCountVisible'] > 0) { |
|
143
|
|
|
if ($unitsDef[$i]['All']['UT'] == 0) { |
|
144
|
|
|
$ManDamageAll = ($this->ManDamageT-(($this->ManDamageT* $unitsDef[$i]['Base']['Armor'])/100))* $unitsDef[$i]['All']['ManCount']; |
|
145
|
|
|
} else { |
|
146
|
|
|
$ManDamageAll = ($this->ManDamageA-(($this->ManDamageA* $unitsDef[$i]['Base']['Armor'])/100))* $unitsDef[$i]['All']['ManCount']; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
if ($this->DamageMagicAll > 0) { |
|
150
|
|
|
$ManDamageAll += $this->DamageMagicAll -(($this->DamageMagicAll * $unitsDef[$i]['Base']['Armor'])/100); |
|
151
|
|
|
} |
|
152
|
|
|
if ($this->DamageMagicShield > 0) { |
|
153
|
|
|
$ManDamageShield += $this->DamageMagicShield -(($this->DamageMagicShield* $unitsDef[$i]['Base']['Armor'])/100); |
|
154
|
|
|
} |
|
155
|
|
|
if ($this->DamageMagicHP > 0) { |
|
156
|
|
|
$ManDamageHP += $this->DamageMagicHP -(($this->DamageMagicHP * $unitsDef[$i]['Base']['Armor'])/100); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
$unitsDef[$i]['All']['Shield'] -= $ManDamageShield; |
|
160
|
|
|
if ($unitsDef[$i]['All']['Shield'] < 0) { |
|
161
|
|
|
$unitsDef[$i]['All']['Shield'] = 0; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
$HPmax = $unitsDef[$i]['Base']['HP'] * $unitsDef[$i]['All']['ManCount']; |
|
166
|
|
|
|
|
167
|
|
|
$unitsDef[$i]['All']['HP'] -= $ManDamageHP; |
|
168
|
|
|
if ($unitsDef[$i]['All']['HP'] < 0) { |
|
169
|
|
|
$unitsDef[$i]['All']['HP'] = 0; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
$unitsDef[$i]['All']['Shield'] -= $ManDamageAll; |
|
173
|
|
|
if ($unitsDef[$i]['All']['Shield'] < 0) { |
|
174
|
|
|
$unitsDef[$i]['All']['HP'] += $unitsDef[$i]['All']['Shield']; |
|
175
|
|
|
$unitsDef[$i]['All']['Shield'] = 0; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
$this->healingLive($unitsDef, $i, $HPmax); |
|
179
|
|
|
$this->healingTech($unitsDef, $i, $HPmax); |
|
180
|
|
|
|
|
181
|
|
|
if ($unitsDef[$i]['All']['HP'] < 0) { |
|
182
|
|
|
$unitsDef[$i]['All']['HP'] = 0; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$this->unitsDef = $unitsDef; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
private function healingLive(&$unitsDef, $i, $HPmax) |
|
189
|
|
|
{ |
|
190
|
|
|
if ($this->HealingLive > 0) { |
|
191
|
|
|
if ($unitsDef[$i]['All']['Bio']) { |
|
192
|
|
|
if ($unitsDef[$i]['All']['HP'] < $HPmax) { |
|
193
|
|
|
$HPtemp = $HPmax - $unitsDef[$i]['All']['HP']; |
|
194
|
|
|
if ($this->HealingLive >= $HPtemp) { |
|
195
|
|
|
$this->HealingLive -= $HPtemp; |
|
196
|
|
|
$unitsDef[$i]['All']['HP'] += $HPtemp; |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
private function healingTech(&$unitsDef, $i, $HPmax) |
|
204
|
|
|
{ |
|
205
|
|
|
if ($this->HealingTech > 0) { |
|
206
|
|
|
if (!$unitsDef[$i]['All']['Bio']) { |
|
207
|
|
|
if ($unitsDef[$i]['All']['HP'] < $HPmax) { |
|
208
|
|
|
$HPtemp = $HPmax - $unitsDef[$i]['All']['HP']; |
|
209
|
|
|
if ($this->HealingTech >= $HPtemp) { |
|
210
|
|
|
$this->HealingTech -= $HPtemp; |
|
211
|
|
|
$unitsDef[$i]['All']['HP'] += $HPtemp; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|