1 | <?php |
||||
2 | /** |
||||
3 | * |
||||
4 | * @package rpg |
||||
5 | * @version $Id$ |
||||
6 | * @copyright (c) 2009-2010 Gorlum for http://supernova.ws |
||||
7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
||||
8 | * |
||||
9 | */ |
||||
10 | |||||
11 | |||||
12 | /** |
||||
13 | * |
||||
14 | * This function changes rpg_points for user |
||||
15 | * You should ALWAYS use this function and NEVER directly change rpg_points by yourself |
||||
16 | * Otherwise refferal system wouldn't work and no logs would be made |
||||
17 | * "No logs" means you can never check if the user cheating with DM |
||||
18 | * |
||||
19 | * @package rpg |
||||
20 | * |
||||
21 | */ |
||||
22 | |||||
23 | /** |
||||
24 | * @param int $user_id |
||||
25 | * @param int $change_type |
||||
26 | * @param float $dark_matter |
||||
27 | * @param bool $comment |
||||
28 | * @param bool $already_changed |
||||
29 | * |
||||
30 | * @return bool|int |
||||
31 | */ |
||||
32 | function rpg_points_change($user_id, $change_type, $dark_matter, $comment = false, $already_changed = false) { |
||||
33 | global $debug, $config, $dm_change_legit, $user; |
||||
34 | |||||
35 | if(!$user_id) { |
||||
36 | return false; |
||||
37 | } |
||||
38 | |||||
39 | $dm_change_legit = true; |
||||
40 | $sn_data_dark_matter_db_name = pname_resource_name(RES_DARK_MATTER); |
||||
41 | |||||
42 | if($already_changed) { |
||||
43 | $rows_affected = 1; |
||||
44 | } else { |
||||
45 | $changeset = array(); |
||||
46 | $a_user = db_user_by_id($user_id, true); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||||
47 | if($dark_matter < 0) { |
||||
48 | $dark_matter_exists = mrc_get_level($a_user, null, RES_DARK_MATTER, false, true); |
||||
49 | $dark_matter_exists < 0 ? $dark_matter_exists = 0 : false; |
||||
50 | $metamatter_to_reduce = -$dark_matter - $dark_matter_exists; |
||||
51 | if($metamatter_to_reduce > 0) { |
||||
52 | $metamatter_exists = mrc_get_level($a_user, null, RES_METAMATTER); |
||||
53 | if($metamatter_exists < $metamatter_to_reduce) { |
||||
54 | $debug->error('Ошибка снятия ТМ - ММ+ТМ меньше, чем сумма для снятия!', 'Ошибка снятия ТМ', LOG_ERR_INT_NOT_ENOUGH_DARK_MATTER); |
||||
55 | } |
||||
56 | if(is_array($comment)) { |
||||
57 | $comment = call_user_func_array('sprintf', $comment); |
||||
58 | } |
||||
59 | // mm_points_change($user_id, $change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); |
||||
60 | SN::$auth->account->metamatter_change($change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); |
||||
61 | $dark_matter = -$dark_matter_exists; |
||||
62 | } |
||||
63 | } else { |
||||
64 | $changeset[] = "`dark_matter_total` = `dark_matter_total` + '{$dark_matter}'"; |
||||
65 | } |
||||
66 | $dark_matter ? $changeset[] = "`{$sn_data_dark_matter_db_name}` = `{$sn_data_dark_matter_db_name}` + '{$dark_matter}'" : false; |
||||
67 | !empty($changeset) ? db_user_set_by_id($user_id, implode(',', $changeset)) : false; |
||||
0 ignored issues
–
show
The function
db_user_set_by_id() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
68 | $rows_affected = SN::$db->db_affected_rows(); |
||||
69 | } |
||||
70 | |||||
71 | if($rows_affected || !$dark_matter) { |
||||
72 | $page_url = SN::$db->db_escape($_SERVER['SCRIPT_NAME']); |
||||
73 | if(is_array($comment)) { |
||||
0 ignored issues
–
show
|
|||||
74 | $comment = call_user_func_array('sprintf', $comment); |
||||
75 | } |
||||
76 | $comment = SN::$db->db_escape($comment); |
||||
77 | $row = db_user_by_id($user_id, false); |
||||
0 ignored issues
–
show
The function
db_user_by_id() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
78 | $row['username'] = SN::$db->db_escape($row['username']); |
||||
79 | doquery( |
||||
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
80 | "INSERT INTO {{log_dark_matter}} (`log_dark_matter_username`, `log_dark_matter_reason`, |
||||
81 | `log_dark_matter_amount`, `log_dark_matter_comment`, `log_dark_matter_page`, `log_dark_matter_sender`) |
||||
82 | VALUES ( |
||||
83 | '{$row['username']}', {$change_type}, |
||||
84 | {$dark_matter}, '{$comment}', '{$page_url}', {$user_id} |
||||
85 | );"); |
||||
86 | |||||
87 | if($user['id'] == $user_id) { |
||||
88 | $user['dark_matter'] += $dark_matter; |
||||
89 | } |
||||
90 | |||||
91 | if($dark_matter > 0) { |
||||
92 | $old_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1 FOR UPDATE;", '', true); |
||||
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
93 | if($old_referral['id']) { |
||||
94 | doquery("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter}' WHERE `id` = {$user_id} LIMIT 1;"); |
||||
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
95 | $new_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1;", '', true); |
||||
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
96 | |||||
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) { |
||||
99 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL, $partner_bonus, "Incoming From Referral ID {$user_id}"); |
||||
100 | } |
||||
101 | } |
||||
102 | } |
||||
103 | } else { |
||||
104 | $debug->warning("Error adjusting Dark Matter for player ID {$user_id} (Player Not Found?) with {$dark_matter}. Reason: {$comment}", 'Dark Matter Change', 402); |
||||
105 | } |
||||
106 | |||||
107 | $dm_change_legit = false; |
||||
108 | return $rows_affected; |
||||
109 | } |
||||
110 | |||||
111 | function rpg_level_up(&$user, $type, $xp_to_add = 0) |
||||
112 | { |
||||
113 | $q = 1.03; |
||||
114 | |||||
115 | switch($type) |
||||
116 | { |
||||
117 | case RPG_STRUCTURE: |
||||
118 | $field_level = 'lvl_minier'; |
||||
119 | $field_xp = 'xpminier'; |
||||
120 | $b1 = 50; |
||||
121 | $comment = 'Level Up For Structure Building'; |
||||
122 | break; |
||||
123 | |||||
124 | case RPG_RAID: |
||||
125 | $field_level = 'lvl_raid'; |
||||
126 | $field_xp = 'xpraid'; |
||||
127 | $b1 = 10; |
||||
128 | $comment = 'Level Up For Raiding'; |
||||
129 | break; |
||||
130 | |||||
131 | case RPG_TECH: |
||||
132 | $field_level = 'player_rpg_tech_level'; |
||||
133 | $field_xp = 'player_rpg_tech_xp'; |
||||
134 | $b1 = 50; |
||||
135 | $comment = 'Level Up For Research'; |
||||
136 | break; |
||||
137 | |||||
138 | case RPG_EXPLORE: |
||||
139 | $field_level = 'player_rpg_explore_level'; |
||||
140 | $field_xp = 'player_rpg_explore_xp'; |
||||
141 | $b1 = 10; |
||||
142 | $comment = 'Level Up For Exploration'; |
||||
143 | $q = 1.05; |
||||
144 | break; |
||||
145 | |||||
146 | default: |
||||
147 | break; |
||||
148 | |||||
149 | } |
||||
150 | |||||
151 | $xp = &$user[$field_xp]; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
152 | |||||
153 | if($xp_to_add) |
||||
154 | { |
||||
155 | $xp += $xp_to_add; |
||||
156 | db_user_set_by_id($user['id'], "`{$field_xp}` = `{$field_xp}` + '{$xp_to_add}'"); |
||||
0 ignored issues
–
show
The function
db_user_set_by_id() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
157 | } |
||||
158 | |||||
159 | $level = $user[$field_level]; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
160 | while($xp > rpg_xp_for_level($level + 1, $b1, $q)) |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
161 | { |
||||
162 | $level++; |
||||
163 | } |
||||
164 | $level -= $user[$field_level]; |
||||
165 | if($level > 0) |
||||
166 | { |
||||
167 | db_user_set_by_id($user['id'], "`{$field_level}` = `{$field_level}` + '{$level}'"); |
||||
0 ignored issues
–
show
The function
db_user_set_by_id() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
168 | rpg_points_change($user['id'], $type, $level * 1000, $comment); |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
169 | $user[$field_level] += $level; |
||||
170 | } |
||||
171 | } |
||||
172 | |||||
173 | function rpg_xp_for_level($level, $b1, $q) |
||||
174 | { |
||||
175 | return floor($b1 * (pow($q, $level) - 1)/($q - 1)); |
||||
176 | } |
||||
177 | |||||
178 | function rpg_get_miner_xp($level) |
||||
179 | { |
||||
180 | return rpg_xp_for_level($level, 50, 1.03); |
||||
181 | } |
||||
182 | |||||
183 | function RPG_get_raider_xp($level) |
||||
184 | { |
||||
185 | return rpg_xp_for_level($level, 10, 1.03); |
||||
186 | } |
||||
187 | |||||
188 | function rpg_get_tech_xp($level) |
||||
189 | { |
||||
190 | return rpg_xp_for_level($level, 50, 1.03); |
||||
191 | } |
||||
192 | |||||
193 | function rpg_get_explore_xp($level) |
||||
194 | { |
||||
195 | return rpg_xp_for_level($level, 10, 1.05); |
||||
196 | } |
||||
197 |