Перенос функций, вызываемых один раз в файлы, из которых они вызываются. Раскрытие функций-однострочников.

This commit is contained in:
Igor Barkov [iwork]
2018-07-02 18:35:25 +03:00
parent 54e64ff1ec
commit 44d106696f
15 changed files with 2108 additions and 2099 deletions
+230
View File
@@ -9,6 +9,218 @@ $user = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$_S
include("functions.php");
include('cave/cave_bots.php');
function cancarry($m, $u)
{
global $user;
if (!$u) {
$u = $user['id'];
}
$bp = mysql_fetch_array(mysql_query("SELECT SUM(`massa`) AS `massa`, SUM(`gmeshok`) AS `gmeshok` FROM `inventory` WHERE `owner` = '$u[id]' AND `dressed` = 1 AND `setsale` = 0"));
$mw = 40 * $user['level'] + $user['vinos'] + $bp['gmeshok'];
if ($bp['massa'] + $m > $mw) {
return false;
}
return true;
}
function placeinbackpack($qty, $userid = 0)
{
global $user;
if (!$userid) {
$userid = $user['id'];
}
if ($userid == $user['id']) {
$user1 = $user;
} else {
$user1 = mysql_fetch_array(mysql_query("SELECT `id`, `level` FROM `users` WHERE `id` = '$user1[id]' LIMIT 1"));
}
$cnt = mysql_fetch_assoc(mysql_query("SELECT COUNT(`id`) AS `cnt` FROM `inventory` WHERE `owner` = '$user1[id]' AND `dressed` = 0 AND `setsale` = 0"));
return $cnt['cnt'] + $qty <= backpacksize($user1['id']);
}
function backpacksize($u = 0)
{ // $l * 10 +5
$l = 0;
if ($u) {
$l = $u['level'];
}
if ($l == 0) {
return 75;
}
if ($l == 1) {
return 100;
}
if ($l == 2) {
return 125;
}
if ($l == 3) {
return 175;
}
if ($l == 4) {
return 225;
}
if ($l == 5) {
return 325;
}
if ($l == 6) {
return 425;
}
if ($l == 7) {
return 525;
}
if ($l == 8) {
return 625;
}
if ($l == 9) {
return 725;
}
if ($l == 10) {
return 825;
}
if ($l == 11) {
return 925;
}
if ($l >= 12) {
return 1025;
}
}
function battlewithbot($b, $name = '', $time = 3, $blood = 1, $group = 1, $battleid = 0, $otherbots = array(), $noredir = 0, $userid = 0, $type = 1)
{
global $user;
if (!$userid) {
$user1 = $user;
} elseif (is_array($userid)) {
$user1 = $userid;
} else {
$user1 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '$userid' LIMIT 1"));
}
$bot = mysql_fetch_array(mysql_query("SELECT `login`, `maxhp` FROM `users` WHERE `id` = '$b' LIMIT 1"));
if (!$name) {
$name = $bot['login'];
}
if ($battleid) {
$botid = mysql_fetch_assoc(mysql_query("SELECT `id` FROM `bots` WHERE `prototype` = '$b' AND `battle` = '$battleid' LIMIT 1"));
} elseif ($group) {
$arha = mysql_fetch_array(mysql_query("SELECT * FROM `bots` WHERE `prototype` = '$b' ORDER BY `id` DESC LIMIT 1"));
$battleid = $arha['battle'];
$botid = $arha['id'];
}
if (@$battleid > 0) {
$bd = mysql_fetch_array(mysql_query("SELECT * FROM `battle` WHERE `id` = '$battleid' LIMIT 1"));
$battle = unserialize($bd['teams']);
$t1 = explode(";", $bd['t1']);
$t2 = explode(";", $bd['t2']);
$ak = array_keys($battle[$t2[0]]);
$battle[$user1['id']] = $battle[$ak[0]];
foreach ($battle[$user1['id']] as $k => $v) {
$battle[$user1['id']][$k] = array(0, 0, time());
$battle[$k][$user1['id']] = array(0, 0, time());
}
if (in_array($botid, $t1)) {
$ttt = 2;
} else {
$ttt = 1;
}
if ($user1['invis'] == 1) {
addlog($battleid, '<span class=date>' . date("H:i") . '</span> <b>невидимка</b> вмешался в поединок!<BR>');
} else {
addlog($battleid, '<span class=date>' . date("H:i") . '</span> ' . nick5($user1['id'], "B" . $ttt) . ' вмешался в поединок!<BR>');
}
mysql_query('UPDATE `battle` SET `teams` = \'' . serialize($battle) . '\', `t' . $ttt . '` = CONCAT(`t' . $ttt . '`,\';' . $user1['id'] . '\') WHERE `id` = ' . $battleid . ' LIMIT 1');
mysql_query("UPDATE `users` SET `battle` = " . $battleid . ", `zayavka` = 0 WHERE `id`= " . $user1['id'] . " LIMIT 1");
if (!$noredir) {
header("Location: fbattle.php");
}
} else {
mysql_query("INSERT INTO `bots` (`name`, `prototype`, `battle`, `hp`) VALUES ('$name', '$b', '', '" . $bot['maxhp'] . "')");
$botnames = array();
$botnames[$name] = 1;
$hps[$b] = $bot['maxhp'];
$botid1 = mysql_insert_id();
$cond = " `id` = '$botid1' ";
$teams = array();
$teams[$user1['id']][$botid1] = array(0, 0, time());
$teams[$botid1][$user1['id']] = array(0, 0, time());
$t2 = "$botid1";
$others = "";
$hps = array();
foreach ($otherbots as $k => $v) {
if (@$botnames[$v['name']]) {
$i = 1;
while (@$botnames["$v[name] ($i)"]) $i++;
$botname = "$v[name] ($i)";
} else {
$botname = $v['name'];
}
$botnames[$botname] = 1;
if (!@$hps[$v['id']]) {
$hps[$v['id']] = mysql_fetch_array(mysql_query("SELECT `maxhp` FROM `users` WHERE `id` = '$v[id]' LIMIT 1"));
}
mysql_query("INSERT INTO `bots` (`name`, `prototype`, `battle`, `hp`) VALUES ('$botname', '$v[id]', '', '" . $hps[$v['id']]['maxhp'] . "')");
$botid = mysql_insert_id();
$cond .= " OR `id` = '$botid' ";
$teams[$user1['id']][$botid] = array(0, 0, time());
$teams[$botid][$user1['id']] = array(0, 0, time());
$others .= "<span class=date>" . date("H:i") . "</span> <span class=B2>$botname</span> вмешался в поединок.<BR>";
$t2 .= ";$botid";
}
mysql_query("INSERT INTO `battle` (`id`, `coment`, `teams`, `timeout`, `type`, `status`, `t1`, `t2`, `to1`, `to2`, `blood`, `date`) VALUES (NULL, '', '" . serialize($teams) . "', '" . $time . "', '$type', '0', '" . $user1['id'] . "', '" . $t2 . "', '" . time() . "', '" . time() . "', '$blood', '" . date("Y-m-d H:i") . "')");
$battleid = mysql_insert_id();
mysql_query("UPDATE `bots` SET `battle` = {$battleid} WHERE $cond");
mysql_query("UPDATE `users` SET `battle` = {$battleid} WHERE `id` = {$user1['id']} LIMIT 1");
if ($user1['invis'] == 1) {
$rr = "<b>невидимка</b> и <b>" . nick::id($botid1)->full(1) . "</b>";
} else {
$rr = "<b>" . nick::id($user1['id'])->full(1) . "</b> и <b>" . nick::id($botid1)->full(1) . "</b>";
}
addlog($battleid, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>" . ($others ? "$others<BR>" : ""));
if (!$noredir) {
header("Location: fbattle.php");
}
}
return $battleid;
}
function gotoroom($r, $redir = 1)
{
mysql_query("UPDATE `users`, `online` SET `users`.`room` = '$r', `online`.`room` = '$r' WHERE `online`.`id` = `users`.`id` AND `online`.`id` = '{$_SESSION['uid']}'");
if ($redir) {
redirectbyroom($r);
}
}
function redirectbyroom($r)
{
global $canalenters;
if (in_array($r, $canalenters)) {
header("location: enter_cave.php");
die();
}
if ($r == 1) {
header("location: main.php");
die();
}
}
$roomnames = array(621 => "Рудник");
if($user["login"] == "Rallo Tabs") {
@@ -194,6 +406,24 @@ function loadmap() {
$map = unserialize($map['map']);
}
function getslot($i, $user1 = 0)
{
global $userslots, $user;
if (!$user1) {
$user1 = $user;
}
foreach ($userslots as $k => $v) {
if ($user1[$v] == $i) {
return $v;
}
}
}
function getcavedata($caveleader, $floor)
{
return unserialize(implode("", file("cavedata/$caveleader-$floor.dat")));
}
if(!in_array($user['room'], $caverooms)) {
header("Location: main.php");
die('Not in this life ...');