1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 13.02.2018 8:17 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Ube\Ube4_1; |
7
|
|
|
|
8
|
|
|
use DBStaticPlanet; |
9
|
|
|
|
10
|
|
|
class Ube4_1Prepare { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Заполняет начальные данные по данным миссии |
14
|
|
|
* |
15
|
|
|
* @param $mission_data |
16
|
|
|
* |
17
|
|
|
* @return array |
18
|
|
|
*/ |
19
|
|
|
public function ube_attack_prepare(&$mission_data, &$fleet_list_on_hold) { |
20
|
|
|
/* |
|
|
|
|
21
|
|
|
UBE_OPTIONS[UBE_LOADED] |
22
|
|
|
UBE_OPTIONS[UBE_SIMULATOR] |
23
|
|
|
UBE_OPTIONS[UBE_EXCHANGE] |
24
|
|
|
UBE_OPTIONS[UBE_MOON_WAS] |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
$fleet_row = &$mission_data['fleet']; |
28
|
|
|
$destination_planet = &$mission_data['dst_planet']; |
29
|
|
|
|
30
|
|
|
$ube_time = $fleet_row['fleet_start_time']; |
31
|
|
|
$combat_data = [ |
32
|
|
|
UBE_TIME => $ube_time, |
33
|
|
|
UBE_OBJ_PREPARATOR => $this, |
34
|
|
|
UBE_OBJ_CALCULATOR => new \Ube\Ube4_1\Ube4_1Calc(), |
35
|
|
|
]; |
36
|
|
|
// TODO: Не допускать атаки игроком своих же флотов - т.е. холд против атаки |
37
|
|
|
// Готовим инфу по атакуемой планете |
38
|
|
|
$this->ube_attack_prepare_planet($combat_data, $destination_planet); |
39
|
|
|
|
40
|
|
|
// Готовим инфу по удержанию |
41
|
|
|
foreach ($fleet_list_on_hold as $fleet) { |
42
|
|
|
ube_attack_prepare_fleet($combat_data, $fleet, false); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// Готовим инфу по атакующим |
46
|
|
|
if ($fleet_row['fleet_group']) { |
47
|
|
|
$acs_fleet_list = fleet_list_by_group($fleet_row['fleet_group']); |
48
|
|
|
foreach ($acs_fleet_list as $fleet) { |
49
|
|
|
ube_attack_prepare_fleet($combat_data, $fleet, true); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
} else { |
52
|
|
|
ube_attack_prepare_fleet($combat_data, $fleet_row, true); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Готовим опции |
56
|
|
|
$combat_data[UBE_OPTIONS][UBE_MOON_WAS] = $destination_planet['planet_type'] == PT_MOON || is_array(DBStaticPlanet::db_planet_by_parent($destination_planet['id'], true, '`id`')); |
57
|
|
|
$combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] = $fleet_row['fleet_mission']; |
58
|
|
|
global $config; |
|
|
|
|
59
|
|
|
$combat_data[UBE_OPTIONS][UBE_METHOD] = $config->game_ube_method ? $config->game_ube_method : 0; |
60
|
|
|
|
61
|
|
|
return $combat_data; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// ------------------------------------------------------------------------------------------------ |
65
|
|
|
// Заполняет данные по игроку |
66
|
|
|
public function ube_attack_prepare_player(&$combat_data, $player_id, $is_attacker) { |
67
|
|
|
/** |
68
|
|
|
* @var \Ube\Ube4_1\Ube4_1Calc $ubeCalc |
69
|
|
|
*/ |
70
|
|
|
$ubeCalc = $combat_data[UBE_OBJ_CALCULATOR]; |
71
|
|
|
|
72
|
|
|
if (!isset($combat_data[UBE_PLAYERS][$player_id])) { |
73
|
|
|
$combat_data[UBE_PLAYERS][$player_id] = array(UBE_ATTACKER => $is_attacker); |
74
|
|
|
$player_info = &$combat_data[UBE_PLAYERS][$player_id]; |
75
|
|
|
|
76
|
|
|
$player_data = db_user_by_id($player_id, true); |
|
|
|
|
77
|
|
|
$player_info[UBE_NAME] = $player_data['username']; |
78
|
|
|
$player_info[UBE_AUTH_LEVEL] = $player_data['authlevel']; |
79
|
|
|
$combat_data[UBE_OPTIONS][UBE_COMBAT_ADMIN] = $combat_data[UBE_OPTIONS][UBE_COMBAT_ADMIN] || $player_data['authlevel']; // Участвует ли админ в бою? |
80
|
|
|
$player_info[UBE_PLAYER_DATA] = $player_data; |
81
|
|
|
|
82
|
|
|
$admiral_bonus = mrc_get_level($player_data, false, MRC_ADMIRAL) * get_unit_param(MRC_ADMIRAL, P_BONUS_VALUE) / 100; |
|
|
|
|
83
|
|
|
foreach ($ubeCalc->ube_convert_techs as $unit_id => $ube_id) { |
84
|
|
|
$player_info[UBE_BONUSES][$ube_id] += mrc_get_level($player_data, false, $unit_id) * get_unit_param($unit_id, P_BONUS_VALUE) / 100 + $admiral_bonus; |
85
|
|
|
} |
86
|
|
|
} else { |
87
|
|
|
$combat_data[UBE_PLAYERS][$player_id][UBE_ATTACKER] = $combat_data[UBE_PLAYERS][$player_id][UBE_ATTACKER] || $is_attacker; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Заполняет данные по флоту |
94
|
|
|
* |
95
|
|
|
* Через жопу для сохранения обратной совместимости |
96
|
|
|
* |
97
|
|
|
* @param $combat_data |
98
|
|
|
* @param $fleet |
99
|
|
|
* @param $is_attacker |
100
|
|
|
* |
101
|
|
|
* @deprecated |
102
|
|
|
*/ |
103
|
|
|
public function sn_ube_attack_prepare_fleet(&$combat_data, &$fleet, $is_attacker) { |
104
|
|
|
$fleet_owner_id = $fleet['fleet_owner']; |
105
|
|
|
$fleet_id = $fleet['fleet_id']; |
106
|
|
|
|
107
|
|
|
$this->ube_attack_prepare_player($combat_data, $fleet_owner_id, $is_attacker); |
108
|
|
|
|
109
|
|
|
$fleet_data = sys_unit_str2arr($fleet['fleet_array']); |
110
|
|
|
|
111
|
|
|
$combat_data[UBE_FLEETS][$fleet_id][UBE_OWNER] = $fleet_owner_id; |
112
|
|
|
$fleet_info = &$combat_data[UBE_FLEETS][$fleet_id]; |
113
|
|
|
$fleet_info[UBE_FLEET_GROUP] = $fleet['fleet_group']; |
114
|
|
|
foreach ($fleet_data as $unit_id => $unit_count) { |
115
|
|
|
if (!$unit_count) { |
116
|
|
|
continue; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$unit_type = get_unit_param($unit_id, P_UNIT_TYPE); |
120
|
|
|
if ($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
121
|
|
|
$fleet_info[UBE_COUNT][$unit_id] = $unit_count; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$fleet_info[UBE_RESOURCES] = array( |
126
|
|
|
RES_METAL => $fleet['fleet_resource_metal'], |
127
|
|
|
RES_CRYSTAL => $fleet['fleet_resource_crystal'], |
128
|
|
|
RES_DEUTERIUM => $fleet['fleet_resource_deuterium'], |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$fleet_info[UBE_PLANET] = array( |
132
|
|
|
// TODO: Брать имя и кэшировать ИД и имя планеты? |
133
|
|
|
PLANET_GALAXY => $fleet['fleet_start_galaxy'], |
134
|
|
|
PLANET_SYSTEM => $fleet['fleet_start_system'], |
135
|
|
|
PLANET_PLANET => $fleet['fleet_start_planet'], |
136
|
|
|
PLANET_TYPE => $fleet['fleet_start_type'], |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Заполняет данные по планете |
142
|
|
|
* |
143
|
|
|
* @param $combat_data |
144
|
|
|
* @param $planet |
145
|
|
|
*/ |
146
|
|
|
protected function ube_attack_prepare_planet(&$combat_data, &$planet) { |
147
|
|
|
/** |
148
|
|
|
* @var \Ube\Ube4_1\Ube4_1Calc $ubeCalc |
149
|
|
|
*/ |
150
|
|
|
$ubeCalc = $combat_data[UBE_OBJ_CALCULATOR]; |
151
|
|
|
|
152
|
|
|
$player_id = $planet['id_owner']; |
153
|
|
|
|
154
|
|
|
$this->ube_attack_prepare_player($combat_data, $player_id, false); |
155
|
|
|
|
156
|
|
|
$player = &$combat_data[UBE_PLAYERS][$player_id][UBE_PLAYER_DATA]; |
157
|
|
|
|
158
|
|
|
$combat_data[UBE_FLEETS][0] = array(UBE_OWNER => $player_id); |
159
|
|
|
$fleet_info = &$combat_data[UBE_FLEETS][0]; |
160
|
|
|
|
161
|
|
|
foreach (sn_get_groups('combat') as $unit_id) { |
162
|
|
|
if ($unit_count = mrc_get_level($player, $planet, $unit_id)) { |
163
|
|
|
$fleet_info[UBE_COUNT][$unit_id] = $unit_count; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
foreach (sn_get_groups('resources_loot') as $resource_id) { |
168
|
|
|
$fleet_info[UBE_RESOURCES][$resource_id] = floor(mrc_get_level($player, $planet, $resource_id)); |
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
if ($fortifier_level = mrc_get_level($player, $planet, MRC_FORTIFIER)) { |
172
|
|
|
$fortifier_bonus = $fortifier_level * get_unit_param(MRC_FORTIFIER, P_BONUS_VALUE) / 100; |
173
|
|
|
foreach ($ubeCalc->ube_combat_bonus_list as $ube_id) { |
174
|
|
|
$fleet_info[UBE_BONUSES][$ube_id] += $fortifier_bonus; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$combat_data[UBE_OUTCOME][UBE_PLANET] = $fleet_info[UBE_PLANET] = array( |
179
|
|
|
PLANET_ID => $planet['id'], |
180
|
|
|
PLANET_NAME => $planet['name'], |
181
|
|
|
PLANET_GALAXY => $planet['galaxy'], |
182
|
|
|
PLANET_SYSTEM => $planet['system'], |
183
|
|
|
PLANET_PLANET => $planet['planet'], |
184
|
|
|
PLANET_TYPE => $planet['planet_type'], |
185
|
|
|
PLANET_SIZE => $planet['diameter'], |
186
|
|
|
); |
187
|
|
|
|
188
|
|
|
$combat_data[UBE_OPTIONS][UBE_DEFENDER_ACTIVE] = $player['onlinetime'] >= $combat_data[UBE_TIME] - 60 * 60 * 24 * 7; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
} |
192
|
|
|
|
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.