From bdbb359e200593903ebe3c1b8bddf95d93e019a3 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Fri, 13 Oct 2023 18:02:45 +0300 Subject: [PATCH] refactor #php8 --- _incl_data/class/Dialog.php | 2 +- _incl_data/class/Dungeon.php | 943 +++++++++++++----------------- modules_data/location/dungeon.php | 108 ++-- 3 files changed, 456 insertions(+), 597 deletions(-) diff --git a/_incl_data/class/Dialog.php b/_incl_data/class/Dialog.php index 0428d244..b0d07fd0 100644 --- a/_incl_data/class/Dialog.php +++ b/_incl_data/class/Dialog.php @@ -983,7 +983,7 @@ class Dialog if ($this->info['tr_dn'] != $d->info['id2']) { $go = 0; } elseif ($this->info['x'] != 0 || $this->info['y'] != 0) { - if ($d->testLike($u->info['x'], $u->info['y'], $this->info['x'], $this->info['y']) != 1) { + if (!$d->cellIsGoodforAction($u->info['x'], $u->info['y'], $this->info['x'], $this->info['y'])) { $go = 0; } //если бот погиб diff --git a/_incl_data/class/Dungeon.php b/_incl_data/class/Dungeon.php index b874dfc3..5d8c12db 100644 --- a/_incl_data/class/Dungeon.php +++ b/_incl_data/class/Dungeon.php @@ -1,33 +1,18 @@ 558, 1 => 722, 2 => 718, 3 => 700, 4 => 291, 5 => 545, 6 => 533, 7 => 536, 8 => 628, 9 => 710, 10 => 654, 11 => 684, 12 => 689, 13 => 552, 14 => 552, 15 => 716, - 16 => 320, 17 => 290, 18 => 543, 19 => 528, 20 => 540, 21 => 627, 22 => 709, 23 => 653, 24 => 681, 25 => 687, 26 => 523, 27 => 523, 28 => 712, 29 => 1151, 30 => 544, - 31 => 541, 32 => 525, 33 => 539, 34 => 633, 35 => 707, 36 => 647, 37 => 680, 38 => 685, 39 => 567, 40 => 717, 41 => 706, 42 => 527, 43 => 537, 44 => 626, 45 => 708, - 46 => 723, 47 => 651, 48 => 683, 49 => 686, 50 => 2862, 51 => 2863, 52 => 2864, - ]; - private $bs; - private array $map = [0 => []]; - private array $cord = ['x' => 0]; - private array $sg = [ - 1 => [1 => 1, 2 => 2, 3 => 3, 4 => 4], - 2 => [1 => 2, 2 => 3, 3 => 4, 4 => 1], - 3 => [1 => 3, 2 => 4, 3 => 1, 4 => 2], - 4 => [1 => 4, 2 => 1, 3 => 2, 4 => 3], - ]; - /** * 1-9: передняя стенка, в 2-х шагах;
* 10-23: растояние: 1 шаг;
@@ -39,186 +24,145 @@ class Dungeon * @var array */ public readonly array $walls; + private array $userinfo; + private array $userstats; + private array $itbs = [ + 0 => 558, 1 => 722, 2 => 718, 3 => 700, 4 => 291, 5 => 545, 6 => 533, 7 => 536, 8 => 628, 9 => 710, 10 => 654, 11 => 684, 12 => 689, 13 => 552, 14 => 552, 15 => 716, + 16 => 320, 17 => 290, 18 => 543, 19 => 528, 20 => 540, 21 => 627, 22 => 709, 23 => 653, 24 => 681, 25 => 687, 26 => 523, 27 => 523, 28 => 712, 29 => 1151, 30 => 544, + 31 => 541, 32 => 525, 33 => 539, 34 => 633, 35 => 707, 36 => 647, 37 => 680, 38 => 685, 39 => 567, 40 => 717, 41 => 706, 42 => 527, 43 => 537, 44 => 626, 45 => 708, + 46 => 723, 47 => 651, 48 => 683, 49 => 686, 50 => 2862, 51 => 2863, 52 => 2864, + ]; + private readonly array $bs; + private array $map = []; + private array $cord = ['x' => 0]; + private array $sg = [ + 1 => [1 => 1, 2 => 2, 3 => 3, 4 => 4], + 2 => [1 => 2, 2 => 3, 3 => 4, 4 => 1], + 3 => [1 => 3, 2 => 4, 3 => 1, 4 => 2], + 4 => [1 => 4, 2 => 1, 3 => 2, 4 => 3], + ]; public function __construct(User $user = null) { if (!$user) { $user = User::start(); } + $this->userinfo = $user->info; + $this->userstats = $user->stats; - global $u; - $this->info = Db::getRow('select * from dungeon_now where id = ?', [$user->info['dnow']]); - + $this->info = Db::getRow('select * from dungeon_now where id = ?', [$this->userinfo['dnow']]); $this->id_dng = $this->info['id2']; - $this->gs = $u->info['s']; + $this->gs = $this->userinfo['s']; if ($this->gs < 1 || $this->gs > 4) { $this->gs = 1; } - if ($this->info['bsid'] > 0) { - $this->bs = mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `bs_turnirs` WHERE `city` = "' . $u->info['city'] . '" AND `id` = "' . $this->info['bsid'] . '" AND `time_start` = "' . $this->info['time_start'] . '" LIMIT 1' - ) - ); - } + $this->getBs(); - if (isset($_GET['itm_luck']) && $this->info['bsid'] == 0) { - $this->itm_luck((int)$_GET['itm_luck']); - } elseif (isset($_GET['itm_unluck']) && $this->info['bsid'] == 0) { - $this->itm_unluck((int)$_GET['itm_unluck']); - } elseif (isset($_GET['atack'])) { - $this->atack((int)$_GET['atack']); - } elseif (isset($_GET['take'])) { - $this->takeinv((int)$_GET['take']); - } elseif (isset($_GET['take_obj'])) { - $this->takeit((int)$_GET['take_obj']); - } elseif (isset($_GET['look'])) { - if ((int)$_GET['look'] == 1) { - if ($this->gs == 1) { - $this->gs = 2; - } elseif ($this->gs == 2) { - $this->gs = 3; - } elseif ($this->gs == 3) { - $this->gs = 4; - } elseif ($this->gs == 4) { - $this->gs = 1; - } - } elseif ((int)$_GET['look'] == 2) { - if ($this->gs == 1) { - $this->gs = 4; - } elseif ($this->gs == 2) { - $this->gs = 1; - } elseif ($this->gs == 3) { - $this->gs = 2; - } elseif ($this->gs == 4) { - $this->gs = 3; - } - } - mysql_query( - 'UPDATE `stats` SET `s` = "' . ((int)$this->gs) . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' - ); - $u->info['s'] = $this->gs; - } elseif (isset($_GET['go'])) { - //перемещение - $this->testGo((int)$_GET['go']); - } + match (true) { + isset($_GET['itm_luck']) && $this->info['bsid'] == 0 => $this->itmLuck((int)$_GET['itm_luck']), + isset($_GET['itm_unluck']) && $this->info['bsid'] == 0 => $this->itmUnluck((int)$_GET['itm_unluck']), + isset($_GET['atack']) => $this->atack((int)$_GET['atack']), + isset($_GET['take']) => $this->takeinv((int)$_GET['take']), + isset($_GET['take_obj']) => $this->takeit((int)$_GET['take_obj']), + isset($_GET['look']) => $this->look((int)$_GET['look'], $user), + isset($_GET['go']) => $this->testGo((int)$_GET['go']), // перемещение + }; - /* генерируем вид персонажа (только карта) - $this->gs = 1; //смотрим прямо - 2; //смотрим лево - 3; //смотрим вниз - 4; //смотрим право - ( ( ( `y` >= '.$u->info['y'].' && `y` <= '.($u->info['y']+4).' ) && ( `x` >= '.($u->info['x']-1).' && `x` <= '.($u->info['x']+1).' ) ) || ( (`x` = '.($u->info['x']+2).' || `x` = '.($u->info['x']-2).') && ( `y` = '.($u->info['y']+3).' || `y` = '.($u->info['y']+4).' ) ) ) - */ + /* генерируем вид персонажа (только карта) */ - $whr = [1 => ' ((`x` <= ' . ($u->info['x'] + 2) . ' && `x` >= ' . ($u->info['x'] - 2) . ') && (`y` >= ' . $u->info['y'] . ' && `y` <= ' . ($u->info['y'] + 4) . ')) ', //прямо - 3 => ' ((`x` <= ' . ($u->info['x'] + 2) . ' && `x` >= ' . ($u->info['x'] - 2) . ') && (`y` <= ' . $u->info['y'] . ' && `y` >= ' . ($u->info['y'] - 4) . ')) ', //вниз - 2 => ' ((`x` <= ' . $u->info['x'] . ' && `x` >= ' . ($u->info['x'] - 4) . ') && (`y` <= ' . ($u->info['y'] + 2) . ' && `y` >= ' . ($u->info['y'] - 2) . ')) ', //лево - 4 => ' ((`x` >= ' . $u->info['x'] . ' && `x` <= ' . ($u->info['x'] + 4) . ') && (`y` <= ' . ($u->info['y'] + 2) . ' && `y` >= ' . ($u->info['y'] - 2) . ')) ', //право + $queryArgsXY = [ + 1 => [$user->info['x'] + 2, $user->info['x'] - 2, $user->info['y'] + 4, $user->info['y'],], + 2 => [$user->info['x'] + 2, $user->info['x'] - 2, $user->info['y'], $user->info['y'] - 4,], + 3 => [$user->info['x'], $user->info['x'] - 4, $user->info['y'] + 2, $user->info['y'] - 2,], + 4 => [$user->info['x'] + 4, $user->info['x'], $user->info['y'] + 2, $user->info['y'] - 2,], ]; - $i = 1; - $sp = mysql_query( - 'SELECT * FROM `dungeon_map` WHERE `id_dng` = "' . $this->id_dng . '" AND ' . $whr[$this->gs] . ' ORDER BY `y` ASC , `x` ASC LIMIT 25' - ); - while ($pl = mysql_fetch_assoc($sp)) { - $this->map[0][$pl['y'] . '_' . $pl['x']] = $pl; - $i++; + $cellsCount = 1; + + $dungeonMap = Db::getRows("select * from dungeon_map where id_dng = ? and x <= ? and x >= ? and y <= ? and y >= ? order by y, x limit 25", + [$this->id_dng, $queryArgsXY[$this->gs][1], $queryArgsXY[$this->gs][2], $queryArgsXY[$this->gs][3], $queryArgsXY[$this->gs][4]]); + + foreach ($dungeonMap as $mapCell) { + $this->map[0][$mapCell['y'] . '_' . $mapCell['x']] = $mapCell; + $cellsCount++; } - $this->map['good'] = $i; //целых клеток + + $this->map['good'] = $cellsCount; //целых клеток $this->map[1] = $this->genMatix(); $this->lookDungeon(); } - public function itm_luck($id) + private function getBs(): void { - global $u; - $fxv = ['itm' => mysql_fetch_assoc( - mysql_query( - 'SELECT `im`.*,`ish`.* FROM `dungeon_items` AS `ish` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `ish`.`item_id`) WHERE `ish`.`dn` = "' . $this->info['id'] . '" AND `ish`.`id` = "' . mysql_real_escape_string( - $id - ) . '" AND `ish`.`take` = "0" AND `ish`.`delete` = "0" AND `ish`.`x` = "' . $u->info['x'] . '" AND `ish`.`y` = "' . $u->info['y'] . '" LIMIT 1' - ) - ), 'luck' => mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_actions` WHERE `uid` = "' . $u->info['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string( - $id - ) . '" LIMIT 1' - ) - ), 'luck2' => mysql_fetch_assoc( - mysql_query( - 'SELECT COUNT(*) FROM `dungeon_actions` WHERE `uid` = "' . $u->info['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string( - $id - ) . '" LIMIT 1' - ) - )]; - if ($u->stats['silver'] >= 3) { //дополнительный бросок - $fxv['luck2'][0]--; + if ($this->info['bsid'] <= 0) { + return; } - if ($fxv['itm']['user'] > 0) { - $this->error = 'Розыгрыш предмет уже завершился...'; - } elseif (!isset($fxv['itm']['id'])) { + $this->bs = Db::getRow('select * from bs_turnirs where id = ? and time_start = ?', [$this->info['bsid'], $this->info['time_start']]); + } + + private function itmLuck(int $id): void + { + if ($this->info['bsid'] != 0 || empty($id)) { + return; + } + + $item = Db::getRow('select * from dungeon_items left join items_main on items_main.id = item_id where dn = ? and dungeon_items.id = ? and take = 0 and x = ? and y = ?', + [$this->info['id'], $id, $this->userinfo['x'], $this->userinfo['y']]); + $luck = Db::getValue('select count(id) from dungeon_actions where uid = ? and dn = ? and vars = ?', [$this->userinfo['id'], $this->info['id'], 'luck_itm' . $id]); + + $luck2 = $luck; + + if ($this->userstats['silver'] >= 3) { //дополнительный бросок + $luck2--; + } + if ($item['user'] > 0) { + $this->error = 'Розыгрыш предмета уже завершился...'; + } elseif (!isset($item['id'])) { $this->error .= '
Предмет не найден
'; - } elseif ($fxv['luck2'][0] > 0) { - $this->error .= '
Вы уже учавствуете в розыгрыше "' . $fxv['itm']['name'] . '", ожидаем других участников еще ' . $u->timeOut( - $fxv['itm']['time'] - time() + 300 - ) . '
'; + } elseif ($luck2 > 0) { + $this->error .= '
Вы уже учавствуете в розыгрыше "' . $item['name'] . '", ожидаем других участников еще ' . + Conversion::secondsToTimeout($item['time'] - time() + 300) . '
'; } else { - $luck_users = mysql_fetch_assoc( - mysql_query( - 'SELECT COUNT(`id`) FROM `dungeon_actions` WHERE `uid` = "' . $u->info['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string( - $id - ) . '" LIMIT 1' - ) - ); - $luck_users = $luck_users[0]; - if ($luck_users < 1) { - mysql_query( - 'UPDATE `dungeon_items` SET `time` = "' . time() . '" WHERE `id` = "' . $fxv['itm']['id'] . '" LIMIT 1' - ); + if ($luck < 1) { + Db::sql('update dungeon_items set time = unix_timestamp() where id = ?', [$item['id']]); } + $rndl = rand(1, 100); - mysql_query( - 'INSERT INTO `dungeon_actions` (`uid`,`dn`,`x`,`y`,`time`,`vars`,`vals`) VALUES ( - "' . $u->info['id'] . '","' . $u->info['dnow'] . '","' . $u->info['x'] . '","' . $u->info['y'] . '","' . time() . '", - "luck_itm' . mysql_real_escape_string($id) . '","' . $rndl . '" - )' - ); - if ($u->info['sex'] == 0) { - $fxv['text'] = '' . $u->info['login'] . ' выбросил *' . $rndl . '* в споре за предмет "' . $fxv['itm']['name'] . '"'; + + Db::sql('insert into dungeon_actions (uid, dn, x, y, time, vars, vals) values (?,?,?,?,unix_timestamp(),?,?)', + [$this->userinfo['id'], $this->userinfo['dnow'], $this->userinfo['x'], $this->userinfo['y'], 'luck_itm' . $id, $rndl]); + + if ($this->userinfo['sex'] == 0) { + $this->sys_chat(sprintf('%s выбросил *%s* в споре за предмет «%s»', $this->userinfo['login'], $rndl, $item['name'])); } else { - $fxv['text'] = '' . $u->info['login'] . ' выбросила *' . $rndl . '* в споре за предмет "' . $fxv['itm']['name'] . '"'; + $this->sys_chat(sprintf('%s выбросила *%s* в споре за предмет «%s»', $this->userinfo['login'], $rndl, $item['name'])); } - $this->sys_chat($fxv['text']); - $this->error .= '
Вы выбросили ' . $rndl . ' в споре за "' . $fxv['itm']['name'] . '"
'; + + $this->error .= sprintf('
Вы выбросили *%s* в споре за предмет «%s»
', $rndl, $item['name']); } - $this->test_luck($id); - unset($fxv); + $this->testLuck($id); } public function sys_chat($rtxt) { - global $u; $cmsg = new ChatMessage(); - $cmsg->setDn($u->info['dnow']); - $cmsg->setCity($u->info['city']); - $cmsg->setRoom($u->info['room']); + $cmsg->setDn($this->userinfo['dnow']); + $cmsg->setRoom($this->userinfo['room']); $cmsg->setText($rtxt); $cmsg->setType(6); $cmsg->setTypeTime(1); (new Chat())->sendMsg($cmsg); } - public function test_luck($id) + private function testLuck($id): void { - global $u; $fxv = ['itm' => mysql_fetch_assoc( mysql_query( 'SELECT `im`.*,`ish`.* FROM `dungeon_items` AS `ish` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `ish`.`item_id`) WHERE `ish`.`dn` = "' . $this->info['id'] . '" AND `ish`.`id` = "' . mysql_real_escape_string( $id - ) . '" AND `ish`.`take` = "0" AND `ish`.`delete` = "0" AND `ish`.`x` = "' . $u->info['x'] . '" AND `ish`.`y` = "' . $u->info['y'] . '" LIMIT 1' + ) . '" AND `ish`.`take` = "0" AND `ish`.`delete` = "0" AND `ish`.`x` = "' . $this->userinfo['x'] . '" AND `ish`.`y` = "' . $this->userinfo['y'] . '" LIMIT 1' ) ), 'luck_count' => mysql_fetch_assoc( mysql_query( @@ -258,84 +202,60 @@ class Dungeon $this->error .= '
Розыгрыш завершен! Победитель ' . $fxv['user_win']['login'] . '!
'; } } else { - $this->error .= '
У остальных участников осталось ' . $u->timeOut( + $this->error .= '
У остальных участников осталось ' . Conversion::secondsToTimeout( $fxv['itm']['time'] + 300 - time() ) . ' мин. до конца розыгрыша
'; } - unset($fxv); + } - public function itm_unluck($id) + private function itmUnluck($id): void { - global $u; - $fxv = ['itm' => mysql_fetch_assoc( - mysql_query( - 'SELECT `im`.*,`ish`.* FROM `dungeon_items` AS `ish` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `ish`.`item_id`) WHERE `ish`.`dn` = "' . $this->info['id'] . '" AND `ish`.`id` = "' . mysql_real_escape_string( - $id - ) . '" AND `ish`.`take` = "0" AND `ish`.`delete` = "0" AND `ish`.`x` = "' . $u->info['x'] . '" AND `ish`.`y` = "' . $u->info['y'] . '" LIMIT 1' - ) - ), 'luck' => mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_actions` WHERE `uid` = "' . $u->info['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string( - $id - ) . '" LIMIT 1' - ) - )]; - if ($fxv['itm']['user'] > 0) { + $item = Db::getRow('select * from dungeon_items left join items_main on items_main.id = item_id where dn = ? and dungeon_items.id = ? and take = 0 and x = ? and y = ?', + [$this->info['id'], $id, $this->userinfo['x'], $this->userinfo['y']]); + + $luck = Db::getRow('select *, count(id) as count from dungeon_actions where uid = ? and dn = ? and vars = ?', [$this->userinfo['id'], $this->info['id'], 'luck_itm' . $id]); + + if ($item['user'] > 0) { $this->error = 'Розыгрыш предмет уже завершился...'; - } elseif (!isset($fxv['itm']['id'])) { + } elseif (!isset($item['id'])) { $this->error .= '
Предмет не найден
'; - } elseif (isset($fxv['luck']['id'])) { - if ($fxv['luck']['vals'] == 0) { - $this->error .= '
Вы уже отказались от участия в розыгрыше "' . $fxv['itm']['name'] . '"
'; + } elseif (isset($luck['id'])) { + if ($luck['vals'] == 0) { + $this->error .= '
Вы уже отказались от участия в розыгрыше "' . $item['name'] . '"
'; } else { - $this->error .= '
Вы уже учавствуете в розыгрыше "' . $fxv['itm']['name'] . '", ожидаем других участников еще ' . $u->timeOut( - $fxv['itm']['time'] - time() + 300 + $this->error .= '
Вы уже учавствуете в розыгрыше "' . $item['name'] . '", ожидаем других участников еще ' . Conversion::secondsToTimeout( + $item['time'] - time() + 300 ) . '
'; } } else { - $luck_users = mysql_fetch_assoc( - mysql_query( - 'SELECT COUNT(`id`) FROM `dungeon_actions` WHERE `uid` = "' . $u->info['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string( - $id - ) . '" LIMIT 1' - ) - ); - $luck_users = $luck_users[0]; - if ($luck_users < 1) { - mysql_query( - 'UPDATE `dungeon_items` SET `time` = "' . time() . '" WHERE `id` = "' . $fxv['itm']['id'] . '" LIMIT 1' - ); + if ($luck['count'] < 1) { + Db::sql('update dungeon_items set time = unix_timestamp() where id = ?', [$item['id']]); } - if ($u->info['sex'] == 0) { - $fxv['text'] = '' . $u->info['login'] . ' отказался от спора за предмет "' . $fxv['itm']['name'] . '"'; + if ($this->userinfo['sex'] == 0) { + $this->sys_chat(sprintf('%s отказался от спора за предмет «%s»', $this->userinfo['login'], $item['name'])); } else { - $fxv['text'] = '' . $u->info['login'] . ' отказалась от спора за предмет "' . $fxv['itm']['name'] . '"'; + $this->sys_chat(sprintf('%s отказалась от спора за предмет «%s»', $this->userinfo['login'], $item['name'])); } - $this->sys_chat($fxv['text']); - mysql_query( - 'INSERT INTO `dungeon_actions` (`uid`,`dn`,`x`,`y`,`time`,`vars`,`vals`) VALUES ( - "' . $u->info['id'] . '","' . $u->info['dnow'] . '","' . $u->info['x'] . '","' . $u->info['y'] . '","' . time() . '", - "luck_itm' . mysql_real_escape_string($id) . '","0" - )' - ); - $this->error .= '
Вы отказались от участия в розыгрыше "' . $fxv['itm']['name'] . '"
'; + + Db::sql('insert into dungeon_actions (uid, dn, x, y, time, vars, vals) values (?,?,?,?,unix_timestamp(),?,?)', + [$this->userinfo['id'], $this->userinfo['dnow'], $this->userinfo['x'], $this->userinfo['y'], 'luck_itm' . $id, '0']); + + $this->error .= '
Вы отказались от участия в розыгрыше "' . $item['name'] . '"
'; } - unset($fxv); } - public function atack($id) + private function atack($id) { - global $u, $c, $code; $bot = mysql_fetch_assoc( mysql_query( 'SELECT * FROM `dungeon_bots` WHERE `id2` = "' . $id . '" AND `for_dn` = "0" AND `dn` = "' . $this->info['id'] . '" AND `delete` = "0" LIMIT 1' ) ); if (isset($bot['id2'])) { - if (($u->info['x'] != $bot['x'] || $bot['y'] != $u->info['y']) && $this->testLike( - $u->info['x'], $u->info['y'], $bot['x'], $bot['y'] - ) == 1) { + if (($this->userinfo['x'] != $bot['x'] || $bot['y'] != $this->userinfo['y']) && $this->cellIsGoodforAction( + $this->userinfo['x'], $this->userinfo['y'], $bot['x'], $bot['y'] + )) { //Создаем подеинок $tbtl = mysql_fetch_assoc( mysql_query( @@ -345,11 +265,10 @@ class Dungeon if (isset($tbtl['id'])) { //вступаем в поединок mysql_query( - 'UPDATE `users` SET `battle` = "' . $tbtl['id'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `users` SET `battle` = "' . $tbtl['id'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); - mysql_query('UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'); - /*#$this->error = 'Нападаем ... '; // */ - //header('location: main.php'); + mysql_query('UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'); + die(''); } else { $btl_id = 0; @@ -363,7 +282,7 @@ class Dungeon "' . $this->info['id'] . '", "' . $bot['x'] . '", "' . $bot['y'] . '", - "' . $u->info['city'] . '", + "' . $this->userinfo['city'] . '", "' . time() . '", "' . $btl['players'] . '", "' . $btl['timeout'] . '", @@ -390,7 +309,7 @@ class Dungeon 'UPDATE `dungeon_bots` SET `inBattle` = "' . $btl_id . '" WHERE `id2` = "' . $pl['id2'] . '" LIMIT 1' ); while ($jui <= $pl['colvo']) { - $k = $u->addNewbot($pl['id_bot'], null, null, $logins_bot); + $k = User::start()->addNewbot($pl['id_bot'], null, null, $logins_bot); $logins_bot = $k['logins_bot']; if ($k != false) { $upd = mysql_query( @@ -411,13 +330,11 @@ class Dungeon unset($logins_bot); if ($j > 0) { mysql_query( - 'UPDATE `users` SET `battle` = "' . $btl_id . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `users` SET `battle` = "' . $btl_id . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); mysql_query( - 'UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); - /*#$this->error = 'Нападаем ...';// */ // - //header('location: main.php'); die(''); } else { $this->error = 'Не удалось напасть, ошибка обьекта нападения ...'; @@ -438,16 +355,16 @@ class Dungeon ) . '" LIMIT 1' ) ); - if (($u->info['x'] != $bot['x'] || $bot['y'] != $u->info['y']) && $this->testLike( - $u->info['x'], $u->info['y'], $bot['x'], $bot['y'] - ) == 1) { + if (($this->userinfo['x'] != $bot['x'] || $bot['y'] != $this->userinfo['y']) && $this->cellIsGoodforAction( + $this->userinfo['x'], $this->userinfo['y'], $bot['x'], $bot['y'] + )) { //Создаем подеинок $tbtl = mysql_fetch_assoc( mysql_query( 'SELECT * FROM `battle` WHERE `dn_id` = "' . $this->info['id'] . '" AND `team_win` = "-1" AND `x` = "' . $bot['x'] . '" AND `y` = "' . $bot['y'] . '" LIMIT 1' ) ); - //die('Нападения временно запрещены. ['.$tbtl['id'].'] 5-10 мин.'); + if (isset($tbtl['id'])) { //вступаем в поединок $lstm = mysql_fetch_assoc( @@ -456,21 +373,21 @@ class Dungeon ) ); mysql_query( - 'UPDATE `users` SET `battle` = "' . $tbtl['id'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `users` SET `battle` = "' . $tbtl['id'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); $nextteam = $lstm['team'] + 1; mysql_query( - 'UPDATE `stats` SET `team` = "' . $nextteam . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `team` = "' . $nextteam . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); mysql_query( - 'UPDATE `stats` SET `x` = "' . $bot['x'] . '", `y` = "' . $bot['y'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `x` = "' . $bot['x'] . '", `y` = "' . $bot['y'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); - // + if ($this->info['bsid'] > 0) { $me_real = mysql_fetch_assoc( mysql_query( - 'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `inUser` = "' . $u->info['id'] . '" AND `login` = "' . $u->info['login'] . '" LIMIT 1' + 'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `inUser` = "' . $this->userinfo['id'] . '" AND `login` = "' . $this->userinfo['login'] . '" LIMIT 1' ) ); $usr_real = mysql_fetch_assoc( @@ -479,10 +396,10 @@ class Dungeon ) ); mysql_query( - 'UPDATE `stats` SET `tactic7`= 20.000 WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `tactic7`= 20.000 WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); //Заносим в лог БС - if ($u->info['sex'] == 0) { + if ($this->userinfo['sex'] == 0) { $text = '{u1} вмешался в поединок напав на {u2} »»'; } else { $text = '{u1} вмешалася в поединок напав на {u2} »»'; @@ -523,10 +440,8 @@ class Dungeon // } // - $this->error = 'Нападаем ... '; + $this->error = 'Нападаем ... '; } else { - $btl_id = 0; - //$expB = -77.77; if ($this->info['id2'] == 1) { $expB = 200; } @@ -536,14 +451,14 @@ class Dungeon $btl['inTurnir'] = $this->info['bsid']; } - $ins = mysql_query( + mysql_query( 'INSERT INTO `battle` (`inTurnir`,`dungeon`,`dn_id`,`x`,`y`,`city`,`time_start`,`players`,`timeout`,`type`,`invis`,`noinc`,`travmChance`,`typeBattle`,`addExp`,`money`) VALUES ( "' . $btl['inTurnir'] . '", "' . $this->info['id2'] . '", "' . $this->info['id'] . '", "' . $bot['x'] . '", "' . $bot['y'] . '", - "' . $u->info['city'] . '", + "' . $this->userinfo['city'] . '", "' . time() . '", "' . $btl['players'] . '", "' . $btl['timeout'] . '", @@ -557,7 +472,7 @@ class Dungeon ); $btl_id = mysql_insert_id(); mysql_query( - 'UPDATE `stats` SET `x` = "' . $bot['x'] . '", `y` = "' . $bot['y'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `x` = "' . $bot['x'] . '", `y` = "' . $bot['y'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); mysql_query( 'UPDATE `stats` SET `x` = "' . $bot['x'] . '", `y` = "' . $bot['y'] . '" WHERE `id` = "' . $bot['id'] . '" LIMIT 1' @@ -566,10 +481,10 @@ class Dungeon if ($btl_id > 0) { //Добавляем ботов mysql_query( - 'UPDATE `users` SET `battle` = "' . $btl_id . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `users` SET `battle` = "' . $btl_id . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); mysql_query( - 'UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); mysql_query( @@ -577,13 +492,13 @@ class Dungeon ); mysql_query('UPDATE `stats` SET `team` = "2" WHERE `id` = "' . $bot['id'] . '" LIMIT 1'); - if ($u->stats['hpNow'] < 1) { - $u->stats['hpNow'] = 1; + if ($this->userstats['hpNow'] < 1) { + $this->userstats['hpNow'] = 1; mysql_query( - 'UPDATE `stats` SET `hpNow` = "1" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `hpNow` = "1" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); mysql_query( - 'UPDATE `users` SET `lose` = `lose` + 1 WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `users` SET `lose` = `lose` + 1 WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); } @@ -601,7 +516,7 @@ class Dungeon $me_real = mysql_fetch_assoc( mysql_query( - 'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `inUser` = "' . $u->info['id'] . '" AND `login` = "' . $u->info['login'] . '" LIMIT 1' + 'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `inUser` = "' . $this->userinfo['id'] . '" AND `login` = "' . $this->userinfo['login'] . '" LIMIT 1' ) ); $usr_real = mysql_fetch_assoc( @@ -611,7 +526,7 @@ class Dungeon ); //Заносим в лог БС - if ($u->info['sex'] == 0) { + if ($this->userinfo['sex'] == 0) { $text = '{u1} напал на {u2} завязался бой »»'; } else { $text = '{u1} напала на {u2} завязался бой »»'; @@ -652,7 +567,7 @@ class Dungeon // } - $this->error = 'Нападаем ... '; + $this->error = 'Нападаем ... '; } else { $this->error = 'Не удалось создать поединок ...'; } @@ -666,53 +581,47 @@ class Dungeon } } - public function testLike($x1, $y1, $x2, $y2) + /** + * доступна-ли эта клетка для действий из $x1,$y1 в $x2,$y2 ? + * @param int $x1 + * @param int $y1 + * @param int $x2 + * @param int $y2 + * @return bool + */ + public function cellIsGoodforAction(int $x1, int $y1, int $x2, int $y2): bool { - //из $x1,$y1 в $x2,$y2 - //доступна-ли эта клетка для действий - $r = 0; - $c1 = mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_map` WHERE `x` = "' . $x1 . '" AND `y` = "' . $y1 . '" AND `id_dng` = "' . $this->info['id2'] . '" LIMIT 1' - ) - ); - $c2 = mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_map` WHERE `x` = "' . $x2 . '" AND `y` = "' . $y2 . '" AND `id_dng` = "' . $this->info['id2'] . '" LIMIT 1' - ) - ); - if (isset($c1['id']) && isset($c2['id'])) { - if ($x1 == $x2 && $y1 == $y2) { - $r = 1; - } elseif ($x1 == $x2 - 1 && $c1['go_1'] == 1) //право - { - $r = 1; - } elseif ($x1 == $x2 + 1 && $c1['go_2'] == 1) //лево - { - $r = 1; - } elseif ($y1 == $y2 - 1 && $c1['go_3'] == 1) //верх - { - $r = 1; - } elseif ($y1 == $y2 + 1 && $c1['go_4'] == 1) //низ - { - $r = 1; - } + $c1 = self::getDungeonMapCellRow($x1, $y1, $this->info['id2']); + $c2 = self::getDungeonMapCellRow($x2, $y2, $this->info['id2']); + if (empty($c1) || empty($c2)) { + return false; } - return $r; + + return + $x1 === $x2 && $y1 === $y2 || + $x1 === $x2 - 1 && $c1['go_1'] === 1 || //right + $x1 === $x2 + 1 && $c1['go_2'] === 1 || // left + $y1 === $y2 - 1 && $c1['go_3'] === 1 || // up + $y1 === $y2 + 1 && $c1['go_4'] === 1; // down + + } + + private static function getDungeonMapCellRow(int $x, int $y, int $dungeonId): array + { + return Db::getRow('select * from dungeon_map where id_dng = ? and x = ? and y = ? limit 1', [$dungeonId, $x, $y]) ?: []; } //Предметы для БС - public function takeinv($id) + private function takeinv($id) { - global $u, $c, $code; $obj = mysql_fetch_assoc( mysql_query( 'SELECT * FROM `dungeon_items` WHERE `id` = "' . $id . '" AND `for_dn` = "0" AND `dn` = "' . $this->info['id'] . '" LIMIT 1' ) ); if (isset($obj['id'])) { - $this->test_luck($id); + $this->testLuck($id); $fxv = ['luck_count' => mysql_fetch_assoc( mysql_query( 'SELECT COUNT(*) FROM `dungeon_actions` WHERE `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string( @@ -723,16 +632,16 @@ class Dungeon mysql_query('SELECT COUNT(*) FROM `stats` WHERE `dnow` = "' . $this->info['id'] . '" LIMIT 1') )]; if ($obj['user'] == 0 && $fxv['user_count'][0] > $fxv['luck_count'][0] && $fxv['user_count'][0] > 1 && $this->info['bsid'] == 0) { - $this->error = 'Вы не можете сейчас поднять этот предмет, дождитесь завершения розыгрыша. Осталось ' . $u->timeOut( + $this->error = 'Вы не можете сейчас поднять этот предмет, дождитесь завершения розыгрыша. Осталось ' . Conversion::secondsToTimeout( $obj['time'] - time() + 300 ); - } elseif ($u->info['x'] != $obj['x'] || $obj['y'] != $u->info['y']) { + } elseif ($this->userinfo['x'] != $obj['x'] || $obj['y'] != $this->userinfo['y']) { $this->error = 'Предмет не найден ...'; } else { if ($obj['take'] > 0) { $this->error = 'Кто-то опередил вас ...'; } else { - if ($obj['user'] > 0 && $obj['user'] != $u->info['id'] && $obj['time'] > time() - 300) { + if ($obj['user'] > 0 && $obj['user'] != $this->userinfo['id'] && $obj['time'] > time() - 300) { $uo = mysql_fetch_assoc( mysql_query( 'SELECT `id`,`login`,`sex` FROM `users` WHERE `id` = "' . $obj['user'] . '" LIMIT 1' @@ -752,7 +661,7 @@ class Dungeon unset($uo); } else { $upd = mysql_query( - 'UPDATE `dungeon_items` SET `take` = "' . $u->info['id'] . '" WHERE `id` = "' . $obj['id'] . '" LIMIT 1' + 'UPDATE `dungeon_items` SET `take` = "' . $this->userinfo['id'] . '" WHERE `id` = "' . $obj['id'] . '" LIMIT 1' ); if ($upd) { $it = mysql_fetch_assoc( @@ -761,14 +670,14 @@ class Dungeon if (isset($it['id'])) { $data = '|noremont=1|frompisher=' . $this->info['id2']; if ($it['ts'] != 0) { - $data .= '|sudba=' . $u->info['login']; + $data .= '|sudba=' . $this->userinfo['login']; } if ($obj['data'] != '') { $data .= $obj['data']; } - $data = str_replace('|sudba=-1', '|sudba=' . $u->info['login'] . '', $data); + $data = str_replace('|sudba=-1', '|sudba=' . $this->userinfo['login'] . '', $data); - $idl = ItemsModel::addItem($obj['item_id'], $u->info['id'], $data, $obj); + $idl = ItemsModel::addItem($obj['item_id'], $this->userinfo['id'], $data, $obj); if ($obj['del'] > 0) { mysql_query( 'UPDATE `items_users` SET `dn_delete` = 1 WHERE `id` = "' . $idl . '" LIMIT 1' @@ -777,7 +686,7 @@ class Dungeon unset($idl); if ($this->info['bsid'] == 0) { - $rtxt = '' . $u->info['login'] . ' поднял предмет "' . $it['name'] . '"'; + $rtxt = '' . $this->userinfo['login'] . ' поднял предмет "' . $it['name'] . '"'; if ($obj['quest'] > 0) { $rtxt .= ' (Квест)'; } @@ -796,17 +705,20 @@ class Dungeon } } - public function addItem($i) + /** + * добавляем предмет в пещеру (возможно выпал из бота или из сундука) + * @param array $i + * @return void + */ + private function addItem(array $i): void { - //добавляем предмет в пещеру (возможно выпал из бота или из сундука) - return mysql_query( - 'INSERT INTO `dungeon_items` (`dn`,`user`,`item_id`,`time`,`x`,`y`,`bot`,`del`) VALUES ("' . $this->info['id'] . '","' . $i['uid'] . '","' . $i['iid'] . '","' . $i['time'] . '","' . $i['x'] . '","' . $i['y'] . '","' . $i['bid'] . '","' . ((int)$i['del']) . '")' - ); + Db::sql('insert into dungeon_items (dn, user, item_id, time, x, y, bot, del) values (?,?,?,unix_timestamp(),?,?,0,?)', + [$this->info['id'], $i['uid'], $i['iid'], $i['x'], $i['y'], (int)$i['del']]); } - public function takeit($id) + private function takeit($id) { - global $u, $c, $code, $magic; + $u = User::start(); $obj = mysql_fetch_assoc( mysql_query( 'SELECT * FROM `dungeon_obj` WHERE `id` = "' . $id . '" AND `for_dn` = "0" AND `dn` = "' . $this->info['id'] . '" LIMIT 1' @@ -836,7 +748,7 @@ class Dungeon if (isset($tbot['id2'])) { $this->error = 'Не удалось, что-то или кто-то мешает ...'; - } elseif ($this->testLike($u->info['x'], $u->info['y'], $obj['x'], $obj['y']) != 1) { + } elseif (!$this->cellIsGoodforAction($this->userinfo['x'], $this->userinfo['y'], $obj['x'], $obj['y'])) { $this->error = 'Не удалось, слишком далеко ...!'; } else { $a = explode('|', $obj['action']); @@ -858,7 +770,7 @@ class Dungeon //[0] - x , [1] - y $bot_itm = mysql_fetch_assoc( mysql_query( - 'SELECT `u`.`id2`,`st`.`login` FROM `dungeon_bots` AS `u` LEFT JOIN `test_bot` AS `st` ON (`u`.`id_bot` = `st`.`id`) WHERE `u`.`dn` = "' . $u->info['dnow'] . '" AND `u`.`x` = "' . $itm[0] . '" AND `u`.`y` = "' . $itm[1] . '" AND `u`.`delete` = "0" LIMIT 10' + 'SELECT `u`.`id2`,`st`.`login` FROM `dungeon_bots` AS `u` LEFT JOIN `test_bot` AS `st` ON (`u`.`id_bot` = `st`.`id`) WHERE `u`.`dn` = "' . $this->userinfo['dnow'] . '" AND `u`.`x` = "' . $itm[0] . '" AND `u`.`y` = "' . $itm[1] . '" AND `u`.`delete` = "0" LIMIT 10' ) ); if (isset($bot_itm['id2'])) { @@ -888,20 +800,15 @@ class Dungeon //Проверяем кого нужно убить и убили-ли $j = 1; $jn = 0; - mysql_fetch_assoc( - mysql_query( - 'SELECT `x`,`y`,`id`,`hpNow` FROM `stats` WHERE `dnow` = "' . $this->info['id'] . '" AND ( (`x` = ' . ($obj['x'] + 1) . ' AND `y` = ' . ($obj['y']) . ') OR (`x` = ' . ($obj['x'] - 1) . ' AND `y` = ' . ($obj['y']) . ') OR (`x` = ' . ($obj['x']) . ' AND `y` = ' . ($obj['y'] + 1) . ') OR (`x` = ' . ($obj['x']) . ' AND `y` = ' . ($obj['y'] - 1) . ') ) LIMIT 1' - ) - ); while ($j < count($t)) { $itm = explode('.', $t[$j]); //[0] - x , [1] - y $bot_itm_sp = mysql_query( - 'SELECT `u`.*,`st`.* FROM `dungeon_bots` AS `u` LEFT JOIN `test_bot` AS `st` ON (`u`.`id_bot` = `st`.`id`) WHERE `u`.`dn` = "' . $u->info['dnow'] . '" AND `u`.`x` = "' . $itm[0] . '" AND `u`.`y` = "' . $itm[1] . '" AND `u`.`delete` = "0" LIMIT 50' + 'SELECT `u`.*,`st`.* FROM `dungeon_bots` AS `u` LEFT JOIN `test_bot` AS `st` ON (`u`.`id_bot` = `st`.`id`) WHERE `u`.`dn` = "' . $this->userinfo['dnow'] . '" AND `u`.`x` = "' . $itm[0] . '" AND `u`.`y` = "' . $itm[1] . '" AND `u`.`delete` = "0" LIMIT 50' ); while ($bot_itm = mysql_fetch_assoc($bot_itm_sp)) { $jn++; - $this->botAtack($bot_itm, $u->info, 1); + $this->botAtack($bot_itm, $this->userinfo, 1); } $j++; } @@ -931,8 +838,7 @@ class Dungeon mysql_query('SELECT `name` FROM `items_main` WHERE `id` = "' . $itm[0] . '" LIMIT 1') ); mysql_query( - 'UPDATE `items_users` SET `delete` = "' . time( - ) . '" WHERE `item_id` = "' . $itm[0] . '" AND `uid` = "' . $u->info['id'] . '" AND (`delete` = 0 OR `delete` = 100) AND `inShop` = 0 AND `inTransfer` = 0 AND `inOdet` = 0 LIMIT ' . $itm[1] + 'UPDATE `items_users` SET `delete` = "' . time() . '" WHERE `item_id` = "' . $itm[0] . '" AND `uid` = "' . $this->userinfo['id'] . '" AND (`delete` = 0 OR `delete` = 100) AND `inShop` = 0 AND `inTransfer` = 0 AND `inOdet` = 0 LIMIT ' . $itm[1] ); $r .= 'Предмет "' . $uitm['name'] . '" (x' . $itm[1] . ') был утрачен...
'; $j++; @@ -941,13 +847,12 @@ class Dungeon //требует предмет для действия $j = 0; $t = explode(',', $s[1]); - $j = 0; $tr_gd = 1; while ($j < count($t)) { $itm = explode('=', $t[$j]); $uitm = mysql_fetch_array( mysql_query( - 'SELECT COUNT(`id`) FROM `items_users` WHERE `item_id` = "' . $itm[0] . '" AND `uid` = "' . $u->info['id'] . '" AND (`delete` = 0 OR `delete` = 100) AND `inShop` = 0 AND `inTransfer` = 0 AND `inOdet` = 0 LIMIT ' . $itm[1] + 'SELECT COUNT(`id`) FROM `items_users` WHERE `item_id` = "' . $itm[0] . '" AND `uid` = "' . $this->userinfo['id'] . '" AND (`delete` = 0 OR `delete` = 100) AND `inShop` = 0 AND `inTransfer` = 0 AND `inOdet` = 0 LIMIT ' . $itm[1] ) ); $uitm = $uitm[0]; @@ -966,15 +871,12 @@ class Dungeon $tr_gd = 0; $r .= 'Странно, но ничего не произошло...
'; } - if ($tr_gd == 1) { - //все отлично - } else { + if ($tr_gd != 1) { $i = count($a); } } elseif ($s[0] == 'repl_ptp') { require_once('dnaction/_dungeon_replace.php'); die(); - //header('Location: ../../modules_data/location/_dungeon_replace.php'); } elseif ($s[0] == 'add_eff') { //Кастуем эффект $t = explode(',', $s[1]); @@ -982,7 +884,7 @@ class Dungeon while ($j < count($t)) { $itm = explode('=', $t[$j]); $ch = $u->testAction( - '`vars` = "add_eff_' . $this->info['id'] . '_' . $obj['id'] . '" AND `uid` = "' . $u->info['id'] . '" LIMIT ' . (1 + (int)$itm[2]) . '', + '`vars` = "add_eff_' . $this->info['id'] . '_' . $obj['id'] . '" AND `uid` = "' . $this->userinfo['id'] . '" LIMIT ' . (1 + (int)$itm[2]) . '', 2 ); //кол-во прошлых попыток $ch = $ch[0]; @@ -1001,7 +903,8 @@ class Dungeon ); if (isset($eff_d['id2'])) { //добавляем эффект - $us = $magic->addEffect($u->info['id'], $itm[0], 1); + + $us = (new Magic())->addEffect($this->userinfo['id'], $itm[0], 1); if ($us[0] == 1) { $r .= '
На Вас наложили заклятие "' . $eff_d['mname'] . '".
'; } else { @@ -1016,7 +919,7 @@ class Dungeon $r .= '
Не удалось...
'; } $u->addAction( - time(), 'add_eff_' . $this->info['id'] . '_' . $obj['id'], $u->info['city'] + time(), 'add_eff_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city'] ); } else { //уже нельзя юзать @@ -1049,21 +952,21 @@ class Dungeon } elseif ($itm[1] > 0) { $r .= '
Вы прикоснулись к магии... Здоровье: +' . $itm[1] . ' HP
'; } - $u->info['hpNow'] += $itm[1]; - if ($u->info['hpNow'] < 1) { + $this->userinfo['hpNow'] += $itm[1]; + if ($this->userinfo['hpNow'] < 1) { $r .= '
Вы перемещены в точку возрождения...
'; mysql_query( - 'UPDATE `stats` SET `hpNow` = "' . $u->info['hpNow'] . '",`x` = "' . $u->info['res_x'] . '",`y` = "' . $u->info['res_y'] . '",`s` = "' . $u->info['res_s'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `hpNow` = "' . $this->userinfo['hpNow'] . '",`x` = "' . $this->userinfo['res_x'] . '",`y` = "' . $this->userinfo['res_y'] . '",`s` = "' . $this->userinfo['res_s'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); } else { mysql_query( - 'UPDATE `stats` SET `hpNow` = "' . $u->info['hpNow'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `hpNow` = "' . $this->userinfo['hpNow'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); } } } $u->addAction( - time(), 'bafit_' . $this->info['id'] . '_' . $obj['id'], $u->info['city'] + time(), 'bafit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city'] ); } //записываем попытку @@ -1077,17 +980,17 @@ class Dungeon } #$r .= 'Позиция сохранена. Теперь после смерти вы оживете здесь.'; mysql_query( - 'UPDATE `stats` SET `res_x` = "' . $obj['x'] . '",`res_y` = "' . $obj['y'] . '",`res_s` = "' . $u->info['s'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `res_x` = "' . $obj['x'] . '",`res_y` = "' . $obj['y'] . '",`res_s` = "' . $this->userinfo['s'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); } elseif ($s[0] == 'look_text') { $itm = explode('=', $s[1]); $r .= $itm[rand(0, count($itm) - 1)]; } elseif ($s[0] == 'save_pos_xy') { $itm = explode('=', $s[1]); - $u->info['res_x'] = $itm[0]; - $u->info['res_y'] = $itm[1]; + $this->userinfo['res_x'] = $itm[0]; + $this->userinfo['res_y'] = $itm[1]; $upd = mysql_query( - 'UPDATE `stats` SET `res_x` = "' . $u->info['x'] . '",`res_y` = "' . $u->info['y'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `res_x` = "' . $this->userinfo['x'] . '",`res_y` = "' . $this->userinfo['y'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); if ($upd) { $r .= 'Вы куда-то переместились... на этот раз удачно...
'; @@ -1097,12 +1000,12 @@ class Dungeon } elseif ($s[0] == 'port') { //телепортирует пользователя $itm = explode('=', $s[1]); - $u->info['x'] = $itm[0]; - $u->info['y'] = $itm[1]; + $this->userinfo['x'] = $itm[0]; + $this->userinfo['y'] = $itm[1]; $upd = mysql_query( 'UPDATE `stats` SET - `x` = "' . $u->info['x'] . '",`y` = "' . $u->info['y'] . '" - WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + `x` = "' . $this->userinfo['x'] . '",`y` = "' . $this->userinfo['y'] . '" + WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); if ($upd) { $r .= 'Вы куда-то переместились... на этот раз удачно...
'; @@ -1111,10 +1014,10 @@ class Dungeon } } elseif ($s[0] == 'save_port') { $itm = explode('=', $s[1]); - $u->info['res_x'] = $itm[0]; - $u->info['res_y'] = $itm[1]; + $this->userinfo['res_x'] = $itm[0]; + $this->userinfo['res_y'] = $itm[1]; $upd = mysql_query( - 'UPDATE `stats` SET `res_x` = "' . $u->info['res_x'] . '", `res_y` = "' . $u->info['res_y'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `res_x` = "' . $this->userinfo['res_x'] . '", `res_y` = "' . $this->userinfo['res_y'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); } elseif ($s[0] == 'itm') { //Добавляем предмет @@ -1123,7 +1026,7 @@ class Dungeon while ($j < count($t)) { $itm = explode('=', $t[$j]); $ch = $u->testAction( - '`uid` = "' . $u->info['id'] . '" AND `vars` = "takeit_' . $this->info['id'] . '_' . $obj['id'] . '" LIMIT ' . (1 + (int)$itm[2]) . '', + '`uid` = "' . $this->userinfo['id'] . '" AND `vars` = "takeit_' . $this->info['id'] . '_' . $obj['id'] . '" LIMIT ' . (1 + (int)$itm[2]) . '', 2 ); //кол-во прошлых попыток $ch = $ch[0]; @@ -1147,7 +1050,7 @@ class Dungeon if (isset($it['id'])) { $r .= 'Вы обнаружили предмет "' . $it['name'] . '".
'; $this->addItem( - ['uid' => $u->info['id'], 'iid' => $it['id'], 'time' => time(), 'x' => $u->info['x'], 'y' => $u->info['y'], 'bid' => 0, 'del' => (int)$itm[4]] + ['uid' => $this->userinfo['id'], 'iid' => $it['id'], 'x' => $this->userinfo['x'], 'y' => $this->userinfo['y'], 'del' => (int)$itm[4]] ); } } else { @@ -1155,7 +1058,7 @@ class Dungeon $r .= 'Вы ничего не нашли ...
'; } $u->addAction( - time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $u->info['city'] + time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city'] ); } //записываем попытку @@ -1169,7 +1072,7 @@ class Dungeon if ($nj == 0) { $itm = explode('=', $t[$j]); $ch = $u->testAction( - '`uid` = "' . $u->info['id'] . '" AND `vars` = "takeit_' . $this->info['id'] . '_' . $obj['id'] . '" LIMIT ' . (1 + (int)$itm[2]) . '', + '`uid` = "' . $this->userinfo['id'] . '" AND `vars` = "takeit_' . $this->info['id'] . '_' . $obj['id'] . '" LIMIT ' . (1 + (int)$itm[2]) . '', 2 ); //кол-во прошлых попыток $ch = $ch[0]; @@ -1193,17 +1096,17 @@ class Dungeon if (isset($it['id'])) { $r .= 'Вы обнаружили предмет "' . $it['name'] . '".
'; $u->addAction( - time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $u->info['city'] + time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city'] ); $this->addItem( - ['uid' => $u->info['id'], 'iid' => $it['id'], 'time' => time(), 'x' => $u->info['x'], 'y' => $u->info['y'], 'bid' => 0, 'del' => (int)$itm[4]] + ['uid' => $this->userinfo['id'], 'iid' => $it['id'], 'x' => $this->userinfo['x'], 'y' => $this->userinfo['y'], 'del' => (int)$itm[4]] ); $nj++; } } else { //неудачная попытка $u->addAction( - time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $u->info['city'] + time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city'] ); $r .= 'Вы ничего не нашли ...
'; } @@ -1241,17 +1144,17 @@ class Dungeon if (isset($it['id'])) { $r .= 'Вы обнаружили предмет "' . $it['name'] . '".
'; $u->addAction( - time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $u->info['city'] + time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city'] ); $this->addItem( - ['uid' => $u->info['id'], 'iid' => $it['id'], 'time' => time(), 'x' => $u->info['x'], 'y' => $u->info['y'], 'bid' => 0, 'del' => (int)$itm[4]] + ['uid' => $this->userinfo['id'], 'iid' => $it['id'], 'x' => $this->userinfo['x'], 'y' => $this->userinfo['y'], 'del' => (int)$itm[4]] ); $nj++; } } else { //неудачная попытка $u->addAction( - time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $u->info['city'] + time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city'] ); $r .= 'Вы ничего не нашли ...
'; } @@ -1339,28 +1242,49 @@ class Dungeon } } - public function testGo($id) + /** + * @param int $a + * @param User $user + * @return void + */ + private function look(int $a, User $user): void { - global $u, $c, $code; - $go = 0; - if ($id == 1) { - //вперед - $go = $this->sg[$this->gs][1]; - } elseif ($id == 2) { - //назад - $go = $this->sg[$this->gs][3]; - } elseif ($id == 3) { - //на право - $go = $this->sg[$this->gs][4]; - } elseif ($id == 4) { - //на лево - $go = $this->sg[$this->gs][2]; + if (!in_array($a, [1, 2])) { + return; } - $thp = mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_map` WHERE `x` = "' . $u->info['x'] . '" AND `y` = "' . $u->info['y'] . '" AND `id_dng` = "' . $this->info['id2'] . '" LIMIT 1' - ) - ); + match ($a) { + 1 => match ($this->gs) { + 1 => $this->gs = 2, + 2 => $this->gs = 3, + 3 => $this->gs = 4, + 4 => $this->gs = 1, + }, + 2 => match ($this->gs) { + 1 => $this->gs = 4, + 2 => $this->gs = 1, + 3 => $this->gs = 2, + 4 => $this->gs = 3, + }, + }; + + Db::sql('update stats set s = ? where id = ?', [$this->gs, $user->info['id']]); + $user->info['s'] = $this->gs; + } + + + //Розыгрыш предмета + + private function testGo($id) + { + match ($id) { + 1 => $go = $this->sg[$this->gs][1], // up + 2 => $go = $this->sg[$this->gs][3], // down + 3 => $go = $this->sg[$this->gs][4], // right + 4 => $go = $this->sg[$this->gs][2], // left + }; + + $thp = self::getDungeonMapCellRow($this->userinfo['x'], $this->userinfo['y'], $this->info['id2']); + $ng = [4 => 1, 2 => 2, 1 => 3, 3 => 4]; if (isset($thp['id']) && $thp['go_' . $ng[$go]] == 0) { $go = 0; @@ -1376,20 +1300,14 @@ class Dungeon $tgo[0] += 1; } - $tbot = mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_bots` WHERE `x` = "' . ($u->info['x'] + (int)$tgo[0]) . '" AND `y` = "' . ($u->info['y'] + (int)$tgo[1]) . '" AND `dn` = "' . $this->info['id'] . '" AND `for_dn` = "0" AND `delete` = "0" LIMIT 1' - ) - ); - if (isset($tbot['id2']) && $u->info['admin'] == 0) { + $tbot = $this->getBot($this->userinfo['x'] + (int)$tgo[0], $this->userinfo['y'] + (int)$tgo[1], $this->info['id']); + + if (isset($tbot['id2']) && $this->userinfo['admin'] == 0) { $go = 0; } - $tmap = mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_map` WHERE `x` = "' . $u->info['x'] . '" AND `y` = "' . $u->info['y'] . '" AND `id_dng` = "' . $this->info['id2'] . '" LIMIT 1' - ) - ); + $tmap = self::getDungeonMapCellRow($this->userinfo['x'], $this->userinfo['y'], $this->info['id2']); + //наличие предмета if ($tmap['tr_items'] != '') { $ti = explode(',', $tmap['tr_items']); @@ -1398,20 +1316,11 @@ class Dungeon while ($i < count($ti)) { $ti2 = explode('=', $ti[$i]); if ($ti2[0] > 0 && $ti2[1] > 0) { - $num_rows = mysql_num_rows( - mysql_query( - 'SELECT * FROM `items_users` WHERE `uid` = "' . $u->info['id'] . '" AND `delete` = "0" AND `inShop` = "0" AND `item_id` = "' . ((int)$ti2[0]) . '" LIMIT ' . ((int)$ti2[1]) . '' - ) - ); - if ($num_rows < (int)$ti2[1]) { - $tgo = $ti2[2]; - if ($tgo != '0000' && $tgo[$ng[$go] - 1] == 1) { - $go = 0; - $trm = mysql_fetch_assoc( - mysql_query('SELECT * FROM `items_main` WHERE `id` = "' . ((int)$ti2[0]) . '" LIMIT 1') - ); - $trnit .= '"' . $trm['name'] . '", '; - } + $num_rows = Db::getValue('select count(*) from items_users where uid = ? and inShop = 0 and item_id = ? limit ?', [$this->userinfo['id'], (int)$ti2[0], (int)$ti2[1]]); + if ($num_rows < (int)$ti2[1] && $ti2[2] != '0000' && $ti2[2][$ng[$go] - 1] == 1) { + $go = 0; + $trm = Db::getValue('select name from items_main where id = ?', [(int)$ti2[0]]); + $trnit .= '"' . $trm . '", '; } } $i++; @@ -1422,63 +1331,55 @@ class Dungeon } } - $tmGo = $u->info['timeGo'] - time(); //сколько секунд осталось + $tmGo = $this->userinfo['timeGo'] - time(); //сколько секунд осталось if ($tmGo > 0) { $go = 0; $this->error = 'Не так быстро...'; } - if ($u->aves['now'] >= $u->aves['max']) { + if (User::start()->aves['now'] >= User::start()->aves['max']) { $go = 0; $this->error = 'Вы не можете перемещаться, рюкзак переполнен ...'; } if ($go > 0) { - if ($go == 1) { - $u->info['y'] += 1; - } elseif ($go == 2) { - $u->info['x'] -= 1; - } elseif ($go == 3) { - $u->info['y'] -= 1; - } elseif ($go == 4) { - $u->info['x'] += 1; - } - if ($u->stats['speed_dungeon'] > 0) { - $tmap['timeGO'] = round($tmap['timeGO'] / 100 * (100 - $u->stats['speed_dungeon'])); + match ($go) { + 1 => $this->userinfo['y'] += 1, + 2 => $this->userinfo['x'] -= 1, + 3 => $this->userinfo['y'] -= 1, + 4 => $this->userinfo['x'] += 1, + }; + + if ($this->userstats['speed_dungeon'] > 0) { + $tmap['timeGO'] = round($tmap['timeGO'] / 100 * (100 - $this->userstats['speed_dungeon'])); if ($tmap['timeGO'] < 2) { $tmap['timeGO'] = 1; } } - $u->info['timeGo'] = time() + $tmap['timeGO']; - $u->info['timeGoL'] = time(); - $tmap0 = mysql_fetch_assoc( - mysql_query( - 'SELECT `id`,`teleport` FROM `dungeon_map` WHERE `id_dng` = "' . $tmap['id_dng'] . '" AND `x` = "' . $u->info['x'] . '" AND `y` = "' . $u->info['y'] . '" LIMIT 1' - ) - ); - if ($tmap0['teleport'] > 0) { - $tmap1 = mysql_fetch_assoc( - mysql_query( - 'SELECT `id`,`x`,`y` FROM `dungeon_map` WHERE `id` = "' . $tmap0['teleport'] . '" LIMIT 1' - ) - ); - if (isset($tmap1['id'])) { - $u->info['x'] = $tmap1['x']; - $u->info['y'] = $tmap1['y']; - $this->error = 'Вы переместились в другую комнату...'; - } + $this->userinfo['timeGo'] = time() + $tmap['timeGO']; + $this->userinfo['timeGoL'] = time(); + + + $tmaps = Db::getRow('select id, x, y from dungeon_map where id = (select teleport from dungeon_map where id_dng = ? and x = ? and y = ?)', + [$tmap['id_dng'], $this->userinfo['x'], $this->userinfo['y']]); + + if (isset($tmaps['id'])) { + $this->userinfo['x'] = $tmaps['x']; + $this->userinfo['y'] = $tmaps['y']; + $this->error = 'Вы переместились в другую комнату...'; } - mysql_query( - 'UPDATE `stats` SET `x` = "' . $u->info['x'] . '",`y` = "' . $u->info['y'] . '",`timeGo` = "' . $u->info['timeGo'] . '",`timeGoL` = "' . $u->info['timeGoL'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' - ); - unset($id); + + Db::sql('update stats set x = ?, y = ?, timeGo = ?, timeGoL = ? where id = ?', + [$this->userinfo['x'], $this->userinfo['y'], $this->userinfo['timeGo'], $this->userinfo['timeGoL'], $this->userinfo['id']]); } } + private function getBot(int $x, int $y, int $dn) + { + return Db::getRow('select * from dungeon_bots where x = ? and y = ? and dn = ? and for_dn = 0', [$x, $y, $dn]); + } - //Розыгрыш предмета - - public function genMatix(): array + private function genMatix(): array { $r = []; if ($this->gs == 1) { @@ -1570,15 +1471,14 @@ class Dungeon return $r; } - public function getMatrix($y, $x) + private function getMatrix($y, $x) { - global $u; $this->cord['x']++; - $this->cord[($u->info['y'] + $y) . '_' . ($u->info['x'] + $x)] = $this->cord['x']; - return $this->map[0][($u->info['y'] + $y) . '_' . ($u->info['x'] + $x)] ?? []; + $this->cord[($this->userinfo['y'] + $y) . '_' . ($this->userinfo['x'] + $x)] = $this->cord['x']; + return $this->map[0][($this->userinfo['y'] + $y) . '_' . ($this->userinfo['x'] + $x)] ?? []; } - private function lookDungeon() + private function lookDungeon(): array { $pd = array_fill(1, 28, 0); @@ -1670,6 +1570,7 @@ class Dungeon /* Генерируем персонажей и ботов на карте */ + return $pd; } /** Видим ли мы стену? @@ -1688,14 +1589,8 @@ class Dungeon return $r > 0; } - public function initPoint(int $x, int $y): void - { - $this->point = Db::getRow('select * from dungeon_map where id_dng = ? and x = ? and y = ? limit 1', [$this->info['id2'], $x, $y]); - } - public function pickitem($obj, int $itm, $for, $data = '', $dn_delete = false, $chat = 0): bool { - global $u; $itm = mysql_fetch_assoc( mysql_query('SELECT `id`,`name` FROM `items_main` WHERE `id` = "' . $itm . '" LIMIT 1') ); @@ -1705,15 +1600,15 @@ class Dungeon $tou = 0; //какому юзеру предназначено /* выделяем случайного юзера из команды */ $asex = ''; - if ($u->info['sex'] == 1) { + if ($this->userinfo['sex'] == 1) { $asex = 'а'; } if ($for > 0) { $tou = $for; - $rtxt = '' . $u->info['login'] . ' обнаружил' . $asex . ' предмет "' . $itm['name'] . '" в "' . $obj['name'] . '"'; + $rtxt = '' . $this->userinfo['login'] . ' обнаружил' . $asex . ' предмет "' . $itm['name'] . '" в "' . $obj['name'] . '"'; } else { - $rtxt = '' . $u->info['login'] . ' обнаружил' . $asex . ' предмет "' . $itm['name'] . '" в "' . $obj['name'] . '", и вы решили разыграть его'; + $rtxt = '' . $this->userinfo['login'] . ' обнаружил' . $asex . ' предмет "' . $itm['name'] . '" в "' . $obj['name'] . '", и вы решили разыграть его'; } $dn_delete = $dn_delete ? 1 : 0; @@ -1724,12 +1619,12 @@ class Dungeon 'INSERT INTO `dungeon_items` (`dn_delete`,`data`,`dn`,`user`,`item_id`,`time`,`x`,`y`) VALUES ( "' . $dn_delete . '", "' . mysql_real_escape_string($data) . '", - "' . $u->info['dnow'] . '", + "' . $this->userinfo['dnow'] . '", "' . $tou . '", "' . $itm['id'] . '", "' . time() . '", - "' . $u->info['x'] . '", - "' . $u->info['y'] . '")' + "' . $this->userinfo['x'] . '", + "' . $this->userinfo['y'] . '")' ); return true; @@ -1737,8 +1632,6 @@ class Dungeon public function n_lead(string $who, int $lead): void { - global $u; - $to = Db::getRow('select stats.id, dnow from users left join stats on users.id = stats.id where login = ?', [$who]); if ($this->info['uid'] != $lead) { @@ -1753,13 +1646,13 @@ class Dungeon mysql_query( 'UPDATE `dungeon_now` SET `uid` = "' . $to['id'] . '" WHERE `id` = "' . $this->info['id'] . '" LIMIT 1' ); - if ($u->info['sex'] == 0) { + if ($this->userinfo['sex'] == 0) { $this->sys_chat( - '' . $u->info['login'] . ' передал лидерство в группе персонажу ' . $who . '' + '' . $this->userinfo['login'] . ' передал лидерство в группе персонажу ' . $who . '' ); } else { $this->sys_chat( - '' . $u->info['login'] . ' передала лидерство в группе персонажу ' . $who . '' + '' . $this->userinfo['login'] . ' передала лидерство в группе персонажу ' . $who . '' ); } @@ -1769,8 +1662,6 @@ class Dungeon public function go_to_hell(string $who, int $lead): void { - global $u; - $to = Db::getRow('select stats.id, dnow from users left join stats on users.id = stats.id where login = ?', [$who]); if ($this->info['uid'] != $lead) { @@ -1783,9 +1674,9 @@ class Dungeon $this->error = 'Персонаж не найден в вашей команде...'; } else { $rb = 321; // Магический портал - if ($u->info['room'] == 304) { + if ($this->userinfo['room'] == 304) { $rb = 209; // Вход в ледяную пещеру - } elseif ($u->info['room'] == 396) { + } elseif ($this->userinfo['room'] == 396) { $rb = 395; // Канализация (Ангелс) } elseif ($this->info['id2'] == 3) { $rb = 293; // Вход в Катакомбы @@ -1818,26 +1709,26 @@ class Dungeon $city = mysql_fetch_assoc( mysql_query('SELECT `id`, `city` FROM `room` WHERE `id` = "' . $rb . '" LIMIT 1') ); - mysql_query('UPDATE `stats` SET `dnow` = "0" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'); + mysql_query('UPDATE `stats` SET `dnow` = "0" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'); mysql_query( - 'UPDATE `users` SET `room` = "' . $rb . '", `city`="' . $city['city'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `users` SET `room` = "' . $rb . '", `city`="' . $city['city'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); //удаляем все предметы которые пропадают после выхода из пещеры mysql_query( - 'UPDATE `items_users` SET `delete` = "' . time() . '" WHERE `uid` = "' . $u->info['id'] . '" AND `dn_delete` = "1" LIMIT 1000' + 'UPDATE `items_users` SET `delete` = "' . time() . '" WHERE `uid` = "' . $this->userinfo['id'] . '" AND `dn_delete` = "1" LIMIT 1000' ); mysql_query( - 'UPDATE `items_users` SET `delete` = "' . time() . '" WHERE `uid` = "' . $u->info['id'] . '" AND (`item_id` = "1189" OR `item_id` = "4447" OR `item_id` = "1174") LIMIT 1000' + 'UPDATE `items_users` SET `delete` = "' . time() . '" WHERE `uid` = "' . $this->userinfo['id'] . '" AND (`item_id` = "1189" OR `item_id` = "4447" OR `item_id` = "1174") LIMIT 1000' ); - if ($u->info['sex'] == 0) { + if ($this->userinfo['sex'] == 0) { $this->sys_chat( - '' . $u->info['login'] . ' выгнал из похода персонажа ' . $who . '' + '' . $this->userinfo['login'] . ' выгнал из похода персонажа ' . $who . '' ); } else { $this->sys_chat( - '' . $u->info['login'] . ' выгнала из похода персонажа ' . $who . '' + '' . $this->userinfo['login'] . ' выгнала из похода персонажа ' . $who . '' ); } @@ -1845,12 +1736,10 @@ class Dungeon } } - public function usersDng($laba = false) + public function usersDng($laba = false): string { - global $u, $c; $r = ''; - $stt = []; - if ($laba == false) { + if (!$laba) { $sp = mysql_query( 'SELECT `u`.`id`,`st`.`id` FROM `stats` AS `u` LEFT JOIN `users` AS `st` ON (`st`.`id` = `u`.`id`) WHERE `u`.`dnow` = "' . $this->info['id'] . '" LIMIT 10' ); @@ -1860,13 +1749,13 @@ class Dungeon ); } while ($pl = mysql_fetch_assoc($sp)) { - $stt = $u->getStats($pl['id'], 0); + $stt = (new Stats(User::start()))->getStats($pl['id']); if ($stt['mpAll'] > 0) { $pm = $stt['mpNow'] / $stt['mpAll'] * 100; } $ph = $stt['hpNow'] / $stt['hpAll'] * 100; $r .= ' - +
  ' . $u->microLogin($pl['id'], 1) . '  
  ' . User::start()->microLogin($pl['id'], 1) . '   info['uid'] == $pl['id']) { $r .= ''; } - if ($this->info['uid'] == $u->info['id'] && $pl['id'] == $u->info['id'] && $this->info['id2'] != 15) { + if ($this->info['uid'] == $this->userinfo['id'] && $pl['id'] == $this->userinfo['id'] && $this->info['id2'] != 15) { $r .= ' '; $r .= ' '; } $r .= '

'; $r .= ''; } - unset($stt, $ph, $pm); + return $r; } public function testDie() { - global $u, $c, $code; $dies = mysql_fetch_assoc( mysql_query( - 'SELECT COUNT(`id`) FROM `dungeon_actions` WHERE `uid` = "' . $u->info['id'] . '" AND `dn` = "' . $u->info['dnow'] . '" AND `vars` = "die" LIMIT 1' + 'SELECT COUNT(`id`) FROM `dungeon_actions` WHERE `uid` = "' . $this->userinfo['id'] . '" AND `dn` = "' . $this->userinfo['dnow'] . '" AND `vars` = "die" LIMIT 1' ) ); $dies = $dies[0]; - if ($u->stats['hpNow'] < 1 || $dies > 2) { + if ($this->userstats['hpNow'] < 1 || $dies > 2) { + mysql_query( + 'INSERT INTO `dungeon_actions` (`dn`,`uid`,`x`,`y`,`time`,`vars`,`vals`) VALUES ( + "' . $this->userinfo['dnow'] . '","' . $this->userinfo['id'] . '","' . $this->userinfo['x'] . '","' . $this->userinfo['y'] . '","' . time() . '","die","" + )' + ); if ($dies < 2) { - mysql_query( - 'INSERT INTO `dungeon_actions` (`dn`,`uid`,`x`,`y`,`time`,`vars`,`vals`) VALUES ( - "' . $u->info['dnow'] . '","' . $u->info['id'] . '","' . $u->info['x'] . '","' . $u->info['y'] . '","' . time() . '","die","" - )' - ); //21:50 Ярополк трагически погиб и находится в комнате "Этаж 2 - Водосток" $dnow = mysql_fetch_assoc( - mysql_query('SELECT id2 FROM `dungeon_now` WHERE `id` = "' . $u->info['dnow'] . '" LIMIT 1') + mysql_query('SELECT id2 FROM `dungeon_now` WHERE `id` = "' . $this->userinfo['dnow'] . '" LIMIT 1') ); $room = mysql_fetch_assoc( mysql_query( - 'SELECT name FROM `dungeon_map_info` WHERE `x` = "' . $u->info['res_x'] . '" AND `y` = "' . $u->info['res_y'] . '" AND `id_dng` = "' . $dnow['id2'] . '" LIMIT 1' + 'SELECT name FROM `dungeon_map_info` WHERE `x` = "' . $this->userinfo['res_x'] . '" AND `y` = "' . $this->userinfo['res_y'] . '" AND `id_dng` = "' . $dnow['id2'] . '" LIMIT 1' ) ); - if ($u->info['sex'] == 0) { + if ($this->userinfo['sex'] == 0) { $this->sys_chat( - '' . $u->info['login'] . ' трагически погиб и находится в комнате "' . $room['name'] . '"' + '' . $this->userinfo['login'] . ' трагически погиб и находится в комнате "' . $room['name'] . '"' ); } else { $this->sys_chat( - '' . $u->info['login'] . ' трагически погибла и находится в комнате "' . $room['name'] . '"' + '' . $this->userinfo['login'] . ' трагически погибла и находится в комнате "' . $room['name'] . '"' ); } mysql_query( - 'UPDATE `stats` SET `hpNow` = "1",`x` = "' . $u->info['res_x'] . '",`y` = "' . $u->info['res_y'] . '",`s` = "' . $u->info['res_s'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1' + 'UPDATE `stats` SET `hpNow` = "1",`x` = "' . $this->userinfo['res_x'] . '",`y` = "' . $this->userinfo['res_y'] . '",`s` = "' . $this->userinfo['res_s'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1' ); //header('location: main.php'); die(''); } else { - mysql_query( - 'INSERT INTO `dungeon_actions` (`dn`,`uid`,`x`,`y`,`time`,`vars`,`vals`) VALUES ( - "' . $u->info['dnow'] . '","' . $u->info['id'] . '","' . $u->info['x'] . '","' . $u->info['y'] . '","' . time() . '","die","" - )' - ); //21:50 Ярополк трагически погиб и находится в комнате "Этаж 2 - Водосток" - if ($u->info['sex'] == 0) { - $this->sys_chat('' . $u->info['login'] . ' трагически погиб без права на воскрешение'); + if ($this->userinfo['sex'] == 0) { + $this->sys_chat('' . $this->userinfo['login'] . ' трагически погиб без права на воскрешение'); } else { - $this->sys_chat('' . $u->info['login'] . ' трагически погибла без права на воскрешение'); + $this->sys_chat('' . $this->userinfo['login'] . ' трагически погибла без права на воскрешение'); } $_GET['exitd'] = true; } } } - public function itemsMap() + public function itemsMap(): string { - global $u, $c, $code; $r = ''; $liveUsers = Db::getValue('select count(*) from stats where dnow = ?', [$this->info['id']]); $sp = mysql_query( - 'SELECT `im`.*,`ish`.* FROM `dungeon_items` AS `ish` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `ish`.`item_id`) WHERE `ish`.`dn` = "' . $this->info['id'] . '" AND `ish`.`take` = "0" AND `ish`.`delete` = "0" AND ( `ish`.`onlyfor` = "0" OR `ish`.`onlyfor` = "' . $u->info['id'] . '" ) AND `ish`.`x` = "' . $u->info['x'] . '" AND `ish`.`y` = "' . $u->info['y'] . '" LIMIT 100' + 'SELECT `im`.*,`ish`.* FROM `dungeon_items` AS `ish` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `ish`.`item_id`) WHERE `ish`.`dn` = "' . $this->info['id'] . '" AND `ish`.`take` = "0" AND `ish`.`delete` = "0" AND ( `ish`.`onlyfor` = "0" OR `ish`.`onlyfor` = "' . $this->userinfo['id'] . '" ) AND `ish`.`x` = "' . $this->userinfo['x'] . '" AND `ish`.`y` = "' . $this->userinfo['y'] . '" LIMIT 100' ); while ($pl = mysql_fetch_assoc($sp)) { $action = 'main.php?take=' . $pl['id'] . ''; $tk = 0; $luck_users = mysql_fetch_assoc( mysql_query( - 'SELECT COUNT(`id`) FROM `dungeon_actions` WHERE `uid` = "' . $u->info['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string( + 'SELECT COUNT(`id`) FROM `dungeon_actions` WHERE `uid` = "' . $this->userinfo['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string( $pl['id'] ) . '" LIMIT 1' ) @@ -1987,7 +1869,7 @@ class Dungeon if ($pl['user'] == 0 && $liveUsers > 1 && ($pl['time'] + 300 > time() || $luck_users < 1)) { $fxv = mysql_fetch_assoc( mysql_query( - 'SELECT * FROM `dungeon_actions` WHERE `uid` = "' . $u->info['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . $pl['id'] . '" LIMIT 1' + 'SELECT * FROM `dungeon_actions` WHERE `uid` = "' . $this->userinfo['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . $pl['id'] . '" LIMIT 1' ) ); //Розыгрыш @@ -2008,20 +1890,19 @@ class Dungeon return $r; } - public function genObjects() + public function genObjects(): string { - global $u; ////i:{id,name,mapPoint,action,img,type}, //'count':1,0:{0:1234,1:'Сундук',2:5,3:'',4:'test.gif',5:0,6:position,7:width,8:heigh,9:left,10:top}, //psition 0 - по центру , 1- сверху, 2- слева, 3- снизу, 4- справа $r = ''; - $whr = [1 => ' (((`u`.`x` <= ' . ($u->info['x'] + 2) . ' && `u`.`x` >= ' . ($u->info['x'] - 2) . ') && (`u`.`y` >= ' . ($u->info['y'] + 1) . ' && `u`.`y` <= ' . ($u->info['y'] + 4) . ')) OR (`u`.`y` = ' . $u->info['y'] . ' && `u`.`x` = ' . $u->info['x'] . ')) ', //прямо - 3 => ' (((`u`.`x` <= ' . ($u->info['x'] + 2) . ' && `u`.`x` >= ' . ($u->info['x'] - 2) . ') && (`u`.`y` <= ' . ($u->info['y'] - 1) . ' && `u`.`y` >= ' . ($u->info['y'] - 4) . ')) OR (`u`.`y` = ' . $u->info['y'] . ' && `u`.`x` = ' . $u->info['x'] . ')) ', //вниз - 2 => ' (((`u`.`x` <= ' . ($u->info['x'] - 1) . ' && `u`.`x` >= ' . ($u->info['x'] - 4) . ') && (`u`.`y` <= ' . ($u->info['y'] + 2) . ' && `u`.`y` >= ' . ($u->info['y'] - 2) . '))OR (`u`.`y` = ' . $u->info['y'] . ' && `u`.`x` = ' . $u->info['x'] . ')) ', //лево - 4 => ' (((`u`.`x` >= ' . ($u->info['x'] + 1) . ' && `u`.`x` <= ' . ($u->info['x'] + 4) . ') && (`u`.`y` <= ' . ($u->info['y'] + 2) . ' && `u`.`y` >= ' . ($u->info['y'] - 2) . ')) OR (`u`.`y` = ' . $u->info['y'] . ' && `u`.`x` = ' . $u->info['x'] . ')) ', //право + $whr = [1 => ' (((`u`.`x` <= ' . ($this->userinfo['x'] + 2) . ' && `u`.`x` >= ' . ($this->userinfo['x'] - 2) . ') && (`u`.`y` >= ' . ($this->userinfo['y'] + 1) . ' && `u`.`y` <= ' . ($this->userinfo['y'] + 4) . ')) OR (`u`.`y` = ' . $this->userinfo['y'] . ' && `u`.`x` = ' . $this->userinfo['x'] . ')) ', //прямо + 3 => ' (((`u`.`x` <= ' . ($this->userinfo['x'] + 2) . ' && `u`.`x` >= ' . ($this->userinfo['x'] - 2) . ') && (`u`.`y` <= ' . ($this->userinfo['y'] - 1) . ' && `u`.`y` >= ' . ($this->userinfo['y'] - 4) . ')) OR (`u`.`y` = ' . $this->userinfo['y'] . ' && `u`.`x` = ' . $this->userinfo['x'] . ')) ', //вниз + 2 => ' (((`u`.`x` <= ' . ($this->userinfo['x'] - 1) . ' && `u`.`x` >= ' . ($this->userinfo['x'] - 4) . ') && (`u`.`y` <= ' . ($this->userinfo['y'] + 2) . ' && `u`.`y` >= ' . ($this->userinfo['y'] - 2) . '))OR (`u`.`y` = ' . $this->userinfo['y'] . ' && `u`.`x` = ' . $this->userinfo['x'] . ')) ', //лево + 4 => ' (((`u`.`x` >= ' . ($this->userinfo['x'] + 1) . ' && `u`.`x` <= ' . ($this->userinfo['x'] + 4) . ') && (`u`.`y` <= ' . ($this->userinfo['y'] + 2) . ' && `u`.`y` >= ' . ($this->userinfo['y'] - 2) . ')) OR (`u`.`y` = ' . $this->userinfo['y'] . ' && `u`.`x` = ' . $this->userinfo['x'] . ')) ', //право ]; $sp = mysql_query( - 'SELECT `u`.* FROM `dungeon_obj` AS `u` WHERE `u`.`dn` = "' . $u->info['dnow'] . '" AND `u`.`for_dn` = "0" AND ((`u`.`s` = "0" OR `u`.`s` = "' . $this->gs . '") OR `u`.`s2` = "' . $this->gs . '") AND ' . $whr[$this->gs] . ' LIMIT 150' + 'SELECT `u`.* FROM `dungeon_obj` AS `u` WHERE `u`.`dn` = "' . $this->userinfo['dnow'] . '" AND `u`.`for_dn` = "0" AND ((`u`.`s` = "0" OR `u`.`s` = "' . $this->gs . '") OR `u`.`s2` = "' . $this->gs . '") AND ' . $whr[$this->gs] . ' LIMIT 150' ); $i = 0; $pos = []; @@ -2032,9 +1913,9 @@ class Dungeon if ( $pl['fix_x_y'] != 0 && - ($pl['fix_x_y'] != 1 || $pl['x'] != $u->info['x']) && - ($pl['fix_x_y'] != 2 || $pl['y'] != $u->info['y']) && - ($pl['fix_x_y'] != 3 || $pl['x'] != $u->info['x'] || $pl['y'] != $u->info['y']) + ($pl['fix_x_y'] != 1 || $pl['x'] != $this->userinfo['x']) && + ($pl['fix_x_y'] != 2 || $pl['y'] != $this->userinfo['y']) && + ($pl['fix_x_y'] != 3 || $pl['x'] != $this->userinfo['x'] || $pl['y'] != $this->userinfo['y']) ) { continue; } @@ -2128,33 +2009,32 @@ class Dungeon return 'count:' . $i . $r; } - public function genUsers() + public function genUsers(): string { - global $u; ////i:{id,login,mapPoint,sex,obraz,type,users_p}, //'count':1,0:{0:1015,1:'Test1',2:5,3:0,4:'1',5:'user',6:1}, $r = ''; $whr = [ - 1 => ' ((x <= ' . ($u->info['x'] + 2) . ' && x >= ' . ($u->info['x'] - 2) . ') && (y >= ' . $u->info['y'] . ' && y <= ' . ($u->info['y'] + 4) . ')) ', //прямо - 2 => ' ((x <= ' . $u->info['x'] . ' && x >= ' . ($u->info['x'] - 4) . ') && (y <= ' . ($u->info['y'] + 2) . ' && y >= ' . ($u->info['y'] - 2) . ')) ', //лево - 3 => ' ((x <= ' . ($u->info['x'] + 2) . ' && x >= ' . ($u->info['x'] - 2) . ') && (y <= ' . $u->info['y'] . ' && y >= ' . ($u->info['y'] - 4) . ')) ', //вниз - 4 => ' ((x >= ' . $u->info['x'] . ' && x <= ' . ($u->info['x'] + 4) . ') && (y <= ' . ($u->info['y'] + 2) . ' && y >= ' . ($u->info['y'] - 2) . ')) ', //право + 1 => ' ((x <= ' . ($this->userinfo['x'] + 2) . ' && x >= ' . ($this->userinfo['x'] - 2) . ') && (y >= ' . $this->userinfo['y'] . ' && y <= ' . ($this->userinfo['y'] + 4) . ')) ', //прямо + 2 => ' ((x <= ' . $this->userinfo['x'] . ' && x >= ' . ($this->userinfo['x'] - 4) . ') && (y <= ' . ($this->userinfo['y'] + 2) . ' && y >= ' . ($this->userinfo['y'] - 2) . ')) ', //лево + 3 => ' ((x <= ' . ($this->userinfo['x'] + 2) . ' && x >= ' . ($this->userinfo['x'] - 2) . ') && (y <= ' . $this->userinfo['y'] . ' && y >= ' . ($this->userinfo['y'] - 4) . ')) ', //вниз + 4 => ' ((x >= ' . $this->userinfo['x'] . ' && x <= ' . ($this->userinfo['x'] + 4) . ') && (y <= ' . ($this->userinfo['y'] + 2) . ' && y >= ' . ($this->userinfo['y'] - 2) . ')) ', //право ]; $whrVals = [ // x <= ? && x >= ? && y <= ? && y >= ? - 1 => [$u->info['x'] + 2, $u->info['x'] - 2, $u->info['y'] + 4, $u->info['y'],], // прямо x< x> y< y> - 2 => [$u->info['x'], $u->info['x'] - 4, $u->info['y'] + 2, $u->info['y'] - 2,], // лево x< x> y< y> - 3 => [$u->info['x'] + 2, $u->info['x'] - 2, $u->info['y'], $u->info['y'] - 4,], // низ x< x> y< y> - 4 => [$u->info['x'] + 4, $u->info['x'], $u->info['y'] + 2, $u->info['y'] - 2,], // право x< x> y< y> + 1 => [$this->userinfo['x'] + 2, $this->userinfo['x'] - 2, $this->userinfo['y'] + 4, $this->userinfo['y'],], // прямо x< x> y< y> + 2 => [$this->userinfo['x'], $this->userinfo['x'] - 4, $this->userinfo['y'] + 2, $this->userinfo['y'] - 2,], // лево x< x> y< y> + 3 => [$this->userinfo['x'] + 2, $this->userinfo['x'] - 2, $this->userinfo['y'], $this->userinfo['y'] - 4,], // низ x< x> y< y> + 4 => [$this->userinfo['x'] + 4, $this->userinfo['x'], $this->userinfo['y'] + 2, $this->userinfo['y'] - 2,], // право x< x> y< y> ]; // $tmsu = mysql_fetch_assoc( - mysql_query('SELECT * FROM `katok_now` WHERE `clone` = "' . $u->info['id'] . '" LIMIT 1') + mysql_query('SELECT * FROM `katok_now` WHERE `clone` = "' . $this->userinfo['id'] . '" LIMIT 1') ); // $sp = mysql_query( - 'SELECT `u`.*,`st`.* FROM `stats` AS `u` LEFT JOIN `users` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`dnow` = "' . $u->info['dnow'] . '" AND ' . $whr[$this->gs] . ' AND `u`.`id` != "' . $u->info['id'] . '" LIMIT 100' + 'SELECT `u`.*,`st`.* FROM `stats` AS `u` LEFT JOIN `users` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`dnow` = "' . $this->userinfo['dnow'] . '" AND ' . $whr[$this->gs] . ' AND `u`.`id` != "' . $this->userinfo['id'] . '" LIMIT 100' ); $i = 0; $pos = []; @@ -2194,12 +2074,12 @@ class Dungeon //отображаем ботов // - //$sp = mysql_query('SELECT `u`.*,`st`.* FROM `dungeon_bots` AS `u` LEFT JOIN `test_bot` AS `st` ON (`u`.`id_bot` = `st`.`id`) WHERE `u`.`dn` = "'.$u->info['dnow'].'" AND `u`.`atack` = "0" AND `u`.`delete` = "0" AND `u`.`inBattle` = "0" AND `u`.`go_bot` > 0 ORDER BY `u`.`go_bot` ASC LIMIT 35'); + //$sp = mysql_query('SELECT `u`.*,`st`.* FROM `dungeon_bots` AS `u` LEFT JOIN `test_bot` AS `st` ON (`u`.`id_bot` = `st`.`id`) WHERE `u`.`dn` = "'.$this->userinfo['dnow'].'" AND `u`.`atack` = "0" AND `u`.`delete` = "0" AND `u`.`inBattle` = "0" AND `u`.`go_bot` > 0 ORDER BY `u`.`go_bot` ASC LIMIT 35'); // Выбираем Ботов в подземельи, которые Не в бою, Живые, и не дальше чем -\+30 по X и -\+35 по Y (дабы не гонять всех ботов, меньше выборка). $sp = mysql_query( - 'SELECT `db`.*, `tb`.* FROM `dungeon_bots` AS `db` LEFT JOIN `test_bot` AS `tb` ON (`db`.`id_bot` = `tb`.`id`) LEFT JOIN `stats` as `st` ON (`st`.`dnow` = `db`.`dn`) WHERE `db`.`dn` = "' . $u->info['dnow'] . '" AND `db`.`x` > `st`.`x`-30 AND `db`.`x` < `st`.`x`+30 AND `db`.`y` > `st`.`y`-35 AND `db`.`y` < `st`.`y`+35 AND `db`.`atack` = "0" AND `db`.`delete` = "0" AND `db`.`inBattle` = "0" AND `db`.`go_bot` > 0 GROUP BY `db`.`id2` ORDER BY `db`.`go_bot` ASC LIMIT 100' + 'SELECT `db`.*, `tb`.* FROM `dungeon_bots` AS `db` LEFT JOIN `test_bot` AS `tb` ON (`db`.`id_bot` = `tb`.`id`) LEFT JOIN `stats` as `st` ON (`st`.`dnow` = `db`.`dn`) WHERE `db`.`dn` = "' . $this->userinfo['dnow'] . '" AND `db`.`x` > `st`.`x`-30 AND `db`.`x` < `st`.`x`+30 AND `db`.`y` > `st`.`y`-35 AND `db`.`y` < `st`.`y`+35 AND `db`.`atack` = "0" AND `db`.`delete` = "0" AND `db`.`inBattle` = "0" AND `db`.`go_bot` > 0 GROUP BY `db`.`id2` ORDER BY `db`.`go_bot` ASC LIMIT 100' ); while ($pl = mysql_fetch_assoc($sp)) { //перемещение бота, каждые 3-10 сек. @@ -2213,7 +2093,7 @@ class Dungeon $tgx = 0; } } - $vlb = $this->testLike($pl['x'], $pl['y'], $pl['x'] + $tgx, $pl['y'] + $tgy); + $vlb = $this->cellIsGoodforAction($pl['x'], $pl['y'], $pl['x'] + $tgx, $pl['y'] + $tgy); //Кто-то рядом $tuz = mysql_fetch_assoc( mysql_query( @@ -2221,7 +2101,7 @@ class Dungeon ) ); - if (isset($tuz['id']) && $this->testLike($pl['x'], $pl['y'], $tuz['x'], $tuz['y']) == 1) { + if (isset($tuz['id']) && $this->cellIsGoodforAction($pl['x'], $pl['y'], $tuz['x'], $tuz['y'])) { $tuz['x'] = $pl['x']; $tuz['y'] = $pl['y']; mysql_query( @@ -2229,13 +2109,13 @@ class Dungeon ); $this->botAtack($pl, $tuz, 1);//Тут $sps = mysql_query( - 'SELECT `db`.*, `tb`.* FROM `dungeon_bots` AS `db` LEFT JOIN `test_bot` AS `tb` ON (`db`.`id_bot` = `tb`.`id`) LEFT JOIN `stats` as `st` ON (`st`.`dnow` = `db`.`dn`) WHERE `db`.`dn` = "' . $u->info['dnow'] . '" AND `db`.`x` ="' . $tuz['x'] . '" AND `db`.`y` ="' . $tuz['y'] . '" AND `db`.`atack` = "0" AND `db`.`delete` = "0" AND `db`.`inBattle` = "0" GROUP BY `db`.`id2` ORDER BY `db`.`go_bot` ASC LIMIT 50' + 'SELECT `db`.*, `tb`.* FROM `dungeon_bots` AS `db` LEFT JOIN `test_bot` AS `tb` ON (`db`.`id_bot` = `tb`.`id`) LEFT JOIN `stats` as `st` ON (`st`.`dnow` = `db`.`dn`) WHERE `db`.`dn` = "' . $this->userinfo['dnow'] . '" AND `db`.`x` ="' . $tuz['x'] . '" AND `db`.`y` ="' . $tuz['y'] . '" AND `db`.`atack` = "0" AND `db`.`delete` = "0" AND `db`.`inBattle` = "0" GROUP BY `db`.`id2` ORDER BY `db`.`go_bot` ASC LIMIT 50' ); while ($pll = mysql_fetch_assoc($sps)) { $this->botAtack($pll, $tuz, 1); } - } elseif ($vlb == 1) { // Передвижение ботов. + } elseif ($vlb) { // Передвижение ботов. $pl['go_bot'] = time() + 10 + rand(1, 5); $pl['x'] += $tgx; $pl['y'] += $tgy; @@ -2243,15 +2123,13 @@ class Dungeon 'UPDATE `dungeon_bots` SET `x` = "' . $pl['x'] . '",`y` = "' . $pl['y'] . '",`go_bot` = "' . $pl['go_bot'] . '" WHERE `id2` = "' . $pl['id2'] . '" LIMIT 1' ); } - unset($tgx, $tgy, $vlb, $tuz); } } $botsArr = Db::getRows( - 'select * from dungeon_bots left join test_bot on dungeon_bots.id_bot = test_bot.id where dn = ? and x <= ? and x >= ? and y <= ? and y >= ? limit 50', [ - $u->info['dnow'], $whrVals[$this->gs][0], $whrVals[$this->gs][1], $whrVals[$this->gs][2], $whrVals[$this->gs][3], - ] + 'select * from dungeon_bots left join test_bot on dungeon_bots.id_bot = test_bot.id where dn = ? and x <= ? and x >= ? and y <= ? and y >= ? limit 50', + [$this->userinfo['dnow'], $whrVals[$this->gs][0], $whrVals[$this->gs][1], $whrVals[$this->gs][2], $whrVals[$this->gs][3],] ); foreach ($botsArr as $pl) { @@ -2261,7 +2139,7 @@ class Dungeon // } // // $sp = mysql_query( - // 'SELECT `u`.*,`st`.* FROM `dungeon_bots` AS `u` LEFT JOIN `test_bot` AS `st` ON (`u`.`id_bot` = `st`.`id`) WHERE `u`.`dn` = "' . $u->info['dnow'] . '" AND ' . $whr[$this->gs] . ' AND `u`.`delete` = "0" LIMIT 50' + // 'SELECT `u`.*,`st`.* FROM `dungeon_bots` AS `u` LEFT JOIN `test_bot` AS `st` ON (`u`.`id_bot` = `st`.`id`) WHERE `u`.`dn` = "' . $this->userinfo['dnow'] . '" AND ' . $whr[$this->gs] . ' AND `u`.`delete` = "0" LIMIT 50' // ); // while ($pl = mysql_fetch_assoc($sp)) { $i++; @@ -2287,7 +2165,6 @@ class Dungeon public function testGone($id) { - global $u, $c, $code; $go = 0; if ($id == 1) { //вперед @@ -2302,11 +2179,9 @@ class Dungeon //на лево $go = $this->sg[$this->gs][2]; } - $thp = mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_map` WHERE `x` = "' . $u->info['x'] . '" AND `y` = "' . $u->info['y'] . '" AND `id_dng` = "' . $this->info['id2'] . '" LIMIT 1' - ) - ); + + $thp = self::getDungeonMapCellRow($this->userinfo['x'], $this->userinfo['y'], $this->info['id2']); + $ng = [4 => 1, 2 => 2, 1 => 3, 3 => 4]; if (isset($thp['id']) && $thp['go_' . $ng[$go]] == 0) { $go = 0; @@ -2322,15 +2197,17 @@ class Dungeon $tgo[0] += 1; } - $tbot = mysql_fetch_assoc( - mysql_query( - 'SELECT * FROM `dungeon_bots` WHERE `x` = "' . ($u->info['x'] + (int)$tgo[0]) . '" AND `y` = "' . ($u->info['y'] + (int)$tgo[1]) . '" AND `dn` = "' . $this->info['id'] . '" AND `for_dn` = "0" AND `delete` = "0" LIMIT 1' - ) - ); - if (isset($tbot['id2']) && $u->info['admin'] == 0) { + $tbot = $this->getBot($this->userinfo['x'] + (int)$tgo[0], $this->userinfo['y'] + (int)$tgo[1], $this->info['id']); + + if (isset($tbot['id2']) && $this->userinfo['admin'] == 0) { $go = 0; } return $go; } + + public function initPoint(int $x, int $y): void + { + $this->point = self::getDungeonMapCellRow($this->info['id2'], $x, $y); + } } diff --git a/modules_data/location/dungeon.php b/modules_data/location/dungeon.php index 24c0840d..4a7b5403 100644 --- a/modules_data/location/dungeon.php +++ b/modules_data/location/dungeon.php @@ -3,8 +3,9 @@ use Core\Config; use Core\Db; -echo ""; - +echo ""; if (!defined('GAME')) { die(); } @@ -147,10 +148,10 @@ if ($d->point['fileadd'] == 0 && $d->point['file'] != '0' && $d->point['file'] ! } } else { ?> - + '; $qsee .= 'Задание:   ' . $pl['info'] . ' ' . $r . '
'; @@ -846,7 +823,7 @@ if ($d->point['fileadd'] == 0 && $d->point['file'] != '0' && $d->point['file'] ! position: absolute; top: -8px; left: -6px; - / / background-image: url("/drgn/bg/r.gif"); + / / background-image: url(" /drgn/bg/r.gif"); } @@ -889,7 +866,7 @@ if ($d->point['fileadd'] == 0 && $d->point['file'] != '0' && $d->point['file'] ! $sb1 = Db::getRow('select x, y from dungeon_obj where name like ? and dn = ? limit 1', ['%Шайба%', $d->info['id']]); while($pl = mysql_fetch_array($sp)) { - $css = '"background-image":"url('. Config::img() .'/fon555.png)",'; + $css = '"background-image":"url(' . Config::img() . '/fon555.png)",'; $j = 0; while ($j < 4) { @@ -902,7 +879,7 @@ if ($d->point['fileadd'] == 0 && $d->point['file'] != '0' && $d->point['file'] ! } if(!empty($sb1) && $sb1['x'] == $pl['x'] && $sb1['y'] == $pl['y'] ) { - echo '$("#min_' . $pl['x'] . '_' . $pl['y'] . '").html("info['s'] . '\" title=\"Шайба!\" style=\"margin:2px 3px 3px 2px;background-image:url('. Config::img() .'/i/move/shb.gif)\" src=\"'. Config::img() .'/1x1.gif\" width=\"7\" height=\"7\">");'; + echo '$("#min_' . $pl['x'] . '_' . $pl['y'] . '").html("info['s'] . '\" title=\"Шайба!\" style=\"margin:2px 3px 3px 2px;background-image:url(' . Config::img() . '/i/move/shb.gif)\" src=\"' . Config::img() . '/1x1.gif\" width=\"7\" height=\"7\">");'; }elseif ($u->info['x'] == $pl['x'] && $u->info['y'] == $pl['y']) { if ($d->info['id2'] == 15) { $tmbth = 4; @@ -912,9 +889,9 @@ if ($d->point['fileadd'] == 0 && $d->point['file'] != '0' && $d->point['file'] ! } elseif ($tm['team'] == 2) { $tmbth = 2; } - echo '$("#min_' . $pl['x'] . '_' . $pl['y'] . '").html("info['s'] . '\" title=\"Это Вы\" style=\"margin:2px 3px 3px 2px;background-image:url('. Config::img() .'/i/move/p' . $tmbth . '/d0.gif)\" src=\"'. Config::img() .'/1x1.gif\" width=\"7\" height=\"7\">");'; + echo '$("#min_' . $pl['x'] . '_' . $pl['y'] . '").html("info['s'] . '\" title=\"Это Вы\" style=\"margin:2px 3px 3px 2px;background-image:url(' . Config::img() . '/i/move/p' . $tmbth . '/d0.gif)\" src=\"' . Config::img() . '/1x1.gif\" width=\"7\" height=\"7\">");'; } else { - echo '$("#min_' . $pl['x'] . '_' . $pl['y'] . '").html("info['s'] . '\" title=\"Это Вы\" style=\"margin:2px 3px 3px 2px;background-image:url('. Config::img() .'/i/move/p1/d0.gif)\" src=\"'. Config::img() .'/1x1.gif\" width=\"7\" height=\"7\">");'; + echo '$("#min_' . $pl['x'] . '_' . $pl['y'] . '").html("info['s'] . '\" title=\"Это Вы\" style=\"margin:2px 3px 3px 2px;background-image:url(' . Config::img() . '/i/move/p1/d0.gif)\" src=\"' . Config::img() . '/1x1.gif\" width=\"7\" height=\"7\">");'; } } elseif ($d->info['id2'] == 15) { $tmbth = 4; @@ -930,12 +907,12 @@ if ($d->point['fileadd'] == 0 && $d->point['file'] != '0' && $d->point['file'] ! ) ); if (isset($tbshin['id'])) { - echo '$("#min_' . $pl['x'] . '_' . $pl['y'] . '").html("info['s'] . '\" title=\"Шайба!\" style=\"margin:2px 3px 3px 2px;background-image:url('. Config::img() .'/i/move/shb.gif)\" src=\"'. Config::img() .'/1x1.gif\" width=\"7\" height=\"7\">");'; + echo '$("#min_' . $pl['x'] . '_' . $pl['y'] . '").html("info['s'] . '\" title=\"Шайба!\" style=\"margin:2px 3px 3px 2px;background-image:url(' . Config::img() . '/i/move/shb.gif)\" src=\"' . Config::img() . '/1x1.gif\" width=\"7\" height=\"7\">");'; } else { - echo '$("#min_' . $uxy[$pl['x'] . '_' . $pl['y']]['x'] . '_' . $uxy[$pl['x'] . '_' . $pl['y']]['y'] . '").html("");'; + echo '$("#min_' . $uxy[$pl['x'] . '_' . $pl['y']]['x'] . '_' . $uxy[$pl['x'] . '_' . $pl['y']]['y'] . '").html("");'; } }elseif (isset($uxy[$pl['x'] . '_' . $pl['y']])) { - echo '$("#min_' . $uxy[$pl['x'] . '_' . $pl['y']]['x'] . '_' . $uxy[$pl['x'] . '_' . $pl['y']]['y'] . '").html("");'; + echo '$("#min_' . $uxy[$pl['x'] . '_' . $pl['y']]['x'] . '_' . $uxy[$pl['x'] . '_' . $pl['y']]['y'] . '").html("");'; } elseif( isset($bxy[$pl['x'] . '_' . $pl['y']]) ) { $bobrz = $bxy[$pl['x'] . '_' . $pl['y']]['obraz']; @@ -960,18 +937,23 @@ if ($d->point['fileadd'] == 0 && $d->point['file'] != '0' && $d->point['file'] !
- + testGone(3) > 0) { ?> - + testGone(4) > 0) { ?> - + testGone(2) > 0) { ?> - + testGone(1) > 0) { ?> - +