1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 25.01.2018 7:50 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Pages\Deprecated; |
7
|
|
|
|
8
|
|
|
use Planet\DBStaticPlanet; |
9
|
|
|
use SN; |
10
|
|
|
use HelperString; |
11
|
|
|
use Exception; |
12
|
|
|
use Planet\Planet; |
13
|
|
|
use template; |
14
|
|
|
|
15
|
|
|
class PageOverview extends PageDeprecated { |
16
|
|
|
/** |
17
|
|
|
* @var \classConfig $config |
18
|
|
|
*/ |
19
|
|
|
protected $config; |
20
|
|
|
/** |
21
|
|
|
* @var \core_auth $auth |
22
|
|
|
*/ |
23
|
|
|
protected $auth; |
24
|
|
|
/** |
25
|
|
|
* @var \classLocale $lang |
26
|
|
|
*/ |
27
|
|
|
protected $lang; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Planet $planet |
31
|
|
|
*/ |
32
|
|
|
protected $planet; |
33
|
|
|
|
34
|
|
|
public function __construct() { |
35
|
|
|
parent::__construct(); |
36
|
|
|
|
37
|
|
|
$this->lang = SN::$lang; |
38
|
|
|
$this->config = SN::$config; |
39
|
|
|
$this->auth = SN::$auth; |
40
|
|
|
|
41
|
|
|
lng_include('overview'); |
42
|
|
|
lng_include('mrc_mercenary'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function setPlanetById($planetId) { |
46
|
|
|
$this->planet = new Planet($planetId); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getPlanet() { |
50
|
|
|
if (empty($this->planet)) { |
51
|
|
|
throw new Exception('No planet in Overview'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $this->planet; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function route() { |
58
|
|
|
global $user, $planetrow, $que, $user_option_list; |
|
|
|
|
59
|
|
|
|
60
|
|
|
$this->setPlanetById($planetrow['id']); |
61
|
|
|
|
62
|
|
|
switch ($mode = sys_get_param_str('mode')) { |
|
|
|
|
63
|
|
|
case 'manage': |
64
|
|
|
$this->manage($user, $planetrow); |
65
|
|
|
break; |
66
|
|
|
|
67
|
|
|
default: |
68
|
|
|
$this->overview($user, $planetrow, $que, $user_option_list); |
69
|
|
|
break; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param $user |
75
|
|
|
* @param $planetrow |
76
|
|
|
* @param $que |
77
|
|
|
* @param $user_option_list |
78
|
|
|
*/ |
79
|
|
|
public function overview($user, $planetrow, $que, $user_option_list) { |
80
|
|
|
$this->setPlanetById($planetrow['id']); |
81
|
|
|
|
82
|
|
|
$this->planet->sn_sys_sector_buy(); |
|
|
|
|
83
|
|
|
|
84
|
|
|
rpg_level_up($user, RPG_STRUCTURE); |
85
|
|
|
rpg_level_up($user, RPG_RAID); |
86
|
|
|
rpg_level_up($user, RPG_TECH); |
87
|
|
|
rpg_level_up($user, RPG_EXPLORE); |
88
|
|
|
|
89
|
|
|
if (sys_get_param_str('rename') && $new_name = sys_get_param_str('new_name')) { |
90
|
|
|
$planetrow['name'] = $new_name; |
91
|
|
|
$new_name_safe = db_escape($new_name); |
92
|
|
|
DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`name` = '{$new_name_safe}'"); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if (!empty($theResult = $this->planet->sn_sys_planet_core_transmute($user))) { |
|
|
|
|
96
|
|
|
$this->resultMessageList->add($theResult['MESSAGE'], $theResult['STATUS']); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$template = gettemplate('planet_overview', true); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER); |
|
|
|
|
102
|
|
|
$template->assign_recursive($this->planet->tpl_planet_density_info($user_dark_matter)); |
|
|
|
|
103
|
|
|
|
104
|
|
|
$fleets_to_planet = []; |
105
|
|
|
$planet_count = 0; |
106
|
|
|
$planets_query = DBStaticPlanet::db_planet_list_sorted($user, false, '*'); |
107
|
|
|
foreach ($planets_query as $an_id => $planetRecord) { |
|
|
|
|
108
|
|
|
$fleet_list = flt_get_fleets_to_planet($planetRecord); |
109
|
|
|
if (!empty($fleet_list['own']['count'])) { |
110
|
|
|
$fleets_to_planet[$an_id] = tpl_parse_fleet_sn($fleet_list['own']['total'], getUniqueFleetId($planetRecord)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ($planetRecord['planet_type'] == PT_MOON) { |
114
|
|
|
continue; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$planet_count++; |
118
|
|
|
|
119
|
|
|
sn_db_transaction_start(); |
120
|
|
|
$updatedData = sys_o_get_updated($user, $planetRecord['id'], SN_TIME_NOW, false, true); |
121
|
|
|
sn_db_transaction_commit(); |
122
|
|
|
|
123
|
|
|
$templatizedPlanet = tpl_parse_planet($user, $updatedData['planet']); |
124
|
|
|
$templatizedPlanet += tpl_parse_planet_result_fleet($updatedData['planet'], $fleet_list); |
125
|
|
|
$templatizedPlanet += tpl_parse_planet_moon($planetRecord['id']); |
126
|
|
|
|
127
|
|
|
$template->assign_block_vars('planet', $templatizedPlanet); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$fleets = flt_parse_fleets_to_events(fleet_and_missiles_list_incoming($user['id'])); |
131
|
|
|
tpl_assign_fleet($template, $fleets_to_planet); |
|
|
|
|
132
|
|
|
tpl_assign_fleet($template, $fleets); |
|
|
|
|
133
|
|
|
|
134
|
|
|
$lune = $planetrow['planet_type'] == PT_PLANET ? DBStaticPlanet::db_planet_by_parent($planetrow['id']) : DBStaticPlanet::db_planet_by_id($planetrow['parent_planet']); |
135
|
|
|
if ($lune) { |
136
|
|
|
$template->assign_vars([ |
137
|
|
|
'MOON_ID' => $lune['id'], |
138
|
|
|
'MOON_IMG' => $lune['image'], |
139
|
|
|
'MOON_NAME' => $lune['name'], |
140
|
|
|
]); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$template->assign_recursive($this->planet->int_planet_pretemplate($user)); |
144
|
|
|
|
145
|
|
|
if (!defined('GAME_STRUCTURES_DISABLED') || !GAME_STRUCTURES_DISABLED) { |
|
|
|
|
146
|
|
|
$this->templateQue($template, QUE_STRUCTURES, $que); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$this->templateQue($template, SUBQUE_FLEET, $que); |
150
|
|
|
if (!defined('GAME_DEFENSE_DISABLED') || !GAME_DEFENSE_DISABLED) { |
|
|
|
|
151
|
|
|
$this->templateQue($template, SUBQUE_DEFENSE, $que); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$template->assign_vars($this->templateGridSizes($user, $user_option_list, $planet_count)); |
155
|
|
|
|
156
|
|
|
$template->assign_vars($this->templateSector($user, $user_dark_matter)); |
157
|
|
|
|
158
|
|
|
$planet_recyclers_orbiting = 0; |
159
|
|
|
foreach (sn_get_groups('flt_recyclers') as $recycler_id) { |
160
|
|
|
$planet_recyclers_orbiting += mrc_get_level($user, $planetrow, $recycler_id); |
161
|
|
|
} |
162
|
|
|
$governor_level = $planetrow['PLANET_GOVERNOR_ID'] ? mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID'], false, true) : 0; |
163
|
|
|
$template->assign_vars([ |
164
|
|
|
'USER_ID' => $user['id'], |
165
|
|
|
'user_username' => $user['username'], |
166
|
|
|
'USER_AUTHLEVEL' => $user['authlevel'], |
167
|
|
|
|
168
|
|
|
'NEW_MESSAGES' => $user['new_message'], |
169
|
|
|
// TODO |
170
|
|
|
// 'NEW_LEVEL_MINER' => $level_miner, |
|
|
|
|
171
|
|
|
// 'NEW_LEVEL_RAID' => $level_raid, |
|
|
|
|
172
|
|
|
|
173
|
|
|
'planet_diameter' => HelperString::numberFloorAndFormat($planetrow['diameter']), |
174
|
|
|
|
175
|
|
|
'metal_debris' => HelperString::numberFloorAndFormat($planetrow['debris_metal']), |
176
|
|
|
'crystal_debris' => HelperString::numberFloorAndFormat($planetrow['debris_crystal']), |
177
|
|
|
'PLANET_RECYCLERS' => $planet_recyclers_orbiting, |
178
|
|
|
'planet_image' => $planetrow['image'], |
179
|
|
|
'planet_temp_min' => $planetrow['temp_min'], |
180
|
|
|
'planet_temp_avg' => round(($planetrow['temp_min'] + $planetrow['temp_max']) / 2), |
181
|
|
|
'planet_temp_max' => $planetrow['temp_max'], |
182
|
|
|
'planet_density' => $planetrow['density'], |
183
|
|
|
'planet_density_index' => $planetrow['density_index'], |
184
|
|
|
'planet_density_text' => $this->lang['uni_planet_density_types'][$planetrow['density_index']], |
185
|
|
|
|
186
|
|
|
'GATE_LEVEL' => mrc_get_level($user, $planetrow, STRUC_MOON_GATE), |
187
|
|
|
'GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow), |
188
|
|
|
|
189
|
|
|
'ADMIN_EMAIL' => $this->config->game_adminEmail, |
190
|
|
|
|
191
|
|
|
'PLANET_GOVERNOR_ID' => $planetrow['PLANET_GOVERNOR_ID'], |
192
|
|
|
'PLANET_GOVERNOR_LEVEL' => $governor_level, |
193
|
|
|
'PLANET_GOVERNOR_LEVEL_PLUS' => mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID']) - $governor_level, |
194
|
|
|
'PLANET_GOVERNOR_NAME' => $this->lang['tech'][$planetrow['PLANET_GOVERNOR_ID']], |
195
|
|
|
|
196
|
|
|
'IS_CAPITAL' => $planetrow['planet_type'] == PT_PLANET && $planetrow['id'] == $user['id_planet'], |
197
|
|
|
'IS_MOON' => $planetrow['planet_type'] == PT_MOON, |
198
|
|
|
|
199
|
|
|
'DARK_MATTER' => $user_dark_matter, |
200
|
|
|
|
201
|
|
|
'PAGE_HEADER' => $this->lang['ov_overview'] . " - " . $this->lang['sys_planet_type'][$planetrow['planet_type']] . " {$planetrow['name']} [{$planetrow['galaxy']}:{$planetrow['system']}:{$planetrow['planet']}]", |
202
|
|
|
]); |
203
|
|
|
tpl_set_resource_info($template, $planetrow, $fleets_to_planet); |
204
|
|
|
|
205
|
|
|
$this->resultMessageList->templateAdd($template); |
206
|
|
|
|
207
|
|
|
display($template); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param $user |
212
|
|
|
* @param $planetrow |
213
|
|
|
*/ |
214
|
|
|
public function manage($user, $planetrow) { |
215
|
|
|
$this->setPlanetById($planetrow['id']); |
216
|
|
|
|
217
|
|
|
$this->planet->sn_sys_sector_buy('overview.php?mode=manage'); |
|
|
|
|
218
|
|
|
|
219
|
|
|
$user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER); |
|
|
|
|
220
|
|
|
if (!empty($theResult = $this->planet->sn_sys_planet_core_transmute($user))) { |
|
|
|
|
221
|
|
|
$this->resultMessageList->add($theResult['MESSAGE'], $theResult['STATUS']); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$template = gettemplate('planet_manage', true); |
|
|
|
|
225
|
|
|
$planet_id = sys_get_param_id('planet_id'); |
226
|
|
|
|
227
|
|
|
if (sys_get_param_str('rename') && $new_name = sys_get_param_str('new_name')) { |
228
|
|
|
$planetrow['name'] = $new_name; |
229
|
|
|
DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`name` = '{$new_name}'"); |
230
|
|
|
} elseif (sys_get_param_str('action') == 'make_capital') { |
231
|
|
|
try { |
232
|
|
|
sn_db_transaction_start(); |
233
|
|
|
$user = db_user_by_id($user['id'], true, '*'); |
|
|
|
|
234
|
|
|
$planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*'); |
235
|
|
|
|
236
|
|
|
if ($planetrow['planet_type'] != PT_PLANET) { |
237
|
|
|
throw new exception($this->lang['ov_capital_err_not_a_planet'], ERR_ERROR); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
if ($planetrow['id'] == $user['id_planet']) { |
241
|
|
|
throw new exception($this->lang['ov_capital_err_capital_already'], ERR_ERROR); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
if ($user_dark_matter < $this->config->planet_capital_cost) { |
245
|
|
|
throw new exception($this->lang['ov_capital_err_no_dark_matter'], ERR_ERROR); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
rpg_points_change($user['id'], RPG_CAPITAL, -$this->config->planet_capital_cost, |
249
|
|
|
array('Planet %s ID %d at coordinates %s now become Empire Capital', $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow)) |
250
|
|
|
); |
251
|
|
|
|
252
|
|
|
db_user_set_by_id($user['id'], "id_planet = {$planetrow['id']}, galaxy = {$planetrow['galaxy']}, system = {$planetrow['system']}, planet = {$planetrow['planet']}"); |
|
|
|
|
253
|
|
|
|
254
|
|
|
$user['id_planet'] = $planetrow['id']; |
255
|
|
|
$this->resultMessageList->add($this->lang['ov_capital_err_none'], ERR_NONE); |
256
|
|
|
sn_db_transaction_commit(); |
257
|
|
|
sys_redirect('overview.php?mode=manage'); |
258
|
|
|
} catch (exception $e) { |
259
|
|
|
sn_db_transaction_rollback(); |
260
|
|
|
$this->resultMessageList->add($e->getMessage(), $e->getCode()); |
261
|
|
|
} |
262
|
|
|
} elseif (sys_get_param_str('action') == 'planet_teleport') { |
263
|
|
|
try { |
264
|
|
|
if (!uni_coordinates_valid($new_coordinates = array( |
265
|
|
|
'galaxy' => sys_get_param_int('new_galaxy'), |
266
|
|
|
'system' => sys_get_param_int('new_system'), |
267
|
|
|
'planet' => sys_get_param_int('new_planet'))) |
268
|
|
|
) { |
269
|
|
|
throw new exception($this->lang['ov_teleport_err_wrong_coordinates'], ERR_ERROR); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
sn_db_transaction_start(); |
273
|
|
|
// При телепорте обновлять данные не надо - просто получить текущие данные и залочить их |
274
|
|
|
$user = db_user_by_id($user['id'], true, '*'); |
|
|
|
|
275
|
|
|
$planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*'); |
276
|
|
|
|
277
|
|
|
$can_teleport = uni_planet_teleport_check($user, $planetrow, $new_coordinates); |
278
|
|
|
if ($can_teleport['result'] != ERR_NONE) { |
279
|
|
|
throw new exception($can_teleport['message'], $can_teleport['result']); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
rpg_points_change($user['id'], RPG_TELEPORT, -$this->config->planet_teleport_cost, |
283
|
|
|
array($this->lang['ov_teleport_log_record'], $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow), uni_render_coordinates($new_coordinates)) |
284
|
|
|
); |
285
|
|
|
$planet_teleport_next = SN_TIME_NOW + $this->config->planet_teleport_timeout; |
286
|
|
|
DBStaticPlanet::db_planet_set_by_gspt($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'], PT_ALL, |
287
|
|
|
"galaxy = {$new_coordinates['galaxy']}, system = {$new_coordinates['system']}, planet = {$new_coordinates['planet']}, planet_teleport_next = {$planet_teleport_next}"); |
288
|
|
|
|
289
|
|
|
if ($planetrow['id'] == $user['id_planet']) { |
290
|
|
|
db_user_set_by_id($user['id'], "galaxy = {$new_coordinates['galaxy']}, system = {$new_coordinates['system']}, planet = {$new_coordinates['planet']}"); |
|
|
|
|
291
|
|
|
} |
292
|
|
|
sn_db_transaction_commit(); |
293
|
|
|
|
294
|
|
|
$user = db_user_by_id($user['id'], true, '*'); |
|
|
|
|
295
|
|
|
$planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*'); |
296
|
|
|
$this->resultMessageList->add($this->lang['ov_teleport_err_none'], ERR_NONE); |
297
|
|
|
sys_redirect('overview.php?mode=manage'); |
298
|
|
|
} catch (exception $e) { |
299
|
|
|
sn_db_transaction_rollback(); |
300
|
|
|
$this->resultMessageList->add($e->getMessage(), $e->getCode()); |
301
|
|
|
} |
302
|
|
|
} elseif (sys_get_param_str('action') == 'planet_abandon') { |
303
|
|
|
if ($this->auth->password_check(sys_get_param('abandon_confirm'))) { |
304
|
|
|
if ($user['id_planet'] != $user['current_planet'] && $user['current_planet'] == $planet_id) { |
305
|
|
|
$destroyed = SN_TIME_NOW + 60 * 60 * 24; |
306
|
|
|
DBStaticPlanet::db_planet_set_by_id($user['current_planet'], "`destruyed`='{$destroyed}', `id_owner`=0"); |
307
|
|
|
DBStaticPlanet::db_planet_set_by_parent($user['current_planet'], "`destruyed`='{$destroyed}', `id_owner`=0"); |
308
|
|
|
db_user_set_by_id($user['id'], '`current_planet` = `id_planet`'); |
|
|
|
|
309
|
|
|
messageBox($this->lang['ov_delete_ok'], $this->lang['colony_abandon'], 'overview.php?mode=manage'); |
310
|
|
|
} else { |
311
|
|
|
messageBox($this->lang['ov_delete_wrong_planet'], $this->lang['colony_abandon'], 'overview.php?mode=manage'); |
312
|
|
|
} |
313
|
|
|
} else { |
314
|
|
|
messageBox($this->lang['ov_delete_wrong_pass'], $this->lang['colony_abandon'], 'overview.php?mode=manage'); |
315
|
|
|
} |
316
|
|
|
} elseif (($hire = sys_get_param_int('hire')) && in_array($hire, sn_get_groups('governors'))) { |
317
|
|
|
$this->planet->governorHire($hire); |
318
|
|
|
|
319
|
|
|
sys_redirect('overview.php?mode=manage'); |
320
|
|
|
die(); |
|
|
|
|
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
// TODO - refresh planet by itself |
324
|
|
|
$this->setPlanetById($planetrow['id']); |
325
|
|
|
$template->assign_recursive($this->planet->int_planet_pretemplate($user)); |
326
|
|
|
|
327
|
|
|
foreach (sn_get_groups('governors') as $governor_id) { |
328
|
|
|
if ($planetrow['planet_type'] == PT_MOON && $governor_id == MRC_TECHNOLOGIST) { |
329
|
|
|
continue; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
$governor_level = $planetrow['PLANET_GOVERNOR_ID'] == $governor_id ? $planetrow['PLANET_GOVERNOR_LEVEL'] : 0; |
333
|
|
|
$build_data = eco_get_build_data($user, $planetrow, $governor_id, $governor_level); |
334
|
|
|
$template->assign_block_vars('governors', array( |
335
|
|
|
'ID' => $governor_id, |
336
|
|
|
'NAME' => $this->lang['tech'][$governor_id], |
337
|
|
|
'COST' => $build_data[BUILD_CREATE][RES_DARK_MATTER], |
338
|
|
|
'MAX' => get_unit_param($governor_id, P_MAX_STACK), |
339
|
|
|
'LEVEL' => $governor_level, |
340
|
|
|
'LEVEL_PLUS' => mrc_get_level($user, $planetrow, $governor_id) - $governor_level, |
341
|
|
|
)); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
$user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER); |
345
|
|
|
$template->assign_recursive($this->planet->tpl_planet_density_info($user_dark_matter)); |
|
|
|
|
346
|
|
|
|
347
|
|
|
$template->assign_vars($this->templateSector($user, $user_dark_matter)); |
348
|
|
|
|
349
|
|
|
$can_teleport = uni_planet_teleport_check($user, $planetrow); |
350
|
|
|
$template->assign_vars(array( |
351
|
|
|
'DARK_MATTER' => $user_dark_matter, |
352
|
|
|
|
353
|
|
|
'CAN_TELEPORT' => $can_teleport['result'] == ERR_NONE, |
354
|
|
|
'CAN_NOT_TELEPORT_MSG' => $can_teleport['message'], |
355
|
|
|
'TELEPORT_COST_TEXT' => prettyNumberStyledCompare($this->config->planet_teleport_cost, $user_dark_matter), |
|
|
|
|
356
|
|
|
|
357
|
|
|
'IS_CAPITAL' => $planetrow['id'] == $user['id_planet'], |
358
|
|
|
'CAN_CAPITAL' => $user_dark_matter >= $this->config->planet_capital_cost, |
359
|
|
|
'CAPITAL_COST_TEXT' => prettyNumberStyledCompare($this->config->planet_capital_cost, $user_dark_matter), |
360
|
|
|
|
361
|
|
|
'PAGE_HINT' => $this->lang['ov_manage_page_hint'], |
362
|
|
|
)); |
363
|
|
|
|
364
|
|
|
$this->resultMessageList->templateAdd($template); |
365
|
|
|
|
366
|
|
|
display($template, $this->lang['rename_and_abandon_planet']); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* @param $user |
371
|
|
|
* @param $user_dark_matter |
372
|
|
|
* |
373
|
|
|
* @return array |
374
|
|
|
*/ |
375
|
|
|
protected function templateSector($user, $user_dark_matter) { |
376
|
|
|
$sector_cost = eco_get_build_data($user, $this->planet->asArray(), UNIT_SECTOR, mrc_get_level($user, $this->planet->asArray(), UNIT_SECTOR), true); |
377
|
|
|
$sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; |
378
|
|
|
$planet_fill = floor($this->planet->field_current / eco_planet_fields_max($this->planet->asArray()) * 100); |
|
|
|
|
379
|
|
|
$planet_fill = $planet_fill > 100 ? 100 : $planet_fill; |
380
|
|
|
$vararray = [ |
381
|
|
|
'planet_field_current' => $this->planet->field_current, |
382
|
|
|
'planet_field_max' => eco_planet_fields_max($this->planet->asArray()), |
383
|
|
|
'PLANET_FILL' => floor($this->planet->field_current / eco_planet_fields_max($this->planet->asArray()) * 100), |
384
|
|
|
'PLANET_FILL_BAR' => $planet_fill, |
385
|
|
|
'SECTOR_CAN_BUY' => $sector_cost <= $user_dark_matter, |
386
|
|
|
'SECTOR_COST' => $sector_cost, |
387
|
|
|
'SECTOR_COST_TEXT' => HelperString::numberFloorAndFormat($sector_cost), |
388
|
|
|
]; |
389
|
|
|
|
390
|
|
|
return $vararray; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @param template $template |
396
|
|
|
* @param int $que_type |
397
|
|
|
* @param $que |
398
|
|
|
*/ |
399
|
|
|
protected function templateQue($template, $que_type, $que) { |
400
|
|
|
// $que = que_get($planet->id_owner, $planet->id, $que_type); |
|
|
|
|
401
|
|
|
$que = $que['ques'][$que_type][$this->planet->id_owner][$this->planet->id]; |
402
|
|
|
|
403
|
|
|
$que_length = 0; |
404
|
|
|
if (!empty($que)) { |
405
|
|
|
foreach ($que as $que_item) { |
406
|
|
|
$template->assign_block_vars('que', que_tpl_parse_element($que_item)); |
407
|
|
|
} |
408
|
|
|
$que_length = count($que); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
$template->assign_block_vars('ques', [ |
412
|
|
|
'ID' => $que_type, |
413
|
|
|
'NAME' => $this->lang['sys_ques'][$que_type], |
414
|
|
|
'LENGTH' => $que_length, |
415
|
|
|
]); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Calculates planet grid sizes (horizontal and vertical) for Planet Overview |
420
|
|
|
* |
421
|
|
|
* @param $user |
422
|
|
|
* @param $user_option_list |
423
|
|
|
* @param $planet_count |
424
|
|
|
* |
425
|
|
|
* @return array |
426
|
|
|
*/ |
427
|
|
|
protected function templateGridSizes($user, $user_option_list, $planet_count) { |
428
|
|
|
$overview_planet_rows = $user['opt_int_overview_planet_rows']; |
429
|
|
|
$overview_planet_columns = $user['opt_int_overview_planet_columns']; |
430
|
|
|
|
431
|
|
|
if ($overview_planet_rows <= 0 && $overview_planet_columns <= 0) { |
432
|
|
|
$overview_planet_rows = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_rows']; |
433
|
|
|
$overview_planet_columns = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_columns']; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
if ($overview_planet_rows > 0 && $overview_planet_columns <= 0) { |
437
|
|
|
$overview_planet_columns = ceil($planet_count / $overview_planet_rows); |
438
|
|
|
} |
439
|
|
|
$vararray = [ |
440
|
|
|
'LIST_ROW_COUNT' => $overview_planet_rows, |
441
|
|
|
'LIST_COLUMN_COUNT' => $overview_planet_columns, |
442
|
|
|
]; |
443
|
|
|
|
444
|
|
|
return $vararray; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
} |
448
|
|
|
|
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state