@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @version 41a6.49 |
12 | 12 | */ |
13 | 13 | public static function unit_dump_header() { |
14 | - if(!defined('DEBUG_UBE')) { |
|
14 | + if (!defined('DEBUG_UBE')) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @version 41a6.49 |
49 | 49 | */ |
50 | 50 | public static function unit_dump(UBEUnit $unit, $desc = '', UBEUnit $before = null) { |
51 | - if(!defined('DEBUG_UBE')) { |
|
51 | + if (!defined('DEBUG_UBE')) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | // print("<td>" . $this->units_lost . "</td>"); |
76 | 76 | // print("<td>" . $this->units_restored . "</td>"); |
77 | 77 | // print("<td>" . $this->capacity . "</td>"); |
78 | - print("<td>" . round($unit->share_of_side_armor, 4) . "</td>"); |
|
78 | + print("<td>".round($unit->share_of_side_armor, 4)."</td>"); |
|
79 | 79 | print('</tr>'); |
80 | 80 | } |
81 | 81 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @version 41a6.49 |
87 | 87 | */ |
88 | 88 | public static function unit_dump_footer() { |
89 | - if(!defined('DEBUG_UBE')) { |
|
89 | + if (!defined('DEBUG_UBE')) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | * @return UBEUnit |
102 | 102 | */ |
103 | 103 | public static function unit_dump_defender(UBEUnit $attacking_unit_pool, UBEUnit $defending_unit_pool, $defending_fleet_id) { |
104 | - if(!defined('DEBUG_UBE')) { |
|
104 | + if (!defined('DEBUG_UBE')) { |
|
105 | 105 | return null; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $classLocale = classLocale::$lang; |
109 | 109 | |
110 | - print("[{$attacking_unit_pool->unitId}]{$classLocale['tech'][$attacking_unit_pool->unitId]}" . |
|
111 | - ' attacks ' . |
|
112 | - $defending_fleet_id . '@' . "[{$defending_unit_pool->unitId}]{$classLocale['tech'][$defending_unit_pool->unitId]}" . |
|
113 | - ' with ' . pretty_number($defending_unit_pool->attack_income) . |
|
110 | + print("[{$attacking_unit_pool->unitId}]{$classLocale['tech'][$attacking_unit_pool->unitId]}". |
|
111 | + ' attacks '. |
|
112 | + $defending_fleet_id.'@'."[{$defending_unit_pool->unitId}]{$classLocale['tech'][$defending_unit_pool->unitId]}". |
|
113 | + ' with '.pretty_number($defending_unit_pool->attack_income). |
|
114 | 114 | '<br>' |
115 | 115 | ); |
116 | 116 | $before = clone $defending_unit_pool; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @version 41a6.49 |
128 | 128 | */ |
129 | 129 | public static function unit_dump_delta(UBEUnit $unit, $field, UBEUnit $before = null) { |
130 | - if(!defined('DEBUG_UBE')) { |
|
130 | + if (!defined('DEBUG_UBE')) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | print(pretty_number($unit->$field)); |
137 | 137 | print("</td>"); |
138 | 138 | print("<td>"); |
139 | - if(!empty($before)) { |
|
140 | - print('' . pretty_number($unit->$field - $before->$field) . ''); |
|
139 | + if (!empty($before)) { |
|
140 | + print(''.pretty_number($unit->$field - $before->$field).''); |
|
141 | 141 | } |
142 | 142 | print("</td>"); |
143 | 143 | } |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | * @version 2016-02-25 23:42:45 41a4.68 |
37 | 37 | */ |
38 | 38 | public function make_snapshot(UBEFleetList $UBEFleetList) { |
39 | - foreach($UBEFleetList->_container as $fleet_id => $UBEFleet) { |
|
40 | - foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
|
39 | + foreach ($UBEFleetList->_container as $fleet_id => $UBEFleet) { |
|
40 | + foreach ($UBEFleet->unit_list->_container as $UBEUnit) { |
|
41 | 41 | $this->snapshot[$fleet_id][$UBEUnit->unitId] = new UBESnapshotUnit(); |
42 | 42 | $this->snapshot[$fleet_id][$UBEUnit->unitId]->init_from_UBEUnit($UBEUnit); |
43 | 43 | } |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | * @version 2016-02-25 23:42:45 41a4.68 |
54 | 54 | */ |
55 | 55 | public function sql_generate_unit_array(array &$sql_perform_ube_report_unit, &$unit_sort_order, UBEFleetList $UBEFleetList, array $outer_prefix) { |
56 | - foreach($this->snapshot as $fleet_id => $fleet_snapshot) { |
|
56 | + foreach ($this->snapshot as $fleet_id => $fleet_snapshot) { |
|
57 | 57 | $inner_prefix = array( |
58 | 58 | $UBEFleetList[$fleet_id]->owner_id, |
59 | 59 | $fleet_id, |
60 | 60 | ); |
61 | - foreach($fleet_snapshot as $unit_id => $unit_snapshot) { |
|
61 | + foreach ($fleet_snapshot as $unit_id => $unit_snapshot) { |
|
62 | 62 | $sql_perform_ube_report_unit[] = array_merge( |
63 | 63 | $outer_prefix, |
64 | 64 | $inner_prefix, |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | UBE_PLAYER_IS_DEFENDER => array(), |
102 | 102 | ); |
103 | 103 | |
104 | - foreach($this->snapshot as $fleet_id => $fleet_snapshot) { |
|
104 | + foreach ($this->snapshot as $fleet_id => $fleet_snapshot) { |
|
105 | 105 | $fleet_owner_id = $ube->fleet_list[$fleet_id]->owner_id; |
106 | 106 | $planet_ube_row = $ube->fleet_list[$fleet_id]->UBE_PLANET; |
107 | 107 | |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | 'PLAYER_NAME' => htmlentities($ube->players[$fleet_owner_id]->name, ENT_COMPAT, 'UTF-8'), |
112 | 112 | ); |
113 | 113 | |
114 | - if(is_array($planet_ube_row)) { |
|
114 | + if (is_array($planet_ube_row)) { |
|
115 | 115 | $template_fleet += $planet_ube_row; |
116 | 116 | $template_fleet[PLANET_NAME] = $template_fleet[PLANET_NAME] ? htmlentities($template_fleet[PLANET_NAME], ENT_COMPAT, 'UTF-8') : ''; |
117 | 117 | $template_fleet['PLANET_TYPE_TEXT'] = $lang['sys_planet_type_sh'][$template_fleet['PLANET_TYPE']]; |
118 | 118 | } |
119 | 119 | |
120 | - foreach($fleet_snapshot as $unit_id => $unit_snapshot) { |
|
120 | + foreach ($fleet_snapshot as $unit_id => $unit_snapshot) { |
|
121 | 121 | $template_fleet['.']['ship'][] = $unit_snapshot->report_render_unit($prevSnapshot[$fleet_id][$unit_id]); |
122 | 122 | } |
123 | 123 |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | $debris_for_moon = $debris->debris_total(); |
72 | 72 | |
73 | - if(!$debris_for_moon) { |
|
73 | + if (!$debris_for_moon) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $moon_chance = min($debris_for_moon / UBE_MOON_DEBRIS_PER_PERCENT, UBE_MOON_PERCENT_MAX); // TODO Configure |
79 | 79 | $moon_chance = $moon_chance >= UBE_MOON_PERCENT_MIN ? $moon_chance : 0; |
80 | 80 | $this->create_chance = $moon_chance; |
81 | - if($moon_chance) { |
|
82 | - if($is_simulator || mt_rand(1, 100) <= $moon_chance) { |
|
81 | + if ($moon_chance) { |
|
82 | + if ($is_simulator || mt_rand(1, 100) <= $moon_chance) { |
|
83 | 83 | $this->status = UBE_MOON_CREATE_SUCCESS; |
84 | 84 | $this->moon_diameter = round($is_simulator ? $moon_chance * 150 + 1999 : mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999)); |
85 | 85 | |
86 | - if($debris_for_moon <= UBE_MOON_DEBRIS_MAX_SPENT) { |
|
86 | + if ($debris_for_moon <= UBE_MOON_DEBRIS_MAX_SPENT) { |
|
87 | 87 | $debris->_reset(); |
88 | 88 | } else { |
89 | 89 | $moon_debris_left_percent = ($debris_for_moon - UBE_MOON_DEBRIS_MAX_SPENT) / $debris_for_moon; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function moon_destroy_try($reapers) { |
104 | 104 | // TODO: $is_simulator |
105 | - if($reapers <= 0) { |
|
105 | + if ($reapers <= 0) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @version 2016-02-25 23:42:45 41a4.68 |
121 | 121 | */ |
122 | 122 | public function calculate_moon(UBE $ube) { |
123 | - if(UBE_MOON_EXISTS == $this->status) { |
|
124 | - if($ube->mission_type_id == MT_DESTROY && $ube->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
123 | + if (UBE_MOON_EXISTS == $this->status) { |
|
124 | + if ($ube->mission_type_id == MT_DESTROY && $ube->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
125 | 125 | $reapers = $ube->fleet_list->ube_calculate_attack_reapers(); |
126 | 126 | $this->moon_destroy_try($reapers); |
127 | 127 | } |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function report_generate_array() { |
137 | 137 | return array( |
138 | - 'ube_report_moon' => (int)$this->status, |
|
139 | - 'ube_report_moon_chance' => (int)$this->create_chance, |
|
140 | - 'ube_report_moon_size' => (float)$this->moon_diameter, |
|
141 | - 'ube_report_moon_reapers' => (int)$this->reapers_status, |
|
142 | - 'ube_report_moon_destroy_chance' => (int)$this->destroy_chance, |
|
143 | - 'ube_report_moon_reapers_die_chance' => (int)$this->reaper_die_chance, |
|
138 | + 'ube_report_moon' => (int) $this->status, |
|
139 | + 'ube_report_moon_chance' => (int) $this->create_chance, |
|
140 | + 'ube_report_moon_size' => (float) $this->moon_diameter, |
|
141 | + 'ube_report_moon_reapers' => (int) $this->reapers_status, |
|
142 | + 'ube_report_moon_destroy_chance' => (int) $this->destroy_chance, |
|
143 | + 'ube_report_moon_reapers_die_chance' => (int) $this->reaper_die_chance, |
|
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @param $planet_id |
172 | 172 | */ |
173 | 173 | public function db_apply_result($planet_info, $destination_user_id) { |
174 | - if($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
174 | + if ($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
175 | 175 | $moon_row = uni_create_moon($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], $destination_user_id, $this->moon_diameter, '', false); |
176 | 176 | $this->moon_name = $moon_row['name']; |
177 | 177 | unset($moon_row); |
178 | - } elseif($this->status == UBE_MOON_DESTROY_SUCCESS) { |
|
178 | + } elseif ($this->status == UBE_MOON_DESTROY_SUCCESS) { |
|
179 | 179 | DBStaticPlanet::db_planet_delete_by_id($planet_info[PLANET_ID]); |
180 | 180 | } |
181 | 181 | } |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | $classLocale = classLocale::$lang; |
185 | 185 | |
186 | 186 | $text_defender = ''; |
187 | - if($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
187 | + if ($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
188 | 188 | $text_defender .= "{$classLocale['ube_report_moon_created']} {$this->moon_diameter} {$classLocale['sys_kilometers_short']}<br /><br />"; |
189 | - } elseif($this->status == UBE_MOON_CREATE_FAILED) { |
|
189 | + } elseif ($this->status == UBE_MOON_CREATE_FAILED) { |
|
190 | 190 | $text_defender .= "{$classLocale['ube_report_moon_chance']} {$this->create_chance}%<br /><br />"; |
191 | 191 | } |
192 | 192 | |
193 | - if($ube->mission_type_id == MT_DESTROY) { |
|
194 | - if($this->reapers_status == UBE_MOON_REAPERS_NONE) { |
|
193 | + if ($ube->mission_type_id == MT_DESTROY) { |
|
194 | + if ($this->reapers_status == UBE_MOON_REAPERS_NONE) { |
|
195 | 195 | $text_defender .= classLocale::$lang['ube_report_moon_reapers_none']; |
196 | 196 | } else { |
197 | 197 | $text_defender .= "{$classLocale['ube_report_moon_reapers_wave']}. {$classLocale['ube_report_moon_reapers_chance']} {$this->destroy_chance}%. "; |
198 | - $text_defender .= classLocale::$lang[$this->status == UBE_MOON_DESTROY_SUCCESS ? 'ube_report_moon_reapers_success' : 'ube_report_moon_reapers_failure'] . "<br />"; |
|
198 | + $text_defender .= classLocale::$lang[$this->status == UBE_MOON_DESTROY_SUCCESS ? 'ube_report_moon_reapers_success' : 'ube_report_moon_reapers_failure']."<br />"; |
|
199 | 199 | |
200 | 200 | $text_defender .= "{$classLocale['ube_report_moon_reapers_outcome']} {$this->reaper_die_chance}%. "; |
201 | 201 | $text_defender .= classLocale::$lang[$this->reapers_status == UBE_MOON_REAPERS_RETURNED ? 'ube_report_moon_reapers_survive' : 'ube_report_moon_reapers_died']; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @version 2016-02-25 23:42:45 41a4.68 |
221 | 221 | */ |
222 | 222 | public function ubeInitLoadStatis($destination_planet) { |
223 | - if($destination_planet['planet_type'] == PT_MOON || is_array($moon = DBStaticPlanet::db_planet_by_parent($destination_planet['id'], true, '`id`'))) { |
|
223 | + if ($destination_planet['planet_type'] == PT_MOON || is_array($moon = DBStaticPlanet::db_planet_by_parent($destination_planet['id'], true, '`id`'))) { |
|
224 | 224 | $this->status = UBE_MOON_EXISTS; |
225 | 225 | $this->moon_diameter = !empty($moon['planet_type']) && $moon['planet_type'] == PT_MOON ? $moon['diameter'] : $destination_planet['diameter']; |
226 | 226 | $this->reapers_status = UBE_MOON_REAPERS_NONE; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function report_render_rounds(&$template_result, UBE $ube) { |
27 | 27 | $round_count = $this->count(); |
28 | - for($round = 1; $round <= $round_count - 1; $round++) { |
|
28 | + for ($round = 1; $round <= $round_count - 1; $round++) { |
|
29 | 29 | $template_result['.']['round'][] = array( |
30 | 30 | 'NUMBER' => $round, |
31 | 31 | '.' => array( |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function sql_generate_unit_array(array &$sql_perform_ube_report_unit, $ube_report_id, UBEFleetList $UBEFleetList) { |
50 | 50 | $unit_sort_order = 1; |
51 | - foreach($this->_container as $round_number => $UBERound) { |
|
51 | + foreach ($this->_container as $round_number => $UBERound) { |
|
52 | 52 | $outer_prefix = array( |
53 | 53 | $ube_report_id, |
54 | 54 | $round_number, |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function db_load_round_list_from_report_row($report_row, UBE $ube) { |
68 | 68 | $query = doquery("SELECT * FROM {{ube_report_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_unit_id`"); |
69 | - while($report_unit_row = db_fetch($query)) { |
|
69 | + while ($report_unit_row = db_fetch($query)) { |
|
70 | 70 | $round_number = $report_unit_row['ube_report_unit_round']; |
71 | - if(!isset($this[$round_number])) { |
|
71 | + if (!isset($this[$round_number])) { |
|
72 | 72 | $this[$round_number] = new UBERound(); |
73 | 73 | $this[$round_number]->init_round_from_report_unit_row($report_unit_row); |
74 | 74 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function debris_add_resource($resource_id, $resource_amount) { |
29 | 29 | // В обломках может быть только металл или кристалл |
30 | - if($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) { |
|
30 | + if ($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | $this->debris[$resource_id] += $resource_amount; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param bool $is_simulator |
39 | 39 | */ |
40 | 40 | public function add_wrecks(array $wreckage, $is_simulator) { |
41 | - foreach($wreckage as $resource_id => $resource_amount) { |
|
41 | + foreach ($wreckage as $resource_id => $resource_amount) { |
|
42 | 42 | $this->debris_add_resource($resource_id, floor($resource_amount * |
43 | 43 | ($is_simulator |
44 | 44 | ? UBE_SHIP_WRECKS_TO_DEBRIS_AVG |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param bool $is_simulator |
55 | 55 | */ |
56 | 56 | public function add_cargo_drop(array $dropped_resources, $is_simulator) { |
57 | - foreach($dropped_resources as $resource_id => $resource_amount) { |
|
57 | + foreach ($dropped_resources as $resource_id => $resource_amount) { |
|
58 | 58 | $this->debris_add_resource($resource_id, floor($resource_amount * |
59 | 59 | ($is_simulator |
60 | 60 | ? UBE_CARGO_DROPPED_TO_DEBRIS_AVG |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param $moon_debris_left_part |
94 | 94 | */ |
95 | 95 | public function debris_adjust_proportional($moon_debris_left_part) { |
96 | - foreach($this->debris as $resource_id => &$resource_amount) { |
|
96 | + foreach ($this->debris as $resource_id => &$resource_amount) { |
|
97 | 97 | $resource_amount = floor($resource_amount * $moon_debris_left_part); |
98 | 98 | } |
99 | 99 | } |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function report_generate_array() { |
116 | 116 | return array( |
117 | - 'ube_report_debris_metal' => (float)$this->debris_get_resource(RES_METAL), |
|
118 | - 'ube_report_debris_crystal' => (float)$this->debris_get_resource(RES_CRYSTAL), |
|
119 | - 'ube_report_debris_total_in_metal' => (float)$this->debris_in_metal(), |
|
117 | + 'ube_report_debris_metal' => (float) $this->debris_get_resource(RES_METAL), |
|
118 | + 'ube_report_debris_crystal' => (float) $this->debris_get_resource(RES_CRYSTAL), |
|
119 | + 'ube_report_debris_total_in_metal' => (float) $this->debris_in_metal(), |
|
120 | 120 | ); |
121 | 121 | } |
122 | 122 |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | * @param array $arguments |
20 | 20 | */ |
21 | 21 | public function __call($method_name, array $arguments) { |
22 | - foreach($this->_container as $object) { |
|
23 | - if(is_object($object) && method_exists($object, $method_name)) { |
|
22 | + foreach ($this->_container as $object) { |
|
23 | + if (is_object($object) && method_exists($object, $method_name)) { |
|
24 | 24 | call_user_func_array(array($object, $method_name), $arguments); |
25 | 25 | } |
26 | 26 | } |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function getSumProperty($property_name) { |
37 | 37 | $result = 0.0; |
38 | - foreach($this->_container as $object) { |
|
39 | - if(is_object($object) && property_exists($object, $property_name)) { |
|
38 | + foreach ($this->_container as $object) { |
|
39 | + if (is_object($object) && property_exists($object, $property_name)) { |
|
40 | 40 | $result += $object->$property_name; |
41 | 41 | } |
42 | 42 | } |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | 54 | public function aggregateByMethod($method_name, &$result) { |
55 | - foreach($this->_container as $object) { |
|
56 | - if(is_object($object) && method_exists($object, $method_name)) { |
|
55 | + foreach ($this->_container as $object) { |
|
56 | + if (is_object($object) && method_exists($object, $method_name)) { |
|
57 | 57 | call_user_func(array($object, $method_name), $result); |
58 | 58 | } |
59 | 59 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | parent::setUnitId($unitId); |
51 | 51 | |
52 | 52 | // Reset combat stats?? |
53 | - if($this->_unitId) { |
|
53 | + if ($this->_unitId) { |
|
54 | 54 | $this->amplify = $this->info[P_AMPLIFY]; |
55 | 55 | $this->capacity = $this->info[P_CAPACITY]; |
56 | 56 | $this->price[RES_METAL] = $this->info[P_COST][RES_METAL]; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $this->bonus_attack = $this->info[P_ATTACK]; |
73 | 73 | $this->bonus_shield = $this->info[P_SHIELD]; |
74 | 74 | $this->bonus_armor = $this->info[P_ARMOR]; |
75 | - if(is_object($this->unit_bonus)) { |
|
75 | + if (is_object($this->unit_bonus)) { |
|
76 | 76 | $this->bonus_attack = floor($this->bonus_attack * $this->unit_bonus->calcBonus(P_ATTACK)); |
77 | 77 | $this->bonus_shield = floor($this->bonus_shield * $this->unit_bonus->calcBonus(P_SHIELD)); |
78 | 78 | $this->bonus_armor = floor($this->bonus_armor * $this->unit_bonus->calcBonus(P_ARMOR)); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $this->randomized_attack = $this->bonus_attack; |
81 | 81 | $this->randomized_shield = $this->bonus_shield; |
82 | 82 | $this->randomized_armor = $this->bonus_armor; |
83 | - if(!$is_simulator) { |
|
83 | + if (!$is_simulator) { |
|
84 | 84 | // TODO - randomize attack if is not simulator |
85 | 85 | $this->randomized_attack = floor($this->bonus_attack * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100)); |
86 | 86 | $this->randomized_shield = floor($this->bonus_shield * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100)); |
@@ -159,22 +159,22 @@ discard block |
||
159 | 159 | * @version 2016-02-25 23:42:45 41a4.68 |
160 | 160 | */ |
161 | 161 | public function restore_unit($is_simulator) { |
162 | - if($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) { |
|
162 | + if ($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
166 | - if($is_simulator) { |
|
166 | + if ($is_simulator) { |
|
167 | 167 | $units_giveback = round($this->units_lost * UBE_DEFENCE_RESTORATION_CHANCE_AVG / 100); // for simulation just return 75% of loss |
168 | 168 | } else { |
169 | 169 | // Checking - should we trigger mass-restore |
170 | - if($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) { |
|
170 | + if ($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) { |
|
171 | 171 | // For large amount - mass-restoring defence |
172 | 172 | $units_giveback = round($this->units_lost * mt_rand(UBE_DEFENCE_RESTORATION_CHANCE_MIN, UBE_DEFENCE_RESTORATION_CHANCE_MAX) / 100); |
173 | 173 | } else { |
174 | 174 | // For small amount - restoring defence per single unit |
175 | 175 | $units_giveback = 0; |
176 | - for($i = 1; $i <= $this->units_lost; $i++) { |
|
177 | - if(mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) { |
|
176 | + for ($i = 1; $i <= $this->units_lost; $i++) { |
|
177 | + if (mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) { |
|
178 | 178 | $units_giveback++; |
179 | 179 | } |
180 | 180 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function receive_damage($is_simulator) { |
195 | 195 | // TODO - Добавить взрывы от полуповрежденных юнитов - т.е. заранее вычислить из убитых юнитов еще количество убитых умножить на вероятность от структуры |
196 | - if($this->_count <= 0) { |
|
196 | + if ($this->_count <= 0) { |
|
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | $this->adjustCount(-$units_lost); |
217 | 217 | |
218 | 218 | // Проверяем - не взорвался ли текущий юнит |
219 | - while($this->_count > 0 && $this->attack_income > 0) { |
|
219 | + while ($this->_count > 0 && $this->attack_income > 0) { |
|
220 | 220 | $this->attack_damaged_unit($is_simulator); |
221 | 221 | } |
222 | 222 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $armor_left = $this->pool_armor % $this->randomized_armor; |
242 | 242 | // Проверка - не атакуем ли мы целый корабль |
243 | 243 | // Такое может быть, если на прошлой итерации поврежденный корабль был взорван и еще осталась входящяя атака |
244 | - if($shield_left == 0 && $armor_left == 0) { |
|
244 | + if ($shield_left == 0 && $armor_left == 0) { |
|
245 | 245 | $shield_left = $this->randomized_shield; |
246 | 246 | $armor_left = $this->randomized_armor; |
247 | 247 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | // Вычитаем этот дамадж из щитов пула |
256 | 256 | $this->pool_shield -= $damage_to_shield; |
257 | 257 | // Если весь дамадж был поглощён щитами - выходим |
258 | - if($this->attack_income <= 0) { |
|
258 | + if ($this->attack_income <= 0) { |
|
259 | 259 | return; |
260 | 260 | } |
261 | 261 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $armor_left -= $damage_to_armor; |
273 | 273 | |
274 | 274 | // Проверяем - осталась ли броня на текущем корабле и вааще |
275 | - if($this->pool_armor <= 0 || $armor_left <= 0) { |
|
275 | + if ($this->pool_armor <= 0 || $armor_left <= 0) { |
|
276 | 276 | // Не осталось - корабль уничтожен |
277 | 277 | $this->adjustCount(-1); |
278 | 278 | |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | $armor_left_percent = $armor_left / $this->randomized_armor * 100; |
284 | 284 | // Проверяем % здоровья |
285 | 285 | // TODO - сделать динамический процент для каждого вида юнитов |
286 | - if($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) { |
|
286 | + if ($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) { |
|
287 | 287 | // Дамадж пошёл по структуре. Чем более поврежден юнит - тем больше шансов у него взорваться |
288 | 288 | $random = $is_simulator ? UBE_CRITICAL_DAMAGE_THRESHOLD / 2 : mt_rand(0, 100); |
289 | - if($random >= $armor_left_percent) { |
|
289 | + if ($random >= $armor_left_percent) { |
|
290 | 290 | $this->adjustCount(-1); |
291 | 291 | $this->unit_count_boom++; |
292 | 292 |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | $this->reset(); |
80 | 80 | $this->db = is_object($db) ? $db : classSupernova::$db; |
81 | 81 | |
82 | - foreach($this->table_check as $table_name) { |
|
83 | - if(empty($this->db->table_list[$table_name])) { |
|
82 | + foreach ($this->table_check as $table_name) { |
|
83 | + if (empty($this->db->table_list[$table_name])) { |
|
84 | 84 | die('Если вы видите это сообщение первый раз после обновления релиза - просто перегрузите страницу.<br /> |
85 | 85 | В противном случае - сообщите Администрации сервера об ошибке.<br/> |
86 | 86 | Не хватает таблицы для работы системы авторизации: ' . $table_name); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | // OK v4.6 |
106 | 106 | public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) { |
107 | - if(!$this->password_check($old_password_unsafe)) { |
|
107 | + if (!$this->password_check($old_password_unsafe)) { |
|
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | // OK v4.5 |
126 | 126 | public function assign_from_db_row($row) { |
127 | 127 | $this->reset(); |
128 | - if(empty($row) || !is_array($row)) { |
|
128 | + if (empty($row) || !is_array($row)) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | $this->account_id = $row['account_id']; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | `account_email` = LOWER('{$email_safe}'), |
243 | 243 | `account_language` = '{$language_safe}'" |
244 | 244 | ); |
245 | - if(!$result) { |
|
245 | + if (!$result) { |
|
246 | 246 | throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR); |
247 | 247 | } |
248 | 248 | |
249 | - if(!($account_id = $this->db->db_insert_id())) { |
|
249 | + if (!($account_id = $this->db->db_insert_id())) { |
|
250 | 250 | throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR); |
251 | 251 | } |
252 | 252 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | WHERE `account_id` = '{$account_id_safe}'" |
277 | 277 | ) ? true : false; |
278 | 278 | |
279 | - if($result) { |
|
279 | + if ($result) { |
|
280 | 280 | $result = $this->db_get_by_id($this->account_id); |
281 | 281 | } |
282 | 282 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | public function metamatter_change($change_type, $metamatter, $comment = '', $already_changed = false) { |
364 | 364 | global $mm_change_legit; |
365 | 365 | |
366 | - if(!$this->is_exists || !($metamatter = round(floatval($metamatter)))) { |
|
366 | + if (!$this->is_exists || !($metamatter = round(floatval($metamatter)))) { |
|
367 | 367 | classSupernova::$debug->error('Ошибка при попытке манипуляции с ММ'); |
368 | 368 | |
369 | 369 | return false; |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | |
374 | 374 | $mm_change_legit = true; |
375 | 375 | // $sn_data_metamatter_db_name = pname_resource_name(RES_METAMATTER); |
376 | - if($already_changed) { |
|
376 | + if ($already_changed) { |
|
377 | 377 | $metamatter_total_delta = 0; |
378 | 378 | $result = -1; |
379 | 379 | } else { |
@@ -383,17 +383,17 @@ discard block |
||
383 | 383 | $result = $this->db->doquery( |
384 | 384 | "UPDATE {{account}} |
385 | 385 | SET |
386 | - `account_metamatter` = `account_metamatter` + '{$metamatter}'" . |
|
387 | - ($metamatter_total_delta ? ", `account_immortal` = IF(`account_metamatter_total` + '{$metamatter_total_delta}' >= {$classConfig->player_metamatter_immortal}, NOW(), `account_immortal`), `account_metamatter_total` = `account_metamatter_total` + '{$metamatter_total_delta}'" : '') . |
|
386 | + `account_metamatter` = `account_metamatter` + '{$metamatter}'". |
|
387 | + ($metamatter_total_delta ? ", `account_immortal` = IF(`account_metamatter_total` + '{$metamatter_total_delta}' >= {$classConfig->player_metamatter_immortal}, NOW(), `account_immortal`), `account_metamatter_total` = `account_metamatter_total` + '{$metamatter_total_delta}'" : ''). |
|
388 | 388 | " WHERE `account_id` = {$account_id_safe}" |
389 | 389 | ); |
390 | - if(!$result) { |
|
390 | + if (!$result) { |
|
391 | 391 | classSupernova::$debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402); |
392 | 392 | } |
393 | 393 | $result = classSupernova::$db->db_affected_rows(); |
394 | 394 | } |
395 | 395 | |
396 | - if(empty(core_auth::$user['id'])) { |
|
396 | + if (empty(core_auth::$user['id'])) { |
|
397 | 397 | $user_list = PlayerToAccountTranslate::db_translate_get_users_from_account_list(core_auth::$main_provider->provider_id, $this->account_id); |
398 | 398 | reset($user_list); |
399 | 399 | $user_id_unsafe = key($user_list); |
@@ -402,30 +402,30 @@ discard block |
||
402 | 402 | } |
403 | 403 | $user_id_safe = $this->db->db_escape($user_id_unsafe); |
404 | 404 | |
405 | - if(!$result) { |
|
405 | + if (!$result) { |
|
406 | 406 | classSupernova::$debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402); |
407 | 407 | } |
408 | 408 | |
409 | - if(!$already_changed) { |
|
409 | + if (!$already_changed) { |
|
410 | 410 | $this->account_metamatter += $metamatter; |
411 | 411 | $this->account_metamatter_total += $metamatter_total_delta; |
412 | 412 | } |
413 | 413 | |
414 | - if(is_array($comment)) { |
|
414 | + if (is_array($comment)) { |
|
415 | 415 | $comment = call_user_func_array('sprintf', $comment); |
416 | 416 | } |
417 | 417 | |
418 | 418 | $result = $this->db_mm_log_insert($comment, $change_type, $metamatter, $user_id_unsafe); |
419 | 419 | |
420 | - if($metamatter > 0 && !empty($user_id_safe)) { |
|
420 | + if ($metamatter > 0 && !empty($user_id_safe)) { |
|
421 | 421 | $old_referral = db_referral_get_by_id($user_id_safe); |
422 | - if($old_referral['id']) { |
|
422 | + if ($old_referral['id']) { |
|
423 | 423 | $dark_matter_from_metamatter = $metamatter * AFFILIATE_MM_TO_REFERRAL_DM; |
424 | 424 | db_referral_update_dm($user_id_safe, $dark_matter_from_metamatter); |
425 | 425 | $new_referral = db_referral_get_by_id($user_id_safe); |
426 | 426 | |
427 | 427 | $partner_bonus = floor($new_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) : 0); |
428 | - if($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) { |
|
428 | + if ($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) { |
|
429 | 429 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL_BOUGHT_MM, $partner_bonus, "Incoming MM From Referral ID {$user_id_safe}"); |
430 | 430 | } |
431 | 431 | } |
@@ -171,6 +171,10 @@ discard block |
||
171 | 171 | * @return bool |
172 | 172 | */ |
173 | 173 | // OK v4.5 |
174 | + |
|
175 | + /** |
|
176 | + * @param string $account_name_unsafe |
|
177 | + */ |
|
174 | 178 | public function db_get_by_name($account_name_unsafe) { |
175 | 179 | $this->reset(); |
176 | 180 | |
@@ -207,6 +211,11 @@ discard block |
||
207 | 211 | * |
208 | 212 | */ |
209 | 213 | // OK v4.5 |
214 | + |
|
215 | + /** |
|
216 | + * @param string $account_name_unsafe |
|
217 | + * @param string $email_unsafe |
|
218 | + */ |
|
210 | 219 | public function db_get_by_name_or_email($account_name_unsafe, $email_unsafe) { |
211 | 220 | $this->reset(); |
212 | 221 | |
@@ -223,6 +232,13 @@ discard block |
||
223 | 232 | * @throws Exception |
224 | 233 | */ |
225 | 234 | // OK v4.5 |
235 | + |
|
236 | + /** |
|
237 | + * @param string $account_name_unsafe |
|
238 | + * @param string $password_raw |
|
239 | + * @param string $email_unsafe |
|
240 | + * @param string $language_unsafe |
|
241 | + */ |
|
226 | 242 | public function db_create($account_name_unsafe, $password_raw, $email_unsafe, $language_unsafe = null, $salt_unsafe = null) { |
227 | 243 | $this->reset(); |
228 | 244 | |
@@ -317,6 +333,11 @@ discard block |
||
317 | 333 | * @return int|string |
318 | 334 | */ |
319 | 335 | // OK 4.8 |
336 | + |
|
337 | + /** |
|
338 | + * @param integer $change_type |
|
339 | + * @param double $metamatter |
|
340 | + */ |
|
320 | 341 | protected function db_mm_log_insert($comment, $change_type, $metamatter, $user_id_unsafe) { |
321 | 342 | $provider_id_safe = intval(core_auth::$main_provider->provider_id); |
322 | 343 | //$account_id_safe = $this->db->db_escape($this->account_id); |
@@ -45,8 +45,8 @@ |
||
45 | 45 | */ |
46 | 46 | protected function quoteStringAsFieldByRef(&$string) { |
47 | 47 | $string = $this->stringEscape($string); |
48 | - if ((string)$string && '*' != $string) { |
|
49 | - $string = '`' . $string . '`'; |
|
48 | + if ((string) $string && '*' != $string) { |
|
49 | + $string = '`'.$string.'`'; |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 |