"' . time() . '" ORDER BY `time` DESC LIMIT 1'));
$real_x = $user['x'];
$real_y = $user['y'];
if ($real_y < 6) {
$real_y = 6;
}
if ($real_x < 6) {
$real_x = 6;
}
if ($real_y > count($map_d) - 7) {
$real_y = count($map_d) - 7;
}
if ($real_x > count($map_d) - 7) {
$real_x = count($map_d) - 7;
}
$objs = [];
$sp = mysql_query('SELECT * FROM `laba_obj` WHERE `lib` = "' . $lab['id'] . '" AND `x` > ' . ($real_x - 7) . ' AND `x` < ' . ($real_x + 7) . ' AND `y` > ' . ($real_y - 12) . ' AND `y` < ' . ($real_y + 12) . ' LIMIT 144');
while ($pl = mysql_fetch_array($sp)) {
$objs[$pl['x']][$pl['y']] = $pl;
}
$i = 1;
$goodgoo = [1 => 0, 2 => 0, 3 => 0, 4 => 0];
while ($i <= 4) {
$goto = ['x' => $user['y'], 'y' => $user['x']];
if ($i == 1) {
$goto['x']--;
} elseif ($i == 2) {
$goto['y']--;
} elseif ($i == 3) {
$goto['x']++;
} elseif ($i == 4) {
$goto['y']++;
}
if ($map_d[$goto['y']][$goto['x']] == 0 && $goto['x'] > 0 && $goto['x'] < count($map_d) - 1 && $user['timeGo'] <= time()) {
$goodgoo[$i] = 1;
}
$i++;
}
if (isset($_GET['goto'])) {
$goto = ['x' => $user['y'], 'y' => $user['x']];
if ($_GET['goto'] == 1) {
$goto['x']--;
} elseif ($_GET['goto'] == 2) {
$goto['y']--;
} elseif ($_GET['goto'] == 3) {
$goto['x']++;
} elseif ($_GET['goto'] == 4) {
$goto['y']++;
}
if ($goodgoo[$_GET['goto']] == 1 && $user['timeGo'] <= time()) {
$user['y'] = $goto['x'];
$user['x'] = $goto['y'];
$real_x = $user['x'];
$real_y = $user['y'];
$varos['timego'] = 0; #5
if (isset($varos['trap1']['id'])) {
$varos['timego'] += 3;
}
if ($user['align'] == 2.99) {
$varos['timego'] = 0;
}
$user['timeGo'] = (time() + $varos['timego']);
$user['timeGoL'] = time();
if (!mysql_query('UPDATE `users` SET `x` = "' . $user['x'] . '", `y` = "' . $user['y'] . '", `timeGoL` = "' . $user['timeGoL'] . '", `timeGo` = "' . $user['timeGo'] . '" WHERE `id` = "' . $user['id'] . '" LIMIT 1')) {
$errors = 'Ошибка перемещения!';
}
}
}
$tmdg = ($user['timeGo'] - time());
$tmdgl = ($user['timeGo'] - $user['timeGoL']);
$tmdgp = floor(100 - $tmdg / $tmdgl * 100);
if ($tmdgp < 1) {
$tmdgp = 1;
} elseif ($tmdgp > 100) {
$tmdgp = 100;
}
$tmdgm = 25 * $tmdgl;
$tmdg = floor(40 / 100 * $tmdgp);
if ($tmdg < 1) {
$tmdg = 1;
} elseif ($tmdg > 40) {
$tmdg = 40;
}
if (isset($_POST['exit'])) {
if ($lab['users'] < 2) {
mysql_query('DELETE FROM `laba_now` WHERE `id` = "' . $lab['id'] . '" LIMIT 1');
mysql_query('DELETE FROM `laba_map` WHERE `id` = "' . $lab['id'] . '" LIMIT 1');
mysql_query('DELETE FROM `laba_obj` WHERE `lib` = "' . $lab['id'] . '"');
mysql_query('DELETE FROM `laba_act` WHERE `lib` = "' . $lab['id'] . '"');
mysql_query('DELETE FROM `laba_itm` WHERE `lib` = "' . $lab['id'] . '"');
} else {
$lab['users']--;
mysql_query('UPDATE `laba_now` SET `users` = "' . $lab['users'] . '" WHERE `id` = "' . $lab['id'] . '" LIMIT 1');
}
$dresed = mysql_query('SELECT `id`, `type` FROM `inventory` WHERE `dressed` = 1 AND `laba` = 2 AND `owner` = "' . $user['id'] . '"');
while ($pl = mysql_fetch_array($dresed)) {
$item = new DressedItems($user['id']);
$item->undressItem($pl['type']);
}
mysql_query('DELETE FROM `inventory` WHERE `laba` > 0 AND `owner` = "' . $user['id'] . '"');
mysql_query("UPDATE `users`, `online` SET `users`.`room` = '1051', `online`.`room` = '1051', `users`.`x` = '0', `users`.`y` = '0', `users`.`laba` = '0' WHERE `online`.`id` = `users`.`id` AND `online`.`id` = '" . $user['id'] . "'");
mysql_query('UPDATE `qst_user` SET `val` = "0" WHERE `uid` = "' . $user['id'] . '" AND `cancel` = "0" AND `finish` = "0"');
addActions(time(), 'go_labirint', (time() + 60 * 60 * 6), $user['id']);
header('Location: lab_enter.php');
}
$itms = '';
if (isset($objs[$user['x']][$user['y']]['id'])) {
$var = [];
$mitm = $objs[$user['x']][$user['y']];
if ($mitm['type'] == 2) {
if ($mitm['use'] == 0) {
$btl_pix = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `battle` > 0 AND `laba` = "' . $lab['id'] . '" AND `x` = "' . $user['x'] . '" AND `y` = "' . $user['y'] . '" LIMIT 1'));
if (!isset($btl_pix['id'])) {
$bots = [
0 => [10025, 10026, 10027, 10028, 10031, 10032, 10033, 10034],
1 => [10111, 10112, 10113, 10114, 10115, 10116],
2 => [10111, 10112, 10113],
];
$bot_pix2 = $bots[$lab['type']];
$teams = [];
$where = '';
$bot_ids = '';
$i = 0;
$j = (1 + rand(0, floor($user['level'] / rand(3, 4))));
while ($i < $j) {
$bot_pix = $bot_pix2[rand(0, count($bot_pix2) - 1)];
$bot_pix = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "' . $bot_pix . '" LIMIT 1'));
mysql_query("INSERT INTO `bots` (`name`, `prototype`, `battle`, `hp`) VALUES ('" . $bot_pix['login'] . " (Бот #$i)', '" . $bot_pix['id'] . "', '', '" . $bot_pix['maxhp'] . "')");
$bot = mysql_insert_id();
$bot_ids .= $bot . ';';
$teams[$user['id']][$bot] = [0, 0, time()];
$teams[$bot][$user['id']] = [0, 0, time()];
$where = ' `id` = ' . $bot . ' OR';
$i++;
}
$bot_ids = rtrim($bot_ids, ';');
$where = rtrim($where, ' OR');
if (!mysql_query("INSERT INTO `battle` (`teams`, `timeout`, `type`, `status`, `t1`, `t2`, `to1`, `to2`, `x`, `y`) VALUES ('" . serialize($teams) . "', '3', '1', '0', '" . $user['id'] . "', '" . $bot_ids . "', '" . time() . "', '" . time() . "', '" . $user['x'] . "', '" . $user['y'] . "')")) {
exit('Error #2');
}
$id = mysql_insert_id();
$bts = explode(';', $bot_ids);
$is = 0;
while ($is <= count($bts)) {
$nicks .= Nick::id($bts[$is])->full(1) . ', ';
$i_d .= $bts[$is] . ', ';
$is++;
}
$nicks = rtrim($nicks, ', ');
$who = '`id` IN (' . rtrim($i_d, ', ') . ')';
if ($user1['invis'] == 1) {
$rr = "невидимка и " . $nicks . "";
} else {
$rr = "" . Nick::id($user['id'])->full(1) . " и " . $nicks . "";
}
if (!mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE " . $who . "")) {
exit('Error #1' . $who);
}
mysql_query("UPDATE `users` SET `battle` = {$id}, `zayavka` = 0 WHERE `id`= {$user['id']} LIMIT 1");
GameLogs::addBattleLog($id, "Часы показывали " . date("Y.m.d H.i") . ", когда " . $rr . " бросили вызов друг другу.
");
} else {
$bd = mysql_fetch_array(mysql_query('SELECT * FROM `battle` WHERE `id` = "' . $btl_pix['battle'] . '" LIMIT 1'));
$botd = mysql_fetch_array(mysql_query('SELECT * FROM `bots` WHERE `battle` = "' . $bd['id'] . '" LIMIT 1'));
$battle = unserialize($bd['teams']);
$ak = array_keys($battle[$botd['id']]);
$battle[$user['id']] = $battle[$ak[0]];
foreach ($battle[$user['id']] as $k => $v) {
$battle[$user['id']][$k] = [0, 0, time()];
$battle[$k][$user['id']] = [0, 0, time()];
}
$t1 = explode(";", $bd['t1']);
$ttt = 1;
GameLogs::addBattleLog($jert['battle'], '' . date("H:i") . ' ' . Nick::id($user['id'])->short() . ' вмешался в поединок!
');
mysql_query('UPDATE `battle` SET `teams` = \'' . serialize($battle) . '\', `t' . $ttt . '` = CONCAT(`t' . $ttt . '`,\';' . $user['id'] . '\') WHERE `id` = "' . $btl_pix['battle'] . '" LIMIT 1');
mysql_query("UPDATE `users` SET `battle` = '" . $bd['id'] . "', `zayavka` = 0 WHERE `id` = '" . $user['id'] . "' LIMIT 1");
header("Location: fbattle.php");
}
exit("");
}
} elseif ($mitm['type'] == 1) {
if ($mitm['use'] == 0) {
$itms .= '