@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $this->sql_index_field = "{$table_name}_name"; |
41 | 41 | $this->sql_value_field = "{$table_name}_value"; |
42 | 42 | |
43 | - if(!$this->_DB_LOADED) { |
|
43 | + if (!$this->_DB_LOADED) { |
|
44 | 44 | $this->db_loadAll(); |
45 | 45 | } |
46 | 46 | } |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function db_loadItem($index) { |
62 | 62 | $result = null; |
63 | - if($index) { |
|
63 | + if ($index) { |
|
64 | 64 | $index_safe = SN::$db->db_escape($index); |
65 | 65 | $queryResult = doquery("SELECT `{$this->sql_value_field}` FROM `{{{$this->table_name}}}` WHERE `{$this->sql_index_field}` = '{$index_safe}' FOR UPDATE", true); |
66 | - if(is_array($queryResult) && !empty($queryResult)) { |
|
66 | + if (is_array($queryResult) && !empty($queryResult)) { |
|
67 | 67 | $this->$index = $result = $queryResult[$this->sql_value_field]; |
68 | 68 | } |
69 | 69 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $this->loadDefaults(); |
76 | 76 | |
77 | 77 | $query = doquery("SELECT * FROM {{{$this->table_name}}} FOR UPDATE;"); |
78 | - while($row = db_fetch($query)) { |
|
78 | + while ($row = db_fetch($query)) { |
|
79 | 79 | $this[$row[$this->sql_index_field]] = $row[$this->sql_value_field]; |
80 | 80 | } |
81 | 81 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | public function loadDefaults() { |
86 | - foreach($this->defaults as $defName => $defValue) { |
|
86 | + foreach ($this->defaults as $defName => $defValue) { |
|
87 | 87 | $this->$defName = $defValue; |
88 | 88 | } |
89 | 89 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | public function db_saveItem($item_list, $value = NULL) { |
96 | - if(empty($item_list)) { |
|
96 | + if (empty($item_list)) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | |
102 | 102 | // Сначала записываем данные в базу - что бы поймать все блокировки |
103 | 103 | $qry = array(); |
104 | - foreach($item_list as $item_name => $item_value) { |
|
105 | - if($item_name) { |
|
104 | + foreach ($item_list as $item_name => $item_value) { |
|
105 | + if ($item_name) { |
|
106 | 106 | $item_value = SN::$db->db_escape($item_value === NULL ? $this->$item_name : $item_value); |
107 | 107 | $item_name = SN::$db->db_escape($item_name); |
108 | 108 | $qry[] = "('{$item_name}', '{$item_value}')"; |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | doquery("REPLACE INTO `{{" . $this->table_name . "}}` (`{$this->sql_index_field}`, `{$this->sql_value_field}`) VALUES " . implode(',', $qry) . ";"); |
112 | 112 | |
113 | 113 | // И только после взятия блокировок - меняем значения в кэше |
114 | - foreach($item_list as $item_name => $item_value) { |
|
115 | - if($item_name && $item_value !== null) { |
|
114 | + foreach ($item_list as $item_name => $item_value) { |
|
115 | + if ($item_name && $item_value !== null) { |
|
116 | 116 | $this->__set($item_name, $item_value); |
117 | 117 | } |
118 | 118 | } |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | public function __get($name) { |
143 | - if($this->force) { |
|
143 | + if ($this->force) { |
|
144 | 144 | $this->force = false; |
145 | 145 | $value = $this->db_loadItem($name); |
146 | 146 | } else { |
147 | 147 | $value = parent::__get($name); |
148 | 148 | } |
149 | 149 | |
150 | - if(isset($this->notEmptyFields[$name]) && empty($value) && isset($this->defaults[$name])) { |
|
150 | + if (isset($this->notEmptyFields[$name]) && empty($value) && isset($this->defaults[$name])) { |
|
151 | 151 | $value = $this->defaults[$name]; |
152 | 152 | } |
153 | 153 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | public function __set($name, $value) { |
158 | - if($this->force) { |
|
158 | + if ($this->force) { |
|
159 | 159 | $this->force = false; |
160 | 160 | $this->db_saveItem($name, $value); |
161 | 161 | } |
@@ -142,9 +142,7 @@ |
||
142 | 142 | // Простое условие - $field_id = $field_value |
143 | 143 | if (is_string($field_id)) { |
144 | 144 | $field_value = |
145 | - $field_value === null ? 'NULL' : |
|
146 | - (is_string($field_value) ? "'" . SN::$db->db_escape($field_value) . "'" : |
|
147 | - (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
145 | + $field_value === null ? 'NULL' : (is_string($field_value) ? "'" . SN::$db->db_escape($field_value) . "'" : (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
148 | 146 | $the_conditions[] = "`{$field_id}` = {$field_value}"; |
149 | 147 | } else { |
150 | 148 | die('Неподдерживаемый тип условия'); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | set_error_handler([$this, 'handlerQueryWarning']); |
226 | 226 | $sqlquery = $this->db_sql_query($sql); |
227 | - if(!$sqlquery) { |
|
227 | + if (!$sqlquery) { |
|
228 | 228 | $debug->error(SN::$db->db_error() . "<br />$sql<br />", 'SQL Error'); |
229 | 229 | } |
230 | 230 | restore_error_handler(); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | $q1 = $this->db_sql_query("SHOW INDEX FROM {$prefixedTableName_safe};"); |
397 | 397 | while ($r1 = db_fetch($q1)) { |
398 | 398 | $indexName = $r1['Key_name']; |
399 | - if(empty($result[$indexName])) { |
|
399 | + if (empty($result[$indexName])) { |
|
400 | 400 | $result[$indexName] = new DbIndexDescription(); |
401 | 401 | } |
402 | 402 | $result[$indexName]->addField($r1); |
@@ -56,7 +56,7 @@ |
||
56 | 56 | $config->pass()->game_disable = GAME_DISABLE_STAT; |
57 | 57 | |
58 | 58 | $statMinimalInterval = intval($config->pass()->stats_minimal_interval); |
59 | - $config->pass()->var_stat_update_end= date(FMT_DATE_TIME_SQL, SN_TIME_NOW + ($statMinimalInterval ? $statMinimalInterval : STATS_RUN_INTERVAL_MINIMUM)); |
|
59 | + $config->pass()->var_stat_update_end = date(FMT_DATE_TIME_SQL, SN_TIME_NOW + ($statMinimalInterval ? $statMinimalInterval : STATS_RUN_INTERVAL_MINIMUM)); |
|
60 | 60 | $config->pass()->var_stat_update_msg = 'Update started'; |
61 | 61 | SN::db_transaction_commit(); |
62 | 62 |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | $planet = $planetrow['planet']; |
66 | 66 | } |
67 | 67 | |
68 | -$uni_galaxy = (int)$uni_galaxy; |
|
69 | -$uni_system = (int)$uni_system; |
|
68 | +$uni_galaxy = (int) $uni_galaxy; |
|
69 | +$uni_system = (int) $uni_system; |
|
70 | 70 | |
71 | 71 | $uni_galaxy = $uni_galaxy < 1 ? 1 : ($uni_galaxy > SN::$config->game_maxGalaxy ? SN::$config->game_maxGalaxy : $uni_galaxy); |
72 | 72 | $uni_system = $uni_system < 1 ? 1 : ($uni_system > SN::$config->game_maxSystem ? SN::$config->game_maxSystem : $uni_system); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | || |
132 | 132 | (!empty($uni_galaxyRowPlanet['destruyed']) && CheckAbandonPlanetState($uni_galaxyRowPlanet)) |
133 | 133 | ) { |
134 | - $template->assign_block_vars('galaxyrow', ['PLANET_NUM' => $Planet,]); |
|
134 | + $template->assign_block_vars('galaxyrow', ['PLANET_NUM' => $Planet, ]); |
|
135 | 135 | continue; |
136 | 136 | } |
137 | 137 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | 'IS_CAPITAL' => $uni_galaxyRowUser['id_planet'] == $uni_galaxyRowPlanet['id'], |
250 | 250 | |
251 | 251 | 'USER_ID' => $uni_galaxyRowUser['id'], |
252 | - 'USER_NAME' => $renderedNick = player_nick_render_to_html($uni_galaxyRowUser, ['icons' => true,]), |
|
252 | + 'USER_NAME' => $renderedNick = player_nick_render_to_html($uni_galaxyRowUser, ['icons' => true, ]), |
|
253 | 253 | 'USER_NAME_JS' => js_safe_string($renderedNick), |
254 | 254 | 'USER_RANK' => in_array($uni_galaxyRowUser['id'], $user_skip_list) ? '-' : $uni_galaxyRowUser['total_rank'], |
255 | 255 | 'USER_BANNED' => $uni_galaxyRowUser['banaday'], |
@@ -29,19 +29,19 @@ discard block |
||
29 | 29 | */ |
30 | 30 | function db_set_make_safe_string($set, $delta = false) { |
31 | 31 | $set_safe = array(); |
32 | - foreach($set as $field => $value) { |
|
33 | - if(empty($field)) { |
|
32 | + foreach ($set as $field => $value) { |
|
33 | + if (empty($field)) { |
|
34 | 34 | continue; |
35 | 35 | } |
36 | 36 | |
37 | 37 | $field = '`' . SN::$db->db_escape($field) . '`'; |
38 | 38 | $new_value = $value; |
39 | - if($value === null) { |
|
39 | + if ($value === null) { |
|
40 | 40 | $new_value = 'NULL'; |
41 | - } elseif(is_string($value) && (string)($new_value = floatval($value)) != (string)$value) { |
|
41 | + } elseif (is_string($value) && (string) ($new_value = floatval($value)) != (string) $value) { |
|
42 | 42 | // non-float |
43 | 43 | $new_value = '"' . SN::$db->db_escape($value) . '"'; |
44 | - } elseif($delta) { |
|
44 | + } elseif ($delta) { |
|
45 | 45 | // float and DELTA-set |
46 | 46 | $new_value = "{$field} + ({$new_value})"; |
47 | 47 | } |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | */ |
62 | 62 | function missile_list_convert_to_fleet(&$missile_db_list, &$fleet_db_list) { |
63 | 63 | // Missile attack |
64 | - foreach($missile_db_list as $irak) { |
|
65 | - if($irak['fleet_end_time'] >= SN_TIME_NOW) { |
|
64 | + foreach ($missile_db_list as $irak) { |
|
65 | + if ($irak['fleet_end_time'] >= SN_TIME_NOW) { |
|
66 | 66 | $irak['fleet_start_type'] = PT_PLANET; |
67 | 67 | $planet_start = DBStaticPlanet::db_planet_by_vector($irak, 'fleet_start_', false, 'name'); |
68 | 68 | $irak['fleet_id'] = -$irak['id']; |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | |
8 | 8 | function que_get_unit_que($unit_id) { |
9 | 9 | $que_type = false; |
10 | - foreach(sn_get_groups('ques') as $que_id => $que_data) { |
|
11 | - if(in_array($unit_id, $que_data['unit_list'])) { |
|
10 | + foreach (sn_get_groups('ques') as $que_id => $que_data) { |
|
11 | + if (in_array($unit_id, $que_data['unit_list'])) { |
|
12 | 12 | $que_type = $que_id; |
13 | 13 | break; |
14 | 14 | } |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | function que_get_max_que_length($user, $planet, $que_id, $que_data = null) { |
22 | 22 | global $config; |
23 | 23 | |
24 | - if(empty($que_data)) { |
|
24 | + if (empty($que_data)) { |
|
25 | 25 | $que_data = sn_get_groups('ques'); |
26 | 26 | $que_data = $que_data[$que_id]; |
27 | 27 | } |
28 | 28 | |
29 | 29 | |
30 | 30 | $que_length = 1; |
31 | - switch($que_id) { |
|
31 | + switch ($que_id) { |
|
32 | 32 | case QUE_RESEARCH: |
33 | 33 | $que_length = $config->server_que_length_research + mrc_get_level($user, '', UNIT_PREMIUM); // TODO - вынести в модуль |
34 | 34 | break; |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | |
43 | 43 | function eco_que_str2arr($que_str) { |
44 | 44 | $que_arr = explode(';', $que_str); |
45 | - foreach($que_arr as $que_index => &$que_item) { |
|
46 | - if($que_item) { |
|
45 | + foreach ($que_arr as $que_index => &$que_item) { |
|
46 | + if ($que_item) { |
|
47 | 47 | $que_item = explode(',', $que_item); |
48 | 48 | } else { |
49 | 49 | unset($que_arr[$que_index]); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | function eco_que_arr2str($que_arr) { |
56 | - foreach($que_arr as &$que_item) { |
|
56 | + foreach ($que_arr as &$que_item) { |
|
57 | 57 | $que_item = implode(',', $que_item); |
58 | 58 | } |
59 | 59 | return implode(';', $que_arr); |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | global $lang, $config; |
65 | 65 | |
66 | 66 | $is_autoconvert = false; |
67 | - if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { |
|
67 | + if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { |
|
68 | 68 | $build_mode = BUILD_CREATE; |
69 | 69 | $is_autoconvert = true; |
70 | 70 | } |
71 | 71 | |
72 | 72 | $unit_amount_qued = 0; |
73 | 73 | try { |
74 | - if(!$user['id']) { |
|
74 | + if (!$user['id']) { |
|
75 | 75 | throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
76 | 76 | } |
77 | 77 | |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | foreach($unit_list as $unit_id => $unit_amount) if($unit_amount) break; |
83 | 83 | } |
84 | 84 | */ |
85 | - if(!$unit_id) { |
|
85 | + if (!$unit_id) { |
|
86 | 86 | throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
87 | 87 | } |
88 | 88 | |
89 | 89 | $que_id = que_get_unit_que($unit_id); |
90 | - if(!$que_id) { |
|
90 | + if (!$que_id) { |
|
91 | 91 | throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
92 | 92 | } |
93 | 93 | |
94 | - if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { |
|
94 | + if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { |
|
95 | 95 | throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION |
96 | 96 | } |
97 | 97 | |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | $que_data = $que_data[$que_id]; |
100 | 100 | |
101 | 101 | // TODO Переделать под подочереди |
102 | - if($que_id == QUE_STRUCTURES) { |
|
102 | + if ($que_id == QUE_STRUCTURES) { |
|
103 | 103 | $sn_groups_build_allow = sn_get_groups('build_allow'); |
104 | 104 | $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']]; |
105 | 105 | |
106 | - if(!isset($que_data['unit_list'][$unit_id])) { |
|
106 | + if (!isset($que_data['unit_list'][$unit_id])) { |
|
107 | 107 | throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION |
108 | 108 | } |
109 | 109 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | // Это нужно, что бы заблокировать пользователя и работу с очередями |
125 | 125 | $user = db_user_by_id($user['id']); |
126 | 126 | // Это нужно, что бы заблокировать планету от списания ресурсов |
127 | - if(isset($planet['id']) && $planet['id']) { |
|
127 | + if (isset($planet['id']) && $planet['id']) { |
|
128 | 128 | $planet = DBStaticPlanet::db_planet_by_id($planet['id'], true); |
129 | 129 | } else { |
130 | 130 | $planet['id'] = 0; |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | $in_que = &$que['in_que'][$que_id][$user['id']][$planet_id]; |
137 | 137 | $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data); |
138 | 138 | // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей |
139 | - if(count($in_que) >= $que_max_length) { |
|
139 | + if (count($in_que) >= $que_max_length) { |
|
140 | 140 | throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION |
141 | 141 | } |
142 | 142 | |
143 | 143 | // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов |
144 | - switch(eco_can_build_unit($user, $planet, $unit_id)) { |
|
144 | + switch (eco_can_build_unit($user, $planet, $unit_id)) { |
|
145 | 145 | case BUILD_ALLOWED: break; |
146 | 146 | case BUILD_UNIT_BUSY: throw new exception('{Строение занято}', ERR_ERROR); break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading |
147 | 147 | // case BUILD_REQUIRE_NOT_MEET: |
148 | 148 | default: |
149 | - if($build_mode == BUILD_CREATE) { |
|
149 | + if ($build_mode == BUILD_CREATE) { |
|
150 | 150 | throw new exception('{Требования не удовлетворены}', ERR_ERROR); |
151 | 151 | } |
152 | 152 | break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | $unit_amount_qued = $unit_amount; |
157 | 157 | $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0; |
158 | 158 | $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued; |
159 | - if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
160 | - if($unit_level >= $unit_max) { |
|
159 | + if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
160 | + if ($unit_level >= $unit_max) { |
|
161 | 161 | throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
162 | 162 | } |
163 | 163 | $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level)); |
164 | 164 | } |
165 | 165 | |
166 | - if($unit_amount < 1) { |
|
166 | + if ($unit_amount < 1) { |
|
167 | 167 | throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
168 | 168 | } |
169 | 169 | |
@@ -179,21 +179,21 @@ discard block |
||
179 | 179 | // { |
180 | 180 | // die('Unit busy'); // TODO EXCEPTION |
181 | 181 | // } |
182 | - if(get_unit_param($unit_id, P_STACKABLE)) { |
|
182 | + if (get_unit_param($unit_id, P_STACKABLE)) { |
|
183 | 183 | // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь |
184 | - if(in_array($unit_id, $group_missile = sn_get_groups('missile'))) { |
|
184 | + if (in_array($unit_id, $group_missile = sn_get_groups('missile'))) { |
|
185 | 185 | // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита |
186 | 186 | $used_silo = 0; |
187 | - foreach($group_missile as $missile_id) { |
|
187 | + foreach ($group_missile as $missile_id) { |
|
188 | 188 | $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0; |
189 | 189 | $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE); |
190 | 190 | } |
191 | 191 | $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo; |
192 | - if($free_silo <= 0) { |
|
192 | + if ($free_silo <= 0) { |
|
193 | 193 | throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
194 | 194 | } |
195 | 195 | $unit_size = get_unit_param($unit_id, P_UNIT_SIZE); |
196 | - if($free_silo < $unit_size) { |
|
196 | + if ($free_silo < $unit_size) { |
|
197 | 197 | throw new exception("{В ракетной шахте нет места для {$lang['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION |
198 | 198 | } |
199 | 199 | $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size))); |
@@ -201,10 +201,10 @@ discard block |
||
201 | 201 | $unit_level = $new_unit_level = 0; |
202 | 202 | } else { |
203 | 203 | $unit_amount = 1; |
204 | - if($que_id == QUE_STRUCTURES) { |
|
204 | + if ($que_id == QUE_STRUCTURES) { |
|
205 | 205 | // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0) |
206 | 206 | $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0; |
207 | - if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) |
|
207 | + if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) |
|
208 | 208 | { |
209 | 209 | throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION |
210 | 210 | } |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | |
223 | 223 | $exchange = array(); |
224 | 224 | $market_get_autoconvert_cost = market_get_autoconvert_cost(); |
225 | - if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
225 | + if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
226 | 226 | $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); |
227 | - if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
227 | + if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
228 | 228 | throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION |
229 | 229 | } |
230 | 230 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | $resource_exchange_rates = array(); |
235 | 235 | $resource_diff = array(); |
236 | 236 | $all_positive = true; |
237 | - foreach($resources_loot as $resource_id) { |
|
237 | + foreach ($resources_loot as $resource_id) { |
|
238 | 238 | $resource_db_name = pname_resource_name($resource_id); |
239 | 239 | $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id)); |
240 | 240 | $resource_exchange_rates[$resource_id] = $config->__get("rpg_exchange_{$resource_db_name}"); |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | $all_positive = $all_positive && ($resource_diff[$resource_id] > 0); |
243 | 243 | } |
244 | 244 | // Нужна автоконвертация |
245 | - if($all_positive) { |
|
245 | + if ($all_positive) { |
|
246 | 246 | $is_autoconvert = false; |
247 | 247 | } else { |
248 | - foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
249 | - if($resource_diff_amount >= 0) { |
|
248 | + foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
249 | + if ($resource_diff_amount >= 0) { |
|
250 | 250 | continue; |
251 | 251 | } |
252 | - foreach($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
253 | - if($resource_got_amount <= 0) { |
|
252 | + foreach ($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
253 | + if ($resource_got_amount <= 0) { |
|
254 | 254 | continue; |
255 | 255 | } |
256 | 256 | $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id]; |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | } |
267 | 267 | |
268 | 268 | $is_autoconvert_ok = true; |
269 | - foreach($resource_diff as $resource_diff_amount2) { |
|
270 | - if($resource_diff_amount2 < 0) { |
|
269 | + foreach ($resource_diff as $resource_diff_amount2) { |
|
270 | + if ($resource_diff_amount2 < 0) { |
|
271 | 271 | $is_autoconvert_ok = false; |
272 | 272 | break; |
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | - if($is_autoconvert_ok) { |
|
276 | + if ($is_autoconvert_ok) { |
|
277 | 277 | $build_data['RESULT'][$build_mode] = BUILD_ALLOWED; |
278 | 278 | $build_data['CAN'][$build_mode] = $unit_amount; |
279 | 279 | } else { |
@@ -282,19 +282,19 @@ discard block |
||
282 | 282 | } |
283 | 283 | } |
284 | 284 | $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount); |
285 | - if($unit_amount <= 0) { |
|
285 | + if ($unit_amount <= 0) { |
|
286 | 286 | throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION |
287 | 287 | } |
288 | 288 | |
289 | - if($new_unit_level < 0) { |
|
289 | + if ($new_unit_level < 0) { |
|
290 | 290 | throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION |
291 | 291 | } |
292 | 292 | |
293 | - if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
293 | + if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
294 | 294 | throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION |
295 | 295 | } |
296 | 296 | |
297 | - if($is_autoconvert) { |
|
297 | + if ($is_autoconvert) { |
|
298 | 298 | ksort($exchange); |
299 | 299 | ksort($resource_got); |
300 | 300 | db_change_units($user, $planet, array( |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | } |
310 | 310 | |
311 | 311 | $unit_amount_qued = 0; |
312 | - while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
312 | + while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
313 | 313 | $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW); |
314 | 314 | // $sqlBlock = QueUnitStatic::que_unit_make_sql($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode); |
315 | 315 | $sqlBlock = SN::$gc->pimp->que_unit_make_sql($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode); |
316 | 316 | |
317 | - array_walk($sqlBlock, function (&$value, $field) { |
|
318 | - if($value === null) { |
|
317 | + array_walk($sqlBlock, function(&$value, $field) { |
|
318 | + if ($value === null) { |
|
319 | 319 | $value = 'NULL'; |
320 | 320 | } elseif (is_string($value)) { |
321 | 321 | $value = "'{$value}'"; |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | |
347 | 347 | SN::db_transaction_commit(); |
348 | 348 | |
349 | - if($redirect) { |
|
349 | + if ($redirect) { |
|
350 | 350 | sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id')); |
351 | 351 | } |
352 | 352 | |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | 'STATUS' => ERR_NONE, |
355 | 355 | 'MESSAGE' => '{Строительство начато}', |
356 | 356 | ); |
357 | - } catch(exception $e) { |
|
357 | + } catch (exception $e) { |
|
358 | 358 | SN::db_transaction_rollback(); |
359 | 359 | $operation_result = array( |
360 | 360 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | ); |
363 | 363 | } |
364 | 364 | |
365 | - if(!empty($operation_result['MESSAGE'])) { |
|
365 | + if (!empty($operation_result['MESSAGE'])) { |
|
366 | 366 | $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . $lang['tech'][$unit_id] . ']'; |
367 | 367 | } |
368 | 368 | |
@@ -376,11 +376,11 @@ discard block |
||
376 | 376 | function que_recalculate($old_que) { |
377 | 377 | $new_que = array(); |
378 | 378 | |
379 | - if(!is_array($old_que['items'])) { |
|
379 | + if (!is_array($old_que['items'])) { |
|
380 | 380 | return $new_que; |
381 | 381 | } |
382 | - foreach($old_que['items'] as $row) { |
|
383 | - if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
382 | + foreach ($old_que['items'] as $row) { |
|
383 | + if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
384 | 384 | continue; |
385 | 385 | } |
386 | 386 | |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | |
392 | 392 | $last_id = count($new_que['items']) - 1; |
393 | 393 | |
394 | - if($row['que_planet_id']) { |
|
394 | + if ($row['que_planet_id']) { |
|
395 | 395 | $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
396 | - } elseif($row['que_type'] == QUE_RESEARCH) { |
|
396 | + } elseif ($row['que_type'] == QUE_RESEARCH) { |
|
397 | 397 | $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
398 | 398 | } |
399 | 399 | $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id]; |
@@ -418,17 +418,17 @@ discard block |
||
418 | 418 | $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0; |
419 | 419 | $global_que = que_get($user['id'], $planet['id'], $que_type, true); |
420 | 420 | |
421 | - if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
421 | + if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
422 | 422 | $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]); |
423 | 423 | |
424 | - foreach($que as $que_item) { |
|
424 | + foreach ($que as $que_item) { |
|
425 | 425 | DBStaticQue::db_que_delete_by_id($que_item['que_id']); |
426 | 426 | |
427 | - if($que_item['que_planet_id_origin']) { |
|
427 | + if ($que_item['que_planet_id_origin']) { |
|
428 | 428 | $planet['id'] = $que_item['que_planet_id_origin']; |
429 | 429 | } |
430 | 430 | |
431 | - if(!isset($planets_locked[$planet['id']])) { |
|
431 | + if (!isset($planets_locked[$planet['id']])) { |
|
432 | 432 | $planets_locked[$planet['id']] = $planet['id'] ? DBStaticPlanet::db_planet_by_id($planet['id'], true) : $planet; |
433 | 433 | } |
434 | 434 | |
@@ -440,15 +440,15 @@ discard block |
||
440 | 440 | RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'], |
441 | 441 | )); |
442 | 442 | |
443 | - if(!$clear) { |
|
443 | + if (!$clear) { |
|
444 | 444 | break; |
445 | 445 | } |
446 | 446 | } |
447 | 447 | |
448 | - if(is_numeric($planet['id'])) { |
|
448 | + if (is_numeric($planet['id'])) { |
|
449 | 449 | DBStaticPlanet::db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
450 | 450 | } |
451 | - elseif(is_numeric($user['id'])) { |
|
451 | + elseif (is_numeric($user['id'])) { |
|
452 | 452 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
453 | 453 | } |
454 | 454 | |
@@ -493,21 +493,21 @@ discard block |
||
493 | 493 | // TODO: Переделать для $que_type === false |
494 | 494 | $planet['id'] = $planet['id'] ? $planet['id'] : 0; |
495 | 495 | |
496 | - if(!is_array($que)) { |
|
496 | + if (!is_array($que)) { |
|
497 | 497 | $que = que_get($user['id'], $planet['id'], $que_type); |
498 | 498 | } |
499 | 499 | |
500 | - if(is_array($que) && isset($que['items'])) { |
|
500 | + if (is_array($que) && isset($que['items'])) { |
|
501 | 501 | $que = $que['ques'][$que_type][$user['id']][$planet['id']]; |
502 | 502 | } |
503 | 503 | |
504 | - if($que) { |
|
505 | - foreach($que as $que_element) { |
|
504 | + if ($que) { |
|
505 | + foreach ($que as $que_element) { |
|
506 | 506 | $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names)); |
507 | 507 | } |
508 | 508 | } |
509 | 509 | |
510 | - if($que_type == QUE_RESEARCH) { |
|
510 | + if ($que_type == QUE_RESEARCH) { |
|
511 | 511 | // TODO Исправить |
512 | 512 | // $template->assign_var('RESEARCH_ONGOING', count($global_que[QUE_RESEARCH][0]) >= $config->server_que_length_research); |
513 | 513 | } |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | $user = db_user_by_id($user['id'], true); |
536 | 536 | |
537 | 537 | $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']); |
538 | - if($planet === null && !$time_left[$user['id']][0]) { |
|
538 | + if ($planet === null && !$time_left[$user['id']][0]) { |
|
539 | 539 | // TODO |
540 | 540 | return $que; |
541 | 541 | } |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | $que_type_id = $planet === null ? QUE_RESEARCH : false; |
545 | 545 | $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false |
546 | 546 | $que = que_get($user['id'], $planet, $que_type_id, true); |
547 | - if(empty($que['items'])) { |
|
547 | + if (empty($que['items'])) { |
|
548 | 548 | return $que; |
549 | 549 | } |
550 | 550 | |
551 | 551 | $planet_list = array(); |
552 | - if($planet !== null) { |
|
552 | + if ($planet !== null) { |
|
553 | 553 | // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них |
554 | 554 | // TODO - от них не надо ничего, кроме ID и que_processed |
555 | 555 | $planet_row = DBStaticPlanet::db_planet_list_by_user_or_planet($user['id'], $planet); |
@@ -558,21 +558,21 @@ discard block |
||
558 | 558 | } |
559 | 559 | |
560 | 560 | // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты |
561 | - if(array_sum($time_left[$user['id']]) == 0) { |
|
561 | + if (array_sum($time_left[$user['id']]) == 0) { |
|
562 | 562 | return $que; |
563 | 563 | } |
564 | 564 | |
565 | 565 | $db_changeset = array(); |
566 | 566 | $unit_changes = array(); |
567 | - foreach($que['items'] as &$que_item) { |
|
567 | + foreach ($que['items'] as &$que_item) { |
|
568 | 568 | $que_player_id = &$que_item['que_player_id']; |
569 | 569 | $que_planet_id = intval($que_item['que_planet_id']); |
570 | 570 | |
571 | 571 | $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']]; |
572 | - if(!isset($que_time_left)) { |
|
572 | + if (!isset($que_time_left)) { |
|
573 | 573 | $que_time_left = $time_left[$que_player_id][$que_planet_id]; |
574 | 574 | } |
575 | - if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
575 | + if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
576 | 576 | continue; |
577 | 577 | } |
578 | 578 | // Дальше мы идем, если только осталось время в очереди И юниты к постройке |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля |
586 | 586 | |
587 | 587 | // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит |
588 | - if($que_time_left >= $que_item['que_time_left']) { |
|
588 | + if ($que_time_left >= $que_item['que_time_left']) { |
|
589 | 589 | // Увеличиваем количество отстроенных юнитов |
590 | 590 | $unit_processed++; |
591 | 591 | // Вычитаем из времени очереди потраченное на постройку время |
@@ -598,12 +598,12 @@ discard block |
||
598 | 598 | $que_item['que_unit_amount'] -= $unit_processed; |
599 | 599 | |
600 | 600 | // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита |
601 | - if($que_item['que_unit_amount'] > 0) { |
|
601 | + if ($que_item['que_unit_amount'] > 0) { |
|
602 | 602 | $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left; |
603 | 603 | $que_time_left = 0; |
604 | 604 | } |
605 | 605 | |
606 | - if($que_item['que_unit_amount'] <= 0) { |
|
606 | + if ($que_item['que_unit_amount'] <= 0) { |
|
607 | 607 | $db_changeset['que'][] = array( |
608 | 608 | 'action' => SQL_OP_DELETE, |
609 | 609 | P_VERSION => 1, |
@@ -629,14 +629,14 @@ discard block |
||
629 | 629 | ); |
630 | 630 | } |
631 | 631 | |
632 | - if($unit_processed) { |
|
632 | + if ($unit_processed) { |
|
633 | 633 | $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); |
634 | 634 | $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta; |
635 | 635 | } |
636 | 636 | } |
637 | 637 | |
638 | - foreach($time_left as $player_id => $planet_data) { |
|
639 | - foreach($planet_data as $planet_id => $time_on_planet) { |
|
638 | + foreach ($time_left as $player_id => $planet_data) { |
|
639 | + foreach ($planet_data as $planet_id => $time_on_planet) { |
|
640 | 640 | $table = $planet_id ? 'planets' : 'users'; |
641 | 641 | $id = $planet_id ? $planet_id : $player_id; |
642 | 642 | $db_changeset[$table][] = array( |
@@ -652,8 +652,8 @@ discard block |
||
652 | 652 | ), |
653 | 653 | ); |
654 | 654 | |
655 | - if(is_array($unit_changes[$player_id][$planet_id])) { |
|
656 | - foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
655 | + if (is_array($unit_changes[$player_id][$planet_id])) { |
|
656 | + foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
657 | 657 | $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null); |
658 | 658 | } |
659 | 659 | } |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | $que = que_recalculate($que); |
664 | 664 | |
665 | 665 | // TODO: Re-enable quests for Alliances |
666 | - if(!empty($unit_changes) && !$user['user_as_ally']) { |
|
666 | + if (!empty($unit_changes) && !$user['user_as_ally']) { |
|
667 | 667 | $quest_list = qst_get_quests($user['id'], QUEST_STATUS_ALL); |
668 | 668 | $quest_triggers = qst_active_triggers($quest_list); |
669 | 669 | $quest_rewards = array(); |
@@ -671,26 +671,26 @@ discard block |
||
671 | 671 | |
672 | 672 | |
673 | 673 | $xp_incoming = array(); |
674 | - foreach($unit_changes as $user_id => $planet_changes) { |
|
675 | - foreach($planet_changes as $planet_id => $changes) { |
|
674 | + foreach ($unit_changes as $user_id => $planet_changes) { |
|
675 | + foreach ($planet_changes as $planet_id => $changes) { |
|
676 | 676 | $planet_this = $planet_id ? SN::db_get_record_by_id(LOC_PLANET, $planet_id) : array(); |
677 | - foreach($changes as $unit_id => $unit_value) { |
|
677 | + foreach ($changes as $unit_id => $unit_value) { |
|
678 | 678 | $que_id = que_get_unit_que($unit_id); |
679 | 679 | $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value; |
680 | - if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
680 | + if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
681 | 681 | $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1); |
682 | 682 | $build_data = $build_data[BUILD_CREATE]; |
683 | - foreach(sn_get_groups('resources_loot') as $resource_id) { |
|
683 | + foreach (sn_get_groups('resources_loot') as $resource_id) { |
|
684 | 684 | $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена |
685 | 685 | } |
686 | 686 | } |
687 | 687 | |
688 | - if(is_array($quest_triggers)) { |
|
688 | + if (is_array($quest_triggers)) { |
|
689 | 689 | // TODO: Check mutiply condition quests |
690 | 690 | $quest_trigger_list = array_keys($quest_triggers, $unit_id); |
691 | 691 | |
692 | - if(is_array($quest_trigger_list)) { |
|
693 | - foreach($quest_trigger_list as $quest_id) { |
|
692 | + if (is_array($quest_trigger_list)) { |
|
693 | + foreach ($quest_trigger_list as $quest_id) { |
|
694 | 694 | if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE) { |
695 | 695 | if ($quest_list[$quest_id]['quest_unit_amount'] <= $unit_level_new) { |
696 | 696 | $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list']; |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч |
709 | 709 | qst_reward($user, $quest_rewards, $quest_list, $quest_statuses); |
710 | 710 | |
711 | - foreach($xp_incoming as $que_id => $xp) { |
|
711 | + foreach ($xp_incoming as $que_id => $xp) { |
|
712 | 712 | rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000); |
713 | 713 | } |
714 | 714 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | function sys_user_vacation($user) { |
13 | 13 | global $config; |
14 | 14 | |
15 | - if(sys_get_param_str('vacation') == 'leave') { |
|
15 | + if (sys_get_param_str('vacation') == 'leave') { |
|
16 | 16 | if ($user['vacation'] < SN_TIME_NOW) { |
17 | 17 | $user['vacation'] = 0; |
18 | 18 | $user['vacation_next'] = SN_TIME_NOW + $config->player_vacation_timeout; |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
23 | - if($user['vacation']) { |
|
23 | + if ($user['vacation']) { |
|
24 | 24 | // sn_sys_logout(false, true); |
25 | 25 | // core_auth::logout(false, true); |
26 | 26 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | \DBAL\DbQuery::build()->setTable('users')->setValues($field_set)->doInsert(); |
164 | 164 | $user_new = db_user_by_id(SN::$db->db_insert_id()); |
165 | 165 | |
166 | - if(!($options['galaxy'] && $options['system'] && $options['planet'])) { |
|
166 | + if (!($options['galaxy'] && $options['system'] && $options['planet'])) { |
|
167 | 167 | $options['galaxy'] = SN::$config->LastSettedGalaxyPos; |
168 | 168 | $options['system'] = SN::$config->LastSettedSystemPos; |
169 | 169 | $segment_size = floor(SN::$config->game_maxPlanet / 3); |
@@ -171,19 +171,19 @@ discard block |
||
171 | 171 | $segment++; |
172 | 172 | $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size); |
173 | 173 | |
174 | - while(true) { |
|
175 | - if($options['planet'] > SN::$config->game_maxPlanet) { |
|
174 | + while (true) { |
|
175 | + if ($options['planet'] > SN::$config->game_maxPlanet) { |
|
176 | 176 | $options['planet'] = mt_rand(0, $segment_size - 1) + 1; |
177 | 177 | $options['system']++; |
178 | 178 | } |
179 | - if($options['system'] > SN::$config->game_maxSystem) { |
|
179 | + if ($options['system'] > SN::$config->game_maxSystem) { |
|
180 | 180 | $options['system'] = 1; |
181 | 181 | $options['galaxy']++; |
182 | 182 | } |
183 | 183 | $options['galaxy'] > SN::$config->game_maxGalaxy ? $options['galaxy'] = 1 : false; |
184 | 184 | |
185 | 185 | $galaxy_row = DBStaticPlanet::db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id'); |
186 | - if(!$galaxy_row['id']) { |
|
186 | + if (!$galaxy_row['id']) { |
|
187 | 187 | SN::$config->db_saveItem(array( |
188 | 188 | 'LastSettedGalaxyPos' => $options['galaxy'], |
189 | 189 | 'LastSettedSystemPos' => $options['system'], |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $username_safe = SN::$db->db_escape($username_unsafe); |
205 | 205 | doquery("REPLACE INTO `{{player_name_history}}` SET `player_id` = {$user_new['id']}, `player_name` = '{$username_safe}'"); |
206 | 206 | |
207 | - if(!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) { |
|
207 | + if (!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) { |
|
208 | 208 | doquery("INSERT INTO `{{referrals}}` SET `id` = {$user_new['id']}, `id_partner` = {$options['partner_id']}"); |
209 | 209 | } |
210 | 210 |
@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | function rpg_points_change($user_id, $change_type, $dark_matter, $comment = false, $already_changed = false) { |
33 | 33 | global $debug, $config, $dm_change_legit, $user; |
34 | 34 | |
35 | - if(!$user_id) { |
|
35 | + if (!$user_id) { |
|
36 | 36 | return false; |
37 | 37 | } |
38 | 38 | |
39 | 39 | $dm_change_legit = true; |
40 | 40 | $sn_data_dark_matter_db_name = pname_resource_name(RES_DARK_MATTER); |
41 | 41 | |
42 | - if($already_changed) { |
|
42 | + if ($already_changed) { |
|
43 | 43 | $rows_affected = 1; |
44 | 44 | } else { |
45 | 45 | $changeset = array(); |
46 | 46 | $a_user = db_user_by_id($user_id, true); |
47 | - if($dark_matter < 0) { |
|
47 | + if ($dark_matter < 0) { |
|
48 | 48 | $dark_matter_exists = mrc_get_level($a_user, null, RES_DARK_MATTER, false, true); |
49 | 49 | $dark_matter_exists < 0 ? $dark_matter_exists = 0 : false; |
50 | 50 | $metamatter_to_reduce = -$dark_matter - $dark_matter_exists; |
51 | - if($metamatter_to_reduce > 0) { |
|
51 | + if ($metamatter_to_reduce > 0) { |
|
52 | 52 | $metamatter_exists = mrc_get_level($a_user, null, RES_METAMATTER); |
53 | - if($metamatter_exists < $metamatter_to_reduce) { |
|
53 | + if ($metamatter_exists < $metamatter_to_reduce) { |
|
54 | 54 | $debug->error('Ошибка снятия ТМ - ММ+ТМ меньше, чем сумма для снятия!', 'Ошибка снятия ТМ', LOG_ERR_INT_NOT_ENOUGH_DARK_MATTER); |
55 | 55 | } |
56 | - if(is_array($comment)) { |
|
56 | + if (is_array($comment)) { |
|
57 | 57 | $comment = call_user_func_array('sprintf', $comment); |
58 | 58 | } |
59 | 59 | // mm_points_change($user_id, $change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | $rows_affected = SN::$db->db_affected_rows(); |
69 | 69 | } |
70 | 70 | |
71 | - if($rows_affected || !$dark_matter) { |
|
71 | + if ($rows_affected || !$dark_matter) { |
|
72 | 72 | $page_url = SN::$db->db_escape($_SERVER['SCRIPT_NAME']); |
73 | - if(is_array($comment)) { |
|
73 | + if (is_array($comment)) { |
|
74 | 74 | $comment = call_user_func_array('sprintf', $comment); |
75 | 75 | } |
76 | 76 | $comment = SN::$db->db_escape($comment); |
@@ -84,18 +84,18 @@ discard block |
||
84 | 84 | {$dark_matter}, '{$comment}', '{$page_url}', {$user_id} |
85 | 85 | );"); |
86 | 86 | |
87 | - if($user['id'] == $user_id) { |
|
87 | + if ($user['id'] == $user_id) { |
|
88 | 88 | $user['dark_matter'] += $dark_matter; |
89 | 89 | } |
90 | 90 | |
91 | - if($dark_matter > 0) { |
|
91 | + if ($dark_matter > 0) { |
|
92 | 92 | $old_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1 FOR UPDATE;", '', true); |
93 | - if($old_referral['id']) { |
|
93 | + if ($old_referral['id']) { |
|
94 | 94 | doquery("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter}' WHERE `id` = {$user_id} LIMIT 1;"); |
95 | 95 | $new_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1;", '', true); |
96 | 96 | |
97 | 97 | $partner_bonus = floor($new_referral['dark_matter'] / $config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= $config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / $config->rpg_bonus_divisor) : 0); |
98 | - if($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { |
|
98 | + if ($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { |
|
99 | 99 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL, $partner_bonus, "Incoming From Referral ID {$user_id}"); |
100 | 100 | } |
101 | 101 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | { |
113 | 113 | $q = 1.03; |
114 | 114 | |
115 | - switch($type) |
|
115 | + switch ($type) |
|
116 | 116 | { |
117 | 117 | case RPG_STRUCTURE: |
118 | 118 | $field_level = 'lvl_minier'; |
@@ -150,19 +150,19 @@ discard block |
||
150 | 150 | |
151 | 151 | $xp = &$user[$field_xp]; |
152 | 152 | |
153 | - if($xp_to_add) |
|
153 | + if ($xp_to_add) |
|
154 | 154 | { |
155 | 155 | $xp += $xp_to_add; |
156 | 156 | db_user_set_by_id($user['id'], "`{$field_xp}` = `{$field_xp}` + '{$xp_to_add}'"); |
157 | 157 | } |
158 | 158 | |
159 | 159 | $level = $user[$field_level]; |
160 | - while($xp > rpg_xp_for_level($level + 1, $b1, $q)) |
|
160 | + while ($xp > rpg_xp_for_level($level + 1, $b1, $q)) |
|
161 | 161 | { |
162 | 162 | $level++; |
163 | 163 | } |
164 | 164 | $level -= $user[$field_level]; |
165 | - if($level > 0) |
|
165 | + if ($level > 0) |
|
166 | 166 | { |
167 | 167 | db_user_set_by_id($user['id'], "`{$field_level}` = `{$field_level}` + '{$level}'"); |
168 | 168 | rpg_points_change($user['id'], $type, $level * 1000, $comment); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | function rpg_xp_for_level($level, $b1, $q) |
174 | 174 | { |
175 | - return floor($b1 * (pow($q, $level) - 1)/($q - 1)); |
|
175 | + return floor($b1 * (pow($q, $level) - 1) / ($q - 1)); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | function rpg_get_miner_xp($level) |