2189 lines
114 KiB
PHP
2189 lines
114 KiB
PHP
<?php
|
||
|
||
use Core\Db;
|
||
use Helper\Conversion;
|
||
use Model\ActionModel;
|
||
use User\ItemsModel;
|
||
use User\Stats;
|
||
|
||
class Dungeon
|
||
{
|
||
public array $info;
|
||
public string $error; //карта
|
||
public int $gs = 1;
|
||
public string $information;
|
||
public int $id_dng;
|
||
public array $point;
|
||
/**
|
||
* 1-9: передняя стенка, в 2-х шагах;<br>
|
||
* 10-23: растояние: 1 шаг;<br>
|
||
* 24: стена прямо слева от персонажа;<br>
|
||
* 25: стена прямо справа от персонажа;<br>
|
||
* 26: стена прямо перед персонажем;<br>
|
||
* 27: стена слева от персонажа;<br>
|
||
* 28: стена справа от персонажа;
|
||
* @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;
|
||
|
||
$this->info = Db::getRow('select * from dungeon_now where id = ?', [$this->userinfo['dnow']]);
|
||
|
||
$this->id_dng = $this->info['id2'];
|
||
$this->gs = $this->userinfo['s'];
|
||
if ($this->gs < 1 || $this->gs > 4) {
|
||
$this->gs = 1;
|
||
}
|
||
|
||
$this->getBs();
|
||
|
||
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']), // перемещение
|
||
default => null,
|
||
};
|
||
|
||
/* генерируем вид персонажа (только карта) */
|
||
|
||
$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,],
|
||
];
|
||
|
||
$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'] = $cellsCount; //целых клеток
|
||
$this->map[1] = $this->genMatix();
|
||
$this->lookDungeon();
|
||
}
|
||
|
||
private function getBs(): void
|
||
{
|
||
if ($this->info['bsid'] <= 0) {
|
||
return;
|
||
}
|
||
$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 .= '<div>Предмет не найден</div>';
|
||
} elseif ($luck2 > 0) {
|
||
$this->error .= '<div>Вы уже учавствуете в розыгрыше "' . $item['name'] . '", ожидаем других участников еще ' .
|
||
Conversion::secondsToTimeout($item['time'] - time() + 300) . '</div>';
|
||
} else {
|
||
if ($luck < 1) {
|
||
Db::sql('update dungeon_items set time = unix_timestamp() where id = ?', [$item['id']]);
|
||
}
|
||
|
||
$rndl = rand(1, 100);
|
||
|
||
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('<b>%s</b> выбросил *%s* в споре за предмет «%s»', $this->userinfo['login'], $rndl, $item['name']));
|
||
} else {
|
||
$this->sys_chat(sprintf('<b>%s</b> выбросила *%s* в споре за предмет «%s»', $this->userinfo['login'], $rndl, $item['name']));
|
||
}
|
||
|
||
$this->error .= sprintf('<div>Вы выбросили *%s* в споре за предмет «%s»</div>', $rndl, $item['name']);
|
||
}
|
||
$this->testLuck($id);
|
||
}
|
||
|
||
public function sys_chat($rtxt)
|
||
{
|
||
$cmsg = new ChatMessage();
|
||
$cmsg->setDn($this->userinfo['dnow']);
|
||
$cmsg->setRoom($this->userinfo['room']);
|
||
$cmsg->setText($rtxt);
|
||
$cmsg->setType(6);
|
||
$cmsg->setTypeTime(1);
|
||
(new Chat())->sendMsg($cmsg);
|
||
}
|
||
|
||
private function testLuck($id): void
|
||
{
|
||
$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` = "' . $this->userinfo['x'] . '" AND `ish`.`y` = "' . $this->userinfo['y'] . '" LIMIT 1'
|
||
)
|
||
), '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(
|
||
$id
|
||
) . '" LIMIT 1'
|
||
)
|
||
), 'user_count' => mysql_fetch_assoc(
|
||
mysql_query('SELECT COUNT(*) FROM `stats` WHERE `dnow` = "' . $this->info['id'] . '" LIMIT 1')
|
||
)];
|
||
$fxv['luck_count'] = $fxv['luck_count'][0];
|
||
$fxv['user_count'] = $fxv['user_count'][0];
|
||
|
||
if (($fxv['luck_count'] >= $fxv['user_count'] || $fxv['itm']['time'] + 300 < time()) && !empty($fxv['itm']['user'])) {
|
||
$fxv['sp'] = mysql_query(
|
||
'SELECT * FROM `dungeon_actions` WHERE `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string(
|
||
$id
|
||
) . '" ORDER BY `vals` DESC LIMIT ' . $fxv['luck_count'] . ''
|
||
);
|
||
$fxv['winner'] = [];
|
||
$fxv['win_val'] = 0;
|
||
unset($fxv['pl'], $fxv['sp']);
|
||
if (count($fxv['winner']) > 1) {
|
||
//Розыгрыш еще раз между победителями
|
||
$this->error .= '<div>Розыгрыш завершен!</div>';
|
||
} elseif (count($fxv['winner']) == 1) {
|
||
$fxv['user_win'] = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT `id`,`login`,`sex` FROM `users` WHERE `id` = "' . $fxv['winner'][0] . '" LIMIT 1'
|
||
)
|
||
);
|
||
$fxv['text'] = '<b>' . $fxv['user_win']['login'] . '</b> выигрывает в споре за предмет "' . $fxv['itm']['name'] . '"';
|
||
$this->sys_chat($fxv['text']);
|
||
mysql_query(
|
||
'UPDATE `dungeon_items` SET `time` = "' . time() . '",`user` = "' . $fxv['user_win']['id'] . '" WHERE `id` = "' . $fxv['itm']['id'] . '" LIMIT 1'
|
||
);
|
||
$this->error .= '<div>Розыгрыш завершен! Победитель <b>' . $fxv['user_win']['login'] . '</b>!</div>';
|
||
}
|
||
} else {
|
||
$this->error .= '<div>У остальных участников осталось ' . Conversion::secondsToTimeout(
|
||
$fxv['itm']['time'] + 300 - time()
|
||
) . ' мин. до конца розыгрыша</div>';
|
||
}
|
||
|
||
}
|
||
|
||
private function itmUnluck($id): void
|
||
{
|
||
$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($item['id'])) {
|
||
$this->error .= '<div>Предмет не найден</div>';
|
||
} elseif (isset($luck['id'])) {
|
||
if ($luck['vals'] == 0) {
|
||
$this->error .= '<div>Вы уже отказались от участия в розыгрыше "' . $item['name'] . '"</div>';
|
||
} else {
|
||
$this->error .= '<div>Вы уже учавствуете в розыгрыше "' . $item['name'] . '", ожидаем других участников еще ' . Conversion::secondsToTimeout(
|
||
$item['time'] - time() + 300
|
||
) . '</div>';
|
||
}
|
||
} else {
|
||
if ($luck['count'] < 1) {
|
||
Db::sql('update dungeon_items set time = unix_timestamp() where id = ?', [$item['id']]);
|
||
}
|
||
if ($this->userinfo['sex'] == 0) {
|
||
$this->sys_chat(sprintf('<b>%s</b> отказался от спора за предмет «%s»', $this->userinfo['login'], $item['name']));
|
||
} else {
|
||
$this->sys_chat(sprintf('<b>%s</b> отказалась от спора за предмет «%s»', $this->userinfo['login'], $item['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 .= '<div>Вы отказались от участия в розыгрыше "' . $item['name'] . '"</div>';
|
||
}
|
||
}
|
||
|
||
private function atack($id)
|
||
{
|
||
$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 (($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'
|
||
)
|
||
);
|
||
if (isset($tbtl['id'])) {
|
||
//вступаем в поединок
|
||
mysql_query(
|
||
'UPDATE `users` SET `battle` = "' . $tbtl['id'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
mysql_query('UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1');
|
||
|
||
die('<script>top.frames[\'main\'].location = "main.php";</script>');
|
||
} else {
|
||
$btl_id = 0;
|
||
//$expB = -77.77;
|
||
$expB = 0;
|
||
$btl = ['players' => '', 'timeout' => 120, 'type' => 0, 'invis' => 0, 'noinc' => 0, 'travmChance' => 0, 'typeBattle' => 0, 'addExp' => $expB, 'money' => 0];
|
||
|
||
$ins = mysql_query(
|
||
'INSERT INTO `battle` (`dungeon`,`dn_id`,`x`,`y`,`city`,`time_start`,`players`,`timeout`,`type`,`invis`,`noinc`,`travmChance`,`typeBattle`,`addExp`,`money`) VALUES (
|
||
"' . $this->info['id2'] . '",
|
||
"' . $this->info['id'] . '",
|
||
"' . $bot['x'] . '",
|
||
"' . $bot['y'] . '",
|
||
"' . $this->userinfo['city'] . '",
|
||
"' . time() . '",
|
||
"' . $btl['players'] . '",
|
||
"' . $btl['timeout'] . '",
|
||
"' . $btl['type'] . '",
|
||
"' . $btl['invis'] . '",
|
||
"' . $btl['noinc'] . '",
|
||
"' . $btl['travmChance'] . '",
|
||
"' . $btl['typeBattle'] . '",
|
||
"' . $btl['addExp'] . '",
|
||
"' . $btl['money'] . '")'
|
||
);
|
||
$btl_id = mysql_insert_id();
|
||
|
||
if ($btl_id > 0) {
|
||
//Добавляем ботов
|
||
$sp = mysql_query(
|
||
'SELECT * FROM `dungeon_bots` WHERE `for_dn` = "0" AND `dn` = "' . $this->info['id'] . '" AND `x` = "' . $bot['x'] . '" AND `y` = "' . $bot['y'] . '" AND `delete` = "0" LIMIT 1001'
|
||
);
|
||
$j = 0;
|
||
$logins_bot = [];
|
||
while ($pl = mysql_fetch_assoc($sp)) {
|
||
$jui = 1;
|
||
mysql_query(
|
||
'UPDATE `dungeon_bots` SET `inBattle` = "' . $btl_id . '" WHERE `id2` = "' . $pl['id2'] . '" LIMIT 1'
|
||
);
|
||
while ($jui <= $pl['colvo']) {
|
||
$k = User::start()->addNewbot($pl['id_bot'], null, null, $logins_bot);
|
||
$logins_bot = $k['logins_bot'];
|
||
if ($k != false) {
|
||
$upd = mysql_query(
|
||
'UPDATE `users` SET `battle` = "' . $btl_id . '" WHERE `id` = "' . $k['id'] . '" LIMIT 1'
|
||
);
|
||
if ($upd) {
|
||
$upd = mysql_query(
|
||
'UPDATE `stats` SET `x`="' . $bot['x'] . '",`y`="' . $bot['y'] . '",`team` = "2" WHERE `id` = "' . $k['id'] . '" LIMIT 1'
|
||
);
|
||
if ($upd) {
|
||
$j++;
|
||
}
|
||
}
|
||
}
|
||
$jui++;
|
||
}
|
||
}
|
||
unset($logins_bot);
|
||
if ($j > 0) {
|
||
mysql_query(
|
||
'UPDATE `users` SET `battle` = "' . $btl_id . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
mysql_query(
|
||
'UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
die('<script>top.frames[\'main\'].location = "main.php";</script>');
|
||
} else {
|
||
$this->error = 'Не удалось напасть, ошибка обьекта нападения ...';
|
||
}
|
||
} else {
|
||
$this->error = 'Не удалось создать поединок ...';
|
||
}
|
||
}
|
||
} else {
|
||
$this->error = 'Не удалось напасть ...';
|
||
}
|
||
} else {
|
||
if (isset($this->bs['id']) || $this->info['id2'] == 15) {
|
||
$bot = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT `u`.*,`st`.* FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`id` = "' . mysql_real_escape_string(
|
||
$id
|
||
) . '" LIMIT 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'
|
||
)
|
||
);
|
||
|
||
if (isset($tbtl['id'])) {
|
||
//вступаем в поединок
|
||
$lstm = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT `u`.*,`st`.* FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`battle`="' . $tbtl['id'] . '" ORDER BY `st`.`team` DESC LIMIT 1'
|
||
)
|
||
);
|
||
mysql_query(
|
||
'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` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
mysql_query(
|
||
'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` = "' . $this->userinfo['id'] . '" AND `login` = "' . $this->userinfo['login'] . '" LIMIT 1'
|
||
)
|
||
);
|
||
$usr_real = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `inUser` = "' . $bot['id'] . '" AND `login` = "' . $bot['login'] . '" LIMIT 1'
|
||
)
|
||
);
|
||
mysql_query(
|
||
'UPDATE `stats` SET `tactic7`= 20.000 WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
//Заносим в лог БС
|
||
if ($this->userinfo['sex'] == 0) {
|
||
$text = '{u1} вмешался в поединок напав на {u2} <a target=_blank href=/logs.php?log=' . $tbtl['id'] . ' >»»</a>';
|
||
} else {
|
||
$text = '{u1} вмешалася в поединок напав на {u2} <a target=_blank href=/logs.php?log=' . $tbtl['id'] . ' >»»</a>';
|
||
}
|
||
if (isset($usr_real['id'])) {
|
||
$usrreal = '';
|
||
if ($usr_real['align'] > 0) {
|
||
$usrreal .= '<img src=//img.new-combats.tech/i/align/align' . $usr_real['align'] . '.gif width=12 height=15 >';
|
||
}
|
||
if ($usr_real['clan'] > 0) {
|
||
$usrreal .= '<img src=//img.new-combats.tech/i/clan/' . $usr_real['clan'] . '.gif width=24 height=15 >';
|
||
}
|
||
$usrreal .= '<b>' . $usr_real['login'] . '</b>[' . $usr_real['level'] . ']<a target=_blank href=/info/' . $usr_real['id'] . ' ><img width=12 heihgt=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
|
||
} else {
|
||
$mereal = '<i>Невидимка</i>[??]';
|
||
}
|
||
if (isset($me_real['id'])) {
|
||
$mereal = '';
|
||
if ($me_real['align'] > 0) {
|
||
$mereal .= '<img src=//img.new-combats.tech/i/align/align' . $me_real['align'] . '.gif width=12 height=15 >';
|
||
}
|
||
if ($me_real['clan'] > 0) {
|
||
$mereal .= '<img src=//img.new-combats.tech/i/clan/' . $me_real['clan'] . '.gif width=24 height=15 >';
|
||
}
|
||
$mereal .= '<b>' . $me_real['login'] . '</b>[' . $me_real['level'] . ']<a target=_blank href=/info/' . $me_real['id'] . ' ><img width=12 heihgt=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
|
||
} else {
|
||
$mereal = '<i>Невидимка</i>[??]';
|
||
}
|
||
$text = str_replace('{u1}', $mereal, $text);
|
||
$text = str_replace('{u2}', $usrreal, $text);
|
||
//Добавляем в лог БС
|
||
mysql_query(
|
||
'INSERT INTO `bs_logs` (`type`,`text`,`time`,`id_bs`,`count_bs`,`city`,`m`,`u`) VALUES (
|
||
"1", "' . mysql_real_escape_string($text) . '", "' . time() . '", "' . $this->bs['id'] . '", "' . $this->bs['count'] . '", "' . $this->bs['city'] . '",
|
||
"' . round($this->bs['money'] * 0.85, 2) . '","' . $i . '"
|
||
)'
|
||
);
|
||
//
|
||
}
|
||
//
|
||
$this->error = 'Нападаем ... <script>location="main.php?rnd=' . PassGen::intCode() . '";</script>';
|
||
} else {
|
||
if ($this->info['id2'] == 1) {
|
||
$expB = 200;
|
||
}
|
||
$btl = ['players' => '', 'timeout' => 40, 'type' => 0, 'invis' => 0, 'noinc' => 0, 'travmChance' => 0, 'typeBattle' => 0, 'addExp' => $expB, 'money' => 0, 'inTurnir' => 0];
|
||
|
||
if ($this->info['bsid'] > 0) {
|
||
$btl['inTurnir'] = $this->info['bsid'];
|
||
}
|
||
|
||
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'] . '",
|
||
"' . $this->userinfo['city'] . '",
|
||
"' . time() . '",
|
||
"' . $btl['players'] . '",
|
||
"' . $btl['timeout'] . '",
|
||
"' . $btl['type'] . '",
|
||
"' . $btl['invis'] . '",
|
||
"' . $btl['noinc'] . '",
|
||
"' . $btl['travmChance'] . '",
|
||
"' . $btl['typeBattle'] . '",
|
||
"' . $btl['addExp'] . '",
|
||
"' . $btl['money'] . '")'
|
||
);
|
||
$btl_id = mysql_insert_id();
|
||
mysql_query(
|
||
'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'
|
||
);
|
||
|
||
if ($btl_id > 0) {
|
||
//Добавляем ботов
|
||
mysql_query(
|
||
'UPDATE `users` SET `battle` = "' . $btl_id . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
mysql_query(
|
||
'UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
|
||
mysql_query(
|
||
'UPDATE `users` SET `battle` = "' . $btl_id . '" WHERE `id` = "' . $bot['id'] . '" LIMIT 1'
|
||
);
|
||
mysql_query('UPDATE `stats` SET `team` = "2" WHERE `id` = "' . $bot['id'] . '" LIMIT 1');
|
||
|
||
if ($this->userstats['hpNow'] < 1) {
|
||
$this->userstats['hpNow'] = 1;
|
||
mysql_query(
|
||
'UPDATE `stats` SET `hpNow` = "1" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
mysql_query(
|
||
'UPDATE `users` SET `lose` = `lose` + 1 WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
}
|
||
|
||
if ($bot['hpNow'] < 1) {
|
||
$bot['hpNow'] = 1;
|
||
mysql_query(
|
||
'UPDATE `stats` SET `hpNow` = "1" WHERE `id` = "' . $bot['id'] . '" LIMIT 1'
|
||
);
|
||
mysql_query(
|
||
'UPDATE `users` SET `lose` = `lose` + 1 WHERE `id` = "' . $bot['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` = "' . $this->userinfo['id'] . '" AND `login` = "' . $this->userinfo['login'] . '" LIMIT 1'
|
||
)
|
||
);
|
||
$usr_real = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `inUser` = "' . $bot['id'] . '" AND `login` = "' . $bot['login'] . '" LIMIT 1'
|
||
)
|
||
);
|
||
|
||
//Заносим в лог БС
|
||
if ($this->userinfo['sex'] == 0) {
|
||
$text = '{u1} напал на {u2} завязался бой <a target=_blank href=/logs.php?log=' . $btl_id . ' >»»</a>';
|
||
} else {
|
||
$text = '{u1} напала на {u2} завязался бой <a target=_blank href=/logs.php?log=' . $btl_id . ' >»»</a>';
|
||
}
|
||
if (isset($usr_real['id'])) {
|
||
$usrreal = '';
|
||
if ($usr_real['align'] > 0) {
|
||
$usrreal .= '<img src=//img.new-combats.tech/i/align/align' . $usr_real['align'] . '.gif width=12 height=15 >';
|
||
}
|
||
if ($usr_real['clan'] > 0) {
|
||
$usrreal .= '<img src=//img.new-combats.tech/i/clan/' . $usr_real['clan'] . '.gif width=24 height=15 >';
|
||
}
|
||
$usrreal .= '<b>' . $usr_real['login'] . '</b>[' . $usr_real['level'] . ']<a target=_blank href=/info/' . $usr_real['id'] . ' ><img width=12 heihgt=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
|
||
} else {
|
||
$mereal = '<i>Невидимка</i>[??]';
|
||
}
|
||
if (isset($me_real['id'])) {
|
||
$mereal = '';
|
||
if ($me_real['align'] > 0) {
|
||
$mereal .= '<img src=//img.new-combats.tech/i/align/align' . $me_real['align'] . '.gif width=12 height=15 >';
|
||
}
|
||
if ($me_real['clan'] > 0) {
|
||
$mereal .= '<img src=//img.new-combats.tech/i/clan/' . $me_real['clan'] . '.gif width=24 height=15 >';
|
||
}
|
||
$mereal .= '<b>' . $me_real['login'] . '</b>[' . $me_real['level'] . ']<a target=_blank href=/info/' . $me_real['id'] . ' ><img width=12 heihgt=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
|
||
} else {
|
||
$mereal = '<i>Невидимка</i>[??]';
|
||
}
|
||
$text = str_replace('{u1}', $mereal, $text);
|
||
$text = str_replace('{u2}', $usrreal, $text);
|
||
//Добавляем в лог БС
|
||
mysql_query(
|
||
'INSERT INTO `bs_logs` (`type`,`text`,`time`,`id_bs`,`count_bs`,`city`,`m`,`u`) VALUES (
|
||
"1", "' . mysql_real_escape_string($text) . '", "' . time() . '", "' . $this->bs['id'] . '", "' . $this->bs['count'] . '", "' . $this->bs['city'] . '",
|
||
"' . round($this->bs['money'] * 0.85, 2) . '","' . $i . '"
|
||
)'
|
||
);
|
||
//
|
||
}
|
||
|
||
$this->error = 'Нападаем ... <script>location="main.php?rnd=' . PassGen::intCode() . '";</script>';
|
||
} else {
|
||
$this->error = 'Не удалось создать поединок ...';
|
||
}
|
||
}
|
||
} else {
|
||
$this->error = 'Не удалось напасть ...';
|
||
}
|
||
} else {
|
||
$this->error = 'Не удалось напасть, слишком далеко (id' . $id . ') ...';
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* доступна-ли эта клетка для действий из $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
|
||
{
|
||
$c1 = self::getDungeonMapCellRow($x1, $y1, $this->info['id2']);
|
||
$c2 = self::getDungeonMapCellRow($x2, $y2, $this->info['id2']);
|
||
if (empty($c1) || empty($c2)) {
|
||
return false;
|
||
}
|
||
|
||
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]) ?: [];
|
||
}
|
||
|
||
//Предметы для БС
|
||
|
||
private function takeinv($id)
|
||
{
|
||
$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->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(
|
||
$id
|
||
) . '" LIMIT 1'
|
||
)
|
||
), 'user_count' => mysql_fetch_assoc(
|
||
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 = 'Вы не можете сейчас поднять этот предмет, дождитесь завершения розыгрыша. Осталось ' . Conversion::secondsToTimeout(
|
||
$obj['time'] - time() + 300
|
||
);
|
||
} 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'] != $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'
|
||
)
|
||
);
|
||
}
|
||
if (isset($uo['id'])) {
|
||
$this->error = 'Предмет предназначен для "' . $uo['login'] . '". Вы сможете забрать этот предмет, если ';
|
||
if ($uo['sex'] == 1) {
|
||
$this->error .= 'она ';
|
||
} else {
|
||
$this->error .= 'он ';
|
||
}
|
||
$this->error .= ' не поднимет его в течении ' . ceil(
|
||
5 - (time() - $obj['time']) / 60
|
||
) . ' мин.';
|
||
unset($uo);
|
||
} else {
|
||
$upd = mysql_query(
|
||
'UPDATE `dungeon_items` SET `take` = "' . $this->userinfo['id'] . '" WHERE `id` = "' . $obj['id'] . '" LIMIT 1'
|
||
);
|
||
if ($upd) {
|
||
$it = mysql_fetch_assoc(
|
||
mysql_query('SELECT * FROM `items_main` WHERE `id` = "' . $obj['item_id'] . '" LIMIT 1')
|
||
);
|
||
if (isset($it['id'])) {
|
||
$data = '|noremont=1|frompisher=' . $this->info['id2'];
|
||
if ($it['ts'] != 0) {
|
||
$data .= '|sudba=' . $this->userinfo['login'];
|
||
}
|
||
if ($obj['data'] != '') {
|
||
$data .= $obj['data'];
|
||
}
|
||
$data = str_replace('|sudba=-1', '|sudba=' . $this->userinfo['login'] . '', $data);
|
||
|
||
$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'
|
||
);
|
||
}
|
||
unset($idl);
|
||
|
||
if ($this->info['bsid'] == 0) {
|
||
$rtxt = '<b>' . $this->userinfo['login'] . '</b> поднял предмет "' . $it['name'] . '"';
|
||
if ($obj['quest'] > 0) {
|
||
$rtxt .= ' (Квест)';
|
||
}
|
||
$this->sys_chat($rtxt);
|
||
}
|
||
$this->error = 'Вы подняли "' . $it['name'] . '"';
|
||
} else {
|
||
$this->error = 'Не удалось найти предмет ...';
|
||
}
|
||
} else {
|
||
$this->error = 'Не удалось добавить предмет в инвентарь ...';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* добавляем предмет в пещеру (возможно выпал из бота или из сундука)
|
||
* @param array $i
|
||
* @return void
|
||
*/
|
||
private function addItem(array $i): void
|
||
{
|
||
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']]);
|
||
}
|
||
|
||
private function takeit($id)
|
||
{
|
||
$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'
|
||
)
|
||
);
|
||
if (isset($obj['id'])) {
|
||
$tbot = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT id2 FROM `dungeon_bots` WHERE `x` = "' . $obj['x'] . '" AND `y` = "' . $obj['y'] . '" AND `dn` = "' . $this->info['id'] . '" AND `for_dn` = "0" AND `delete` = "0" LIMIT 1'
|
||
)
|
||
);
|
||
|
||
|
||
$i = 0;
|
||
# Создаем МАССИВ { $act_sl['save_pos'] = "save_pos" }или { $act_sl['port'] = "10:20" }
|
||
$act_sl = [];
|
||
$act_sm = explode('|', $obj['action']);
|
||
while ($i < count($act_sm)) {
|
||
$s = explode(':', $act_sm[$i]);
|
||
if (isset($s[1]) && $s[1] != '') {
|
||
$act_sl[$s[0]] = $s[1];
|
||
} else {
|
||
$act_sl[$s[0]] = $s[0];
|
||
}
|
||
$i++;
|
||
}
|
||
|
||
if (isset($tbot['id2'])) {
|
||
$this->error = 'Не удалось, что-то или кто-то мешает ...';
|
||
} elseif (!$this->cellIsGoodforAction($this->userinfo['x'], $this->userinfo['y'], $obj['x'], $obj['y'])) {
|
||
$this->error = 'Не удалось, слишком далеко ...!';
|
||
} else {
|
||
$a = explode('|', $obj['action']);
|
||
$r = '';
|
||
$i = 0;
|
||
while ($i < count($a)) {
|
||
$s = explode(':', $a[$i]);
|
||
|
||
if ($s[0] == 'kill_bot') {
|
||
//Требуется убить ботов
|
||
$t = explode(',', $s[1]);
|
||
$tr_gd = 0;
|
||
|
||
//Проверяем кого нужно убить и убили-ли
|
||
$j = 1;
|
||
$jn = 0;
|
||
while ($j < count($t)) {
|
||
$itm = explode('.', $t[$j]);
|
||
//[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` = "' . $this->userinfo['dnow'] . '" AND `u`.`x` = "' . $itm[0] . '" AND `u`.`y` = "' . $itm[1] . '" AND `u`.`delete` = "0" LIMIT 10'
|
||
)
|
||
);
|
||
if (isset($bot_itm['id2'])) {
|
||
$jn++;
|
||
}
|
||
$j++;
|
||
}
|
||
|
||
if ($jn == 0) {
|
||
$tr_gd = 1;
|
||
}
|
||
|
||
unset($itm, $bot_itm, $jn);
|
||
if ($tr_gd == 0) {
|
||
if ($t[0] == '0') {
|
||
$r .= 'Не удалось, что-то или кто-то мешает ...';
|
||
} else {
|
||
$r .= $t[0];
|
||
}
|
||
$i = count($a);
|
||
}
|
||
} elseif ($s[0] == 'kill_bot_d') {
|
||
//Требуется убить ботов (все боты нападают , если что-то не так )
|
||
$t = explode(',', $s[1]);
|
||
$tr_gd = 0;
|
||
|
||
//Проверяем кого нужно убить и убили-ли
|
||
$j = 1;
|
||
$jn = 0;
|
||
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` = "' . $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, $this->userinfo, 1);
|
||
}
|
||
$j++;
|
||
}
|
||
|
||
if ($jn == 0) {
|
||
$tr_gd = 1;
|
||
}
|
||
|
||
unset($itm, $bot_itm, $jn);
|
||
if ($tr_gd == 0) {
|
||
if ($t[0] == '0') {
|
||
$r .= 'Не удалось, что-то или кто-то мешает ...';
|
||
} else {
|
||
$r .= $t[0];
|
||
}
|
||
$r .= ' Монстры начали атаковать вас!';
|
||
$i = count($a);
|
||
}
|
||
} elseif ($s[0] == 'ditm') {
|
||
//требует предмет для действия
|
||
$j = 0;
|
||
$t = explode(',', $s[1]);
|
||
$tr_gd = 1;
|
||
while ($j < count($t)) {
|
||
$itm = explode('=', $t[$j]);
|
||
$uitm = mysql_fetch_array(
|
||
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` = "' . $this->userinfo['id'] . '" AND (`delete` = 0 OR `delete` = 100) AND `inShop` = 0 AND `inTransfer` = 0 AND `inOdet` = 0 LIMIT ' . $itm[1]
|
||
);
|
||
$r .= 'Предмет "<b>' . $uitm['name'] . '</b>" (x' . $itm[1] . ') был утрачен...<br>';
|
||
$j++;
|
||
}
|
||
} elseif ($s[0] == 'tritm') {
|
||
//требует предмет для действия
|
||
$j = 0;
|
||
$t = explode(',', $s[1]);
|
||
$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` = "' . $this->userinfo['id'] . '" AND (`delete` = 0 OR `delete` = 100) AND `inShop` = 0 AND `inTransfer` = 0 AND `inOdet` = 0 LIMIT ' . $itm[1]
|
||
)
|
||
);
|
||
$uitm = $uitm[0];
|
||
if ($uitm < $itm[1]) {
|
||
$tr_gd = 0;
|
||
$uitm = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT `name` FROM `items_main` WHERE `id` = "' . $itm[0] . '" LIMIT 1'
|
||
)
|
||
);
|
||
$r .= 'Требуется предмет "<b>' . $uitm['name'] . '</b>" (x' . $itm[1] . ')<br>';
|
||
}
|
||
$j++;
|
||
}
|
||
if (rand(0, 10000) > $itm[2] * 100) {
|
||
$tr_gd = 0;
|
||
$r .= 'Странно, но ничего не произошло...<br>';
|
||
}
|
||
if ($tr_gd != 1) {
|
||
$i = count($a);
|
||
}
|
||
} elseif ($s[0] == 'repl_ptp') {
|
||
require_once 'dnaction/_dungeon_replace.php';
|
||
die();
|
||
} elseif ($s[0] == 'add_eff') {
|
||
//Кастуем эффект
|
||
$t = explode(',', $s[1]);
|
||
$j = 0;
|
||
while ($j < count($t)) {
|
||
$itm = explode('=', $t[$j]);
|
||
|
||
$ch = ActionModel::testCount(["uid = {$this->userinfo['id']}", "vars = add_eff_{$this->info['id']}_{$obj['id']}"], 1 + (int)$itm[2]); //кол-во прошлых попыток
|
||
$ch2 = ActionModel::testCount(["vars = add_eff_{$this->info['id']}_{$obj['id']}"], 1 + (int)$itm[4]); //кол-во прошлых попыток (все юзеры)
|
||
|
||
if (($ch2 < $itm[4] || $itm[4] == 0) && $ch < $itm[2]) {
|
||
if ($itm[1] * 100 >= rand(0, 10000)) {
|
||
//удачно
|
||
$eff_d = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT `id2`,`mname` FROM `eff_main` WHERE `id2` = "' . $itm[0] . '" LIMIT 1'
|
||
)
|
||
);
|
||
if (isset($eff_d['id2'])) {
|
||
//добавляем эффект
|
||
|
||
$us = (new Magic())->addEffect($this->userinfo['id'], $itm[0], 1);
|
||
if ($us[0] == 1) {
|
||
$r .= '<div>На Вас наложили заклятие "' . $eff_d['mname'] . '".</div>';
|
||
} else {
|
||
$r .= '<div>Что-то пошло не так... Ощущается чье-то присутствие...</div>';
|
||
}
|
||
} else {
|
||
$r .= '<div>Что-то пошло не так... Слышен чей-то вой...</div>';
|
||
}
|
||
unset($eff_d, $us);
|
||
} else {
|
||
//не удачно
|
||
$r .= '<div>Не удалось...</div>';
|
||
}
|
||
$u->addAction(
|
||
time(), 'add_eff_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city']
|
||
);
|
||
} else {
|
||
//уже нельзя юзать
|
||
$r .= '<div>Что-то пошло не так...</div>';
|
||
}
|
||
|
||
unset($ch, $ch2);
|
||
$j++;
|
||
}
|
||
} elseif ($s[0] == 'mfast') {
|
||
//Добавляем баф //Ловушки и бафы
|
||
$j = 0;
|
||
$t = explode(',', $s[1]);
|
||
while ($j < count($t)) {
|
||
$itm = explode('=', $t[$j]);
|
||
$ch = ActionModel::testCount(["vars = bafit_{$this->info['id']}_{$obj['id']}"], 1 + (int)$itm[2]); //кол-во прошлых попыток
|
||
|
||
if ($ch < $itm[3]) {
|
||
if ($itm[2] * 1000 >= rand(1, 100000)) {
|
||
if ($itm[0] == 'hpNow') {
|
||
$mm = explode('r', $itm[1]);
|
||
if ($mm[1] != 0) {
|
||
$itm[1] = rand($mm[0], $mm[1]);
|
||
}
|
||
if ($itm[1] < 0) {
|
||
$r .= '<div>Вы попали в ловушку... Здоровье: <b>' . $itm[1] . ' HP</b></div>';
|
||
} elseif ($itm[1] > 0) {
|
||
$r .= '<div>Вы прикоснулись к магии... Здоровье: <b>+' . $itm[1] . ' HP</b></div>';
|
||
}
|
||
$this->userinfo['hpNow'] += $itm[1];
|
||
if ($this->userinfo['hpNow'] < 1) {
|
||
$r .= '<div>Вы перемещены в точку возрождения...</div>';
|
||
mysql_query(
|
||
'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` = "' . $this->userinfo['hpNow'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
}
|
||
}
|
||
}
|
||
$u->addAction(
|
||
time(), 'bafit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city']
|
||
);
|
||
}
|
||
//записываем попытку
|
||
$j++;
|
||
}
|
||
} elseif ($s[0] == 'save_pos') {
|
||
if (isset($act_sl['port'])) {
|
||
$itm = explode('=', $act_sl['port']);
|
||
$obj['x'] = $itm[0];
|
||
$obj['y'] = $itm[1];
|
||
}
|
||
#$r .= 'Позиция сохранена. Теперь после смерти вы оживете здесь.';
|
||
mysql_query(
|
||
'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]);
|
||
$this->userinfo['res_x'] = $itm[0];
|
||
$this->userinfo['res_y'] = $itm[1];
|
||
$upd = mysql_query(
|
||
'UPDATE `stats` SET `res_x` = "' . $this->userinfo['x'] . '",`res_y` = "' . $this->userinfo['y'] . '" WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
if ($upd) {
|
||
$r .= 'Вы куда-то переместились... на этот раз удачно...<br>';
|
||
} else {
|
||
$r .= 'Что-то здесь не так ...';
|
||
}
|
||
} elseif ($s[0] == 'port') {
|
||
//телепортирует пользователя
|
||
$itm = explode('=', $s[1]);
|
||
$this->userinfo['x'] = $itm[0];
|
||
$this->userinfo['y'] = $itm[1];
|
||
$upd = mysql_query(
|
||
'UPDATE `stats` SET
|
||
`x` = "' . $this->userinfo['x'] . '",`y` = "' . $this->userinfo['y'] . '"
|
||
WHERE `id` = "' . $this->userinfo['id'] . '" LIMIT 1'
|
||
);
|
||
if ($upd) {
|
||
$r .= 'Вы куда-то переместились... на этот раз удачно...<br>';
|
||
} else {
|
||
$r .= 'Что-то здесь не так ...';
|
||
}
|
||
} elseif ($s[0] == 'save_port') {
|
||
$itm = explode('=', $s[1]);
|
||
$this->userinfo['res_x'] = $itm[0];
|
||
$this->userinfo['res_y'] = $itm[1];
|
||
$upd = mysql_query(
|
||
'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') {
|
||
//Добавляем предмет
|
||
$j = 0;
|
||
$t = explode(',', $s[1]);
|
||
while ($j < count($t)) {
|
||
$itm = explode('=', $t[$j]);
|
||
$ch = ActionModel::testCount(["uid = {$this->userinfo['id']}", "vars = takeit_{$this->info['id']}_{$obj['id']}"], 1 + (int)$itm[2]); //кол-во прошлых попыток
|
||
|
||
if ($ch >= $itm[2]) {
|
||
//закончились попытки
|
||
$r = 'ничего не произошло...<br>';
|
||
} else {
|
||
if ($itm[1] * 1000 >= rand(1, 100000)) {
|
||
|
||
//Случайный предмет (Башня смерти)
|
||
if ($itm[0] == 'random1') {
|
||
$itm[0] = $this->itbs[rand(0, count($this->itbs))];
|
||
}
|
||
|
||
//удачная попытка
|
||
$it = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT * FROM `items_main` WHERE `id`="' . ((int)$itm[0]) . '" LIMIT 1'
|
||
)
|
||
);
|
||
if (isset($it['id'])) {
|
||
$r .= 'Вы обнаружили предмет "<b>' . $it['name'] . '</b>".<br>';
|
||
ItemsModel::addItem($it['id'], $this->userinfo['id']);
|
||
//ItemsModel::addItem(['uid' => $this->userinfo['id'], 'iid' => $it['id'], 'x' => $this->userinfo['x'], 'y' => $this->userinfo['y'], 'del' => (int)$itm[4]]);
|
||
}
|
||
} else {
|
||
//неудачная попытка
|
||
$r .= 'Вы ничего не нашли ...<br>';
|
||
}
|
||
$u->addAction(
|
||
time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city']
|
||
);
|
||
}
|
||
//записываем попытку
|
||
$j++;
|
||
}
|
||
} elseif ($s[0] == 'itm1') {
|
||
//Добавляем предмет , только 1 предмет из всех и все юзеры могут тоже
|
||
$t = explode(',', $s[1]);
|
||
$j = rand(0, count($t));
|
||
$itm = explode('=', $t[$j]);
|
||
$ch = ActionModel::testCount(["uid = {$this->userinfo['id']}", "vars = takeit_{$this->info['id']}_{$obj['id']}"], 1 + (int)$itm[2]); //кол-во прошлых попыток
|
||
|
||
if ($ch >= $itm[2]) {
|
||
//закончились попытки
|
||
$r .= 'Странно, но ничего не произошло... <br>';
|
||
} else {
|
||
if ($itm[1] * 1000 >= rand(1, 100000)) {
|
||
|
||
//Случайный предмет (Башня смерти)
|
||
if ($itm[0] == 'random1') {
|
||
$itm[0] = $this->itbs[rand(0, count($this->itbs))];
|
||
}
|
||
|
||
//удачная попытка
|
||
$it = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT * FROM `items_main` WHERE `id`="' . ((int)$itm[0]) . '" LIMIT 1'
|
||
)
|
||
);
|
||
if (isset($it['id'])) {
|
||
$r .= 'Вы обнаружили предмет "<b>' . $it['name'] . '</b>".<br>';
|
||
$u->addAction(
|
||
time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city']
|
||
);
|
||
ItemsModel::addItem($it['id'], $this->userinfo['id']);
|
||
//ItemsModel::addItem(['uid' => $this->userinfo['id'], 'iid' => $it['id'], 'x' => $this->userinfo['x'], 'y' => $this->userinfo['y'], 'del' => (int)$itm[4]]);
|
||
}
|
||
} else {
|
||
//неудачная попытка
|
||
$u->addAction(
|
||
time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city']
|
||
);
|
||
$r .= 'Вы ничего не нашли ... <br>';
|
||
}
|
||
}
|
||
|
||
} elseif ($s[0] == 'itm2') {
|
||
//Добавляем предмет , только 1 предмет из всех и только 1 юзер может поднять
|
||
|
||
$t = explode(',', $s[1]);
|
||
$j = rand(0, count($t) - 1);
|
||
$itm = explode('=', $t[$j]);
|
||
$ch = ActionModel::testCount(["vars = takeit_{$this->info['id']}_{$obj['id']}"], 1 + (int)$itm[2]); //кол-во прошлых попыток
|
||
|
||
if ($ch >= $itm[2]) {
|
||
//закончились попытки
|
||
$r .= 'Ничего не произошло... <br>';
|
||
} else {
|
||
if ($itm[1] * 1000 >= rand(1, 100000)) {
|
||
|
||
//Случайный предмет (Башня смерти)
|
||
if ($itm[0] == 'random1') {
|
||
$itm[0] = $this->itbs[rand(0, count($this->itbs))];
|
||
}
|
||
|
||
//удачная попытка
|
||
$it = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT * FROM `items_main` WHERE `id`="' . ((int)$itm[0]) . '" LIMIT 1'
|
||
)
|
||
);
|
||
if (isset($it['id'])) {
|
||
$r .= 'Вы обнаружили предмет "<b>' . $it['name'] . '</b>".<br>';
|
||
$u->addAction(
|
||
time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city']
|
||
);
|
||
ItemsModel::addItem($it['id'], $this->userinfo['id']);
|
||
//ItemsModel::addItem(['uid' => $this->userinfo['id'], 'iid' => $it['id'], 'x' => $this->userinfo['x'], 'y' => $this->userinfo['y'], 'del' => (int)$itm[4]]);
|
||
}
|
||
} else {
|
||
//неудачная попытка
|
||
$u->addAction(
|
||
time(), 'takeit_' . $this->info['id'] . '_' . $obj['id'], $this->userinfo['city']
|
||
);
|
||
$r .= 'Вы ничего не нашли ... <br>';
|
||
}
|
||
}
|
||
} elseif ($s[0] == 'fileact') {
|
||
require('dnaction/' . $s[1] . '.php');
|
||
}
|
||
$i++;
|
||
}
|
||
$r = rtrim($r, '\<br>');
|
||
if ($r == '') {
|
||
$r = 'В этот раз не удалось найти что-либо еще';
|
||
}
|
||
$this->error = $r;
|
||
}
|
||
} else {
|
||
$this->error = 'Предмет не найден ...';
|
||
}
|
||
}
|
||
|
||
public function botAtack($bot, $uid, $bs): void
|
||
{
|
||
### FIXME ВОЗМОЖНО тут потерялись [dungeon_bots.bot_group], ячейка отвечающая за группу разных ботов. Не вижу где это ипользуется. Тут только однотипные боты.
|
||
global $u;
|
||
|
||
$battleId = Db::getValue('select users.battle from users left join battle on users.battle = battle.id where users.id = ? and team_win = -1', [$uid['id']]);
|
||
|
||
if (empty($battleId)) { //Создаем поединок
|
||
Db::sql('insert into battle (dungeon, dn_id, x, y, time_start, type) values (?,?,?,?,unix_timestamp(), 0)', [$this->info['id2'], $this->info['id'], $bot['x'], $bot['y']]);
|
||
$battleId = Db::lastInsertId();
|
||
|
||
if ($battleId > 0) { //Добавляем ботов
|
||
$addBotQuantity = 0;
|
||
$dungeonBots = Db::getRow('select id_bot, colvo from dungeon_bots where for_dn = 0 and dn = ? and id2 = ?', [$this->info['id'], $bot['id2']]); //Только тот, который напал и жив ли он?
|
||
Db::sql('update dungeon_bots set inBattle = ? where id2 = ?', [$battleId, $bot['id2']]);
|
||
for ($i = 1; $i <= $dungeonBots['colvo']; $i++) {
|
||
$k = $u->addNewbot($dungeonBots['id_bot'], null, null);
|
||
if (!$k) {
|
||
continue;
|
||
}
|
||
|
||
Db::sql('update users left join stats on users.id = stats.id set battle = ?, team = 2 where users.id = ?', [$battleId, $k['id']]);
|
||
$addBotQuantity++;
|
||
}
|
||
|
||
if ($addBotQuantity > 0) {
|
||
Db::sql('update users left join stats on users.id = stats.id set battle = ?, team = 1 where users.id = ?', [$battleId, $uid['id']]);
|
||
}
|
||
}
|
||
|
||
} else {
|
||
//Добавляем ботов
|
||
$dungeonBots = Db::getRow('select id_bot, colvo from dungeon_bots where for_dn = 0 and dn = ? and id2 = ?', [$this->info['id'], $bot['id2']]);
|
||
Db::sql('update dungeon_bots set inBattle = ? where id2 = ?', [$battleId, $bot['id2']]);
|
||
|
||
$addBotQuantity = 0;
|
||
$botNamesArray = [];
|
||
for ($i = 1; $i <= $dungeonBots['colvo']; $i++) {
|
||
$k = $u->addNewbot($dungeonBots['id_bot'], null, null);
|
||
if (!$k) {
|
||
continue;
|
||
}
|
||
|
||
$botNamesArray[] = $k['login'];
|
||
Db::sql('update users left join stats on users.id = stats.id set battle = ?, team = 2 where users.id = ?', [$battleId, $k['id']]);
|
||
$addBotQuantity++;
|
||
}
|
||
|
||
if ($addBotQuantity > 0) {
|
||
$turnId = Db::getValue('select id_hod from battle_logs where battle = ? order by id_hod desc limit 1', [$battleId]);
|
||
if ($turnId > 0) {
|
||
Db::sql(
|
||
"insert into battle_logs (time, battle, id_hod, text, vars, zona1, zona2, zonb1, zonb2, type) values (unix_timestamp(),?,?,?,concat('time1=', unix_timestamp()),'','','','',1)",
|
||
[
|
||
$battleId,
|
||
$turnId + 1,
|
||
'{tm1} В поединок вмешались: <strong>' . implode(', ', $botNamesArray) . '</strong>.',
|
||
]
|
||
);
|
||
}
|
||
|
||
Db::sql('update users left join stats on users.id = stats.id set battle = ?, team = 1 where users.id = ?', [$battleId, $uid['id']]);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @param int $a
|
||
* @param User $user
|
||
* @return void
|
||
*/
|
||
private function look(int $a, User $user): void
|
||
{
|
||
if (!in_array($a, [1, 2])) {
|
||
return;
|
||
}
|
||
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): void
|
||
{
|
||
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;
|
||
}
|
||
$tgo = [0 => 0, 1 => 0];
|
||
if ($go == 1) {
|
||
$tgo[1] += 1;
|
||
} elseif ($go == 2) {
|
||
$tgo[0] -= 1;
|
||
} elseif ($go == 3) {
|
||
$tgo[1] -= 1;
|
||
} elseif ($go == 4) {
|
||
$tgo[0] += 1;
|
||
}
|
||
|
||
$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 = self::getDungeonMapCellRow($this->userinfo['x'], $this->userinfo['y'], $this->info['id2']);
|
||
|
||
//наличие предмета
|
||
if ($tmap['tr_items'] != '') {
|
||
$ti = explode(',', $tmap['tr_items']);
|
||
$i = 0;
|
||
$trnit = '';
|
||
while ($i < count($ti)) {
|
||
$ti2 = explode('=', $ti[$i]);
|
||
if ($ti2[0] > 0 && $ti2[1] > 0) {
|
||
$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++;
|
||
}
|
||
if ($trnit != '') {
|
||
$trnit = rtrim($trnit, ', ');
|
||
$this->error = 'У вас нет подходящего предмета. Требуется ' . $trnit;
|
||
}
|
||
}
|
||
|
||
$tmGo = $this->userinfo['timeGo'] - time(); //сколько секунд осталось
|
||
if ($tmGo > 0) {
|
||
$go = 0;
|
||
$this->error = 'Не так быстро...';
|
||
}
|
||
|
||
if (User::start()->aves['now'] >= User::start()->aves['max']) {
|
||
$go = 0;
|
||
$this->error = 'Вы не можете перемещаться, рюкзак переполнен ...';
|
||
}
|
||
|
||
if ($go > 0) {
|
||
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;
|
||
}
|
||
}
|
||
$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 = 'Вы переместились в другую комнату...';
|
||
}
|
||
|
||
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]);
|
||
}
|
||
|
||
private function genMatix(): array
|
||
{
|
||
$r = [];
|
||
if ($this->gs == 1) {
|
||
//1; //смотрим прямо
|
||
$r[1] = $this->getMatrix(0, -1); # слева от меня
|
||
$r[2] = $this->getMatrix(0, 0); # подомной
|
||
$r[3] = $this->getMatrix(0, 1); # справа от меня
|
||
$r[4] = $this->getMatrix(1, -1); # слева +1 вперед
|
||
$r[5] = $this->getMatrix(1, 0); # передомной +1
|
||
$r[6] = $this->getMatrix(1, 1); # справа +1 вперед
|
||
$r[7] = $this->getMatrix(2, 1); # справа +2 вперед
|
||
$r[8] = $this->getMatrix(2, 0); # передомной +2
|
||
$r[9] = $this->getMatrix(2, -1); # слева +2 вперед
|
||
$r[10] = $this->getMatrix(3, -2); # слева через одну, +3 вперед
|
||
$r[11] = $this->getMatrix(3, -1); # слева +3 вперед
|
||
$r[12] = $this->getMatrix(3, 0); # передомной +3
|
||
$r[13] = $this->getMatrix(3, 1); # справа +3 вперед
|
||
$r[14] = $this->getMatrix(3, 2); # справа через одну, +3 вперед
|
||
$r[15] = $this->getMatrix(4, 0); # передомной +4
|
||
$r[16] = $this->getMatrix(4, -1); # слева +4 вперед
|
||
$r[17] = $this->getMatrix(4, 1); # справа +4 вперед
|
||
$r[18] = $this->getMatrix(4, 2); # справа через одну, +4 вперед
|
||
$r[19] = $this->getMatrix(4, -2); # слева через одну, +4 вперед
|
||
|
||
} elseif ($this->gs == 2) {
|
||
//2; //смотрим лево
|
||
$r[1] = $this->getMatrix(-1, 0);
|
||
$r[2] = $this->getMatrix(0, 0);
|
||
$r[3] = $this->getMatrix(1, 0);
|
||
$r[4] = $this->getMatrix(-1, -1);
|
||
$r[5] = $this->getMatrix(0, -1);
|
||
$r[6] = $this->getMatrix(1, -1);
|
||
$r[7] = $this->getMatrix(1, -2);
|
||
$r[8] = $this->getMatrix(0, -2);
|
||
$r[9] = $this->getMatrix(-1, -2);
|
||
$r[10] = $this->getMatrix(-2, -3);
|
||
$r[11] = $this->getMatrix(-1, -3);
|
||
$r[12] = $this->getMatrix(0, -3);
|
||
$r[13] = $this->getMatrix(1, -3);
|
||
$r[14] = $this->getMatrix(2, -3);
|
||
$r[15] = $this->getMatrix(0, -4);
|
||
$r[16] = $this->getMatrix(-1, -4);
|
||
$r[17] = $this->getMatrix(1, -4);
|
||
$r[18] = $this->getMatrix(2, -4);
|
||
$r[19] = $this->getMatrix(-2, -4);
|
||
} elseif ($this->gs == 3) {
|
||
//3; //смотрим вниз
|
||
$r[1] = $this->getMatrix(0, 1);
|
||
$r[2] = $this->getMatrix(0, 0);
|
||
$r[3] = $this->getMatrix(0, -1);
|
||
$r[4] = $this->getMatrix(-1, 1);
|
||
$r[5] = $this->getMatrix(-1, 0);
|
||
$r[6] = $this->getMatrix(-1, -1);
|
||
$r[7] = $this->getMatrix(-2, -1);
|
||
$r[8] = $this->getMatrix(-2, 0);
|
||
$r[9] = $this->getMatrix(-2, 1);
|
||
$r[10] = $this->getMatrix(-3, 2);
|
||
$r[11] = $this->getMatrix(-3, 1);
|
||
$r[12] = $this->getMatrix(-3, 0);
|
||
$r[13] = $this->getMatrix(-3, -1);
|
||
$r[14] = $this->getMatrix(-3, -2);
|
||
$r[15] = $this->getMatrix(-4, 0);
|
||
$r[16] = $this->getMatrix(-4, 1);
|
||
$r[17] = $this->getMatrix(-4, -1);
|
||
$r[18] = $this->getMatrix(-4, -2);
|
||
$r[19] = $this->getMatrix(-4, 2);
|
||
} elseif ($this->gs == 4) {
|
||
//4; //смотрим право
|
||
$r[1] = $this->getMatrix(1, 0);
|
||
$r[2] = $this->getMatrix(0, 0);
|
||
$r[3] = $this->getMatrix(-1, 0);
|
||
$r[4] = $this->getMatrix(1, 1);
|
||
$r[5] = $this->getMatrix(0, 1);
|
||
$r[6] = $this->getMatrix(-1, 1);
|
||
$r[7] = $this->getMatrix(-1, 2);
|
||
$r[8] = $this->getMatrix(0, 2);
|
||
$r[9] = $this->getMatrix(1, 2);
|
||
$r[10] = $this->getMatrix(2, 3);
|
||
$r[11] = $this->getMatrix(1, 3);
|
||
$r[12] = $this->getMatrix(0, 3);
|
||
$r[13] = $this->getMatrix(-1, 3);
|
||
$r[14] = $this->getMatrix(-2, 3);
|
||
$r[15] = $this->getMatrix(0, 4);
|
||
$r[16] = $this->getMatrix(1, 4);
|
||
$r[17] = $this->getMatrix(-1, 4);
|
||
$r[18] = $this->getMatrix(-2, 4);
|
||
$r[19] = $this->getMatrix(2, 4);
|
||
}
|
||
return $r;
|
||
}
|
||
|
||
private function getMatrix($y, $x)
|
||
{
|
||
$this->cord['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(): array
|
||
{
|
||
$pd = array_fill(1, 28, 0);
|
||
|
||
//global $pd;
|
||
/* Генерируем изображение карты */
|
||
|
||
/* LEVEL 1 */
|
||
if ($this->testSt(2, 4)) {
|
||
$pd[28] = 1;
|
||
}
|
||
if ($this->testSt(2, 2)) {
|
||
$pd[27] = 1;
|
||
}
|
||
if ($this->testSt(2, 1)) {
|
||
$pd[26] = 1;
|
||
}
|
||
if ($this->testSt(3, 1)) {
|
||
$pd[25] = 1;
|
||
}
|
||
if ($this->testSt(1, 1)) {
|
||
$pd[24] = 1;
|
||
}
|
||
|
||
/* LEVEL 2 */
|
||
if ($this->testSt(5, 4)) {
|
||
$pd[23] = 1;
|
||
}
|
||
if ($this->testSt(5, 2)) {
|
||
$pd[22] = 1;
|
||
}
|
||
if ($this->testSt(5, 1)) {
|
||
$pd[21] = 1;
|
||
}
|
||
if ($this->testSt(6, 1)) {
|
||
$pd[20] = 1;
|
||
}
|
||
if ($this->testSt(4, 1)) {
|
||
$pd[19] = 1;
|
||
}
|
||
|
||
/* LEVEL 3 */
|
||
if ($this->testSt(8, 4)) {
|
||
$pd[18] = 1;
|
||
}
|
||
if ($this->testSt(8, 2)) {
|
||
$pd[17] = 1;
|
||
}
|
||
if ($this->testSt(8, 1)) {
|
||
$pd[16] = 1;
|
||
}
|
||
if ($this->testSt(7, 1)) {
|
||
$pd[15] = 1;
|
||
}
|
||
if ($this->testSt(9, 1)) {
|
||
$pd[14] = 1;
|
||
}
|
||
|
||
/* LEVEL 4 */
|
||
if ($this->testSt(12, 4) || $this->testSt(13, 2)) {
|
||
$pd[13] = 1;
|
||
}
|
||
if ($this->testSt(12, 2) || $this->testSt(11, 4)) {
|
||
$pd[12] = 1;
|
||
}
|
||
if ($this->testSt(13, 1) || $this->testSt(17, 3)) {
|
||
$pd[11] = 1;
|
||
} //8
|
||
if ($this->testSt(11, 1) || $this->testSt(16, 3)) {
|
||
$pd[10] = 1;
|
||
} //7
|
||
if ($this->testSt(12, 1)) {
|
||
$pd[9] = 1;
|
||
}
|
||
if ($this->testSt(14, 1) || $this->testSt(18, 3)) {
|
||
$pd[6] = 1;
|
||
} //2
|
||
if ($this->testSt(10, 1) || $this->testSt(19, 3)) {
|
||
$pd[5] = 1;
|
||
} //1
|
||
if ($this->testSt(16, 4) || $this->testSt(15, 2)) {
|
||
$pd[4] = 1;
|
||
}
|
||
if ($this->testSt(15, 4) || $this->testSt(17, 2)) {
|
||
$pd[3] = 1;
|
||
}
|
||
|
||
$this->walls = $pd;
|
||
/* Генерируем предметы на карте */
|
||
|
||
/* Генерируем персонажей и ботов на карте */
|
||
|
||
return $pd;
|
||
}
|
||
|
||
/** Видим ли мы стену?
|
||
* @param int $id
|
||
* @param int $s в какую сторону смотрим
|
||
* @return bool
|
||
*/
|
||
private function testSt(int $id, int $s): bool
|
||
{
|
||
$r = 0;
|
||
//заменяем отображение стен в зависимости от угла обзора
|
||
$s = $this->sg[$this->gs][$s];
|
||
if (isset($this->map[1][$id]['id'])) {
|
||
$r = $this->map[1][$id]['st'][($s - 1)];
|
||
}
|
||
return $r > 0;
|
||
}
|
||
|
||
public function pickitem($obj, int $itm, $for, $data = '', $dn_delete = false, $chat = 0): bool
|
||
{
|
||
$itm = mysql_fetch_assoc(
|
||
mysql_query('SELECT `id`,`name` FROM `items_main` WHERE `id` = "' . $itm . '" LIMIT 1')
|
||
);
|
||
if (!isset($itm['id'])) {
|
||
return false;
|
||
}
|
||
$tou = 0; //какому юзеру предназначено
|
||
/* выделяем случайного юзера из команды */
|
||
$asex = '';
|
||
if ($this->userinfo['sex'] == 1) {
|
||
$asex = 'а';
|
||
}
|
||
|
||
if ($for > 0) {
|
||
$tou = $for;
|
||
$rtxt = '<b>' . $this->userinfo['login'] . '</b> обнаружил' . $asex . ' предмет "' . $itm['name'] . '" в "' . $obj['name'] . '"';
|
||
} else {
|
||
$rtxt = '<b>' . $this->userinfo['login'] . '</b> обнаружил' . $asex . ' предмет "' . $itm['name'] . '" в "' . $obj['name'] . '", и вы решили разыграть его';
|
||
}
|
||
$dn_delete = $dn_delete ? 1 : 0;
|
||
|
||
if ($chat == 0) {
|
||
$this->sys_chat($rtxt);
|
||
}
|
||
mysql_query(
|
||
'INSERT INTO `dungeon_items` (`dn_delete`,`data`,`dn`,`user`,`item_id`,`time`,`x`,`y`) VALUES (
|
||
"' . $dn_delete . '",
|
||
"' . mysql_real_escape_string($data) . '",
|
||
"' . $this->userinfo['dnow'] . '",
|
||
"' . $tou . '",
|
||
"' . $itm['id'] . '",
|
||
"' . time() . '",
|
||
"' . $this->userinfo['x'] . '",
|
||
"' . $this->userinfo['y'] . '")'
|
||
);
|
||
|
||
return true;
|
||
}
|
||
|
||
public function n_lead(string $who, int $lead): void
|
||
{
|
||
$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) {
|
||
$this->error = '<b>Вы не лидер...</b>';
|
||
} elseif (!isset($to['id'])) {
|
||
$this->error = '<b>Персонаж не найден...</b>';
|
||
} elseif ($to['id'] == $this->info['uid']) {
|
||
$this->error = '<b>Вы и так лидер...</b>';
|
||
} elseif ($to['dnow'] != $this->info['id']) {
|
||
$this->error = '<b>Персонаж не найден в вашей команде...</b>';
|
||
} else {
|
||
mysql_query(
|
||
'UPDATE `dungeon_now` SET `uid` = "' . $to['id'] . '" WHERE `id` = "' . $this->info['id'] . '" LIMIT 1'
|
||
);
|
||
if ($this->userinfo['sex'] == 0) {
|
||
$this->sys_chat(
|
||
'<b>' . $this->userinfo['login'] . '</b> передал лидерство в группе персонажу <b>' . $who . '</b>'
|
||
);
|
||
} else {
|
||
$this->sys_chat(
|
||
'<b>' . $this->userinfo['login'] . '</b> передала лидерство в группе персонажу <b>' . $who . '</b>'
|
||
);
|
||
}
|
||
|
||
exit("<script>top.frames['main'].location = 'main.php'</script>");
|
||
}
|
||
}
|
||
|
||
public function go_to_hell(string $who, int $lead): void
|
||
{
|
||
$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) {
|
||
$this->error = '<b>Вы не лидер...</b>';
|
||
} elseif (!isset($to['id'])) {
|
||
$this->error = '<b>Персонаж не найден...</b>';
|
||
} elseif ($to['id'] == $this->info['uid']) {
|
||
$this->error = '<b>Лидера нельзя выгнать...</b>';
|
||
} elseif ($to['dnow'] != $this->info['id']) {
|
||
$this->error = '<b>Персонаж не найден в вашей команде...</b>';
|
||
} else {
|
||
$rb = 321; // Магический портал
|
||
if ($this->userinfo['room'] == 304) {
|
||
$rb = 209; // Вход в ледяную пещеру
|
||
} elseif ($this->userinfo['room'] == 396) {
|
||
$rb = 395; // Канализация (Ангелс)
|
||
} elseif ($this->info['id2'] == 3) {
|
||
$rb = 293; // Вход в Катакомбы
|
||
} elseif ($this->info['id2'] == 1) {
|
||
$rb = 188; // Вход в Канализацию
|
||
} elseif ($this->info['id2'] == 13) {
|
||
$rb = 275; // Гора Легиона
|
||
} elseif ($this->info['id2'] == 12) {
|
||
$rb = 372; // Вход в Пещеру Тысячи Проклятий
|
||
}
|
||
|
||
|
||
$sp = mysql_query('select * from dungeon_now where time_finish = 0 limit 50');
|
||
while ($pl = mysql_fetch_assoc($sp)) {
|
||
$cn = mysql_fetch_assoc(
|
||
mysql_query('SELECT `id` FROM `stats` WHERE `dnow` = "' . $pl['id'] . '" LIMIT 1')
|
||
);
|
||
if (!isset($cn['id'])) {
|
||
mysql_query('DELETE FROM `dungeon_bots` WHERE `dn` = "' . $pl['id'] . '" AND `for_dn` = "0"');
|
||
mysql_query('DELETE FROM `dungeon_obj` WHERE `dn` = "' . $pl['id'] . '" AND `for_dn` = "0"');
|
||
mysql_query('DELETE FROM `dungeon_items` WHERE `dn` = "' . $pl['id'] . '" AND `for_dn` = "0"');
|
||
mysql_query('DELETE FROM `dungeon_bots` WHERE `dn` = "' . $pl['id'] . '" AND `for_dn` = "0"');
|
||
mysql_query('DELETE FROM `dungeon_actions` WHERE `dn` = "' . $pl['id'] . '"');
|
||
mysql_query(
|
||
'UPDATE `dungeon_now` SET `time_finish` = "' . time() . '" WHERE `id` = "' . $pl['id'] . '" LIMIT 1'
|
||
);
|
||
}
|
||
}
|
||
|
||
$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` = "' . $this->userinfo['id'] . '" LIMIT 1');
|
||
mysql_query(
|
||
'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` = "' . $this->userinfo['id'] . '" AND `dn_delete` = "1" LIMIT 1000'
|
||
);
|
||
|
||
mysql_query(
|
||
'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 ($this->userinfo['sex'] == 0) {
|
||
$this->sys_chat(
|
||
'<b>' . $this->userinfo['login'] . '</b> выгнал из похода персонажа <b>' . $who . '</b>'
|
||
);
|
||
} else {
|
||
$this->sys_chat(
|
||
'<b>' . $this->userinfo['login'] . '</b> выгнала из похода персонажа <b>' . $who . '</b>'
|
||
);
|
||
}
|
||
|
||
exit("<script>top.frames['main'].location = 'main.php'</script>");
|
||
}
|
||
}
|
||
|
||
public function usersDng($laba = false): string
|
||
{
|
||
$r = '';
|
||
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'
|
||
);
|
||
} else {
|
||
$sp = mysql_query(
|
||
'SELECT `u`.`id` FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`st`.`id` = `u`.`id`) WHERE `u`.`room` = 370 AND `st`.`dnow` = "' . $laba . '" AND `st`.`bot` = 0 LIMIT 6'
|
||
);
|
||
}
|
||
while ($pl = mysql_fetch_assoc($sp)) {
|
||
$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 .= '<table border="0" cellspacing="0" cellpadding="0" height="20">
|
||
<tr><td valign="middle"> <font color="#990000">' . User::getLogin($pl['id']) . '</font> </td>
|
||
<td valign="middle" width="120" ';
|
||
if ($stt['mpAll'] < 1) {
|
||
$r .= 'style="padding-top:12px"';
|
||
}
|
||
$r .= '>
|
||
<div style="position:relative;"><div id="vhp' . ($pl['id'] + 1000000000000) . '" title="Уровень жизни" align="left" class="seehp" style="position:absolute; top:-10px; width:120px; height:10px; z-index:12;"> ' . floor(
|
||
$stt['hpNow']
|
||
) . '/' . $stt['hpAll'] . '</div>
|
||
<div title="Уровень жизни" class="hpborder" style="position:absolute; top:-10px; width:120px; height:9px; z-index:13;"><img src="//img.new-combats.tech/1x1.gif" height="9" width="1"></div>
|
||
<div class="hp_3 senohp" style="height:9px; width:' . floor(
|
||
120 / 100 * $ph
|
||
) . 'px; position:absolute; top:-10px; z-index:11;" id="lhp' . ($pl['id'] + 1000000000000) . '"><img src="//img.new-combats.tech/1x1.gif" height="9" width="1"></div>
|
||
<div title="Уровень жизни" class="hp_none" style="position:absolute; top:-10px; width:120px; height:10px; z-index:10;"><img src="//img.new-combats.tech/1x1.gif" height="10"></div>
|
||
';
|
||
if ($stt['mpAll'] > 0) {
|
||
$r .= '<div id="vmp' . ($pl['id'] + 1000000000000) . '" title="Уровень маны" align="left" class="seemp" style="position:absolute; top:0px; width:120px; height:10px; z-index:12;"> ' . floor(
|
||
$stt['mpNow']
|
||
) . '/' . $stt['mpAll'] . '</div>
|
||
<div title="Уровень маны" class="hpborder" style="position:absolute; top:0px; width:120px; height:9px; z-index:13;"><img src="//img.new-combats.tech/1x1.gif" height="9" width="1"></div>
|
||
<div class="hp_mp senohp" style="height:9px; position:absolute; top:0px; width:' . floor(
|
||
120 / 100 * $pm
|
||
) . 'px; z-index:11;" id="lmp' . ($pl['id'] + 1000000000000) . '"><img src="//img.new-combats.tech/1x1.gif" height="9" width="1"></div>
|
||
<div title="Уровень маны" class="hp_none" style="position:absolute; top:0px; width:120px; height:10px; z-index:10;"></div>';
|
||
}
|
||
$r .= '</div></td><td>';
|
||
if ($this->info['uid'] == $pl['id']) {
|
||
$r .= '<img src="//img.new-combats.tech/i/lead1.gif" title="Лидер группы" >';
|
||
}
|
||
if ($this->info['uid'] == $this->userinfo['id'] && $pl['id'] == $this->userinfo['id'] && $this->info['id2'] != 15) {
|
||
$r .= '<a href="javascript: void(0);" onclick="top.n_lead();"><img src="//img.new-combats.tech/i/ico/ico_change_leader.gif" title="Новый лидер" /></a> ';
|
||
$r .= '<a href="javascript: void(0);" onclick="top.go_from_psh();"><img src="//img.new-combats.tech/i/ico/ico_kill_member.gif" title="Выгнать супостата" /></a> ';
|
||
}
|
||
$r .= '</td></tr></table><br>';
|
||
$r .= '<script>top.startHpRegen("main",' . ($pl['id'] + 1000000000000) . ',' . (0 + $stt['hpNow']) . ',' . (0 + $stt['hpAll']) . ',' . (0 + $stt['mpNow']) . ',' . (0 + $stt['mpAll']) . ',0,0,0,0,1)</script>';
|
||
}
|
||
|
||
return $r;
|
||
}
|
||
|
||
public function testDie()
|
||
{
|
||
$dies = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'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 ($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) {
|
||
//21:50 Ярополк трагически погиб и находится в комнате "Этаж 2 - Водосток"
|
||
$dnow = mysql_fetch_assoc(
|
||
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` = "' . $this->userinfo['res_x'] . '" AND `y` = "' . $this->userinfo['res_y'] . '" AND `id_dng` = "' . $dnow['id2'] . '" LIMIT 1'
|
||
)
|
||
);
|
||
|
||
if ($this->userinfo['sex'] == 0) {
|
||
$this->sys_chat(
|
||
'<b>' . $this->userinfo['login'] . '</b> трагически погиб и находится в комнате "' . $room['name'] . '"'
|
||
);
|
||
} else {
|
||
$this->sys_chat(
|
||
'<b>' . $this->userinfo['login'] . '</b> трагически погибла и находится в комнате "' . $room['name'] . '"'
|
||
);
|
||
}
|
||
mysql_query(
|
||
'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('<script>top.frames[\'main\'].location = "main.php";</script>');
|
||
} else {
|
||
//21:50 Ярополк трагически погиб и находится в комнате "Этаж 2 - Водосток"
|
||
if ($this->userinfo['sex'] == 0) {
|
||
$this->sys_chat('<b>' . $this->userinfo['login'] . '</b> трагически погиб без права на воскрешение');
|
||
} else {
|
||
$this->sys_chat('<b>' . $this->userinfo['login'] . '</b> трагически погибла без права на воскрешение');
|
||
}
|
||
$_GET['exitd'] = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
public function itemsMap(): string
|
||
{
|
||
$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` = "' . $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` = "' . $this->userinfo['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string(
|
||
$pl['id']
|
||
) . '" LIMIT 1'
|
||
)
|
||
);
|
||
$luck_users = $luck_users[0];
|
||
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` = "' . $this->userinfo['id'] . '" AND `dn` = "' . $this->info['id'] . '" AND `vars` = "luck_itm' . $pl['id'] . '" LIMIT 1'
|
||
)
|
||
);
|
||
//Розыгрыш
|
||
if (!isset($fxv['id']) && $this->info['bsid'] == 0) {
|
||
$action = "javascript: top.fartgame('{$pl['id']}', '{$pl['img']}', '{$pl['name']}')";
|
||
$tk = 1;
|
||
}
|
||
}
|
||
if ($tk == 0) {
|
||
$r .= '<a onclick="takeItem(' . $pl['id'] . ')"><img style="padding: 5px; cursor: pointer;" title="Взять "' . $pl['name'] . '"" src="//img.new-combats.tech/i/items/' . $pl['img'] . '" /></a>';
|
||
} elseif ($tk == 1) {
|
||
$r .= '<a href="' . $action . '"><img style="padding: 5px; cursor: pointer;" title="Взять "' . $pl['name'] . '"" src="//img.new-combats.tech/i/items/' . $pl['img'] . '" /></a>';
|
||
}
|
||
}
|
||
if ($r != '') {
|
||
$r = '<H4>В комнате разбросаны вещи:</H4>' . $r; //<br> <a onclick="takeItemAll">Подобрать все</a><br>
|
||
}
|
||
return $r;
|
||
}
|
||
|
||
public function genObjects(): string
|
||
{
|
||
////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` <= ' . ($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` = "' . $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 = [];
|
||
while ($pl = mysql_fetch_assoc($sp)) {
|
||
if (!isset($this->cord[$pl['y'] . '_' . $pl['x']])) {
|
||
continue;
|
||
}
|
||
|
||
if (
|
||
$pl['fix_x_y'] != 0 &&
|
||
($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;
|
||
}
|
||
|
||
if (
|
||
($pl['os1'] == 0 && $pl['os2'] == 0 && $pl['os3'] == 0 && $pl['os4'] == 0) ||
|
||
(
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os1'] ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os2'] ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os3'] ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os4']
|
||
)
|
||
) {
|
||
$i++;
|
||
if (!isset($pos[$this->cord[$pl['y'] . '_' . $pl['x']]])) {
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]] = 0;
|
||
}
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]]++;
|
||
$r .= ',' . ($i - 1) . ':{0:' . $pl['id'] . ',1:\'' . $pl['name'] . '\',2:' . (0 + $this->cord[$pl['y'] . '_' . $pl['x']]) . ',3:\'action\',4:\'' . $pl['img'] . '\',5:' . $pl['type'] . ',6:0,7:' . $pl['w'] . ',8:' . $pl['h'] . ',9:' . $pl['left'] . ',10:' . $pl['top'] . ',11:' . $pl['date'] . '}';
|
||
} elseif (
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os1'] - 1 ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os2'] - 1 ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os3'] - 1 ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os4'] - 1
|
||
) {
|
||
$dt2 = explode(',', ltrim(rtrim($pl['date'], '\}'), '\{'));
|
||
$da = [];
|
||
$is = 0;
|
||
while ($is < count($dt2)) {
|
||
$dt2[$is] = explode(':', $dt2[$is]);
|
||
$da[$dt2[$is][0]] = $dt2[$is][1];
|
||
$is++;
|
||
}
|
||
if (isset($da['use'])) {
|
||
unset($da['use']);
|
||
} // Справа
|
||
if (isset($da['rl2'])) {
|
||
$da['rl2'] = -round((int)$da['rl2'] * 1.55);
|
||
} // Слева
|
||
if (isset($da['rl3'])) {
|
||
$da['rl3'] = round((int)$da['rl3'] + 160);
|
||
}
|
||
if (isset($da['rl4'])) {
|
||
$da['rl4'] = round((int)$da['rl4'] - 120);
|
||
}
|
||
$pl['date'] = str_replace('"', '', json_encode($da));
|
||
|
||
|
||
$i++;
|
||
if (!isset($pos[$this->cord[$pl['y'] . '_' . $pl['x']]])) {
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]] = 0;
|
||
}
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]]++;
|
||
$r .= ',' . ($i - 1) . ':{0:' . $pl['id'] . ',1:\'' . $pl['name'] . '\',2:' . (0 + $this->cord[$pl['y'] . '_' . $pl['x']]) . ',3:\'\',4:\'' . $pl['img'] . '\',5:' . $pl['type'] . ',6:0,7:' . $pl['w'] . ',8:' . $pl['h'] . ',9:' . $pl['left'] . ',10:' . $pl['top'] . ',11:' . $pl['date'] . '}';
|
||
} elseif (
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os1'] + 1 ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os2'] + 1 ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os3'] + 1 ||
|
||
$this->cord[$pl['y'] . '_' . $pl['x']] == $pl['os4'] + 1
|
||
) {
|
||
|
||
$dt2 = explode(',', ltrim(rtrim($pl['date'], '\}'), '\{'));
|
||
$da = [];
|
||
$is = 0;
|
||
while ($is < count($dt2)) {
|
||
$dt2[$is] = explode(':', $dt2[$is]);
|
||
$da[$dt2[$is][0]] = $dt2[$is][1];
|
||
$is++;
|
||
}
|
||
if (isset($da['use'])) {
|
||
unset($da['use']);
|
||
} // Справа
|
||
if (isset($da['rl2'])) {
|
||
$da['rl2'] = 355 - round((int)$da['rl2'] * 0.30);
|
||
} // Справа
|
||
if (isset($da['rl3'])) {
|
||
$da['rl3'] = round((int)$da['rl3'] - 160);
|
||
}
|
||
if (isset($da['rl4'])) {
|
||
$da['rl4'] = round((int)$da['rl4'] + 120);
|
||
}
|
||
$pl['date'] = str_replace('"', '', json_encode($da));
|
||
$i++;
|
||
if (!isset($pos[$this->cord[$pl['y'] . '_' . $pl['x']]])) {
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]] = 0;
|
||
}
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]]++;
|
||
$r .= ',' . ($i - 1) . ':{0:' . $pl['id'] . ',1:\'' . $pl['name'] . '\',2:' . (0 + $this->cord[$pl['y'] . '_' . $pl['x']]) . ',3:\'\',4:\'' . $pl['img'] . '\',5:' . $pl['type'] . ',6:0,7:' . $pl['w'] . ',8:' . $pl['h'] . ',9:' . $pl['left'] . ',10:' . $pl['top'] . ',11:' . $pl['date'] . '}';
|
||
}
|
||
}
|
||
return 'count:' . $i . $r;
|
||
}
|
||
|
||
public function genUsers(): string
|
||
{
|
||
////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 <= ' . ($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 => [$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` = "' . $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` = "' . $this->userinfo['dnow'] . '" AND ' . $whr[$this->gs] . ' AND `u`.`id` != "' . $this->userinfo['id'] . '" LIMIT 100'
|
||
);
|
||
$i = 0;
|
||
$pos = [];
|
||
while ($pl = mysql_fetch_assoc($sp)) {
|
||
$i++;
|
||
if (!isset($pos[$this->cord[$pl['y'] . '_' . $pl['x']]])) {
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]] = 0;
|
||
}
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]]++;
|
||
$noat = 0;
|
||
if ($this->info['bsid'] > 0) {
|
||
$noat = 1;
|
||
}
|
||
if ($this->info['id2'] == 15) {
|
||
//Хоккей
|
||
$r .= ',' . ($i - 1) . ':{8:' . $noat . ',0:' . $pl['id'] . ',1:\'' . $pl['login'] . '\',2:' . (0 + $this->cord[$pl['y'] . '_' . $pl['x']]) . ',3:' . $pl['sex'] . ',4:\'' . str_replace(
|
||
'.gif', '', $pl['obraz']
|
||
) . '\',5:\'user\',6:' . $pos[$this->cord[$pl['y'] . '_' . $pl['x']]] . '';
|
||
//
|
||
$tms = mysql_fetch_assoc(
|
||
mysql_query('SELECT * FROM `katok_now` WHERE `clone` = "' . $pl['id'] . '" LIMIT 1')
|
||
);
|
||
if ($tms['team'] == $tmsu['team']) {
|
||
$r .= ',9:1';
|
||
} else {
|
||
$r .= ',9:2';
|
||
}
|
||
$r .= '';
|
||
//
|
||
$r .= '}';
|
||
} else {
|
||
$r .= ',' . ($i - 1) . ':{9:0,8:' . $noat . ',0:' . $pl['id'] . ',1:\'' . $pl['login'] . '\',2:' . (0 + $this->cord[$pl['y'] . '_' . $pl['x']]) . ',3:' . $pl['sex'] . ',4:\'' . str_replace(
|
||
'.gif', '', $pl['obraz']
|
||
) . '\',5:\'user\',6:' . $pos[$this->cord[$pl['y'] . '_' . $pl['x']]] . '}';
|
||
}
|
||
}
|
||
|
||
//отображаем ботов
|
||
//
|
||
//$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` = "' . $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 сек.
|
||
if ($pl['go_bot'] > 0 && $pl['go_bot'] <= time()) {
|
||
$tgx = rand(-1, 1);
|
||
$tgy = rand(-1, 1);
|
||
if ($tgx != 0 && $tgy != 0) {
|
||
if (rand(0, 1) == 1) {
|
||
$tgy = 0;
|
||
} else {
|
||
$tgx = 0;
|
||
}
|
||
}
|
||
$vlb = $this->cellIsGoodforAction($pl['x'], $pl['y'], $pl['x'] + $tgx, $pl['y'] + $tgy);
|
||
//Кто-то рядом
|
||
$tuz = mysql_fetch_assoc(
|
||
mysql_query(
|
||
'SELECT `x`,`y`,`id`,`hpNow` FROM `stats` WHERE `dnow` = "' . $this->info['id'] . '" AND ( (`x` = ' . ($pl['x'] + 1) . ' AND `y` = ' . ($pl['y']) . ') OR (`x` = ' . ($pl['x'] - 1) . ' AND `y` = ' . ($pl['y']) . ') OR (`x` = ' . ($pl['x']) . ' AND `y` = ' . ($pl['y'] + 1) . ') OR (`x` = ' . ($pl['x']) . ' AND `y` = ' . ($pl['y'] - 1) . ') ) LIMIT 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(
|
||
'UPDATE `stats` SET `x` = "' . $tuz['x'] . '" , `y` = "' . $tuz['y'] . '" WHERE `id` = "' . $tuz['id'] . '" LIMIT 1'
|
||
);
|
||
$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` = "' . $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) { // Передвижение ботов.
|
||
$pl['go_bot'] = time() + 10 + rand(1, 5);
|
||
$pl['x'] += $tgx;
|
||
$pl['y'] += $tgy;
|
||
mysql_query(
|
||
'UPDATE `dungeon_bots` SET `x` = "' . $pl['x'] . '",`y` = "' . $pl['y'] . '",`go_bot` = "' . $pl['go_bot'] . '" WHERE `id2` = "' . $pl['id2'] . '" LIMIT 1'
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
$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',
|
||
[$this->userinfo['dnow'], $whrVals[$this->gs][0], $whrVals[$this->gs][1], $whrVals[$this->gs][2], $whrVals[$this->gs][3],]
|
||
);
|
||
|
||
foreach ($botsArr as $pl) {
|
||
if (!isset($this->cord[$pl['y'] . '_' . $pl['x']])) {
|
||
continue;
|
||
}
|
||
// }
|
||
//
|
||
// $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 ' . $whr[$this->gs] . ' AND `u`.`delete` = "0" LIMIT 50'
|
||
// );
|
||
// while ($pl = mysql_fetch_assoc($sp)) {
|
||
$i++;
|
||
if (!isset($pos[$this->cord[$pl['y'] . '_' . $pl['x']]])) {
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]] = 0;
|
||
}
|
||
$pos[$this->cord[$pl['y'] . '_' . $pl['x']]]++;
|
||
$dlg = 0;
|
||
if ($pl['dialog'] > 0) {
|
||
$dlg = $pl['dialog'];
|
||
}
|
||
$noat = 1;
|
||
if ($pl['noatack'] == 1 && $this->info['bsid'] == 0) {
|
||
$noat = 0;
|
||
}
|
||
$r .= ',' . ($i - 1) . ':{9:0,0:' . $pl['id2'] . ',1:\'' . $pl['login'] . '\',2:' . ((int)$this->cord[$pl['y'] . '_' . $pl['x']]) . ',3:' . $pl['sex'] . ',4:\'' . str_replace(
|
||
'.gif', '', $pl['obraz']
|
||
) . '\',5:\'bot\',6:' . $pos[$this->cord[$pl['y'] . '_' . $pl['x']]] . ',7:' . $dlg . ',8:' . $noat . '}';
|
||
}
|
||
|
||
return 'count:' . $i . $r;
|
||
}
|
||
|
||
public function testGone($id)
|
||
{
|
||
$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];
|
||
}
|
||
|
||
$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;
|
||
}
|
||
$tgo = [0 => 0, 1 => 0];
|
||
if ($go == 1) {
|
||
$tgo[1] += 1;
|
||
} elseif ($go == 2) {
|
||
$tgo[0] -= 1;
|
||
} elseif ($go == 3) {
|
||
$tgo[1] -= 1;
|
||
} elseif ($go == 4) {
|
||
$tgo[0] += 1;
|
||
}
|
||
|
||
$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);
|
||
}
|
||
}
|