$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, '' . date("H:i") . ' невидимка вмешался в поединок!
');
} else {
addlog($battleid, '' . date("H:i") . ' ' . Nick::id($user['id'])->short() . ' вмешался в поединок!
');
}
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 .= "" . date("H:i") . " $botname вмешался в поединок.
";
$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 = "невидимка и " . Nick::id($botid1)->full(1) . "";
} else {
$rr = "" . Nick::id($user1['id'])->full(1) . " и " . Nick::id($botid1)->full(1) . "";
}
addlog($battleid, "Часы показывали " . date("Y.m.d H.i") . ", когда " . $rr . " бросили вызов друг другу.
" . ($others ? "$others
" : ""));
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") {
if(isset($_GET['goto'])) {
mysql_query("UPDATE `caveparties` SET `x` = '$_GET[x]', `y` = '$_GET[y]', `floor` = '$_GET[floor]' WHERE `caveparties`.`user` = $user[id] LIMIT 1");
header('Location: cave.php');
exit();
}
header("Content-Type: text/html; charset=utf-8");
}
if($user['battle'] > 0) {
header("location: fbattle.php");
die();
}
$objsizes = array(0 => array(0, 0), 1 => array(120, 60), 2 => array(120, 60), 3 => array(120, 60), 4 => array(110, 72), 5 => array(120, 120));
$objdata[3][0] = array("wd"=>1.44, "ht"=>1.44, "y"=>1, "x"=>176);
$objdata[3][1] = array("coef"=>1, "y"=>202, "x"=>176);
$objdata[1][1] = array("coef"=>1, "y"=>202, "x"=>-65);
$objdata[5][1] = array("coef"=>1, "y"=>202, "x"=>435);
$objdata[3][2] = array("coef"=>0.67, "y"=>162, "x"=>176);
$objdata[1][2] = array("coef"=>0.67, "y"=>162, "x"=>18);
$objdata[5][2] = array("coef"=>0.67, "y"=>162, "x"=>342);
$objdata[3][3] = array("coef"=>0.50, "y"=>141, "x"=>176);
$objdata[1][3] = array("coef"=>0.50, "y"=>141, "x"=>50);
$objdata[5][3] = array("coef"=>0.50, "y"=>141, "x"=>300);
$imgdata[3][0] = array("wd"=>173, "ht"=>317, "y"=>1, "x"=>array(-37, 89, 215));
$imgdata[3][1] = array("wd"=>87, "ht"=>161, "y"=>41, "x"=>array(68, 132, 196));
$imgdata[1][1] = array("wd"=>87, "ht"=>161, "y"=>41, "x"=>array(-171, -44, -44));
$imgdata[5][1] = array("wd"=>87, "ht"=>161, "y"=>41, "x"=>array(308, 308, 435));
$imgdata[3][2] = array("wd"=>58, "ht"=>107, "y"=>55, "x"=>array(104, 147, 189));
$imgdata[1][2] = array("wd"=>58, "ht"=>107, "y"=>55, "x"=>array(-56, 29, 29));
$imgdata[5][2] = array("wd"=>58, "ht"=>107, "y"=>55, "x"=>array(264, 264, 350));
$imgdata[3][3] = array("wd"=>44, "ht"=>81, "y"=>61, "x"=>array(122, 154, 186));
$imgdata[1][3] = array("wd"=>44, "ht"=>81, "y"=>61, "x"=>array(1, 65, 65));
$imgdata[5][3] = array("wd"=>44, "ht"=>81, "y"=>61, "x"=>array(242, 242, 306));
$eventdata[3][1] = array("x" => 176, "y" => 200, "q" => 1);
$eventdata[3][2] = array("x" => 176, "y" => 149, "q" => 0.66);
$eventdata[1][2] = array("x" => 16, "y" => 149, "q" => 0.66);
$eventdata[5][2] = array("x" => 335, "y" => 149, "q" => 0.66);
$eventdata[3][3] = array("x" => 176, "y" => 133, "q" => 0.5);
$eventdata[1][3] = array("x" => 56, "y" => 133, "q" => 0.5);
$eventdata[5][3] = array("x" => 296, "y" => 133, "q" => 0.5);
$objects = array(1 => "Спуск", 2 => "Спуск", 3 => "Спуск", 4 => "Сундук", 5 => "Спуск");
$events = array();
$dialogs = array();
$noautoexit = 0;
function usagesleft($x, $y) {
global $map;
$cell = explode("/", $map[$y*2][$x*2]);
return $cell[3];
}
function takeusage($x, $y) {
global $map;
$cell = explode("/", $map[$y*2][$x*2]);
$cell[3]--;
$map[$y*2][$x*2] = implode("/", $cell);
updmap();
}
function makedeath() {
global $user, $floor, $loses, $x, $y, $dir;
include("cavedata.php");
if(!isset($cavedata[$user['room']]['x'.$floor])) {
$floor = 1;
loadmap();
}
mysql_query("UPDATE `caveparties` SET `floor` = $floor, `x` = '".$cavedata[$user['room']]['x'.$floor]."', `y` = '".$cavedata[$user['room']]['y'.$floor]."', `dir` = '".$cavedata[$user['room']]['dir'.$floor]."', `loses` = (`loses`+1) WHERE `user` = '$user[id]' LIMIT 1");
mysql_query('UPDATE `users` SET `hp` = 1 WHERE `id` = "'.$user['id'].'" LIMIT 1');
$x = $cavedata[$user['room']]['x'.$floor];
$y = $cavedata[$user['room']]['y'.$floor];
$dir = $cavedata[$user['room']]['dir'.$floor];
updparties();
$loses++;
}
function pickupitem($item, $foronetrip, $notmore1, $incave = 0, $podzem = 1, $destiny = 0) {
global $user;
if($notmore1) {
$i = mysql_fetch_assoc(mysql_query("SELECT `id` FROM `inventory` WHERE `prototype` = '$item' AND `owner` = '$user[id]' LIMIT 1"));
if(isset($i['id'])) {
return "Вы уже получили здесь всё необходимое.";
}
}
$flds = array('podzem' => 1, 'podzem' => $podzem);
if($incave) {
$flds['incave'] = 1;
}
$taken = takeshopitem($item, 'shop', '', $foronetrip, $destiny, $flds);
return "Вы получили $taken[name]";
}
function itemtofloor($item, $foronetrip, $incave = 0, $podzem = 1, $from = 'shop', $small = 0) {
global $user, $x, $y, $floor;
$rec = mysql_fetch_array(mysql_query("SELECT `name`, `img` FROM `$from` WHERE `id` = '$item' LIMIT 1"));
mysql_query("INSERT INTO `caveitems` SET `leader` = '$user[caveleader]', `name` = '$rec[name]', `img` = '$rec[img]', `small` = '$small', `x` = '".($x*2)."', `y` = '".($y*2)."', `floor` = '$floor', `item` = '$item', `foronetrip` = '$foronetrip', `incave` = '$incave', `podzem` = '$podzem'");
return "Вы нашли $rec[name].";
}
function makeinjury() {
global $user, $floor, $noautoexit, $loses, $x, $y, $dir;
settravma($user['id'], 20, rand(1, 600), 1, 1);
makedeath();
$noautoexit = 1;
}
function cavewall($w) {
if($w < 100) {
return floor($w/10);
} else {
return floor($w/1000)+100;
}
}
function passablewall($n) {
if($n == 0 || $n == 31) { return true; }
return false;
}
function canmoveto($cell, $freecell = 0, $passing = 0) {
if(!passablewall($passing)) { return false; }
$obj = substr($cell, 0, 1);
if($obj == "e" || $obj == "u" || $obj == "s" || $obj == "p") { return true; }
if(!$freecell && $cell) { return false; }
if($cell == $freecell) { return true; }
return false;
}
function gotoxy($tox, $toy, $tofloor = 0, $msg = '') {
global $map, $x, $y, $floor, $user;
$floor1 = $floor;
$upd = "";
if($tox) {
$tox = $tox/2;
if($upd) { $upd .= ", "; }
$upd .= " `x` = '$tox'";
$x = $tox;
}
if($toy) {
$toy = $toy/2;
if($upd) { $upd .= ", "; }
$upd .= " `y` = '$toy'";
$y = $toy;
}
if($tofloor && $tofloor != $floor) {
if($upd) { $upd .= ", "; }
$upd .= " `floor` = '$tofloor'";
$floor = $tofloor;
}
mysql_query("UPDATE `caveparties` SET $upd WHERE `user` = '$user[id]' LIMIT 1");
if($tofloor && $tofloor != $floor1) {
$map = mysql_fetch_assoc(mysql_query("SELECT `map` FROM `caves` WHERE `leader` = '$user[caveleader]' AND `floor` = '$floor' LIMIT 1"));
$map = unserialize($map);
}
updparties();
if($msg) {
header("Location: ".$_SERVER['PHP_SELF'].($msg ? '?msg='.$msg : '' ));
exit();
}
}
function updparties() {
global $user, $x, $y, $floor, $dir, $party;
foreach ($party as $k => $v) {
if($v['user'] == $user['id']) {
$party[$k]['dir'] = $dir;
$party[$k]['x'] = $x;
$party[$k]['y'] = $y;
$party[$k]['floor'] = $floor;
}
}
}
function loadmap() {
global $user, $map, $floor;
$map = mysql_fetch_array(mysql_query("SELECT `map` FROM `caves` WHERE `leader` = '$user[caveleader]' AND `floor` = '$floor' LIMIT 1"));
$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 ...');
}
if(isset($_GET['direction'])) {
$dir = (int)$_GET['direction'];
if($dir >= 0 && $dir <= 3) {
mysql_query("UPDATE `caveparties` SET `dir` = '$dir' WHERE `user` = '$user[id]' LIMIT 1");
}
}
$party = array();
$r = mysql_query("SELECT `user`, `x`, `y`, `dir`, `login`, `shadow`, `floor`, `loses` FROM `caveparties` WHERE `leader` = '$user[caveleader]' ORDER BY `id` DESC");
while($rec = mysql_fetch_assoc($r)) {
if($rec['user'] == $user['id']) {
$x = $rec['x'];
$y = $rec['y'];
$dir = $rec['dir'];
$floor = $rec['floor'];
$loses = $rec['loses'];
}
$party[] = $rec;
}
if($user['room'] == 621) {
$base = "/underdesigns/alchcave";
}
$maxloses = 3;
if($loses >= $maxloses && !$noautoexit) { $_GET['exit'] = 1; }
if(@$_GET['kill'] && $user['id'] == $user['caveleader'] && $_GET['kill'] != $user['login']) {
foreach($party as $k => $v) {
if($v['login'] == $_GET['kill']) {
mysql_query("DELETE FROM `caveparties` WHERE `user` = '$v[user]'");
mysql_query("UPDATE `users` SET `room` = (`room`-1), `caveleader` = 0 WHERE `id` = '$v[user]' LIMIT 1");
$r = mysql_query("SELECT `id`, `dressed` FROM `inventory` WHERE `owner` = '$v[user]' AND `dressed` = 1 AND `foronetrip` = 1");
if(mysql_num_rows($r) > 0) {
$usr = mysql_fetch_array(mysql_query("SELECT ".implode(",", $userslots)." FROM `users` WHERE `id` = '$v[user]'"));
}
while($rec = mysql_fetch_assoc($r)) {
$slot = getslot($rec['id'], $usr);
if($slot) {
dropitemid(0, $v['user'], $slot);
}
}
mysql_query("DELETE FROM `inventory` WHERE `owner` = '$v[user]' AND `foronetrip` = 1");
unset($party[$k]);
$report = "Персонаж $v[login] исключён из похода.";
break;
}
}
if(!@$report) {
$report="Персонаж $_GET[kill] не найден.";
}
}
if($_GET['change'] && $user['id'] == $user['caveleader'] && $_GET['change'] != $user['login']) {
foreach($party as $k => $v) {
if($v['login'] == $_GET['change']) {
mysql_query("LOCK TABLES `users` WRITE, `caveparties` WRITE, `cavebots` WRITE, `caves` WRITE, `caveitems` WRITE");
mysql_query("UPDATE `users` SET `caveleader` = '$v[user]' WHERE `caveleader` = '$user[id]'");
mysql_query("UPDATE `cavebots` SET `leader` = '$v[user]' WHERE `leader` = '$user[id]'");
mysql_query("UPDATE `caves` SET `leader` = '$v[user]' WHERE `leader` = '$user[id]'");
mysql_query("UPDATE `caveparties` SET `leader` = '$v[user]' WHERE `leader` = '$user[id]'");
mysql_query("UPDATE `caveitems` SET `leader` = '$v[user]' WHERE `leader` = '$user[id]'");
$user['caveleader'] = $v['user'];
$report = "Персонажу $v[login] присвоено лидерство.";
mysql_query("UNLOCK TABLES");
break;
}
}
if(!@$report) {
$report = "Персонаж $_GET[change] не найден.";
}
}
if(@$_GET['useitem'] || @$_GET['usewallitem']) {
mysql_query("LOCK TABLES `effects` WRITE, `cavebots` WRITE, `battle` WRITE, `users` WRITE, `caveparties` WRITE, `caves` WRITE, `shop` WRITE, `inventory` WRITE, `bots` WRITE, `caveitems` WRITE");
}
loadmap();
if(@$_GET['useitem']) {
if($dir == 0) { $tx = $x-1; $ty = $y; }
if($dir == 1) { $tx = $x; $ty = $y-1; }
if($dir == 2) { $tx = $x+1; $ty = $y; }
if($dir == 3) { $tx = $x; $ty = $y+1; }
if(@$_GET['useitem']) {
if(file_exists("underground/objects/$user[room].php")) {
include "underground/objects/$user[room].php";
}
}
list($t, $obj) = explode("/", $map[$ty*2][$tx*2]);
if($t == "o") {
if($obj == 500) {
$report="В этот сундук уже кто-то заглядывал";
}
}
mysql_query("UNLOCK TABLES");
}
function updmap() {
global $map, $user, $floor;
mysql_query("UPDATE `caves` SET `map` = '".serialize($map)."' WHERE `leader` = '$user[caveleader]' AND `floor` = '$floor' LIMIT 1");
}
if(@$_GET['usewallitem']) {
if($dir == 0) { $tx = $x*2-1; $ty = $y*2; }
if($dir == 1) { $tx = $x*2; $ty = $y*2-1; }
if($dir == 2) { $tx = $x*2+1; $ty = $y*2; }
if($dir == 3) { $tx = $x*2; $ty = $y*2+1; }
$obj = $map[$ty][$tx];
if($obj == 18) {
$report = "Вы не обнаружили ничего интересного.";
}
if($obj == 19) {
$report = "Уже проверено, сюда лучше не лазить.";
}
mysql_query("UNLOCK TABLES");
}
$r = mysql_query("SELECT `id`, `bot`, `x`, `y`, `cnt`, `type`, `battle` FROM `cavebots` WHERE `leader` = '$user[caveleader]' AND `floor` = '$floor'");
$mapbots = array();
$ambushes = array();
$cavedata = getcavedata($user['caveleader'], $floor);
if(time()-$cavedata['wander'] > 21) { $wander = 1; } else { $wander = 0; }
$wanderers = array();
while($rec = mysql_fetch_assoc($r)) {
if($rec['type'] == 1 && $wander && $rec['battle'] == 0) {
$wanderers[] = $rec;
continue;
}
if(!@$mapbots[$rec['y']][$rec['x']]) { $mapbots[$rec['y']][$rec['x']] = "b"; }
if(($rec['type'] == 1 || $rec['type'] == 2) && $rec['battle'] == 0) { $ambushes[$rec['y']][$rec['x']] = 1; }
$mapbots[$rec['y']][$rec['x']] .= "/$rec[bot]/$rec[cnt]";
}
if($wander && !isset($_GET['attack'])) {
foreach($wanderers as $k => $v) {
$d = rand(0, 3);
for($i = 0; $i < 4; $i++) {
if($d == 0) { $tx = $v['x']-2; $ty = $v['y'];}
if($d == 1) { $tx = $v['x']; $ty = $v['y']-2;}
if($d == 2) { $tx = $v['x']+2; $ty = $v['y'];}
if($d == 3) { $tx = $v['x']; $ty = $v['y']+2;}
if($user['room'] == 74 || $user['room'] == 76) {
if(strpos($map[$ty][$tx], 's/') !== false && !@$mapbots[$ty][$tx]) {
break;
}
} else {
if($map[$ty][$tx] == 2 && !@$mapbots[$ty][$tx]) {
break;
}
}
$d++;
if($d > 3) {
$d = 0;
}
}
if($i < 4) {
mysql_query("UDPATE `cavebots` set `x` = '$tx', `y` = '$ty' WHERE `id` = '$v[id]' LIMIT 1");
$v['x'] = $tx;
$v['y'] = $ty;
}
if(!@$mapbots[$v['y']][$v['x']]) {
$mapbots[$v['y']][$v['x']] = "b";
}
$ambushes[$v['y']][$v['x']] = 1;
$mapbots[$v['y']][$v['x']] .= "/$v[bot]/$v[cnt]";
}
$cavedata['wander'] = time();
savecavedata($cavedata, $user['caveleader'], $floor);
}
foreach($mapbots as $k => $v) {
foreach($v as $k2 => $v2) {
$map[$k][$k2] = $v2;
}
}
$moved = 0;
if(@$_GET['move'] && $_SESSION['movetime'] < time()) {
if($_GET['move'] == "x1" && canmoveto($map[$y*2][$x*2+2], 2, $map[$y*2][$x*2+1],2)) {
mysql_query("UPDATE `caveparties` SET `x` = (`x`+1) WHERE `user` = '$user[id]' LIMIT 1");
$x++;
$moved=1;
}
if($_GET['move'] == "x2" && canmoveto($map[$y*2][$x*2-2], 2, $map[$y*2][$x*2-1])) {
mysql_query("UPDATE `caveparties` SET `x` = (`x`-1) WHERE `user` = '$user[id]' LIMIT 1");
$x--;
$moved=1;
}
if($_GET['move'] == "y1" && canmoveto($map[$y*2+2][$x*2], 2, $map[$y*2+1][$x*2])) {
mysql_query("UPDATE `caveparties` SET `y` = (`y`+1) WHERE `user` = '$user[id]' LIMIT 1");
$y++;
$moved=1;
}
if($_GET['move'] == "y2" && canmoveto($map[$y*2-2][$x*2], 2, $map[$y*2-1][$x*2])) {
mysql_query("UPDATE `caveparties` SET `y` = (`y`-1) WHERE `user` = '$user[id]' LIMIT 1");
$y--;
$moved=1;
}
updparties();
#$_SESSION['movetime'] = time()+5;
$_SESSION['movetime'] = time();
}
if($moved && (substr($map[$y*2][$x*2], 0, 1) === "e" || substr($map[$y*2][$x*2], 0, 1) === "p")) {
$tx = $x;
$ty = $y;
$tmp = explode("/", $map[$y*2][$x*2]);
if(file_exists("underground/events/$user[room].php")) {
include("underground/events/$user[room].php");
}
}
$ax = 0; $ay = 0;
if($ambushes[$y*2+2][$x*2] && $map[$y*2+1][$x*2] == 0) { $ax = $x; $ay = $y+1; }
if($ambushes[$y*2-2][$x*2] && $map[$y*2-1][$x*2] == 0) { $ax = $x; $ay = $y-1; }
if($ambushes[$y*2][$x*2+2] && $map[$y*2][$x*2+1] == 0) { $ax = $x+1; $ay = $y; }
if($ambushes[$y*2][$x*2-2] && $map[$y*2][$x*2-1] == 0) { $ax = $x-1; $ay = $y; }
if($ax && $ay && $user['hp'] > 0) {
include_once("cavedata.php");
if(!($cavedata[$user['room']]['x'.$floor] == $x && $cavedata[$user['room']]['y'.$floor] == $y)) {
if($ax < $x) {
$dir1 = 0;
} elseif($ax > $x) {
$dir1 = 2;
} elseif($ay < $y) {
$dir1 = 1;
} elseif($ay > $y) {
$dir1 = 3;
}
if($dir != $dir1) {
$dir = $dir1;
mysql_query("UPDATE `caveparties` SET `dir` = '$dir' WHERE `user` = '$user[id]' LIMIT 1");
foreach($party as $k => $v) {
if($v['user'] == $user['id']) {
$party[$k]['dir'] = $dir1;
}
}
}
$_GET['attack'] = 1;
}
}
if(!$_SESSION['movetime']) {
#$_SESSION['movetime'] = time()+5;
$_SESSION['movetime'] = time();
}
if(@$_GET['takeitem']) {
$_GET['takeitem'] = (int)$_GET['takeitem'];
$it = mysql_fetch_array(mysql_query("SELECT `item`, `foronetrip`, `incave`, `podzem` FROM `caveitems` WHERE `leader` = '$user[caveleader]' AND `x` = '".($x*2)."' AND `y` = '".($y*2)."' AND `floor` = '$floor' AND `id` = '$_GET[takeitem]' LIMIT 1"));
if(isset($it['item'])) {
$ms = mysql_fetch_assoc(mysql_query("SELECT `massa` AS `mass` FROM $shop WHERE `id` = '$it[item]' LIMIT 1"));
$shop = 'shop';
if(!placeinbackpack(1, $user['id'])) {
$report = "У вас в рюкзаке слишком много предметов.";
} elseif(!cancarry($ms['mass'], $user)) {
$report = "Ваш рюкзак перегружен.";
} else {
$destiny = 0;
$taken = takeshopitem($it['item'], "$shop", "", $it['foronetrip'], $destiny, array("podzem" => $it["podzem"], "incave" => $it['incave']), 0, 1, "Нашёл в пещере");
if(@$taken['error']) {
$report = $taken['error'];
} else {
mysql_query("DELETE FROM `caveitems` WHERE `leader` = '$user[caveleader]' AND `x` = '".($x*2)."' AND `y` ='".($y*2)."' AND `floor` = '$floor' AND `id` = '$_GET[takeitem]' LIMIT 1");
$report = "Вы нашли $taken[name].";
}
}
} else {
$report = "Кто-то оказался быстрее...";
}
}
if(@$_GET['speak']) {
if($dir == 0) { $x1 = $x*2-2; } elseif($dir == 2) { $x1 = $x*2+2; } else { $x1 = $x*2; }
if($dir == 1) { $y1 = $y*2-2; } elseif($dir == 3) { $y1 = $y*2+2; } else { $y1 = $y*2; }
$cell = $map[$y1][$x1];
$tmp = explode("/", $cell);
if($tmp[0] == "d") {
header("location: dialog.php?char=$tmp[2]");
die();
}
if($tmp[0] == "b" && isset($dialogs[$bots[$tmp[1]]])) {
header("location: dialog.php?char=".$bots[$tmp[1]]);
die();
}
}
if(@$_GET['attack']) {
if($dir == 0) { $by = $y*2; $bx = ($x-1)*2; }
if($dir == 1) { $by = ($y-1)*2; $bx = $x*2; }
if($dir == 2) { $by = $y*2; $bx = ($x+1)*2; }
if($dir == 3) { $by = ($y+1)*2; $bx = $x*2; }
$r = mysql_query("SELECT `bot`, `cnt`, `battle` FROM `cavebots` WHERE `leader` = '$user[caveleader]' AND `x` = $bx AND `y` = $by AND `floor` = '$floor'");
$rec = mysql_fetch_assoc($r);
if($user['hp'] <= $user['maxhp']*0.33) {
$report = 'Вы слишком ослаблены для поединка';
} elseif(isset($rec['bot'])) {
$btl = $rec['battle'];
if($btl > 0) {
battlewithbot($bots[$rec['bot']], "", "", 10, 0, 0, $btl);
} else {
$firstbot = $bots[$rec['bot']];
$otherbots = array();
$rec['cnt']--;
while($rec['cnt'] > 0) {
$otherbots[] = array('id' => $bots[$rec['bot']], 'name' => $botnames[$rec['bot']]);
$rec["cnt"]--;
}
while($rec = mysql_fetch_assoc($r)) {
while($rec['cnt'] > 0) {
$otherbots[] = array('id' => $bots[$rec['bot']], 'name' => $botnames[$rec['bot']]);
$rec['cnt']--;
}
}
$btl = battlewithbot($firstbot, "", "", 10, 0, 0, 0, $otherbots);
mysql_query("UPDATE `cavebots` SET `battle` = '$btl' WHERE `leader` = '$user[caveleader]' AND `x` = '$bx' AND `y` = $by AND `floor` = '$floor'");
}
}
}
if(@$_GET['exit']) {
if(count($party) == 1) {
mysql_query("DELETE FROM `cavebots` WHERE `leader` = '$user[id]'");
mysql_query("DELETE FROM `caves` WHERE `leader` = '$user[id]'");
mysql_query("DELETE FROM `caveparties` WHERE `leader` = '$user[id]'");
mysql_query("DELETE FROM `caveitems` WHERE `leader` = '$user[id]'");
mysql_query("UPDATE `users` SET `caveleader` = 0 WHERE `id` = '$user[id]' LIMIT 1");
} else {
mysql_query("LOCK TABLES `users` WRITE, `caveparties` WRITE, `cavebots` WRITE, `caves` WRITE, `caveitems` WRITE, `diseases` WRITE, `caveeffects` WRITE");
mysql_query("DELETE FROM `caveparties` WHERE `user` = '$user[id]'");
mysql_query("UPDATE `users` SET `caveleader` = 0 WHERE `id` = '$user[id]' LIMIT 1");
if($user['caveleader'] == $user['id']) {
foreach($party as $k => $v) {
if($v['user'] != $user['id']) {
mysql_query("UPDATE `users` SET `caveleader` = '$v[user]' WHERE `caveleader` = '$user[id]'");
mysql_query("UPDATE `cavebots` SET `leader` = '$v[user]' WHERE `leader` = '$user[id]'");
mysql_query("UPDATE `caves` SET `leader` = '$v[user]' WHERE `leader` = '$user[id]'");
mysql_query("UPDATE `caveparties` SET `leader` = '$v[user]' WHERE `leader` = '$user[id]'");
mysql_query("UPDATE `caveitems` SET `leader` = '$v[user]' WHERE `leader` = '$user[id]'");
}
}
}
mysql_query("UNLOCK TABLES");
}
$r = mysql_query("SELECT `id`, `dressed` FROM `inventory` WHERE `owner` = '$user[id]' AND `dressed` = 1 AND `foronetrip` = 1");
while($rec = mysql_fetch_assoc($r)) {
$slot = getslot($rec['id']);
if($slot) {
dropitemid(0, $user['id'], $slot);
}
}
mysql_query("DELETE FROM `inventory` WHERE `owner` = '$user[id]' AND `foronetrip` = 1");
gotoroom($user['room']-1);
}
$standingon = $map[$y*2][$x*2];
foreach($party as $k => $v) {
$map[$v['y']*2][$v['x']*2] = "u/".$v['user'];
}
?>
";
$i = 7;
$centerwall = 8;
while($i > 0) {
if($map[3][$i]) {
$centerwall = $i;
}
$i -= 2;
}
$i = 4;
function drawbot($cell, $x, $y) {
global $botnames, $imgdata, $bots, $dialogs, $user, $floor;
$data = explode("/", $cell);
$i = 1;
$bc = (count($data)-1)/2;
while($data[$i]) {
$bot = $data[$i];
$botname = $botnames[$bot];
$cnt = $data[$i+1];
if($i == 1) {
if($bc == 1) {
$bn = 1;
} else {
$bn = 0;
}
} elseif($i == 3) {
if($bc == 2) {
$bn = 2;
} else {
$bn = 1;
}
} else {
$bn = 2;
}
$aMap = unserialize(mysql_result(mysql_query("SELECT `map` FROM `caves` WHERE `leader` = '$user[caveleader]' AND `floor` = '$floor'"), 0, 0));
if(!$GLOBALS['dir']) {
$xx = ($GLOBALS['x']*2) - ($y*2);
$yy = ($GLOBALS['y']*2) - ($x - 3);
} elseif($GLOBALS['dir'] == 1) {
$xx = ($GLOBALS['x']*2) + ($x - 3);
$yy = ($GLOBALS['y']*2) - ($y*2);
} elseif($GLOBALS['dir'] == 2) {
$xx = ($GLOBALS['x']*2) + ($y * 2);
$yy = ($GLOBALS['y']*2) + ($x - 3);
} else {
$xx = ($GLOBALS['x']*2) - ($x - 3);
$yy = ($GLOBALS['y']*2) + ($y * 2);
}
if(strpos($aMap[$yy][$xx], 'o/') !== false || strpos($aMap[$yy][$xx], 'p/') !== false) {
$ret .= drawobject2($aMap[$yy][$xx], $x, $y);
}
$rrm = $user['room'];
if(isset($dialogs[$bots[$data[1]]]) && ($bots[$data[1]] == 11147 && $user['room'] == 74)) {
$ret .= " 1?" ($cnt)":"")."\" ".($y == 1 && $x == 3?"onclick=\"speakattackmenu(event);\"":"")." width=\"".$imgdata[$x][$y]["wd"]."\" height=\"".$imgdata[$x][$y]["ht"]."\" src=\"/i/dungeon/mobs/$rrm/$bot.gif\" style=\"position: absolute; left: ".$imgdata[$x][$y]["x"][$bn]."px; top: ".$imgdata[$x][$y]["y"]."px;".($x == 3 && $y == 1?"cursor: pointer;":"").($x == 3?"z-index: ".(99-($y*5)).";":"")."\" />";
} else {
$ret .= " 1?" ($cnt)":"")."\" ".($y == 1 && $x == 3?" onclick=\"document.location.href='cave.php?attack=1';\"":"")." width=\"".$imgdata[$x][$y]["wd"]."\" height=\"".$imgdata[$x][$y]["ht"]."\" src=\"/i/dungeon/mobs/$rrm/$bot.gif\" style=\"position: absolute; left: ".$imgdata[$x][$y]["x"][$bn]."px; top: ".$imgdata[$x][$y]["y"]."px;".($x == 3 && $y == 1?"cursor: pointer;":"").($x == 3?"z-index: ".(99-($y*5)).";":"")."\" />";
}#onclick=\"attackmenu(event);\"
$i += 2;
}
return $ret;
}
function drawdialog($cell, $x, $y) {
global $dialogs, $imgdata;
$data = explode("/", $cell);
$i = 1;
$d = $data[2];
$bot = $data[$i];
$botname = $botnames[$bot];
$cnt = $data[$i+1];
$ret = "";
return $ret;
}
function drawuser($cell, $x, $y) {
global $botnames, $imgdata, $party;
$data = explode("/", $cell);
$i = 1;
$bc = (count($data)-1);
while($data[$i]) {
$u = $data[$i];
if($i == 1) {
if($bc == 1) {
$bn = 1;
} else {
$bn = 0;
}
} elseif($i == 3) {
if($bc == 2) {
$bn = 2;
} else {
$bn = 1;
}
} else {
$bn = 2;
}
foreach($party as $k => $v) {
if($v['user'] == $u) {
$udata = $v;
break;
}
}
$ret .= "";
$i++;
}
return $ret;
}
function drawobject($cell, $x, $y) {
global $objects, $imgdata, $user, $objdata, $objsizes, $imgmap;
$tmp = explode("/", $cell);
$obj = $tmp[1];
$ht = round($imgdata[$x][$y]["ht"]/2);
if($objsizes[$obj]) {
$coef=$objdata[$x][$y]["coef"];
$wd=$objsizes[$obj][0]*$coef;
$ht=$objsizes[$obj][1]*$coef;
$left=round($objdata[$x][$y]["x"]-($wd/2));
$top=$objdata[$x][$y]["y"]-$ht;
} elseif($obj == 510) {
$wd=round($imgdata[$x][$y]["wd"]*2.5);
$ht=$imgdata[$x][$y]["ht"];
$left=$imgdata[$x][$y]["x"][1]-round(($wd-$imgdata[$x][$y]["wd"])/2);
$top=$imgdata[$x][$y]["y"];
} elseif ($obj > 600 && $obj < 700) {
$wd=round($imgdata[$x][$y]["wd"]*1.26);
$left=$imgdata[$x][$y]["x"][1]-round(($wd-$imgdata[$x][$y]["wd"])/2);
$top=$imgdata[$x][$y]["y"]+$ht;
} elseif($obj >= 700 && $obj < 800) {
$wd=round($imgdata[$x][$y]["wd"]*1.24);
$ht=$imgdata[$x][$y]["ht"];
$left=$imgdata[$x][$y]["x"][1]-round(($wd-$imgdata[$x][$y]["wd"])/2);
$top=$imgdata[$x][$y]["y"];
} else {
$wd=$imgdata[$x][$y]["wd"];
$left=$imgdata[$x][$y]["x"][1];
$top=$imgdata[$x][$y]["y"]+$ht;
}
$rrm = $user['room'];
if (!isset($imgmap[$obj])) {
$ret .= "
".($y == 1 && $x == 3?"":"")."
".($y == 1 && $x == 3?"":"");
} else {
$ret .= "";
$ret .= $imgmap[$obj]['code'];
}
return $ret;
}
function drawobject2($cell, $x, $y) {
global $objects, $imgdata, $user, $objdata, $objsizes, $imgmap;
$tmp=explode("/", $cell);
$obj=$tmp[1];
$ht=round($imgdata[$x][$y]["ht"]/2);
if($objsizes[$obj]) {
$coef=$objdata[$x][$y]["coef"];
$wd=$objsizes[$obj][0]*$coef;
$ht=$objsizes[$obj][1]*$coef;
$left=round($objdata[$x][$y]["x"]-($wd/2));
$top=$objdata[$x][$y]["y"]-$ht;
} elseif($obj==510) {
$wd=round($imgdata[$x][$y]["wd"]*2.5);
$ht=$imgdata[$x][$y]["ht"];
$left=$imgdata[$x][$y]["x"][1]-round(($wd-$imgdata[$x][$y]["wd"])/2);
$top=$imgdata[$x][$y]["y"];
} elseif($obj>600 && $obj<700) {
$wd=round($imgdata[$x][$y]["wd"]*1.26);
$left=$imgdata[$x][$y]["x"][1]-round(($wd-$imgdata[$x][$y]["wd"])/2);
$top=$imgdata[$x][$y]["y"]+$ht;
} elseif($obj>=700 && $obj<800) {
$wd=round($imgdata[$x][$y]["wd"]*1.24);
$ht=$imgdata[$x][$y]["ht"];
$left=$imgdata[$x][$y]["x"][1]-round(($wd-$imgdata[$x][$y]["wd"])/2);
$top=$imgdata[$x][$y]["y"];
} else {
$wd=$imgdata[$x][$y]["wd"];
$left=$imgdata[$x][$y]["x"][1];
$top=$imgdata[$x][$y]["y"]+$ht;
}
$rrm = $user['room'];
if(!isset($imgmap[$obj])) {
$ret.="
".($y == 1 && $x == 3?"":"")."
".($y == 1 && $x == 3?"":"");
} else {
$ret .= "";
$ret .= $imgmap[$obj]['code'];
}
return $ret;
}
function drawevent($cell, $x, $y) {
global $events, $eventdata;
$tmp = explode("/", $cell);
$obj = $tmp[1];
if($obj == 1) { return ""; }
$wd = round($eventdata[$x][$y]["q"]*$events[$obj]["w"]);
$ht = round($eventdata[$x][$y]["q"]*$events[$obj]["h"]);
$left = round(-$events[$obj]["h"]/2+$eventdata[$x][$y]["x"]);
$top = round($eventdata[$x][$y]["y"]-$events[$obj]["h"]);
$ret .= "";
return $ret;
}
while($i >= 0) {
if($i == 4) {
if($map[0][7]) {
$ret .= "";
}
if($map[0][6]) {
$ret .= "";
}
if($map[-1][6]) {
$ret .= "";
}
}
$wall = $i*2-1;
$sidewall = $i*2;
if($map[1][$sidewall] && $i > 0) {
$obj = substr($map[1][$sidewall], 0, 1);
if($obj == "b") {
$ret .= drawbot($map[1][$sidewall], 1, $i);
} elseif ($obj == "u") {
$ret .= drawuser($map[1][$sidewall], 1, $i, $players);
} elseif ($obj == "o" || $obj=="p") {
$ret .= drawobject($map[1][$sidewall], 1, $i);
} elseif ($obj == "e") {
$ret .= drawevent($map[1][$sidewall], 1, $i);
} elseif ($obj == "d") {
$ret .= drawdialog($map[1][$sidewall], 1, $i);
} elseif ($obj != "s") {
$o = $map[1][$sidewall]-10000;
if($o == 4) {
if($i == 1) {
$ret .= "";
}
if($i == 2) {
$ret .= "";
}
if($i == 3) {
$ret .= "";
}
} else {
if($i== 1) {
$ret .= "";
}
if($i== 2) {
$ret .= "";
}
if($i== 3) {
$ret .= "";
}
}
}
}
if ($map[5][$sidewall] && $i>0) {
$obj=substr($map[5][$sidewall],0,1);
if ($obj=="b") {
$ret.=drawbot($map[5][$sidewall], 5, $i);
} elseif ($obj=="u") {
$ret.=drawuser($map[5][$sidewall], 5, $i, $players);
} elseif ($obj=="o" || $obj=="p") {
$ret.=drawobject($map[5][$sidewall], 5, $i);
} elseif ($obj=="e") {
$ret.=drawevent($map[5][$sidewall], 5, $i);
} elseif ($obj=="d") {
$ret.=drawdialog($map[5][$sidewall], 5, $i);
} elseif ($obj!="s") {
$o=$map[5][$sidewall]-10000;
if ($o==4) {
if ($i==1) $ret.="";
if ($i==2) $ret.="";
if ($i==3) $ret.="";
} else {
if ($i==1) $ret.="";
if ($i==2) $ret.="";
if ($i==3) $ret.="";
}
}
}
if ($i>0 && $map[1][$wall]) $ret.="";
$objInWall = explode('/', $map[4][$sidewall]);
if ($objInWall[1] == 'o') {
if(!passablewall($map[4][$sidewall])) $ret.="";
} else {
if(!passablewall($map[4][$sidewall])) $ret.="";
}
$objInWall = explode('/', $map[2][$sidewall]);
if ($objInWall[1] == 'o') {
if(!passablewall($map[2][$sidewall])) $ret.="";
} else {
if(!passablewall($map[2][$sidewall])) $ret.="";
}
if ($i>0 && $map[5][$wall]) $ret.="";
if ($map[3][$sidewall] && $i>0 && $sidewall<$centerwall) {
$obj=substr($map[3][$sidewall],0,1);
if ($obj=="b") {
$ret.=drawbot($map[3][$sidewall], 3, $i);
} elseif ($obj=="u") {
$ret.=drawuser($map[3][$sidewall], 3, $i, $players);
} elseif ($obj=="o" || $obj=="p") {
$ret.=drawobject($map[3][$sidewall], 3, $i);
} elseif ($obj=="e") {
$ret.=drawevent($map[3][$sidewall], 3, $i);
} elseif ($obj=="d") {
$ret.=drawdialog($map[3][$sidewall], 3, $i);
} elseif ($obj!="s") {
$o=$map[3][$sidewall]-10000;
if ($o==4) {
if ($i==1) $ret.="";
if ($i==2) $ret.="";
if ($i==3) $ret.="";
} else {
if ($i==1) $ret.="";
if ($i==2) $ret.="";
if ($i==3) $ret.="";
}
}
}
if ($map[3][$wall]) {
if ($i>0) $ret.="
2?"style=\"background-image:url('$base/cw$i".cavewall($map[3][$wall]).".gif')\"":"")."> ";
if ($i==1 && $map[3][$wall]>2) {
if ($map[3][$wall]>1000) {
$ret.="";
} elseif ($map[3][$wall]>100) {
$ret.="";
} else $ret.="";
}
$objInWall = explode('/', $map[3][$wall]);
if ($objInWall[1] == "o") {
if ($user['room'] == 83 && !(!$direction && (($x == 13 && $y == 4) || ($x == 12 && $y == 4)))) { // исключение 2-ух клеток в комнате 82
$ret.=drawobject('//' . $objInWall[2], 3, $i);
}
}
$nocenter=1;
}
if ($i==4) {
if ($map[7][6]) $ret.="";
}
$i--;
}
$ret.=" |
";
foreach ($players as $k=>$v) {
if ($v["x"]-($startx/2)>=0 && $v["x"]-($startx/2)<=8 && $v["y"]-($starty/2)>=0 && $v["y"]-($starty/2)<=8) {
$ret.="";
}
}
$ret.="
|
=@$report?>
if ($loses>=3) echo " Вернуться "; if ($loses) echo " Количество смертей: $loses ";
?>
|
$dMap = unserialize(mysql_result(mysql_query("SELECT `map` FROM `cavemaps` WHERE `floor` = $floor AND `room` = ".($user['room'] - 1)), 0, 0));
$cPlace = $dMap[$y*2][$x*2];
$tmp=explode("/", $cPlace);
if($user['room'] == 621) { if($floor == 1) { echo 'Проклятый Рудник, 1 этаж'; } elseif($floor == 2) { echo 'Проклятый Рудник, 2 этаж'; } }
elseif (@$roomnames[$tmp[1]]) echo $roomnames[$tmp[1]];
else echo $rooms[$user["room"]];
?>
Выйти
echo drawmap($map, $party, $x, $y, $dir);
?>
|