Чистка оптимизация и унификация кода.

This commit is contained in:
lopar
2020-08-30 02:21:22 +03:00
parent 8a2dfea36b
commit 427149b90e
16 changed files with 2119 additions and 2019 deletions
+9 -94
View File
@@ -200,38 +200,6 @@ function savecavedata($cavedata, $caveleader, $floor)
fclose($f1);
}
function topsethp()
{
global $user;
if ($user['hp'] >= $user['maxhp'] || $user['battle']) {
return "top.setHP($user[hp], $user[maxhp], 0)";
}
$fulltime = timetoheals($user);
$delay = round(1 / ($user['maxhp'] / $fulltime) * 1000);
return "top.setHP($user[hp], $user[maxhp], $delay);";
}
function check_proc($u)
{
$r = 100;
$usr = db::c()->query('SELECT `id`, `vip`, `vip_time` FROM `users` WHERE `id` = ?i', $u)->fetch_assoc_array();
if ($usr['vip_time'] > time()) {
if ($usr['vip'] == 1) {
$r += 10;
} elseif ($usr['vip'] == 2) {
$r += 15;
} elseif ($usr['vip'] == 3) {
$r += 20;
}
}
$effes = db::c()->query('SELECT SUM(`proc_exp`) AS `sums` FROM `effects` WHERE proc_exp > 0 AND owner = ?i', $usr['id'])->fetch_assoc_array();
if ($effes['sums'] > 0) {
$r += $effes['sums'];
}
return $r;
}
function GiveExp($id, $exp)
{
db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id);
@@ -242,31 +210,13 @@ function GiveRep($id, $rep)
db::c()->query('UPDATE users SET doblest = (doblest + ?i), rep_laba = (rep_laba + ?i) WHERE `id` = ?i', $rep, $rep, $id);
}
// полоска НР
function setHP($hp, $maxhp)
{
if ($hp < $maxhp * 0.33) {
$polosa = 'i/1red.gif';
} elseif ($hp < $maxhp * 0.66) {
$polosa = 'i/1yellow.gif';
} else {
$polosa = 'i/1green.gif';
}
$polosa_width = (122 * ($hp / $maxhp));
$silver_polosa_width = (122 - 122 * ($hp / $maxhp));
return <<<HTML
<IMG SRC=i/herz.gif WIDTH=10 HEIGHT=10 ALT="Уровень жизни">
<IMG SRC=$polosa WIDTH=$polosa_width HEIGHT=10 ALT="Уровень жизни" id=HP1>
<IMG SRC=i/1silver.gif WIDTH=$silver_polosa_width HEIGHT=10 ALT="Уровень жизни" id=HP2>
<span id='hp_value'>$hp / $maxhp</span>
HTML;
}
/**
* @param $current
* @param $maximum
* Генератор прогрессбара.
* @param $current - Текущее значение.
* @param $maximum - Максимальное значение.
* @param string $line_color - Цвет полоски прогрессбара.
* @param string $bg_color - Фон прогрессбара.
* @return string
*/
function showProgressBar($current, $maximum, $line_color = 'limegreen', $bg_color = 'silver')
{
@@ -471,18 +421,6 @@ function show_eff_inf($u, $type)
return $r;
}
function timetoheals($user)
{
$efs = db::c()->query('SELECT SUM(`speed`) AS `speed` FROM `effects` WHERE `owner` = ?i', $user['id'])->fetch_assoc_array();
$efs['speed'] += 0;
if ($efs['speed'] > 0) {
$fulltime = $efs['speed'] * 2000;
} else {
$fulltime = 2000;
}
return $fulltime;
}
/**
* @param $time
* @param $vars
@@ -499,32 +437,9 @@ function addActions($time, $vars, $vls, $uid)
return $ins;
}
function plusorminus($n, $shownum = 1)
function undressall($user_id)
{
if (empty($shownum)) {
if ($n >= 2) {
return "++";
}
if ($n > 0) {
return "+";
}
if ($n < 0) {
return "-";
}
}
if ($n >= 0) {
return "+$n";
} else {
return $n;
}
}
function undressall($id)
{
for ($i = 1; $i <= 26; $i++) {
dropitemid($i, $id);
}
db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?i', $user_id);
}
function dropitemid($slot, $id)
@@ -941,7 +856,7 @@ function destructitem($id)
}
// использовать магию
function usemagic($id)
function usemagic($id, $target)
{
global $user;
$row = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND id = ?i', $user['id'], $id)->fetch_assoc_array();