1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use DBStatic\DBStaticFleetACS; |
4
|
|
|
use DBStatic\DBStaticFleetBashing; |
5
|
|
|
use DBStatic\DBStaticMessages; |
6
|
|
|
use DBStatic\DBStaticPlanet; |
7
|
|
|
use DBStatic\DBStaticUnit; |
8
|
|
|
use DBStatic\DBStaticUser; |
9
|
|
|
use Mission\Mission; |
10
|
|
|
|
11
|
|
|
class UBE { |
12
|
|
|
/** |
13
|
|
|
* Кодовая строка для доступа к отчёту |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
public $report_cypher = ''; |
18
|
|
|
/** |
19
|
|
|
* Время, когда произошел бой - НЕ ВРЕМЯ, КОГДА ОН ОБСЧИТАН! |
20
|
|
|
* |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
public $combat_timestamp = 0; |
24
|
|
|
/** |
25
|
|
|
* Время, потраченное на обсчёт |
26
|
|
|
* |
27
|
|
|
* @var float |
28
|
|
|
*/ |
29
|
|
|
public $time_spent = 0; |
30
|
|
|
public $options_method = 0; |
31
|
|
|
/** |
32
|
|
|
* Является ли этот экземпляр боя загруженным из БД |
33
|
|
|
* |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
public $is_ube_loaded = false; |
37
|
|
|
public $is_admin_in_combat = false; |
38
|
|
|
public $is_defender_active_player = true; |
39
|
|
|
public $is_simulator = false; |
40
|
|
|
|
41
|
|
|
public $mission_type_id = MT_NONE; |
42
|
|
|
public $combat_result = UBE_COMBAT_RESULT_DRAW; |
43
|
|
|
/** |
44
|
|
|
* Флаг РМФ |
45
|
|
|
* |
46
|
|
|
* @var int |
47
|
|
|
*/ |
48
|
|
|
public $is_small_fleet_recce = 0; |
49
|
|
|
public $capture_result = UBE_CAPTURE_DISABLED; |
50
|
|
|
/** |
51
|
|
|
* [$resource_id] => $rate |
52
|
|
|
* |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
public $resource_exchange_rates = array(); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var Mission $combatMission |
59
|
|
|
*/ |
60
|
|
|
public $combatMission = null; |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var UBEPlayerList |
65
|
|
|
*/ |
66
|
|
|
public $players = null; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var UBEFleetList |
70
|
|
|
*/ |
71
|
|
|
public $fleet_list = null; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var UBERoundList |
75
|
|
|
*/ |
76
|
|
|
public $rounds = null; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var UBEMoonCalculator |
80
|
|
|
*/ |
81
|
|
|
public $moon_calculator = null; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var UBEDebris |
85
|
|
|
*/ |
86
|
|
|
public $debris = null; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var array |
90
|
|
|
*/ |
91
|
|
|
public $ube_planet_info = array( |
92
|
|
|
// PLANET_ID => $report_row['ube_report_planet_id'], |
|
|
|
|
93
|
|
|
// PLANET_NAME => $report_row['ube_report_planet_name'], |
94
|
|
|
// PLANET_SIZE => $report_row['ube_report_planet_size'], |
95
|
|
|
// PLANET_GALAXY => $report_row['ube_report_planet_galaxy'], |
96
|
|
|
// PLANET_SYSTEM => $report_row['ube_report_planet_system'], |
97
|
|
|
// PLANET_PLANET => $report_row['ube_report_planet_planet'], |
98
|
|
|
// PLANET_TYPE => $report_row['ube_report_planet_planet_type'], |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var Bonus $planet_bonus |
103
|
|
|
*/ |
104
|
|
|
public $planet_bonus = null; |
105
|
|
|
|
106
|
|
|
public function __construct() { |
107
|
|
|
$this->players = new UBEPlayerList(); |
108
|
|
|
$this->fleet_list = new UBEFleetList(); |
109
|
|
|
$this->moon_calculator = new UBEMoonCalculator(); |
110
|
|
|
$this->debris = new UBEDebris(); |
111
|
|
|
$this->rounds = new UBERoundList(); |
112
|
|
|
$this->planet_bonus = new Bonus(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Заполняет начальные данные по данным миссии |
117
|
|
|
* |
118
|
|
|
* @param Mission $objMission |
119
|
|
|
* |
120
|
|
|
*/ |
121
|
|
|
public function loadDataFromMission(&$objMission) { |
122
|
|
|
$this->combatMission = $objMission; |
123
|
|
|
|
124
|
|
|
// Готовим опции |
125
|
|
|
$this->resource_exchange_rates = get_resource_exchange(); |
126
|
|
|
$this->set_option_from_config(); |
127
|
|
|
|
128
|
|
|
$this->combat_timestamp = $this->combatMission->fleet->time_arrive_to_target; |
129
|
|
|
$this->mission_type_id = $this->combatMission->fleet->mission_type; |
130
|
|
|
|
131
|
|
|
// Готовим инфу по атакующим |
132
|
|
|
$this->fleet_list->ubeInitGetAttackers($this->combatMission->fleet, $this->players); |
133
|
|
|
|
134
|
|
|
// Готовим инфу по удержанию |
135
|
|
|
$this->fleet_list->ubeInitGetFleetsOnHold($this->combatMission->fleet, $this->players); |
136
|
|
|
|
137
|
|
|
// Готовим инфу по атакуемой планете |
138
|
|
|
$this->ubeInitPreparePlanet(); |
139
|
|
|
|
140
|
|
|
$this->moon_calculator->ubeInitLoadStatis($this->combatMission->dst_planet); |
141
|
|
|
$this->is_admin_in_combat = $this->players->authLevelMax > 0; // Участвует ли админ в бою? |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Заполняет данные по планете |
146
|
|
|
*/ |
147
|
|
|
public function ubeInitPreparePlanet() { |
148
|
|
|
$player_id = $this->combatMission->dst_planet['id_owner']; |
149
|
|
|
|
150
|
|
|
$this->players->db_load_player_by_id($player_id, UBE_PLAYER_IS_DEFENDER); |
151
|
|
|
|
152
|
|
|
$player_db_row = $this->players[$player_id]->getDbRow(); |
153
|
|
|
if($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) { |
154
|
|
|
$this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $fortifier_level); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$this->fleet_list->ube_insert_from_planet_row($this->combatMission->dst_planet, $this->players[$player_id], $this->planet_bonus); |
158
|
|
|
|
159
|
|
|
$this->fleet_list->ube_load_from_players($this->players); |
160
|
|
|
|
161
|
|
|
$this->ube_planet_info = $this->fleet_list[0]->UBE_PLANET; |
162
|
|
|
$this->is_defender_active_player = $player_db_row['onlinetime'] >= $this->combat_timestamp - UBE_DEFENDER_ACTIVE_TIMEOUT; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Общий алгоритм расчета боя |
167
|
|
|
* |
168
|
|
|
*/ |
169
|
|
|
protected function sn_ube_combat() { |
170
|
|
|
// TODO: Сделать атаку по типам, когда они будут |
171
|
|
|
//$this->is_simulator = true; |
172
|
|
|
$start = microtime(true); |
173
|
|
|
|
174
|
|
|
// Готовим информацию для первого раунда - проводим все нужные вычисления из исходных данных |
175
|
|
|
pvar_dump($this->fleet_list[79]); |
176
|
|
|
// TODO - тут уже должна быть подсчитана вся инфа для боя, откуда бы не пришли данные - из симулятора или из миссии |
177
|
|
|
$this->fleet_list->ube_prepare_for_next_round($this->is_simulator); |
178
|
|
|
pvar_dump($this->fleet_list[79]); |
179
|
|
|
pdie(); |
180
|
|
|
|
181
|
|
|
$this->rounds[0] = new UBERound(0); |
182
|
|
|
$this->rounds[0]->make_snapshot($this->fleet_list); |
183
|
|
|
|
184
|
|
|
for($round = 1; $round <= 10; $round++) { |
185
|
|
|
// Проводим раунд |
186
|
|
|
defined('DEBUG_UBE') ? print("Round {$round}<br>") : false; |
187
|
|
|
|
188
|
|
|
$this->fleet_list->ube_calculate_attack_results($this); |
189
|
|
|
|
190
|
|
|
defined('DEBUG_UBE') ? print('<hr>') : false; |
191
|
|
|
|
192
|
|
|
$this->rounds[$round] = new UBERound($round); |
193
|
|
|
$this->rounds[$round]->make_snapshot($this->fleet_list); |
194
|
|
|
|
195
|
|
|
// Анализируем итоги текущего раунда и готовим данные для следующего |
196
|
|
|
$this->combat_result = $this->fleet_list->ubeAnalyzeFleetOutcome($round); |
197
|
|
|
if($this->combat_result != UBE_COMBAT_RESULT_DRAW) { |
198
|
|
|
break; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
// Готовим данные для раунда |
202
|
|
|
$this->fleet_list->ube_prepare_for_next_round($this->is_simulator); |
203
|
|
|
} |
204
|
|
|
$this->time_spent = microtime(true) - $start; |
205
|
|
|
|
206
|
|
|
// Делать это всегда - нам нужны результаты боя: луна->обломки->количество осташихся юнитов |
207
|
|
|
$this->sn_ube_combat_analyze(); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Разбирает данные боя для генерации отчета |
213
|
|
|
* |
214
|
|
|
* @version 2016-02-25 23:42:45 41a4.68 |
215
|
|
|
*/ |
216
|
|
|
public function sn_ube_combat_analyze() { |
217
|
|
|
// $lastRound = $this->rounds->get_last_element(); |
|
|
|
|
218
|
|
|
// $this->combat_result = !isset($lastRound->round_outcome) || $lastRound->round_outcome == UBE_COMBAT_RESULT_DRAW_END ? UBE_COMBAT_RESULT_DRAW : $lastRound->round_outcome; |
219
|
|
|
// SFR - Small Fleet Reconnaissance ака РМФ |
220
|
|
|
$this->is_small_fleet_recce = $this->rounds->count() == 2 && $this->combat_result == UBE_COMBAT_RESULT_LOSS; |
|
|
|
|
221
|
|
|
|
222
|
|
|
// $this->debris->_reset(); |
|
|
|
|
223
|
|
|
// Генерируем результат боя |
224
|
|
|
$this->fleet_list->ube_analyze_fleets($this->is_simulator, $this->debris, $this->resource_exchange_rates); |
225
|
|
|
|
226
|
|
|
if(!$this->is_ube_loaded) { |
227
|
|
|
$this->moon_calculator->calculate_moon($this); |
228
|
|
|
|
229
|
|
|
// Лутаем ресурсы - если аттакер выиграл |
230
|
|
|
if($this->combat_result == UBE_COMBAT_RESULT_WIN) { |
231
|
|
|
$this->sn_ube_combat_analyze_loot(); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* |
239
|
|
|
* |
240
|
|
|
* @version 2016-02-25 23:42:45 41a4.68 |
241
|
|
|
*/ |
242
|
|
|
public function sn_ube_combat_analyze_loot() { |
243
|
|
|
$planet_looted_in_metal = 0; |
244
|
|
|
$planet_resource_looted = array( |
245
|
|
|
RES_METAL => 0, |
246
|
|
|
RES_CRYSTAL => 0, |
247
|
|
|
RES_DEUTERIUM => 0, |
248
|
|
|
); |
249
|
|
|
|
250
|
|
|
if( |
251
|
|
|
(($planet_resource_total = $this->fleet_list[0]->get_resources_amount()) > 0) |
252
|
|
|
&& |
253
|
|
|
(($total_capacity = $this->fleet_list->ube_get_capacity_attackers()) > 0) |
254
|
|
|
) { |
255
|
|
|
// Можно вывести только половину ресурсов, но не больше, чем общая вместимость флотов атакующих |
256
|
|
|
$planet_lootable = min($planet_resource_total / 2, $total_capacity); |
257
|
|
|
|
258
|
|
|
// Вычисляем процент вывоза. Каждого ресурса будет вывезено в одинаковых пропорциях |
259
|
|
|
$planet_lootable_percent = $planet_lootable / $planet_resource_total; |
260
|
|
|
|
261
|
|
|
// Вычисляем сколько ресурсов вывезено |
262
|
|
|
foreach($this->fleet_list->_container as $fleet_id => $fleet) { |
263
|
|
|
$looted_in_metal = 0; |
264
|
|
|
foreach($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) { |
265
|
|
|
// Вычисляем какой процент общей емкости трюмов атакующих будет задействован |
266
|
|
|
$fleet_lootable_percent = $fleet->fleet_capacity / $total_capacity; |
267
|
|
|
$looted = floor($resource_amount * $planet_lootable_percent * $fleet_lootable_percent); |
268
|
|
|
|
269
|
|
|
$fleet->resources_looted[$resource_id] = -$looted; |
270
|
|
|
$planet_resource_looted[$resource_id] += $looted; |
271
|
|
|
$looted_in_metal -= $looted * $this->resource_exchange_rates[$resource_id]; |
272
|
|
|
} |
273
|
|
|
$fleet->resources_lost_in_metal[RES_METAL] += $looted_in_metal; |
274
|
|
|
|
275
|
|
|
$planet_looted_in_metal += $looted_in_metal; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
$this->fleet_list[0]->resources_looted = $planet_resource_looted; |
280
|
|
|
$this->fleet_list[0]->resources_lost_in_metal[RES_METAL] -= $planet_looted_in_metal; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
|
285
|
|
|
|
286
|
|
|
|
287
|
|
|
|
288
|
|
|
|
289
|
|
|
|
290
|
|
|
|
291
|
|
|
|
292
|
|
|
|
293
|
|
|
|
294
|
|
|
|
295
|
|
|
|
296
|
|
|
|
297
|
|
|
|
298
|
|
|
|
299
|
|
|
|
300
|
|
|
|
301
|
|
|
|
302
|
|
|
|
303
|
|
|
|
304
|
|
|
|
305
|
|
|
|
306
|
|
|
|
307
|
|
|
|
308
|
|
|
|
309
|
|
|
|
310
|
|
|
|
311
|
|
|
|
312
|
|
|
|
313
|
|
|
|
314
|
|
|
|
315
|
|
|
|
316
|
|
|
|
317
|
|
|
|
318
|
|
|
// ------------------------------------------------------------------------------------------------ |
319
|
|
|
/** |
320
|
|
|
* Записывает результат боя в БД |
321
|
|
|
* |
322
|
|
|
* @return mixed |
323
|
|
|
* |
324
|
|
|
*/ |
325
|
|
|
public function ube_combat_result_apply() { |
326
|
|
|
$destination_user_id = $this->fleet_list[0]->owner_id; |
327
|
|
|
|
328
|
|
|
// Обновляем поле обломков на планете |
329
|
|
|
if(!$this->is_admin_in_combat && $this->debris->debris_total() > 0) { |
330
|
|
|
DBStaticPlanet::db_planet_update_by_gspt( |
331
|
|
|
$this->ube_planet_info[PLANET_GALAXY], $this->ube_planet_info[PLANET_SYSTEM], $this->ube_planet_info[PLANET_PLANET], PT_PLANET, |
332
|
|
|
array(), |
333
|
|
|
array( |
334
|
|
|
'debris_metal' => +$this->debris->debris_get_resource(RES_METAL), |
335
|
|
|
'debris_crystal' => +$this->debris->debris_get_resource(RES_CRYSTAL) |
336
|
|
|
) |
337
|
|
|
); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
foreach($this->fleet_list->_container as $fleet_id => $UBEFleet) { |
341
|
|
|
$ship_count_lost = $UBEFleet->unit_list->unitCountLost(); |
342
|
|
|
|
343
|
|
|
if($fleet_id) { |
344
|
|
|
// Флот |
345
|
|
|
$UBEFleet->db_save_combat_result_fleet($this->is_small_fleet_recce, $this->moon_calculator->get_reapers_status()); |
346
|
|
|
} else { |
347
|
|
|
// Планета |
348
|
|
|
|
349
|
|
|
// Сохраняем изменения ресурсов - если они есть |
350
|
|
|
$resource_delta = $UBEFleet->ube_combat_result_calculate_resources(); |
351
|
|
|
if(!empty($resource_delta)) { |
352
|
|
|
$temp = array(); |
353
|
|
|
foreach($resource_delta as $resource_id => $resource_amount) { |
354
|
|
|
$resource_db_name = pname_resource_name($resource_id); |
355
|
|
|
$temp[$resource_db_name] = $resource_amount; |
356
|
|
|
} |
357
|
|
|
DBStaticPlanet::db_planet_update_adjust_by_id( |
358
|
|
|
$this->ube_planet_info[PLANET_ID], |
359
|
|
|
$temp |
360
|
|
|
); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
if($ship_count_lost) { |
364
|
|
|
$planet_row_cache = $this->players[$destination_user_id]->getDbRow(); |
365
|
|
|
foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
366
|
|
|
DBStaticUnit::dbUpdateOrInsertUnit($UBEUnit->unitId, -$UBEUnit->units_lost, $planet_row_cache, $this->ube_planet_info[PLANET_ID]); |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
// TODO: Связать сабы с флотами констраинтами ON DELETE SET NULL |
373
|
|
|
// Для САБов |
374
|
|
|
$fleet_group_id_list = $this->fleet_list->ube_get_groups(); |
375
|
|
|
if(!empty($fleet_group_id_list)) { |
376
|
|
|
$fleet_group_id_list = implode(',', $fleet_group_id_list); |
377
|
|
|
DBStaticFleetACS::db_acs_delete_by_list($fleet_group_id_list); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
$this->moon_calculator->db_apply_result($this->ube_planet_info, $destination_user_id); |
381
|
|
|
|
382
|
|
|
$bashing_list = array(); |
383
|
|
|
$players_sides = $this->players->get_player_sides(); |
384
|
|
|
foreach($players_sides as $player_id => $player_side) { |
385
|
|
|
if($player_side != UBE_PLAYER_IS_ATTACKER) { |
386
|
|
|
continue; |
387
|
|
|
} |
388
|
|
|
if($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) { |
389
|
|
|
$bashing_list[] = "({$player_id}, {$this->ube_planet_info[PLANET_ID]}, {$this->combat_timestamp})"; |
390
|
|
|
} |
391
|
|
|
if($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) { |
392
|
|
|
$str_loose_or_win = $this->combat_result == UBE_COMBAT_RESULT_WIN ? 'raidswin' : 'raidsloose'; |
393
|
|
|
DBStaticUser::db_user_adjust_by_id( |
394
|
|
|
$player_id, |
395
|
|
|
array( |
396
|
|
|
'xpraid' => +1, |
397
|
|
|
'raids' => +1, |
398
|
|
|
$str_loose_or_win => +1, |
399
|
|
|
) |
400
|
|
|
); |
401
|
|
|
} |
402
|
|
|
} |
403
|
|
|
if(!empty($bashing_list)) { |
404
|
|
|
DBStaticFleetBashing::db_bashing_insert($bashing_list); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
ube_combat_result_apply_from_object($this); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Рассылает письма всем участникам боя |
413
|
|
|
*/ |
414
|
|
|
public function sn_ube_message_send() { |
415
|
|
|
$classLocale = classLocale::$lang; |
416
|
|
|
|
417
|
|
|
// TODO: Отсылать каждому игроку сообщение на его языке! |
418
|
|
|
|
419
|
|
|
$planet_info = &$this->ube_planet_info; |
420
|
|
|
|
421
|
|
|
// Генерируем текст письма |
422
|
|
|
$text_common = sprintf(classLocale::$lang['ube_report_msg_body_common'], |
423
|
|
|
date(FMT_DATE_TIME, $this->combat_timestamp), |
424
|
|
|
classLocale::$lang['sys_planet_type_sh'][$planet_info[PLANET_TYPE]], |
425
|
|
|
$planet_info[PLANET_GALAXY], |
426
|
|
|
$planet_info[PLANET_SYSTEM], |
427
|
|
|
$planet_info[PLANET_PLANET], |
428
|
|
|
htmlentities($planet_info[PLANET_NAME], ENT_COMPAT, 'UTF-8'), |
429
|
|
|
classLocale::$lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : |
430
|
|
|
($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')] |
431
|
|
|
); |
432
|
|
|
|
433
|
|
|
$text_defender = ''; |
434
|
|
|
$debris = $this->debris->get_debris(); |
435
|
|
|
foreach($debris as $resource_id => $resource_amount) { |
436
|
|
|
if($resource_id == RES_DEUTERIUM) { |
437
|
|
|
continue; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
$text_defender .= "{$classLocale['tech'][$resource_id]}: " . pretty_number($resource_amount) . '<br />'; |
441
|
|
|
} |
442
|
|
|
if($text_defender) { |
443
|
|
|
$text_defender = "{$classLocale['ube_report_msg_body_debris']}{$text_defender}<br />"; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
$text_defender .= $this->moon_calculator->message_generate($this); |
447
|
|
|
|
448
|
|
|
$text_defender .= "{$classLocale['ube_report_info_link']}: <a href=\"index.php?page=battle_report&cypher=$this->report_cypher\">{$this->report_cypher}</a>"; |
449
|
|
|
|
450
|
|
|
// TODO: Оптимизировать отсылку сообщений - отсылать пакетами |
451
|
|
|
$player_sides = $this->players->get_player_sides(); |
452
|
|
|
foreach($player_sides as $player_id => $player_side) { |
453
|
|
|
$message = $text_common . ($this->is_small_fleet_recce && ($player_side == UBE_PLAYER_IS_ATTACKER) ? classLocale::$lang['ube_report_msg_body_sfr'] : $text_defender); |
454
|
|
|
DBStaticMessages::msg_send_simple_message($player_id, '', $this->combat_timestamp, MSG_TYPE_COMBAT, classLocale::$lang['sys_mess_tower'], classLocale::$lang['sys_mess_attack_report'], $message); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @param $sym_attacker |
461
|
|
|
* @param $sym_defender |
462
|
|
|
*/ |
463
|
|
|
public function sn_ube_simulator_fleet_converter($sym_attacker, $sym_defender) { |
464
|
|
|
// $this->is_simulator = sys_get_param_int('simulator'); |
|
|
|
|
465
|
|
|
// $this->is_simulator = !empty($this->is_simulator); |
466
|
|
|
$this->is_simulator = true; |
467
|
|
|
$this->mission_type_id = MT_ATTACK; |
468
|
|
|
|
469
|
|
|
$this->players = new UBEPlayerList(); |
470
|
|
|
$this->fleet_list = new UBEFleetList(); |
471
|
|
|
|
472
|
|
|
$this->sn_ube_simulator_fill_side($sym_defender, false); |
473
|
|
|
$this->sn_ube_simulator_fill_side($sym_attacker, true); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* Преобразовывает данные симулятора в данные для расчета боя |
478
|
|
|
* |
479
|
|
|
* @param $side_info |
480
|
|
|
* @param $attacker |
481
|
|
|
* @param int $player_id |
482
|
|
|
* |
483
|
|
|
*/ |
484
|
|
|
public function sn_ube_simulator_fill_side($side_info, $attacker, $player_id = -1) { |
485
|
|
|
$player_id = $player_id == -1 ? $this->players->count() : $player_id; |
486
|
|
|
$fleet_id = $player_id; // FOR SIMULATOR! |
487
|
|
|
|
488
|
|
|
if(empty($this->players[$player_id])) { |
489
|
|
|
$this->players[$player_id] = new UBEPlayer(); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
foreach($side_info as $fleet_data) { |
493
|
|
|
$this->players[$player_id]->name = $player_id; |
494
|
|
|
$this->players[$player_id]->setSide($attacker); |
495
|
|
|
|
496
|
|
|
$objFleet = new UBEFleet(); |
497
|
|
|
$this->fleet_list[$fleet_id] = $objFleet; |
498
|
|
|
|
499
|
|
|
$this->fleet_list[$fleet_id]->owner_id = $player_id; |
500
|
|
|
foreach($fleet_data as $unit_id => $unit_count) { |
501
|
|
|
if(!$unit_count) { |
502
|
|
|
continue; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
$unit_type = get_unit_param($unit_id, P_UNIT_TYPE); |
506
|
|
|
|
507
|
|
|
if($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
508
|
|
|
$this->fleet_list[$fleet_id]->unit_list->unitAdjustCount($unit_id, $unit_count); |
509
|
|
|
} elseif($unit_type == UNIT_RESOURCES) { |
510
|
|
|
$this->fleet_list[$fleet_id]->resource_list[$unit_id] = $unit_count; |
511
|
|
|
} elseif($unit_type == UNIT_TECHNOLOGIES) { |
512
|
|
|
if($unit_id == TECH_WEAPON) { |
513
|
|
|
$this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_WEAPON, $unit_count); |
514
|
|
|
} elseif($unit_id == TECH_SHIELD) { |
515
|
|
|
$this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_SHIELD, $unit_count); |
516
|
|
|
} elseif($unit_id == TECH_ARMOR) { |
517
|
|
|
$this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_ARMOR, $unit_count); |
518
|
|
|
} |
519
|
|
|
} elseif($unit_type == UNIT_GOVERNORS) { |
520
|
|
|
if($unit_id == MRC_FORTIFIER) { |
521
|
|
|
// Фортифаер даёт бонус ко всему |
522
|
|
|
$this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $unit_count); |
523
|
|
|
} |
524
|
|
|
} elseif($unit_type == UNIT_MERCENARIES) { |
525
|
|
|
if($unit_id == MRC_ADMIRAL) { |
526
|
|
|
$this->players[$player_id]->player_bonus->add_unit_by_snid(MRC_ADMIRAL, $unit_count); |
527
|
|
|
} |
528
|
|
|
} |
529
|
|
|
} |
530
|
|
|
} |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* |
536
|
|
|
*/ |
537
|
|
|
public function set_option_from_config() { |
538
|
|
|
$this->options_method = classSupernova::$config->game_ube_method ? classSupernova::$config->game_ube_method : 0; |
|
|
|
|
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
/** |
542
|
|
|
* @return int |
543
|
|
|
*/ |
544
|
|
|
public function get_time_spent() { |
545
|
|
|
return $this->time_spent; |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* @return string |
550
|
|
|
*/ |
551
|
|
|
public function get_cypher() { |
552
|
|
|
return $this->report_cypher; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Статик кусок из flt_mission_attack() |
558
|
|
|
* |
559
|
|
|
* @param Mission $objMission |
560
|
|
|
* |
561
|
|
|
* @return bool |
562
|
|
|
* |
563
|
|
|
*/ |
564
|
|
|
static function flt_mission_attack($objMission) { |
|
|
|
|
565
|
|
|
$ube = new UBE(); |
566
|
|
|
$ube->loadDataFromMission($objMission); |
567
|
|
|
|
568
|
|
|
$ube->sn_ube_combat(); |
569
|
|
|
|
570
|
|
|
flt_planet_capture_from_object($ube); |
571
|
|
|
|
572
|
|
|
$ube_report = new UBEReport(); |
573
|
|
|
$ube_report->sn_ube_report_save($ube); |
574
|
|
|
|
575
|
|
|
$ube->ube_combat_result_apply(); |
576
|
|
|
|
577
|
|
|
$ube->sn_ube_message_send(); |
578
|
|
|
|
579
|
|
|
defined('DEBUG_UBE') ? die('DIE at ' . __FILE__ . ' ' . __LINE__) : false; |
580
|
|
|
|
581
|
|
|
return false; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* @param $template |
586
|
|
|
* |
587
|
|
|
* @return template |
588
|
|
|
*/ |
589
|
|
|
static function sn_battle_report_view(&$template) { |
|
|
|
|
590
|
|
|
global $template_result; |
591
|
|
|
|
592
|
|
|
$ube_report = new UBEReport(); |
593
|
|
|
$ube = $ube_report->sn_ube_report_load(sys_get_param_str('cypher')); |
594
|
|
|
if($ube != UBE_REPORT_NOT_FOUND) { |
595
|
|
|
$ube_report->sn_ube_report_generate($ube, $template_result); |
|
|
|
|
596
|
|
|
|
597
|
|
|
$template = gettemplate('ube_combat_report', $template); |
598
|
|
|
$template->assign_vars(array( |
599
|
|
|
'PAGE_HEADER' => classLocale::$lang['ube_report_info_page_header'], |
600
|
|
|
)); |
601
|
|
|
} else { |
602
|
|
|
message(classLocale::$lang['sys_msg_ube_report_err_not_found'], classLocale::$lang['sys_error']); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
return $template; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
/** |
609
|
|
|
* @param $sym_attacker |
610
|
|
|
* @param $sym_defender |
611
|
|
|
*/ |
612
|
|
|
static function display_simulator(&$sym_attacker, &$sym_defender) { |
|
|
|
|
613
|
|
|
global $template_result; |
614
|
|
|
|
615
|
|
|
$ube = new UBE(); |
616
|
|
|
$ube->sn_ube_simulator_fleet_converter($sym_attacker, $sym_defender); |
617
|
|
|
|
618
|
|
|
$ube->set_option_from_config(); |
619
|
|
|
$ube->sn_ube_combat(); |
620
|
|
|
$ube_report = new UBEReport(); |
621
|
|
|
|
622
|
|
|
if(sys_get_param_str('reload')) { |
623
|
|
|
$ube_new = $ube_report->sn_ube_report_load($ube->get_cypher()); // $combat_data = sn_ube_report_load($combat_data[UBE_REPORT_CYPHER]); |
|
|
|
|
624
|
|
|
if($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) { |
625
|
|
|
$ube = $ube_new; |
626
|
|
|
} |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
// Рендерим их в темплейт |
630
|
|
|
$ube_report->sn_ube_report_generate($ube, $template_result); // sn_ube_report_generate($combat_data, $template_result); |
|
|
|
|
631
|
|
|
|
632
|
|
|
$template_result['MICROTIME'] = $ube->get_time_spent(); // $template_result['MICROTIME'] = $combat_data[UBE_TIME_SPENT]; |
|
|
|
|
633
|
|
|
|
634
|
|
|
$template = gettemplate('ube_combat_report', true); |
635
|
|
|
$template->assign_recursive($template_result); |
636
|
|
|
display($template, '', false, '', false, false, true); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* @param array $report_row |
641
|
|
|
* @param string $report_cypher |
642
|
|
|
*/ |
643
|
|
|
public function load_from_report_row($report_row, $report_cypher) { |
644
|
|
|
$this->is_ube_loaded = true; |
645
|
|
|
|
646
|
|
|
$this->report_cypher = $report_cypher; |
647
|
|
|
|
648
|
|
|
$this->combat_timestamp = strtotime($report_row['ube_report_time_combat']); |
649
|
|
|
$this->time_spent = $report_row['ube_report_time_spent']; |
650
|
|
|
$this->is_admin_in_combat = $report_row['ube_report_combat_admin']; |
651
|
|
|
$this->mission_type_id = $report_row['ube_report_mission_type']; |
652
|
|
|
$this->combat_result = $report_row['ube_report_combat_result']; |
653
|
|
|
|
654
|
|
|
$this->is_small_fleet_recce = intval($report_row['ube_report_combat_sfr']); |
655
|
|
|
$this->capture_result = $report_row['ube_report_capture_result']; |
656
|
|
|
|
657
|
|
|
$this->ube_planet_info = array( |
658
|
|
|
PLANET_ID => $report_row['ube_report_planet_id'], |
659
|
|
|
PLANET_NAME => $report_row['ube_report_planet_name'], |
660
|
|
|
PLANET_SIZE => $report_row['ube_report_planet_size'], |
661
|
|
|
PLANET_GALAXY => $report_row['ube_report_planet_galaxy'], |
662
|
|
|
PLANET_SYSTEM => $report_row['ube_report_planet_system'], |
663
|
|
|
PLANET_PLANET => $report_row['ube_report_planet_planet'], |
664
|
|
|
PLANET_TYPE => $report_row['ube_report_planet_planet_type'], |
665
|
|
|
); |
666
|
|
|
|
667
|
|
|
$this->moon_calculator->load_from_report($report_row); |
668
|
|
|
|
669
|
|
|
$this->debris->load_from_report_row($report_row); |
670
|
|
|
|
671
|
|
|
$query = classSupernova::$db->doSelect("SELECT * FROM {{ube_report_player}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
672
|
|
|
while($player_row = db_fetch($query)) { |
673
|
|
|
$this->players->init_player_from_report_info($player_row); |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
$this->fleet_list->ube_db_load_from_report_row($report_row, $this); |
677
|
|
|
|
678
|
|
|
$this->rounds->db_load_round_list_from_report_row($report_row, $this); |
679
|
|
|
|
680
|
|
|
$this->fleet_list->ube_db_load_fleets_outcome($report_row); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
|
686
|
|
|
// ------------------------------------------------------------------------------------------------ |
687
|
|
|
/** |
688
|
|
|
* Записывает результат боя в БД |
689
|
|
|
* @see unit_captain::ube_combat_result_apply_from_object |
690
|
|
|
* |
691
|
|
|
* @param UBE $ube |
692
|
|
|
* |
693
|
|
|
* @return mixed |
694
|
|
|
* |
695
|
|
|
*/ |
696
|
|
|
function ube_combat_result_apply_from_object(UBE $ube) { return sn_function_call(__FUNCTION__, array($ube)); } |
697
|
|
|
|
698
|
|
|
/** |
699
|
|
|
* Заполняет данные по флоту |
700
|
|
|
* @see unit_captain::ube_attack_prepare_fleet_from_object |
701
|
|
|
* |
702
|
|
|
* @param UBEFleet $UBEFleet |
703
|
|
|
* |
704
|
|
|
* @return mixed |
705
|
|
|
* |
706
|
|
|
*/ |
707
|
|
|
function ube_attack_prepare_fleet_from_object(UBEFleet $UBEFleet) { return sn_function_call(__FUNCTION__, array($UBEFleet)); } |
708
|
|
|
|
709
|
|
|
/** |
710
|
|
|
* @see game_skirmish::flt_planet_capture_from_object |
711
|
|
|
* |
712
|
|
|
* @param UBE $ube |
713
|
|
|
* |
714
|
|
|
* @return mixed |
715
|
|
|
* |
716
|
|
|
*/ |
717
|
|
|
function flt_planet_capture_from_object(UBE $ube) { return sn_function_call(__FUNCTION__, array($ube, &$result)); } |
|
|
|
|
718
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.