|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
4
|
|
|
// Записывает боевой отчет в БД |
|
5
|
|
|
function sn_ube_report_save(&$combat_data) { |
|
6
|
|
|
global $config; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
// Если уже есть ИД репорта - значит репорт был взят из таблицы. С таким мы не работаем |
|
9
|
|
|
if ($combat_data[UBE_REPORT_CYPHER]) { |
|
10
|
|
|
return false; |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
// Генерируем уникальный секретный ключ и проверяем наличие в базе |
|
14
|
|
|
do { |
|
15
|
|
|
$combat_data[UBE_REPORT_CYPHER] = sys_random_string(32); |
|
16
|
|
|
} while (doquery("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$combat_data[UBE_REPORT_CYPHER]}' LIMIT 1 FOR UPDATE", true)); |
|
17
|
|
|
|
|
18
|
|
|
// Инициализация таблицы для пакетной вставки информации |
|
19
|
|
|
$sql_perform = array( |
|
20
|
|
|
'ube_report_player' => array( |
|
21
|
|
|
array( |
|
22
|
|
|
'`ube_report_id`', |
|
23
|
|
|
'`ube_report_player_player_id`', |
|
24
|
|
|
'`ube_report_player_name`', |
|
25
|
|
|
'`ube_report_player_attacker`', |
|
26
|
|
|
'`ube_report_player_bonus_attack`', |
|
27
|
|
|
'`ube_report_player_bonus_shield`', |
|
28
|
|
|
'`ube_report_player_bonus_armor`', |
|
29
|
|
|
), |
|
30
|
|
|
), |
|
31
|
|
|
|
|
32
|
|
|
'ube_report_fleet' => array( |
|
33
|
|
|
array( |
|
34
|
|
|
'`ube_report_id`', |
|
35
|
|
|
'`ube_report_fleet_player_id`', |
|
36
|
|
|
'`ube_report_fleet_fleet_id`', |
|
37
|
|
|
'`ube_report_fleet_planet_id`', |
|
38
|
|
|
'`ube_report_fleet_planet_name`', |
|
39
|
|
|
'`ube_report_fleet_planet_galaxy`', |
|
40
|
|
|
'`ube_report_fleet_planet_system`', |
|
41
|
|
|
'`ube_report_fleet_planet_planet`', |
|
42
|
|
|
'`ube_report_fleet_planet_planet_type`', |
|
43
|
|
|
'`ube_report_fleet_resource_metal`', |
|
44
|
|
|
'`ube_report_fleet_resource_crystal`', |
|
45
|
|
|
'`ube_report_fleet_resource_deuterium`', |
|
46
|
|
|
'`ube_report_fleet_bonus_attack`', |
|
47
|
|
|
'`ube_report_fleet_bonus_shield`', |
|
48
|
|
|
'`ube_report_fleet_bonus_armor`', |
|
49
|
|
|
), |
|
50
|
|
|
), |
|
51
|
|
|
|
|
52
|
|
|
'ube_report_outcome_fleet' => array( |
|
53
|
|
|
array( |
|
54
|
|
|
'`ube_report_id`', |
|
55
|
|
|
'`ube_report_outcome_fleet_fleet_id`', |
|
56
|
|
|
'`ube_report_outcome_fleet_resource_lost_metal`', |
|
57
|
|
|
'`ube_report_outcome_fleet_resource_lost_crystal`', |
|
58
|
|
|
'`ube_report_outcome_fleet_resource_lost_deuterium`', |
|
59
|
|
|
'`ube_report_outcome_fleet_resource_dropped_metal`', |
|
60
|
|
|
'`ube_report_outcome_fleet_resource_dropped_crystal`', |
|
61
|
|
|
'`ube_report_outcome_fleet_resource_dropped_deuterium`', |
|
62
|
|
|
'`ube_report_outcome_fleet_resource_loot_metal`', |
|
63
|
|
|
'`ube_report_outcome_fleet_resource_loot_crystal`', |
|
64
|
|
|
'`ube_report_outcome_fleet_resource_loot_deuterium`', |
|
65
|
|
|
'`ube_report_outcome_fleet_resource_lost_in_metal`', |
|
66
|
|
|
), |
|
67
|
|
|
), |
|
68
|
|
|
|
|
69
|
|
|
'ube_report_outcome_unit' => array( |
|
70
|
|
|
array( |
|
71
|
|
|
'`ube_report_id`', |
|
72
|
|
|
'`ube_report_outcome_unit_fleet_id`', |
|
73
|
|
|
'`ube_report_outcome_unit_unit_id`', |
|
74
|
|
|
'`ube_report_outcome_unit_restored`', |
|
75
|
|
|
'`ube_report_outcome_unit_lost`', |
|
76
|
|
|
'`ube_report_outcome_unit_sort_order`', |
|
77
|
|
|
), |
|
78
|
|
|
), |
|
79
|
|
|
|
|
80
|
|
|
'ube_report_unit' => array( |
|
81
|
|
|
array( |
|
82
|
|
|
'`ube_report_id`', |
|
83
|
|
|
'`ube_report_unit_player_id`', |
|
84
|
|
|
'`ube_report_unit_fleet_id`', |
|
85
|
|
|
'`ube_report_unit_round`', |
|
86
|
|
|
'`ube_report_unit_unit_id`', |
|
87
|
|
|
'`ube_report_unit_count`', |
|
88
|
|
|
'`ube_report_unit_boom`', |
|
89
|
|
|
'`ube_report_unit_attack`', |
|
90
|
|
|
'`ube_report_unit_shield`', |
|
91
|
|
|
'`ube_report_unit_armor`', |
|
92
|
|
|
'`ube_report_unit_attack_base`', |
|
93
|
|
|
'`ube_report_unit_shield_base`', |
|
94
|
|
|
'`ube_report_unit_armor_base`', |
|
95
|
|
|
'`ube_report_unit_sort_order`', |
|
96
|
|
|
), |
|
97
|
|
|
), |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
// Сохраняем общую информацию о бое |
|
101
|
|
|
$outcome = &$combat_data[UBE_OUTCOME]; |
|
102
|
|
|
$ube_report_debris_total_in_metal = ( |
|
103
|
|
|
floatval($outcome[UBE_DEBRIS][RES_METAL]) |
|
104
|
|
|
+ floatval($outcome[UBE_DEBRIS][RES_CRYSTAL]) * floatval($config->rpg_exchange_crystal) |
|
105
|
|
|
) / (floatval($config->rpg_exchange_metal) ? floatval($config->rpg_exchange_metal) : 1); |
|
106
|
|
|
doquery("INSERT INTO `{{ube_report}}` |
|
107
|
|
|
SET |
|
108
|
|
|
`ube_report_cypher` = '{$combat_data[UBE_REPORT_CYPHER]}', |
|
109
|
|
|
`ube_report_time_combat` = '" . date(FMT_DATE_TIME_SQL, $combat_data[UBE_TIME]) . "', |
|
110
|
|
|
`ube_report_time_spent` = {$combat_data[UBE_TIME_SPENT]}, |
|
111
|
|
|
|
|
112
|
|
|
`ube_report_combat_admin` = " . (int)$combat_data[UBE_OPTIONS][UBE_COMBAT_ADMIN] . ", |
|
113
|
|
|
`ube_report_mission_type` = {$combat_data[UBE_OPTIONS][UBE_MISSION_TYPE]}, |
|
114
|
|
|
|
|
115
|
|
|
`ube_report_combat_result` = {$outcome[UBE_COMBAT_RESULT]}, |
|
116
|
|
|
`ube_report_combat_sfr` = " . (int)$outcome[UBE_SFR] . ", |
|
117
|
|
|
|
|
118
|
|
|
`ube_report_debris_metal` = " . (float)$outcome[UBE_DEBRIS][RES_METAL] . ", |
|
119
|
|
|
`ube_report_debris_crystal` = " . (float)$outcome[UBE_DEBRIS][RES_CRYSTAL] . ", |
|
120
|
|
|
`ube_report_debris_total_in_metal` = " . $ube_report_debris_total_in_metal . ", |
|
121
|
|
|
|
|
122
|
|
|
`ube_report_planet_id` = " . (int)$outcome[UBE_PLANET][PLANET_ID] . ", |
|
123
|
|
|
`ube_report_planet_name` = '" . db_escape($outcome[UBE_PLANET][PLANET_NAME]) . "', |
|
124
|
|
|
`ube_report_planet_size` = " . (int)$outcome[UBE_PLANET][PLANET_SIZE] . ", |
|
125
|
|
|
`ube_report_planet_galaxy` = " . (int)$outcome[UBE_PLANET][PLANET_GALAXY] . ", |
|
126
|
|
|
`ube_report_planet_system` = " . (int)$outcome[UBE_PLANET][PLANET_SYSTEM] . ", |
|
127
|
|
|
`ube_report_planet_planet` = " . (int)$outcome[UBE_PLANET][PLANET_PLANET] . ", |
|
128
|
|
|
`ube_report_planet_planet_type` = " . (int)$outcome[UBE_PLANET][PLANET_TYPE] . ", |
|
129
|
|
|
|
|
130
|
|
|
`ube_report_moon` = " . (int)$outcome[UBE_MOON] . ", |
|
131
|
|
|
`ube_report_moon_chance` = " . (int)$outcome[UBE_MOON_CHANCE] . ", |
|
132
|
|
|
`ube_report_moon_size` = " . (float)$outcome[UBE_MOON_SIZE] . ", |
|
133
|
|
|
|
|
134
|
|
|
`ube_report_moon_reapers` = " . (int)$outcome[UBE_MOON_REAPERS] . ", |
|
135
|
|
|
`ube_report_moon_destroy_chance` = " . (int)$outcome[UBE_MOON_DESTROY_CHANCE] . ", |
|
136
|
|
|
`ube_report_moon_reapers_die_chance` = " . (int)$outcome[UBE_MOON_REAPERS_DIE_CHANCE] . ", |
|
137
|
|
|
|
|
138
|
|
|
`ube_report_capture_result` = " . (int)$outcome[UBE_CAPTURE_RESULT] . " |
|
139
|
|
|
"); |
|
140
|
|
|
$ube_report_id = $combat_data[UBE_REPORT_ID] = db_insert_id(); |
|
141
|
|
|
|
|
142
|
|
|
// Сохраняем общую информацию по игрокам |
|
143
|
|
|
foreach ($combat_data[UBE_PLAYERS] as $player_id => &$player_info) { |
|
144
|
|
|
$sql_perform['ube_report_player'][] = array( |
|
145
|
|
|
$ube_report_id, |
|
146
|
|
|
$player_id, |
|
147
|
|
|
|
|
148
|
|
|
"'" . db_escape($player_info[UBE_NAME]) . "'", |
|
149
|
|
|
(int)$player_info[UBE_ATTACKER], |
|
150
|
|
|
|
|
151
|
|
|
(float)$player_info[UBE_BONUSES][UBE_ATTACK], |
|
152
|
|
|
(float)$player_info[UBE_BONUSES][UBE_SHIELD], |
|
153
|
|
|
(float)$player_info[UBE_BONUSES][UBE_ARMOR], |
|
154
|
|
|
); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
// Всякая информация по флотам |
|
158
|
|
|
$unit_sort_order = 0; |
|
159
|
|
|
foreach ($combat_data[UBE_FLEETS] as $fleet_id => &$fleet_info) { |
|
160
|
|
|
// Сохраняем общую информацию по флотам |
|
161
|
|
|
$sql_perform['ube_report_fleet'][] = array( |
|
162
|
|
|
$ube_report_id, |
|
163
|
|
|
$fleet_info[UBE_OWNER], |
|
164
|
|
|
$fleet_id, |
|
165
|
|
|
|
|
166
|
|
|
(float)$fleet_info[UBE_PLANET][PLANET_ID], |
|
167
|
|
|
"'" . db_escape($fleet_info[UBE_PLANET][PLANET_NAME]) . "'", |
|
168
|
|
|
(int)$fleet_info[UBE_PLANET][PLANET_GALAXY], |
|
169
|
|
|
(int)$fleet_info[UBE_PLANET][PLANET_SYSTEM], |
|
170
|
|
|
(int)$fleet_info[UBE_PLANET][PLANET_PLANET], |
|
171
|
|
|
(int)$fleet_info[UBE_PLANET][PLANET_TYPE], |
|
172
|
|
|
|
|
173
|
|
|
(float)$fleet_info[UBE_RESOURCES][RES_METAL], |
|
174
|
|
|
(float)$fleet_info[UBE_RESOURCES][RES_CRYSTAL], |
|
175
|
|
|
(float)$fleet_info[UBE_RESOURCES][RES_DEUTERIUM], |
|
176
|
|
|
|
|
177
|
|
|
(float)$fleet_info[UBE_BONUSES][UBE_ATTACK], |
|
178
|
|
|
(float)$fleet_info[UBE_BONUSES][UBE_SHIELD], |
|
179
|
|
|
(float)$fleet_info[UBE_BONUSES][UBE_ARMOR], |
|
180
|
|
|
); |
|
181
|
|
|
|
|
182
|
|
|
// Сохраняем итоговую информацию по ресурсам флота - потеряно, выброшено, увезено |
|
183
|
|
|
$fleet_outcome_data = &$outcome[UBE_FLEETS][$fleet_id]; |
|
184
|
|
|
$sql_perform['ube_report_outcome_fleet'][] = array( |
|
185
|
|
|
$ube_report_id, |
|
186
|
|
|
$fleet_id, |
|
187
|
|
|
|
|
188
|
|
|
(float)$fleet_outcome_data[UBE_RESOURCES_LOST][RES_METAL], |
|
189
|
|
|
(float)$fleet_outcome_data[UBE_RESOURCES_LOST][RES_CRYSTAL], |
|
190
|
|
|
(float)$fleet_outcome_data[UBE_RESOURCES_LOST][RES_DEUTERIUM], |
|
191
|
|
|
|
|
192
|
|
|
(float)$fleet_outcome_data[UBE_CARGO_DROPPED][RES_METAL], |
|
193
|
|
|
(float)$fleet_outcome_data[UBE_CARGO_DROPPED][RES_CRYSTAL], |
|
194
|
|
|
(float)$fleet_outcome_data[UBE_CARGO_DROPPED][RES_DEUTERIUM], |
|
195
|
|
|
|
|
196
|
|
|
(float)$fleet_outcome_data[UBE_RESOURCES_LOOTED][RES_METAL], |
|
197
|
|
|
(float)$fleet_outcome_data[UBE_RESOURCES_LOOTED][RES_CRYSTAL], |
|
198
|
|
|
(float)$fleet_outcome_data[UBE_RESOURCES_LOOTED][RES_DEUTERIUM], |
|
199
|
|
|
|
|
200
|
|
|
(float)$fleet_outcome_data[UBE_RESOURCES_LOST_IN_METAL][RES_METAL], |
|
201
|
|
|
); |
|
202
|
|
|
|
|
203
|
|
|
// Сохраняем результаты по юнитам - потеряно и восстановлено |
|
204
|
|
|
foreach ($fleet_info[UBE_COUNT] as $unit_id => $unit_count) { |
|
205
|
|
|
if ($fleet_outcome_data[UBE_UNITS_LOST][$unit_id] || $fleet_outcome_data[UBE_DEFENCE_RESTORE][$unit_id]) { |
|
206
|
|
|
$unit_sort_order++; |
|
207
|
|
|
$sql_perform['ube_report_outcome_unit'][] = array( |
|
208
|
|
|
$ube_report_id, |
|
209
|
|
|
$fleet_id, |
|
210
|
|
|
|
|
211
|
|
|
$unit_id, |
|
212
|
|
|
(float)$fleet_outcome_data[UBE_DEFENCE_RESTORE][$unit_id], |
|
213
|
|
|
(float)$fleet_outcome_data[UBE_UNITS_LOST][$unit_id], |
|
214
|
|
|
|
|
215
|
|
|
$unit_sort_order, |
|
216
|
|
|
); |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
// Сохраняем информацию о раундах |
|
222
|
|
|
$unit_sort_order = 0; |
|
223
|
|
|
foreach ($combat_data[UBE_ROUNDS] as $round => &$round_data) { |
|
224
|
|
|
foreach ($round_data[UBE_FLEETS] as $fleet_id => &$fleet_data) { |
|
225
|
|
|
foreach ($fleet_data[UBE_COUNT] as $unit_id => $unit_count) { |
|
226
|
|
|
$unit_sort_order++; |
|
227
|
|
|
|
|
228
|
|
|
$sql_perform['ube_report_unit'][] = array( |
|
229
|
|
|
$ube_report_id, |
|
230
|
|
|
$fleet_data[UBE_FLEET_INFO][UBE_OWNER], |
|
231
|
|
|
$fleet_id, |
|
232
|
|
|
$round, |
|
233
|
|
|
|
|
234
|
|
|
$unit_id, |
|
235
|
|
|
$unit_count, |
|
236
|
|
|
(int)$fleet_data[UBE_UNITS_BOOM][$unit_id], |
|
237
|
|
|
|
|
238
|
|
|
$fleet_data[UBE_ATTACK][$unit_id], |
|
239
|
|
|
$fleet_data[UBE_SHIELD][$unit_id], |
|
240
|
|
|
$fleet_data[UBE_ARMOR][$unit_id], |
|
241
|
|
|
|
|
242
|
|
|
$fleet_data[UBE_ATTACK_BASE][$unit_id], |
|
243
|
|
|
$fleet_data[UBE_SHIELD_BASE][$unit_id], |
|
244
|
|
|
$fleet_data[UBE_ARMOR_BASE][$unit_id], |
|
245
|
|
|
|
|
246
|
|
|
$unit_sort_order, |
|
247
|
|
|
); |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
// Пакетная вставка данных |
|
253
|
|
|
foreach ($sql_perform as $table_name => $table_data) { |
|
254
|
|
|
if (count($table_data) < 2) { |
|
255
|
|
|
continue; |
|
256
|
|
|
} |
|
257
|
|
|
foreach ($table_data as &$record_data) { |
|
258
|
|
|
$record_data = '(' . implode(',', $record_data) . ')'; |
|
259
|
|
|
} |
|
260
|
|
|
$fields = $table_data[0]; |
|
261
|
|
|
unset($table_data[0]); |
|
262
|
|
|
doquery("INSERT INTO {{{$table_name}}} {$fields} VALUES " . implode(',', $table_data)); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
return $combat_data[UBE_REPORT_CYPHER]; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
269
|
|
|
// Читает боевой отчет из БД |
|
270
|
|
|
function sn_ube_report_load($report_cypher) { |
|
271
|
|
|
$report_cypher = db_escape($report_cypher); |
|
272
|
|
|
|
|
273
|
|
|
$report_row = doquery("SELECT * FROM {{ube_report}} WHERE ube_report_cypher = '{$report_cypher}' LIMIT 1", true); |
|
274
|
|
|
if (!$report_row) { |
|
275
|
|
|
return UBE_REPORT_NOT_FOUND; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
$combat_data = array( |
|
279
|
|
|
UBE_OPTIONS => array( |
|
280
|
|
|
UBE_LOADED => true, |
|
281
|
|
|
UBE_COMBAT_ADMIN => $report_row['ube_report_combat_admin'], |
|
282
|
|
|
UBE_MISSION_TYPE => $report_row['ube_report_mission_type'], |
|
283
|
|
|
), |
|
284
|
|
|
|
|
285
|
|
|
UBE_TIME => strtotime($report_row['ube_report_time_combat']), |
|
286
|
|
|
UBE_TIME_SPENT => $report_row['ube_report_time_spent'], |
|
287
|
|
|
UBE_REPORT_CYPHER => $report_cypher, |
|
288
|
|
|
UBE_REPORT_ID => $report_row['ube_report_id'], |
|
289
|
|
|
|
|
290
|
|
|
UBE_OUTCOME => array( |
|
291
|
|
|
UBE_COMBAT_RESULT => $report_row['ube_report_combat_result'], |
|
292
|
|
|
UBE_SFR => $report_row['ube_report_combat_sfr'], |
|
293
|
|
|
|
|
294
|
|
|
UBE_PLANET => array( |
|
295
|
|
|
PLANET_ID => $report_row['ube_report_planet_id'], |
|
296
|
|
|
PLANET_NAME => $report_row['ube_report_planet_name'], |
|
297
|
|
|
PLANET_SIZE => $report_row['ube_report_planet_size'], |
|
298
|
|
|
PLANET_GALAXY => $report_row['ube_report_planet_galaxy'], |
|
299
|
|
|
PLANET_SYSTEM => $report_row['ube_report_planet_system'], |
|
300
|
|
|
PLANET_PLANET => $report_row['ube_report_planet_planet'], |
|
301
|
|
|
PLANET_TYPE => $report_row['ube_report_planet_planet_type'], |
|
302
|
|
|
), |
|
303
|
|
|
|
|
304
|
|
|
UBE_DEBRIS => array( |
|
305
|
|
|
RES_METAL => $report_row['ube_report_debris_metal'], |
|
306
|
|
|
RES_CRYSTAL => $report_row['ube_report_debris_crystal'], |
|
307
|
|
|
), |
|
308
|
|
|
|
|
309
|
|
|
UBE_MOON => $report_row['ube_report_moon'], |
|
310
|
|
|
UBE_MOON_CHANCE => $report_row['ube_report_moon_chance'], |
|
311
|
|
|
UBE_MOON_SIZE => $report_row['ube_report_moon_size'], |
|
312
|
|
|
|
|
313
|
|
|
UBE_MOON_REAPERS => $report_row['ube_report_moon_reapers'], |
|
314
|
|
|
UBE_MOON_DESTROY_CHANCE => $report_row['ube_report_moon_destroy_chance'], |
|
315
|
|
|
UBE_MOON_REAPERS_DIE_CHANCE => $report_row['ube_report_moon_reapers_die_chance'], |
|
316
|
|
|
|
|
317
|
|
|
UBE_CAPTURE_RESULT => $report_row['ube_report_capture_result'], |
|
318
|
|
|
|
|
319
|
|
|
UBE_ATTACKERS => array(), |
|
320
|
|
|
UBE_DEFENDERS => array(), |
|
321
|
|
|
), |
|
322
|
|
|
); |
|
323
|
|
|
|
|
324
|
|
|
$outcome = &$combat_data[UBE_OUTCOME]; |
|
325
|
|
|
|
|
326
|
|
|
$query = doquery("SELECT * FROM {{ube_report_player}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
|
327
|
|
|
while ($player_row = db_fetch($query)) { |
|
328
|
|
|
$combat_data[UBE_PLAYERS][$player_row['ube_report_player_player_id']] = array( |
|
329
|
|
|
UBE_NAME => $player_row['ube_report_player_name'], |
|
330
|
|
|
UBE_ATTACKER => $player_row['ube_report_player_attacker'], |
|
331
|
|
|
|
|
332
|
|
|
UBE_BONUSES => array( |
|
333
|
|
|
UBE_ATTACK => $player_row['ube_report_player_bonus_attack'], |
|
334
|
|
|
UBE_SHIELD => $player_row['ube_report_player_bonus_shield'], |
|
335
|
|
|
UBE_ARMOR => $player_row['ube_report_player_bonus_armor'], |
|
336
|
|
|
), |
|
337
|
|
|
); |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
$query = doquery("SELECT * FROM {{ube_report_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
|
341
|
|
|
while ($fleet_row = db_fetch($query)) { |
|
342
|
|
|
$combat_data[UBE_FLEETS][$fleet_row['ube_report_fleet_fleet_id']] = array( |
|
343
|
|
|
UBE_OWNER => $fleet_row['ube_report_fleet_player_id'], |
|
344
|
|
|
|
|
345
|
|
|
UBE_FLEET_TYPE => $combat_data[UBE_PLAYERS][$fleet_row['ube_report_fleet_player_id']][UBE_ATTACKER] ? UBE_ATTACKERS : UBE_DEFENDERS, |
|
346
|
|
|
|
|
347
|
|
|
UBE_PLANET => array( |
|
348
|
|
|
PLANET_ID => $fleet_row['ube_report_fleet_planet_id'], |
|
349
|
|
|
PLANET_NAME => $fleet_row['ube_report_fleet_planet_name'], |
|
350
|
|
|
PLANET_GALAXY => $fleet_row['ube_report_fleet_planet_galaxy'], |
|
351
|
|
|
PLANET_SYSTEM => $fleet_row['ube_report_fleet_planet_system'], |
|
352
|
|
|
PLANET_PLANET => $fleet_row['ube_report_fleet_planet_planet'], |
|
353
|
|
|
PLANET_TYPE => $fleet_row['ube_report_fleet_planet_planet_type'], |
|
354
|
|
|
), |
|
355
|
|
|
|
|
356
|
|
|
UBE_BONUSES => array( |
|
357
|
|
|
UBE_ATTACK => $player_row['ube_report_fleet_bonus_attack'], |
|
358
|
|
|
UBE_SHIELD => $player_row['ube_report_fleet_bonus_shield'], |
|
359
|
|
|
UBE_ARMOR => $player_row['ube_report_fleet_bonus_armor'], |
|
360
|
|
|
), |
|
361
|
|
|
|
|
362
|
|
|
UBE_RESOURCES => array( |
|
363
|
|
|
RES_METAL => $player_row['ube_report_fleet_resource_metal'], |
|
364
|
|
|
RES_CRYSTAL => $player_row['ube_report_fleet_resource_crystal'], |
|
365
|
|
|
RES_DEUTERIUM => $player_row['ube_report_fleet_resource_deuterium'], |
|
366
|
|
|
), |
|
367
|
|
|
); |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
$combat_data[UBE_ROUNDS] = array(); |
|
371
|
|
|
$rounds_data = &$combat_data[UBE_ROUNDS]; |
|
372
|
|
|
|
|
373
|
|
|
$query = doquery("SELECT * FROM {{ube_report_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_unit_sort_order`"); |
|
374
|
|
|
while ($round_row = db_fetch($query)) { |
|
375
|
|
|
$round = $round_row['ube_report_unit_round']; |
|
376
|
|
|
$fleet_id = $round_row['ube_report_unit_fleet_id']; |
|
377
|
|
|
|
|
378
|
|
|
$side = $combat_data[UBE_FLEETS][$fleet_id][UBE_FLEET_TYPE]; |
|
379
|
|
|
$rounds_data[$round][$side][UBE_ATTACK][$fleet_id] = 0; |
|
380
|
|
|
|
|
381
|
|
|
if (!isset($rounds_data[$round][UBE_FLEETS][$fleet_id])) { |
|
382
|
|
|
$rounds_data[$round][UBE_FLEETS][$fleet_id] = array(); |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
$round_fleet_data = &$rounds_data[$round][UBE_FLEETS][$fleet_id]; |
|
386
|
|
|
$unit_id = $round_row['ube_report_unit_unit_id']; |
|
387
|
|
|
$round_fleet_data[UBE_COUNT][$unit_id] = $round_row['ube_report_unit_count']; |
|
388
|
|
|
$round_fleet_data[UBE_UNITS_BOOM][$unit_id] = $round_row['ube_report_unit_boom']; |
|
389
|
|
|
|
|
390
|
|
|
$round_fleet_data[UBE_ATTACK][$unit_id] = $round_row['ube_report_unit_attack']; |
|
391
|
|
|
$round_fleet_data[UBE_SHIELD][$unit_id] = $round_row['ube_report_unit_shield']; |
|
392
|
|
|
$round_fleet_data[UBE_ARMOR][$unit_id] = $round_row['ube_report_unit_armor']; |
|
393
|
|
|
|
|
394
|
|
|
$round_fleet_data[UBE_ATTACK_BASE][$unit_id] = $round_row['ube_report_unit_attack_base']; |
|
395
|
|
|
$round_fleet_data[UBE_SHIELD_BASE][$unit_id] = $round_row['ube_report_unit_shield_base']; |
|
396
|
|
|
$round_fleet_data[UBE_ARMOR_BASE][$unit_id] = $round_row['ube_report_unit_armor_base']; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
|
|
400
|
|
|
$query = doquery("SELECT * FROM {{ube_report_outcome_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
|
401
|
|
|
while ($row = db_fetch($query)) { |
|
402
|
|
|
$fleet_id = $row['ube_report_outcome_fleet_fleet_id']; |
|
403
|
|
|
|
|
404
|
|
|
$outcome[UBE_FLEETS][$fleet_id] = array( |
|
405
|
|
|
UBE_RESOURCES_LOST => array( |
|
406
|
|
|
RES_METAL => $row['ube_report_outcome_fleet_resource_lost_metal'], |
|
407
|
|
|
RES_CRYSTAL => $row['ube_report_outcome_fleet_resource_lost_crystal'], |
|
408
|
|
|
RES_DEUTERIUM => $row['ube_report_outcome_fleet_resource_lost_deuterium'], |
|
409
|
|
|
), |
|
410
|
|
|
|
|
411
|
|
|
UBE_CARGO_DROPPED => array( |
|
412
|
|
|
RES_METAL => $row['ube_report_outcome_fleet_resource_dropped_metal'], |
|
413
|
|
|
RES_CRYSTAL => $row['ube_report_outcome_fleet_resource_dropped_crystal'], |
|
414
|
|
|
RES_DEUTERIUM => $row['ube_report_outcome_fleet_resource_dropped_deuterium'], |
|
415
|
|
|
), |
|
416
|
|
|
|
|
417
|
|
|
UBE_RESOURCES_LOOTED => array( |
|
418
|
|
|
RES_METAL => $row['ube_report_outcome_fleet_resource_loot_metal'], |
|
419
|
|
|
RES_CRYSTAL => $row['ube_report_outcome_fleet_resource_loot_crystal'], |
|
420
|
|
|
RES_DEUTERIUM => $row['ube_report_outcome_fleet_resource_loot_deuterium'], |
|
421
|
|
|
), |
|
422
|
|
|
|
|
423
|
|
|
UBE_RESOURCES_LOST_IN_METAL => array( |
|
424
|
|
|
RES_METAL => $row['ube_report_outcome_fleet_resource_lost_in_metal'], |
|
425
|
|
|
), |
|
426
|
|
|
); |
|
427
|
|
|
|
|
428
|
|
|
$side = $combat_data[UBE_FLEETS][$fleet_id][UBE_FLEET_TYPE]; |
|
429
|
|
|
|
|
430
|
|
|
$outcome[$side][UBE_FLEETS][$fleet_id] = &$outcome[UBE_FLEETS][$fleet_id]; |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
$query = doquery("SELECT * FROM {{ube_report_outcome_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_outcome_unit_sort_order`"); |
|
434
|
|
|
while ($row = db_fetch($query)) { |
|
435
|
|
|
$fleet_id = $row['ube_report_outcome_unit_fleet_id']; |
|
436
|
|
|
$side = $combat_data[UBE_FLEETS][$fleet_id][UBE_FLEET_TYPE]; |
|
437
|
|
|
$outcome[$side][UBE_FLEETS][$fleet_id][UBE_UNITS_LOST][$row['ube_report_outcome_unit_unit_id']] = $row['ube_report_outcome_unit_lost']; |
|
438
|
|
|
$outcome[$side][UBE_FLEETS][$fleet_id][UBE_DEFENCE_RESTORE][$row['ube_report_outcome_unit_unit_id']] = $row['ube_report_outcome_unit_restored']; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
return $combat_data; |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
|
|
445
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
446
|
|
|
// Парсит инфу о раунде для темплейта |
|
447
|
|
|
function sn_ube_report_round_fleet(&$combat_data, $round) { |
|
448
|
|
|
global $lang; |
|
|
|
|
|
|
449
|
|
|
|
|
450
|
|
|
$fleets_info = &$combat_data[UBE_FLEETS]; |
|
451
|
|
|
$round_template = array(); |
|
452
|
|
|
$round_data = &$combat_data[UBE_ROUNDS][$round]; |
|
453
|
|
|
foreach (array(UBE_ATTACKERS, UBE_DEFENDERS) as $side) { |
|
454
|
|
|
$round_data[$side][UBE_ATTACK] = $round_data[$side][UBE_ATTACK] ? $round_data[$side][UBE_ATTACK] : array(); |
|
455
|
|
|
foreach ($round_data[$side][UBE_ATTACK] as $fleet_id => $temp) { |
|
456
|
|
|
$fleet_data = &$round_data[UBE_FLEETS][$fleet_id]; |
|
457
|
|
|
$fleet_data_prev = &$combat_data[UBE_ROUNDS][$round - 1][UBE_FLEETS][$fleet_id]; |
|
458
|
|
|
$fleet_template = array( |
|
459
|
|
|
'ID' => $fleet_id, |
|
460
|
|
|
'IS_ATTACKER' => $side == UBE_ATTACKERS, |
|
461
|
|
|
'PLAYER_NAME' => htmlentities($combat_data[UBE_PLAYERS][$fleets_info[$fleet_id][UBE_OWNER]][UBE_NAME], ENT_COMPAT, 'UTF-8'), |
|
462
|
|
|
); |
|
463
|
|
|
|
|
464
|
|
|
if (is_array($combat_data[UBE_FLEETS][$fleet_id][UBE_PLANET])) { |
|
465
|
|
|
$fleet_template += $combat_data[UBE_FLEETS][$fleet_id][UBE_PLANET]; |
|
466
|
|
|
$fleet_template[PLANET_NAME] = $fleet_template[PLANET_NAME] ? htmlentities($fleet_template[PLANET_NAME], ENT_COMPAT, 'UTF-8') : ''; |
|
467
|
|
|
$fleet_template['PLANET_TYPE_TEXT'] = $lang['sys_planet_type_sh'][$fleet_template['PLANET_TYPE']]; |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
foreach ($fleet_data[UBE_COUNT] as $unit_id => $unit_count) { |
|
471
|
|
|
$shields_original = $fleet_data[UBE_SHIELD_BASE][$unit_id] * $fleet_data_prev[UBE_COUNT][$unit_id]; |
|
472
|
|
|
$ship_template = array( |
|
473
|
|
|
'ID' => $unit_id, |
|
474
|
|
|
'NAME' => $lang['tech'][$unit_id], |
|
475
|
|
|
'ATTACK' => HelperString::numberFloorAndFormat($fleet_data[UBE_ATTACK][$unit_id]), |
|
476
|
|
|
'SHIELD' => HelperString::numberFloorAndFormat($shields_original), |
|
477
|
|
|
'SHIELD_LOST' => HelperString::numberFloorAndFormat($shields_original - $fleet_data[UBE_SHIELD][$unit_id]), |
|
478
|
|
|
'ARMOR' => HelperString::numberFloorAndFormat($fleet_data_prev[UBE_ARMOR][$unit_id]), |
|
479
|
|
|
'ARMOR_LOST' => HelperString::numberFloorAndFormat($fleet_data_prev[UBE_ARMOR][$unit_id] - $fleet_data[UBE_ARMOR][$unit_id]), |
|
480
|
|
|
'UNITS' => HelperString::numberFloorAndFormat($fleet_data_prev[UBE_COUNT][$unit_id]), |
|
481
|
|
|
'UNITS_LOST' => HelperString::numberFloorAndFormat($fleet_data_prev[UBE_COUNT][$unit_id] - $fleet_data[UBE_COUNT][$unit_id]), |
|
482
|
|
|
'UNITS_BOOM' => HelperString::numberFloorAndFormat($fleet_data[UBE_UNITS_BOOM][$unit_id]), |
|
483
|
|
|
); |
|
484
|
|
|
|
|
485
|
|
|
$fleet_template['.']['ship'][] = $ship_template; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
$round_template[] = $fleet_template; |
|
489
|
|
|
} |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
return $round_template; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
496
|
|
|
// Рендерит таблицу общего результата боя |
|
497
|
|
|
function sn_ube_report_table_render(&$array, $header) { |
|
498
|
|
|
global $lang; |
|
|
|
|
|
|
499
|
|
|
|
|
500
|
|
|
$result = array(); |
|
501
|
|
|
if (!empty($array)) { |
|
502
|
|
|
foreach ($array as $unit_id => $unit_count) { |
|
503
|
|
|
if ($unit_count) { |
|
504
|
|
|
$result[] = array( |
|
505
|
|
|
'NAME' => $lang['tech'][$unit_id], |
|
506
|
|
|
'LOSS' => HelperString::numberFloorAndFormat($unit_count), |
|
507
|
|
|
); |
|
508
|
|
|
} |
|
509
|
|
|
} |
|
510
|
|
|
if ($header && count($result)) { |
|
511
|
|
|
array_unshift($result, array('NAME' => $header)); |
|
512
|
|
|
} |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
return $result; |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
// ------------------------------------------------------------------------------------------------ |
|
519
|
|
|
// Генерирует данные для отчета из разобранных данных боя |
|
520
|
|
|
function sn_ube_report_generate(&$combat_data, &$template_result) { |
|
521
|
|
|
if (!is_array($combat_data)) { |
|
522
|
|
|
return; |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
global $lang; |
|
|
|
|
|
|
526
|
|
|
|
|
527
|
|
|
// Обсчитываем результаты боя из начальных данных |
|
528
|
|
|
$players_info = &$combat_data[UBE_PLAYERS]; |
|
529
|
|
|
$fleets_info = &$combat_data[UBE_FLEETS]; |
|
530
|
|
|
$outcome = &$combat_data[UBE_OUTCOME]; |
|
531
|
|
|
// Генерируем отчет по флотам |
|
532
|
|
|
for ($round = 1; $round <= count($combat_data[UBE_ROUNDS]) - 1; $round++) { |
|
533
|
|
|
$round_template = array( |
|
534
|
|
|
'NUMBER' => $round, |
|
535
|
|
|
'.' => array( |
|
536
|
|
|
'fleet' => sn_ube_report_round_fleet($combat_data, $round), |
|
537
|
|
|
), |
|
538
|
|
|
); |
|
539
|
|
|
$template_result['.']['round'][] = $round_template; |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
// Боевые потери флотов |
|
543
|
|
|
foreach (array(UBE_ATTACKERS, UBE_DEFENDERS) as $side) { |
|
544
|
|
|
if (!is_array($outcome[$side][UBE_FLEETS])) { |
|
545
|
|
|
continue; |
|
546
|
|
|
} |
|
547
|
|
|
foreach ($outcome[$side][UBE_FLEETS] as $fleet_id => $temp) { |
|
548
|
|
|
$player_info = &$players_info[$fleets_info[$fleet_id][UBE_OWNER]]; |
|
549
|
|
|
$fleet_outcome = &$outcome[UBE_FLEETS][$fleet_id]; |
|
550
|
|
|
|
|
551
|
|
|
$template_result['.']['loss'][] = array( |
|
552
|
|
|
'ID' => $fleet_id, |
|
553
|
|
|
'NAME' => $player_info[UBE_NAME], |
|
554
|
|
|
'IS_ATTACKER' => $player_info[UBE_ATTACKER], |
|
555
|
|
|
'.' => array( |
|
556
|
|
|
'param' => array_merge( |
|
557
|
|
|
sn_ube_report_table_render($fleet_outcome[UBE_DEFENCE_RESTORE], $lang['ube_report_info_restored']), |
|
558
|
|
|
sn_ube_report_table_render($fleet_outcome[UBE_UNITS_LOST], $lang['ube_report_info_loss_final']), |
|
559
|
|
|
sn_ube_report_table_render($fleet_outcome[UBE_RESOURCES_LOST], $lang['ube_report_info_loss_resources']), |
|
560
|
|
|
sn_ube_report_table_render($fleet_outcome[UBE_CARGO_DROPPED], $lang['ube_report_info_loss_dropped']), |
|
561
|
|
|
sn_ube_report_table_render($fleet_outcome[UBE_RESOURCES_LOOTED], $lang[$player_info[UBE_ATTACKER] ? 'ube_report_info_loot_lost' : 'ube_report_info_loss_gained']), |
|
562
|
|
|
sn_ube_report_table_render($fleet_outcome[UBE_RESOURCES_LOST_IN_METAL], $lang['ube_report_info_loss_in_metal']) |
|
563
|
|
|
), |
|
564
|
|
|
), |
|
565
|
|
|
); |
|
566
|
|
|
} |
|
567
|
|
|
} |
|
568
|
|
|
|
|
569
|
|
|
// Обломки |
|
570
|
|
|
$debrisOutcome = $combat_data[UBE_OPTIONS][UBE_SIMULATOR] ? $outcome[UBE_DEBRIS_ORIGINAL] : $outcome[UBE_DEBRIS]; |
|
571
|
|
|
$debris = []; |
|
572
|
|
|
foreach ([RES_METAL, RES_CRYSTAL] as $resource_id) { |
|
573
|
|
|
if ($resource_amount = $debrisOutcome[$resource_id]) { |
|
574
|
|
|
$debris[] = array( |
|
575
|
|
|
'NAME' => $lang['tech'][$resource_id], |
|
576
|
|
|
'AMOUNT' => HelperString::numberFloorAndFormat($resource_amount), |
|
577
|
|
|
); |
|
578
|
|
|
} |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
// TODO: $combat_data[UBE_OPTIONS][UBE_COMBAT_ADMIN] - если админский бой не генерировать осколки и не делать луну. Сделать серверную опцию |
|
582
|
|
|
|
|
583
|
|
|
// Координаты, тип и название планеты - если есть |
|
584
|
|
|
//R $planet_owner_id = $combat_data[UBE_FLEETS][0][UBE_OWNER]; |
|
585
|
|
|
if (isset($combat_data[UBE_OUTCOME][UBE_PLANET])) { |
|
586
|
|
|
$template_result += $combat_data[UBE_OUTCOME][UBE_PLANET]; |
|
587
|
|
|
$template_result[PLANET_NAME] = str_replace(' ', ' ', htmlentities($template_result[PLANET_NAME], ENT_COMPAT, 'UTF-8')); |
|
588
|
|
|
} |
|
589
|
|
|
|
|
590
|
|
|
/** @noinspection SpellCheckingInspection */ |
|
591
|
|
|
$template_result += array( |
|
592
|
|
|
'MICROTIME' => $combat_data[UBE_TIME_SPENT], |
|
593
|
|
|
'COMBAT_TIME' => $combat_data[UBE_TIME] ? $combat_data[UBE_TIME] + SN_CLIENT_TIME_DIFF : 0, |
|
594
|
|
|
'COMBAT_TIME_TEXT' => date(FMT_DATE_TIME, $combat_data[UBE_TIME] + SN_CLIENT_TIME_DIFF), |
|
595
|
|
|
'COMBAT_ROUNDS' => count($combat_data[UBE_ROUNDS]) - 1, |
|
596
|
|
|
'UBE_MISSION_TYPE' => $combat_data[UBE_OPTIONS][UBE_MISSION_TYPE], |
|
597
|
|
|
'MT_DESTROY' => MT_DESTROY, |
|
598
|
|
|
'UBE_REPORT_CYPHER' => $combat_data[UBE_REPORT_CYPHER], |
|
599
|
|
|
'UBE_IS_SIMULATOR' => $combat_data[UBE_OPTIONS][UBE_SIMULATOR], |
|
600
|
|
|
|
|
601
|
|
|
'PLANET_TYPE_TEXT' => $lang['sys_planet_type_sh'][$template_result['PLANET_TYPE']], |
|
602
|
|
|
|
|
603
|
|
|
'UBE_MOON' => $outcome[UBE_MOON], |
|
604
|
|
|
'UBE_MOON_CHANCE' => round($outcome[UBE_MOON_CHANCE], 2), |
|
605
|
|
|
'UBE_MOON_SIZE' => $outcome[UBE_MOON_SIZE], |
|
606
|
|
|
'UBE_MOON_REAPERS' => $outcome[UBE_MOON_REAPERS], |
|
607
|
|
|
'UBE_MOON_DESTROY_CHANCE' => $outcome[UBE_MOON_DESTROY_CHANCE], |
|
608
|
|
|
'UBE_MOON_REAPERS_DIE_CHANCE' => $outcome[UBE_MOON_REAPERS_DIE_CHANCE], |
|
609
|
|
|
|
|
610
|
|
|
'UBE_MOON_WAS' => UBE_MOON_WAS, |
|
611
|
|
|
'UBE_MOON_NONE' => UBE_MOON_NONE, |
|
612
|
|
|
'UBE_MOON_CREATE_SUCCESS' => UBE_MOON_CREATE_SUCCESS, |
|
613
|
|
|
'UBE_MOON_CREATE_FAILED' => UBE_MOON_CREATE_FAILED, |
|
614
|
|
|
'UBE_MOON_REAPERS_NONE' => UBE_MOON_REAPERS_NONE, |
|
615
|
|
|
'UBE_MOON_DESTROY_SUCCESS' => UBE_MOON_DESTROY_SUCCESS, |
|
616
|
|
|
'UBE_MOON_REAPERS_RETURNED' => UBE_MOON_REAPERS_RETURNED, |
|
617
|
|
|
|
|
618
|
|
|
'UBE_CAPTURE_RESULT' => $combat_data[UBE_OUTCOME][UBE_CAPTURE_RESULT], |
|
619
|
|
|
'UBE_CAPTURE_RESULT_TEXT' => $lang['ube_report_capture_result'][$combat_data[UBE_OUTCOME][UBE_CAPTURE_RESULT]], |
|
620
|
|
|
|
|
621
|
|
|
'UBE_SFR' => $outcome[UBE_SFR], |
|
622
|
|
|
'UBE_COMBAT_RESULT' => $outcome[UBE_COMBAT_RESULT], |
|
623
|
|
|
'UBE_COMBAT_RESULT_WIN' => UBE_COMBAT_RESULT_WIN, |
|
624
|
|
|
'UBE_COMBAT_RESULT_LOSS' => UBE_COMBAT_RESULT_LOSS, |
|
625
|
|
|
); |
|
626
|
|
|
$template_result['.']['debris'] = $debris; |
|
627
|
|
|
} |
|
628
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state