From 7be1319845cc82b539a3553ed3be2b29ac0b809a Mon Sep 17 00:00:00 2001 From: lopar Date: Tue, 23 Jun 2020 23:24:15 +0300 Subject: [PATCH] Code cleaning. --- functions.php | 342 ++++++++++++++++++++++++++++---------------------- 1 file changed, 192 insertions(+), 150 deletions(-) diff --git a/functions.php b/functions.php index 4a734af..a1649ca 100644 --- a/functions.php +++ b/functions.php @@ -12,7 +12,9 @@ require_once 'config.php'; */ if (isset($_SESSION['uid'])) { $user = (new users_row($_SESSION['uid']))->result(); -} else {echo "Не могу проинициализировать игрока!";} +} else { + echo "Не могу проинициализировать игрока!"; +} if (isset($user['id']) && $user['block'] == 1) { die('user blocked!'); @@ -102,7 +104,9 @@ function takeshopitem($item, $table = "shop", $present = '', $onlyonetrip = '', if ($rec1['koll']) { db::c()->query('UPDATE inventory SET koll = (koll + ?i), massa = (massa + ?i), cost = (cost + ?i) WHERE owner = ?i AND prototype = ?i', $koll, $rec1['massa'] * $koll, $rec1['cost'], $uid, $item); - if (db::c()->getAffectedRows() > 0) return ["img" => $rec1['img'], "name" => $rec1['name']]; + if (db::c()->getAffectedRows() > 0) { + return ["img" => $rec1['img'], "name" => $rec1['name']]; + } $rec1['koll'] = $koll; $rec1['massa'] *= $koll; } @@ -122,14 +126,18 @@ function takeshopitem($item, $table = "shop", $present = '', $onlyonetrip = '', $sql = ""; while ($rec = $r->fetch_assoc()) { - if (!$flds[$rec['Field']]) continue; + if (!$flds[$rec['Field']]) { + continue; + } if ($rec['Field'] == "dategoden") { $goden = $rec1[$rec['Field']]; } if ($rec['Field'] == "goden") { $goden = $rec1[$rec['Field']]; } - if ($rec['Field'] == "id" || $rec['Field'] == "prototype" || $rec['Field'] == "dategoden") continue; + if ($rec['Field'] == "id" || $rec['Field'] == "prototype" || $rec['Field'] == "dategoden") { + continue; + } $sql .= ", `$rec[Field]` = '" . $rec1[$rec['Field']] . "' "; } @@ -153,22 +161,20 @@ function level_up($uid) { global $exptable; $us = db::c()->query('SELECT `id`, `login`, `level`, `money`, `exp`, `vinos`, `nextup`, `stats`, `master`, `maxhp`, `ip`, `in_tower` FROM `users` WHERE `id` =?i', $uid)->fetch_assoc(); - if (isset($us['id'])) { - if ($us['exp'] >= $us['nextup'] && !$us['in_tower']) { - if ($exptable[$us['nextup']][4] == 1) { - addch("Персонаж {$us['login']} перешел на " . ($us['level'] + 1) . " уровень."); - addchp('Внимание! Вы перешли на новый уровень. За это Вы получаете: ' . $exptable[$us['nextup']][3] . ' кр.', '{[]}' . $us['login'] . '{[]}'); - } elseif ($exptable[$us['nextup']][4] == 0) { - addchp('Внимание! Вы перешли на новый АП. За это Вы получаете: ' . $exptable[$us['nextup']][3] . ' кр.', '{[]}' . $us['login'] . '{[]}'); - } - $us['nextup'] = $exptable[$us['nextup']][5]; - $us['stats'] += $exptable[$us['nextup']][0]; - $us['master'] += $exptable[$us['nextup']][1]; - $us['vinos'] += $exptable[$us['nextup']][2]; - $us['maxhp'] += ($exptable[$us['nextup']][2] * 6); - $us['money'] += $exptable[$us['nextup']][3]; - db::c()->query('UPDATE `users` SET `nextup` = ?i, `stats` = ?i, `master` = ?i, `vinos` = ?i, `maxhp` = ?i, `money` = ?i, `level` = ?i WHERE `id` = ?i', $us['nextup'], $us['stats'], $us['master'], $us['vinos'], $us['maxhp'], $us['money'], $us['level'], $us['id']); + if (isset($us['id']) && $us['exp'] >= $us['nextup'] && !$us['in_tower']) { + if ($exptable[$us['nextup']][4] == 1) { + addch("Персонаж {$us['login']} перешел на " . ($us['level'] + 1) . " уровень."); + addchp('Внимание! Вы перешли на новый уровень. За это Вы получаете: ' . $exptable[$us['nextup']][3] . ' кр.', '{[]}' . $us['login'] . '{[]}'); + } elseif ($exptable[$us['nextup']][4] == 0) { + addchp('Внимание! Вы перешли на новый АП. За это Вы получаете: ' . $exptable[$us['nextup']][3] . ' кр.', '{[]}' . $us['login'] . '{[]}'); } + $us['nextup'] = $exptable[$us['nextup']][5]; + $us['stats'] += $exptable[$us['nextup']][0]; + $us['master'] += $exptable[$us['nextup']][1]; + $us['vinos'] += $exptable[$us['nextup']][2]; + $us['maxhp'] += ($exptable[$us['nextup']][2] * 6); + $us['money'] += $exptable[$us['nextup']][3]; + db::c()->query('UPDATE `users` SET `nextup` = ?i, `stats` = ?i, `master` = ?i, `vinos` = ?i, `maxhp` = ?i, `money` = ?i, `level` = ?i WHERE `id` = ?i', $us['nextup'], $us['stats'], $us['master'], $us['vinos'], $us['maxhp'], $us['money'], $us['level'], $us['id']); } } @@ -204,7 +210,6 @@ function topsethp() function nick($user) { - $r = ''; if ($user['align'] > 0) { $al = $user['align']; } else { @@ -215,11 +220,7 @@ function nick($user) } else { $cl = ''; } - $r .= '
' . $cl . ''; - $r .= '' . $user['login'] . ' [' . $user['level'] . '] '; - $r .= ' : ' . $user['hp'] . '/' . $user['maxhp'] . '
'; - $r .= ''; - return $r; + return '
' . $cl . '' . $user['login'] . ' [' . $user['level'] . '] Inf HP : ' . $user['hp'] . ' / ' . $user['maxhp'] . '
'; } function nick4($id, $st) @@ -273,11 +274,13 @@ function ClanImage($clan_id) } } -function GiveExp($id, $exp){ +function GiveExp($id, $exp) +{ db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id); } -function GiveRep($id, $rep){ +function GiveRep($id, $rep) +{ db::c()->query('UPDATE users SET doblest = (doblest + ?i), rep_laba = (rep_laba + ?i) WHERE `id` = ?i', $rep, $rep, $id); } @@ -285,7 +288,6 @@ function GiveRep($id, $rep){ // полоска НР function setHP($hp, $maxhp) { - $rr = ''; if ($hp < $maxhp * 0.33) { $polosa = 'i/1red.gif'; } elseif ($hp < $maxhp * 0.66) { @@ -293,14 +295,14 @@ function setHP($hp, $maxhp) } else { $polosa = 'i/1green.gif'; } - - $rr .= "\"УровеньУровень жизни'; - $rr .= '' . $hp . '/' . $maxhp . ''; - return $rr; + $polosa_width = (122 * ($hp / $maxhp)); + $silver_polosa_width = (122 - 122 * ($hp / $maxhp)); + return << +Уровень жизни +Уровень жизни +$hp / $maxhp +HTML; } @@ -311,7 +313,7 @@ function setHP($hp, $maxhp) function showProgressBar($current, $maximum, $line_color = 'limegreen', $bg_color = 'silver') { $bar = round($current / $maximum * 100); - $output = <<
@@ -319,7 +321,6 @@ function showProgressBar($current, $maximum, $line_color = 'limegreen', $bg_colo $current / $maximum HTML; - return $output; } function echoscroll($slot) @@ -372,7 +373,9 @@ function showhrefmagic($dress) $r = ''; $script = 'main'; - if ($user['battle']) $script = 'fbattle'; + if ($user['battle']) { + $script = 'fbattle'; + } $r .= " невидимка

@@ -554,10 +557,17 @@ function showinf_pers($id, $battle = 0, $me = 0) //FIXME 37 запросов! Т HTML; } else { $r .= '
'; - if (!empty($user['align'])) $r .= " "; - if ($user['block']) $r .= "{$user['login']}"; - else $r .= "$user[login] "; - if (!empty($user['klan'])) $r .= " "; + if (!empty($user['align'])) { + $r .= " "; + } + if ($user['block']) { + $r .= "{$user['login']}"; + } else { + $r .= "$user[login] "; + } + if (!empty($user['klan'])) { + $r .= " "; + } $r .= '
'; $r .= showProgressBar($user['hp'], $user['maxhp']); @@ -608,8 +618,8 @@ HTML; if ($user['bron'] > 0 || $user['rybax'] > 0 || $user['plaw'] > 0) { - $title = ''; $d = ''; + $title = ''; if ($user['plaw']) { $d = $user['plaw']; if ($user['bron']) { @@ -792,8 +802,11 @@ HTML; if ($user['klan']) { $clann = db::c()->query('SELECT `name`, `glava` FROM `clans` WHERE `id` = ?i', $user['klan'])->fetch_assoc(); $r .= $clann['name']; - if ($clann['glava'] == $user['id']) $r .= " - Глава клана
"; - elseif (!empty($user['status'])) $r .= " - " . $user['status'] . "
"; + if ($clann['glava'] == $user['id']) { + $r .= " - Глава клана
"; + } elseif (!empty($user['status'])) { + $r .= " - " . $user['status'] . "
"; + } } if ($user['borntime']) { @@ -803,7 +816,9 @@ HTML; $r .= 'День рождения персонажа: ' . $date3 . '
'; } - if ($user['palcom']) $r .= "
{$user['palcom']}"; + if ($user['palcom']) { + $r .= "
{$user['palcom']}"; + } $r .= '
'; } else { @@ -1092,16 +1107,24 @@ function showpersout($pas = 0) //FIXME Сделать по человеческ Сила: - (+" . $param_bonus['sila'] . ")"; ?> + (+" . $param_bonus['sila'] . ")"; + } ?>
Ловкость: - (+" . $param_bonus['lovk'] . ")"; ?> + (+" . $param_bonus['lovk'] . ")"; + } ?>
Интуиция: - (+" . $param_bonus['inta'] . ")"; ?> + (+" . $param_bonus['inta'] . ")"; + } ?>
Выносливость: - (+" . $param_bonus['vinos'] . ")"; ?> + (+" . $param_bonus['vinos'] . ")"; + } ?>
Интеллект:
Мудрость:
@@ -1158,20 +1181,22 @@ function addActions($time, $vars, $vls, $uid) db::c()->query('LOCK TABLES `actions` WRITE'); $ins = db::c()->query('INSERT INTO `actions` (`uid`,`time`,`city`,`room`,`vars`,`ip`,`vals`) VALUES (?i, ?i, "?s", ?i, "?s", "?s", "?s")', $uid, $time, "capitalcity", 0, $vars, $_SERVER['HTTP_X_REAL_IP'], $vls); db::c()->query('UNLOCK TABLES'); - if ($ins) { - return true; - } else { - return false; - } + return $ins; } function plusorminus($n, $shownum = 1) { if (empty($shownum)) { - if ($n >= 2) return "++"; - if ($n > 0) return "+"; - if ($n < 0) return "-"; + if ($n >= 2) { + return "++"; + } + if ($n > 0) { + return "+"; + } + if ($n < 0) { + return "-"; + } } if ($n >= 0) { return "+$n"; @@ -1270,7 +1295,9 @@ function dropitemid($slot, $id) $user[$slot1] = 0; } return true; - } else return false; + } else { + return false; + } } // снять предмет @@ -1380,8 +1407,9 @@ function dropitem($slot) `u`.`fauvorot` = `u`.`fauvorot` - `i`.`mfauvorot`, `u`.`uminu` = `u`.`uminu` - `i`.`minu`, `u`.`umaxu` = `u`.`umaxu` - `i`.`maxu` - WHERE `i`.`id` = `u`.?f AND `i`.`dressed` = 1 AND `i`.`owner` = ?i AND u.id = ?i', $slot1, $slot1, $user['id'], $user['id'])) + WHERE `i`.`id` = `u`.?f AND `i`.`dressed` = 1 AND `i`.`owner` = ?i AND u.id = ?i', $slot1, $slot1, $user['id'], $user['id'])) { db::c()->query('UPDATE `users` SET `hp` = `maxhp`, `fullhptime` = ?i WHERE `hp` > `maxhp` AND `id` = ?i', time(), $user['id']); + } $wear_raw = db::c()->query('SELECT * FROM `inventory` where `owner` = ?i AND `dressed` = 1', $user['id']); while ($wear_list = $wear_raw->fetch_assoc()) { @@ -1403,17 +1431,13 @@ function dropitem($slot) //если прото в комплекте и не одет if (in_array($get_pro['prototype'], $temp_is) && (!in_array($get_pro['prototype'], $wear_arr))) { $checker = 1; - // echo("
ITEM SETS
"); - //foreach($temp_is as $tis) echo($tis."
"); + //для каждого одетого предмета - foreach ($temp_is as $check_proto) - if ($check_proto != $get_pro['prototype']) { - if (!in_array($check_proto, $wear_arr)) { - $checker = 0; - } - // echo("Checker=".$checker." at set #".$set_id." item #".$check_proto." Compare=".$get_pro['prototype']."
"); + foreach ($temp_is as $check_proto) { + if ($check_proto != $get_pro['prototype'] && !in_array($check_proto, $wear_arr)) { + $checker = 0; } - //echo("Checker=".$checker." at set #".$set_id); + } } @@ -1466,7 +1490,9 @@ function ref_drop() $user = db::c()->query('SELECT `id`, `align` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc(); $ts = db::c()->query('SELECT `id`, `nalign` FROM `inventory` WHERE `id` = ?i', $id)->fetch_assoc(); $al = '(1 = 1)'; - if ($ts['nalign'] == 1.1) $al = '(1 = 2)'; + if ($ts['nalign'] == 1.1) { + $al = '(1 = 2)'; + } $dd = db::c()->query('SELECT `i`.`id` FROM `users` AS `u`, `inventory` AS `i` WHERE `i`.`needident` = 0 AND @@ -1494,11 +1520,7 @@ function ref_drop() `u`.`mdark` >= `i`.`ndark` AND `i`.`setsale` = 0 AND `u`.`id` = ?i', $id, $user['id'], $al, $user['align'], $user['id']); - if ($dd->getNumRows() > 0) { - return true; - } else { - return false; - } + return $dd->getNumRows() > 0; } $slot = ['sergi', 'kulon', 'weap', 'bron', 'r1', 'r2', 'r3', 'helm', 'perchi', 'shit', 'boots', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10']; @@ -1560,6 +1582,9 @@ function destructitem($id) case 23: $slot1 = 'plaw'; break; + default: + $slot1 = 'weap'; + break; } if ($dress['type'] == 5) { if ($user['r1'] == $dress['id']) { @@ -1592,8 +1617,10 @@ function destructitem($id) $slot1 = 'm10'; } } - if (($dress['owner'] == $user['id'])) { - if ($dress['dressed'] == 1) db::c()->query('UPDATE `users` SET ?f = 0 WHERE `id` = ?i', $slot1, $user['id']); + if ($dress['owner'] == $user['id']) { + if ($dress['dressed'] == 1) { + db::c()->query('UPDATE `users` SET ?f = 0 WHERE `id` = ?i', $slot1, $user['id']); + } db::c()->query('DELETE FROM `inventory` WHERE `id` = ?i', $id); } } @@ -1617,68 +1644,72 @@ function usemagic($id) $charge = $incmagic['needcharge']; } - if (($all_magic[$user['id']] < 1) || ($charge == '0')) { - if ((($user['sila'] >= $row['nsila']) && - ($user['lovk'] >= $row['nlovk']) && - ($user['inta'] >= $row['ninta']) && - ($user['vinos'] >= $row['nvinos']) && - ($user['intel'] >= $row['nintel']) && - ($user['level'] >= $row['nlevel']) && - (($user['align'] > 7 && $user['align'] < 8) || ((int)$user['align'] == (int)$row['nalign']) || ($row['nalign'] == 0)) && - ($user['noj'] >= $row['nnoj']) && - ($user['topor'] >= $row['ntopor']) && - ($user['dubina'] >= $row['ndubina']) && - ($user['mec'] >= $row['nmech']) && - ($row['type'] < 13 || $row['type'] == 50) && ($user['mfire'] >= $row['nfire']) && - ($user['mwater'] >= $row['nwater']) && - ($user['mair'] >= $row['nair']) && - ($user['mearth'] >= $row['nearth']) && - ($user['mlight'] >= $row['nlight']) && - ($user['mgray'] >= $row['ngray']) && - ($user['mdark'] >= $row['ndark']) && - ($row['needident'] == 0) - ) || $row['magic'] == 48 || $row['magic'] == 50) { + if ((($all_magic[$user['id']] < 1) || ($charge == '0')) && + (($user['sila'] >= $row['nsila']) && + ($user['lovk'] >= $row['nlovk']) && + ($user['inta'] >= $row['ninta']) && + ($user['vinos'] >= $row['nvinos']) && + ($user['intel'] >= $row['nintel']) && + ($user['level'] >= $row['nlevel']) && + (($user['align'] > 7 && $user['align'] < 8) || ((int)$user['align'] == (int)$row['nalign']) || ($row['nalign'] == 0)) && + ($user['noj'] >= $row['nnoj']) && + ($user['topor'] >= $row['ntopor']) && + ($user['dubina'] >= $row['ndubina']) && + ($user['mec'] >= $row['nmech']) && + ($row['type'] < 13 || $row['type'] == 50) && ($user['mfire'] >= $row['nfire']) && + ($user['mwater'] >= $row['nwater']) && + ($user['mair'] >= $row['nair']) && + ($user['mearth'] >= $row['nearth']) && + ($user['mlight'] >= $row['nlight']) && + ($user['mgray'] >= $row['ngray']) && + ($user['mdark'] >= $row['ndark']) && + ($row['needident'] == 0) + ) || $row['magic'] == 48 || $row['magic'] == 50) { - if (!$row['magic']) { - $incmagic['name'] = $row['includemagicname']; - $incmagic['cur'] = $row['includemagicdex']; - $incmagic['max'] = $row['includemagicmax']; - if ($incmagic['cur'] <= 0) { - return false; - } - $magic['targeted'] = $incmagic['targeted']; - echo ""; - include("magic/" . $incmagic['file']); - echo ""; + if (!$row['magic']) { + $incmagic['name'] = $row['includemagicname']; + $incmagic['cur'] = $row['includemagicdex']; + $incmagic['max'] = $row['includemagicmax']; + if ($incmagic['cur'] <= 0) { + return false; + } + $magic['targeted'] = $incmagic['targeted']; + echo ""; + include("magic/" . $incmagic['file']); + echo ""; + } else { + echo ""; + include("magic/" . $magic['file']); + echo ""; + } + if ($bat) { + if ($row['maxdur'] <= ($row['duration'] + 1)) { + destructitem($row['id']); } else { - echo ""; - include("magic/" . $magic['file']); - echo ""; - } - if ($bat) { - if ($row['maxdur'] <= ($row['duration'] + 1)) { - destructitem($row['id']); + if (!$row['magic']) { + db::c()->query('UPDATE `inventory` SET `includemagicdex` =`includemagicdex` - ?i WHERE id = ?i', $bat, $row['id']); } else { - if (!$row['magic']) { - db::c()->query('UPDATE `inventory` SET `includemagicdex` =`includemagicdex` - ?i WHERE id = ?i', $bat, $row['id']); - } else { - db::c()->query('UPDATE `inventory` SET duration = duration + ?i WHERE id = ?i', $bat, $row['id']); - } + db::c()->query('UPDATE `inventory` SET duration = duration + ?i WHERE id = ?i', $bat, $row['id']); } - if (!$charge) $charge = 0; - //ограничение по кол-ву за ход - if ($user['battle'] > 0) - $bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', $user['battle'])->fetch_assoc_array(); - if ($bat['magic'] == '') - $all_magic = []; - else - $all_magic = unserialize($bat['magic']); - $all_magic[$user['id']] += $charge; - db::c()->query('UPDATE `battle` SET `magic`= "?s" WHERE id = ?i', serialize($all_magic), $user['battle']); } + if (!$charge) { + $charge = 0; + } + //ограничение по кол-ву за ход + if ($user['battle'] > 0) { + $bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', $user['battle'])->fetch_assoc_array(); + } + if ($bat['magic'] == '') { + $all_magic = []; + } else { + $all_magic = unserialize($bat['magic']); + } + $all_magic[$user['id']] += $charge; + db::c()->query('UPDATE `battle` SET `magic`= "?s" WHERE id = ?i', serialize($all_magic), $user['battle']); } } + return false; } function addch($text, $room = 0) @@ -1719,7 +1750,9 @@ function addchp($text, $who, $room = 0) */ function AddChatSystem($msg) { - if ($msg) {db::c()->query('INSERT INTO `chat` (`cid`,`msg`,`type`) VALUES (?i,"?s","?s")', 1, $msg, 'sys');} + if ($msg) { + db::c()->query('INSERT INTO `chat` (`cid`,`msg`,`type`) VALUES (?i,"?s","?s")', 1, $msg, 'sys'); + } } function err($t) @@ -1906,7 +1939,9 @@ function err($t) function telegraph($userId, $text) { db::c()->query('SELECT 1 FROM `users` WHERE `id` = ?i', $userId)->fetch_assoc(); - if (db::c()->getAffectedRows()) db::c()->query('INSERT INTO `telegraph` (receiver, text) VALUES (?i,"?s")', $userId, $text); + if (db::c()->getAffectedRows()) { + db::c()->query('INSERT INTO `telegraph` (receiver, text) VALUES (?i,"?s")', $userId, $text); + } } function get_meshok() @@ -1924,9 +1959,11 @@ function getItemsMassaInfo() { $i_row = db::c()->query('SELECT SUM(`massa`) AS `massa`, SUM(`gmeshok`) AS `massa_bonus` FROM `inventory` WHERE `setsale` = 0 AND `owner` = ?i', $_SESSION['uid'])->fetch_assoc(); $u_row = db::c()->query('SELECT `sila` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc(); - if ($i_row['massa'] > $u_row['sila'] * 4 + $i_row['massa_bonus']) + if ($i_row['massa'] > $u_row['sila'] * 4 + $i_row['massa_bonus']) { return "" . $i_row['massa'] . "/" . ($u_row['sila'] * 4 + $i_row['massa_bonus']); - else return $i_row['massa'] . "/" . ($u_row['sila'] * 4 + $i_row['massa_bonus']); + } else { + return $i_row['massa'] . "/" . ($u_row['sila'] * 4 + $i_row['massa_bonus']); + } } function addlog($id, $log) @@ -1942,7 +1979,7 @@ function addlog($id, $log) function star_sign($month, $day) { - if (empty($month) or empty($day)) { + if (empty($month) || empty($day)) { $month = (int)sprintf("%02d", mt_rand(1, 12)); $day = (int)sprintf("%02d", mt_rand(1, 29)); } @@ -2033,8 +2070,8 @@ function SolveExp($at_id, $def_id, $damage) $pls = count(explode(";", $bt['t1'])) + count(explode(";", $bt['t2'])); if ($pls > 2) { - $mfbot = $bot_active == true ? 0.3 : 1; - $mfbot2 = $bot_def == true ? 0.7 : 1; + $mfbot = $bot_active ? 0.3 : 1; + $mfbot2 = $bot_def ? 0.7 : 1; } else { $mfbot = 1; $mfbot2 = 1; @@ -2042,10 +2079,8 @@ function SolveExp($at_id, $def_id, $damage) if ($expmf == 0) { $expmf = 1; } - $result = ($baseexp[$def['level']]) * ($def_cost[0] / (($at_cost[0] + $def_cost[0]) / 2)) * ($damage / $def['maxhp']) * $expmf * $mfit * $mfbot * $mfbot2; - $result = $result / 3; - $result = round($result, 0); - return $result; + + return round((($baseexp[$def['level']]) * ($def_cost[0] / (($at_cost[0] + $def_cost[0]) / 2)) * ($damage / $def['maxhp']) * $expmf * $mfit * $mfbot * $mfbot2) / 3, 0); } /** @@ -2059,7 +2094,9 @@ function SolveExp($at_id, $def_id, $damage) */ function addToDelo($message, $user_id = 0, $type = 1) { - if (empty($user_id)) $user_id = $_SESSION['uid']; + if (empty($user_id)) { + $user_id = $_SESSION['uid']; + } db::c()->query('INSERT INTO `delo` (pers, text, type, date) VALUES (?i,"?s",?i,?i)', $user_id, $message, $type, time()); return true; } @@ -2096,18 +2133,23 @@ function addOnePoint($name, $param = null) 'mgray' => 'Магия серости', 'mdark' => 'Магия тьмы', ]; - if ($param == 'stat' and in_array($name, $allowed_stats)) { + if ($param == 'stat' && in_array($name, $allowed_stats)) { db::c()->query('UPDATE `users` SET ?f = ?f + 1, `stats` = `stats` - 1 WHERE `id` = ?i', $name, $name, $_SESSION['uid']); echo "Параметр {$naming[$name]} увеличен на 1 ед."; - } elseif ($param == 'mastery' and in_array($name, $allowed_mastery)) { + } elseif ($param == 'mastery' && in_array($name, $allowed_mastery)) { $mastery_level = db::c()->query('SELECT ?f FROM `users` WHERE `id` = ?i', $name, $_SESSION['uid'])->fetch_assoc(); if ($mastery_level[$name] < 10) { db::c()->query('UPDATE `users` SET ?f = ?f + 1, `master` = `master` - 1 WHERE `id` = ?i', $name, $name, $_SESSION['uid']); echo "Параметр {$naming[$name]} увеличен на 1 ед."; - } else echo "Ошибка: параметр достиг максимального значения!"; - } else return null; + } else { + echo "Ошибка: параметр достиг максимального значения!"; + } + } else { + return null; + } } -function checkIntInRange($int, $min = 1, $max = PHP_INT_MAX) { +function checkIntInRange($int, $min = 1, $max = PHP_INT_MAX) +{ return (int)filter_var($int, FILTER_VALIDATE_INT, ['options' => ['min_range' => $min, 'max_range' => $max]]); } \ No newline at end of file