refactor
This commit is contained in:
parent
7266569f69
commit
d36d5361f2
448
_incl_data/crons/DungeonBotLogic.php
Normal file
448
_incl_data/crons/DungeonBotLogic.php
Normal file
@ -0,0 +1,448 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace crons;
|
||||||
|
class DungeonBotLogic
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Перемещение ботов по пещере и напедение, когда игрок рядом.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function start()
|
||||||
|
{
|
||||||
|
# Выбираем всех ботов.
|
||||||
|
# В выборку включено: Позиция бота, Направление куда он может идти, Существует ли рядом Игрок, его координаты и в поединке ли он.
|
||||||
|
$sql = "
|
||||||
|
select
|
||||||
|
dnow.id as this_dn,
|
||||||
|
dnow.id2 as dn_id,
|
||||||
|
dbots.id2,
|
||||||
|
dbots.id_bot,
|
||||||
|
tb.login as login,
|
||||||
|
dbots.colvo,
|
||||||
|
dbots.go_bot,
|
||||||
|
dbots.x,
|
||||||
|
dbots.y,
|
||||||
|
dbots.s,
|
||||||
|
dbots.atack,
|
||||||
|
tb.agressor,
|
||||||
|
dmap.go_1 as goRight,
|
||||||
|
dmap.go_2 as goLeft,
|
||||||
|
dmap.go_3 as goTop,
|
||||||
|
dmap.go_4 as goBottom,
|
||||||
|
dmap.no_bot as noBot,
|
||||||
|
uinfo.id as userId,
|
||||||
|
uinfo.login as userLogin,
|
||||||
|
ustats.hpNow as userHP,
|
||||||
|
ustats.x as userPosX,
|
||||||
|
ustats.y as userPosY,
|
||||||
|
uinfo.battle as userBattle
|
||||||
|
from dungeon_now as dnow
|
||||||
|
left join dungeon_bots as dbots on dbots.dn = dnow.id
|
||||||
|
left join dungeon_map as dmap on (dmap.x = dbots.x and dmap.y = dbots.y and dmap.id_dng = dnow.id2)
|
||||||
|
left join test_bot as tb on dbots.id_bot = tb.id
|
||||||
|
left join stats as ustats on ((ustats.x+1 >= dbots.x and ustats.x-1 <= dbots.x) and (ustats.y+1 >= dbots.y and ustats.y-1 <= dbots.y) and ustats.dnow = dnow.id )
|
||||||
|
left join users as uinfo on ( ustats.id = uinfo.id )
|
||||||
|
where
|
||||||
|
dnow.time_finish = 0 and
|
||||||
|
dbots.atack = 0 and
|
||||||
|
dbots.delete = 0 and
|
||||||
|
dbots.for_dn = 0 and
|
||||||
|
((dbots.go_bot between unix_timestamp() - 32400 and unix_timestamp()) or dbots.go_bot = 1) and dbots.inBattle = 0
|
||||||
|
group by dbots.id2, dbots.go_bot
|
||||||
|
order by dbots.go_bot";
|
||||||
|
|
||||||
|
$botMovements = Db::getRows($sql);
|
||||||
|
foreach ($botMovements as $bot) {
|
||||||
|
$sTo = $bot['s'];
|
||||||
|
$xFrom = $bot['x']; # текущие координаты X
|
||||||
|
$yFrom = $bot['y']; # текущие координаты Y
|
||||||
|
|
||||||
|
$return = self::moveBots($bot['s'], $bot);
|
||||||
|
$xTo = $bot['x'] + $return['x'];
|
||||||
|
$yTo = $bot['y'] + $return['y'];
|
||||||
|
# Проверяем, имеется ли переход по клетке.
|
||||||
|
$inSight = 0;
|
||||||
|
if (isset($bot['id2'])) {
|
||||||
|
if ($xFrom == $xTo && $yFrom == $yTo) { # Если остаемся на месте.
|
||||||
|
$inSight = 1;
|
||||||
|
} elseif (isset($bot['goRight']) && $xFrom == $xTo - 1 && $bot['goRight'] == 1) { //право
|
||||||
|
$sTo = 4;
|
||||||
|
$inSight = 1;
|
||||||
|
} elseif (isset($bot['goLeft']) && $xFrom == $xTo + 1 && $bot['goLeft'] == 1) { //лево
|
||||||
|
$sTo = 2;
|
||||||
|
$inSight = 1;
|
||||||
|
} elseif (isset($bot['goTop']) && $yFrom == $yTo - 1 && $bot['goTop'] == 1) { //верх
|
||||||
|
$sTo = 1;
|
||||||
|
$inSight = 1;
|
||||||
|
} elseif (isset($bot['goBottom']) && $yFrom == $yTo + 1 && $bot['goBottom'] == 1) { //низ
|
||||||
|
$sTo = 3;
|
||||||
|
$inSight = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
isset($bot['userId'], $bot['userPosY'], $bot['userPosX']) &&
|
||||||
|
$bot['userId'] != '' &&
|
||||||
|
$bot['agressor'] == 1 &&
|
||||||
|
(
|
||||||
|
($bot['userPosY'] == $bot['y'] + 1 && $bot['userPosX'] == $bot['x']) ||
|
||||||
|
($bot['userPosY'] == $bot['y'] - 1 && $bot['userPosX'] == $bot['x']) ||
|
||||||
|
($bot['userPosY'] == $bot['y'] && $bot['userPosX'] == $bot['x'] - 1) ||
|
||||||
|
($bot['userPosY'] == $bot['y'] && $bot['userPosX'] == $bot['x'] + 1)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
$bot['userPosY'] = $yFrom;
|
||||||
|
$bot['userPosX'] = $xFrom;
|
||||||
|
Db::sql('update stats set x = ?, y = ? where id = ?', [$xFrom, $yFrom, $bot['userId']]);
|
||||||
|
self::botAttack($bot, $bot);
|
||||||
|
} elseif (
|
||||||
|
isset($bot['userId'], $bot['userPosY'], $bot['userPosX']) &&
|
||||||
|
$bot['userId'] != '' &&
|
||||||
|
$inSight == 1 &&
|
||||||
|
$yTo == $bot['userPosY'] &&
|
||||||
|
$xTo == $bot['userPosX'] &&
|
||||||
|
$bot['atack'] == 1
|
||||||
|
) {
|
||||||
|
self::botAttack($bot, $bot);
|
||||||
|
} elseif ($inSight == 1) { // Передвижение ботов.
|
||||||
|
$bot['go_bot'] = time() + rand(7, 15);
|
||||||
|
Db::sql('update dungeon_bots set x = ?, y = ?, s = ?, go_bot = ? where id2 = ?', [$xTo, $yTo, $sTo, $bot['go_bot'], $bot['id2']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function moveBots($direction, $b): array
|
||||||
|
{
|
||||||
|
$toGoX = 0;
|
||||||
|
$toGoY = 0;
|
||||||
|
|
||||||
|
if (isset($b['noBot']) && $b['noBot'] != '0000') {
|
||||||
|
if ($b['noBot'][0] != '0') {
|
||||||
|
$b['goTop'] = 0;
|
||||||
|
}
|
||||||
|
if ($b['noBot'][1] != '0') {
|
||||||
|
$b['goLeft'] = 0;
|
||||||
|
}
|
||||||
|
if ($b['noBot'][2] != '0') {
|
||||||
|
$b['goBottom'] = 0;
|
||||||
|
}
|
||||||
|
if ($b['noBot'][3] != '0') {
|
||||||
|
$b['goRight'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$go = [
|
||||||
|
1 => ['d' => $b['goTop'], 'go1' => $b['goLeft'], 'go2' => (int)$b['goRight'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
||||||
|
2 => ['d' => $b['goLeft'], 'go1' => (int)$b['goBottom'], 'go2' => $b['goTop'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
||||||
|
3 => ['d' => (int)$b['goBottom'], 'go1' => (int)$b['goRight'], 'go2' => $b['goLeft'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
||||||
|
4 => ['d' => (int)$b['goRight'], 'go1' => $b['goTop'], 'go2' => (int)$b['goBottom'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
||||||
|
];
|
||||||
|
$dir = [
|
||||||
|
1 => ['moveForward' => ['x' => '0', 'y' => '1'], 'moveBack' => ['x' => '0', 'y' => '-1'], 'moveGo1' => ['x' => '-1', 'y' => '0'], 'moveGo2' => ['x' => '1', 'y' => '0']],
|
||||||
|
2 => ['moveForward' => ['x' => '-1', 'y' => '0'], 'moveBack' => ['x' => '1', 'y' => '0'], 'moveGo1' => ['x' => '0', 'y' => '-1'], 'moveGo2' => ['x' => '0', 'y' => '1']],
|
||||||
|
3 => ['moveForward' => ['x' => '0', 'y' => '-1'], 'moveBack' => ['x' => '0', 'y' => '1'], 'moveGo1' => ['x' => '1', 'y' => '0'], 'moveGo2' => ['x' => '-1', 'y' => '0']],
|
||||||
|
4 => ['moveForward' => ['x' => '1', 'y' => '0'], 'moveBack' => ['x' => '-1', 'y' => '0'], 'moveGo1' => ['x' => '0', 'y' => '1'], 'moveGo2' => ['x' => '0', 'y' => '-1']],
|
||||||
|
];
|
||||||
|
$go = $go[$direction];
|
||||||
|
$dir = $dir[$direction];
|
||||||
|
if ($go['d'] == 1) {
|
||||||
|
$toGoY = $dir['moveForward']['y'];
|
||||||
|
$toGoX = $dir['moveForward']['x'];
|
||||||
|
if (rand(1, 100) > 66) {
|
||||||
|
if ($go['go1'] == 1 && $go['go2'] == 0) {
|
||||||
|
$toGoY = $dir['moveGo1']['y'];
|
||||||
|
$toGoX = $dir['moveGo1']['x'];
|
||||||
|
} elseif ($go['go1'] == 0 && $go['go2'] == 1) {
|
||||||
|
$toGoY = $dir['moveGo2']['y'];
|
||||||
|
$toGoX = $dir['moveGo2']['x'];
|
||||||
|
} elseif ($go['go1'] == 1 && $go['go2'] == 1) {
|
||||||
|
$a = rand(1, 2);
|
||||||
|
$toGoY = $dir['moveGo' . $a]['y'];
|
||||||
|
$toGoX = $dir['moveGo' . $a]['x'];
|
||||||
|
}
|
||||||
|
} elseif (rand(1, 100) > 96) {
|
||||||
|
$toGoY = $dir['moveBack']['y'];
|
||||||
|
$toGoX = $dir['moveBack']['x'];
|
||||||
|
}
|
||||||
|
} elseif ($go['d'] == 0) {
|
||||||
|
if ($go['go1'] == 1 && $go['go2'] == 1) {
|
||||||
|
if (rand(0, 1) == 1) {
|
||||||
|
$toGoY = $dir['moveGo1']['y'];
|
||||||
|
$toGoX = $dir['moveGo1']['x'];
|
||||||
|
} else {
|
||||||
|
$toGoY = $dir['moveGo2']['y'];
|
||||||
|
$toGoX = $dir['moveGo2']['x'];
|
||||||
|
}
|
||||||
|
} elseif ($go['go1'] == 1 && $go['go2'] == 0) {
|
||||||
|
$toGoY = $dir['moveGo1']['y'];
|
||||||
|
$toGoX = $dir['moveGo1']['x'];
|
||||||
|
} elseif ($go['go1'] == 0 && $go['go2'] == 1) {
|
||||||
|
$toGoY = $dir['moveGo2']['y'];
|
||||||
|
$toGoX = $dir['moveGo2']['x'];
|
||||||
|
} elseif ($go['go1'] == 0 && $go['go2'] == 0) {
|
||||||
|
$toGoY = $dir['moveBack']['y'];
|
||||||
|
$toGoX = $dir['moveBack']['x'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ['x' => (int)$toGoX, 'y' => (int)$toGoY];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Совершаем действие -> Нападение на игрока.
|
||||||
|
* @param array $bot
|
||||||
|
* @param array $user
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function botAttack(array $bot, array $user)
|
||||||
|
{
|
||||||
|
if (Db::getValue('select count(*) from battle where id = ? and team_win = -1', [$user['userBattle']]) > 0) {
|
||||||
|
self::joinBattle($bot, $user['id'], $user['userBattle']);
|
||||||
|
} else { //Создаем поединок
|
||||||
|
$sql = 'insert into battle (dungeon, dn_id, x, y, city, time_start, type) values (?,?,?,?,?,unix_timestamp(),0)';
|
||||||
|
$args = [
|
||||||
|
$bot['dn_id'],
|
||||||
|
$bot['this_dn'],
|
||||||
|
$bot['x'],
|
||||||
|
$bot['y'],
|
||||||
|
$bot['userCity'],
|
||||||
|
];
|
||||||
|
Db::sql($sql, $args);
|
||||||
|
|
||||||
|
$battleId = Db::lastInsertId();
|
||||||
|
|
||||||
|
if ($battleId > 0) {
|
||||||
|
self::addBots($bot, $user['userId'], $battleId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Вмешиваемся в поединок.
|
||||||
|
* @param array $bot
|
||||||
|
* @param int $userid
|
||||||
|
* @param int $battleid
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function joinBattle(array $bot, int $userid, int $battleid)
|
||||||
|
{
|
||||||
|
$j = 0;
|
||||||
|
$jui = 1;
|
||||||
|
$loginsBot = [];
|
||||||
|
$loginsBotText = [];
|
||||||
|
$loginsBotVars = ['time1=' . time()];
|
||||||
|
|
||||||
|
$loginsBotInBattle = Db::getRows('select substring_index(login, ?, 1) as login2, count(login) as count, login from battle_users where battle = ? and team = 2 group by login2',
|
||||||
|
[' (', $battleid]);
|
||||||
|
|
||||||
|
foreach ($loginsBotInBattle as $row) {
|
||||||
|
$loginsBot[$row['login2']] = (int)$row['count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Db::sql('update dungeon_bots set inBattle = ? where id2 = ?', [$battleid, $bot['id2']]);
|
||||||
|
|
||||||
|
while ($jui <= $bot['colvo']) {
|
||||||
|
$k = self::botAddBattle($bot, $loginsBot);
|
||||||
|
$loginsBot = $k['logins_bot'];
|
||||||
|
$loginsBotText[] = ' <strong>' . $k['login'] . '</strong>';
|
||||||
|
if ($k) {
|
||||||
|
self::queryUsersSetBattle($battleid, $k['id']);
|
||||||
|
self::queryStatsSetTeam(2, $k['id']);
|
||||||
|
$j++;
|
||||||
|
}
|
||||||
|
$jui++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($j > 0) {
|
||||||
|
$loginsBotText = '{tm1} В поединок вмешались: ' . implode(', ', $loginsBotText) . '.';
|
||||||
|
$loginsBotVars = implode('||', $loginsBotVars);
|
||||||
|
$battleLogTurnId = Db::getValue('select id_hod from battle_logs where battle = ? order by id_hod desc limit 1', [$battleid]);
|
||||||
|
|
||||||
|
if ($battleLogTurnId > 0) {
|
||||||
|
Db::sql('insert into battle_logs (time, battle, id_hod, text, vars, zona1, zonb1, zona2, zonb2, type) values (unix_timestamp(), ?,?,?,?,?,?,?,?,1)',
|
||||||
|
[$battleid, $battleLogTurnId + 1, $loginsBotText, $loginsBotVars, '', '', '', '']);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::queryUsersSetBattle($battleid, $userid);
|
||||||
|
self::queryStatsSetTeam(1, $userid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Совершаем нападение -> Добавляем Ботов в поединок
|
||||||
|
* @param array $bot
|
||||||
|
* @param array $loginsBot
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
private static function botAddBattle(array $bot, array $loginsBot)
|
||||||
|
{
|
||||||
|
$addBot = Db::getRow('select
|
||||||
|
login,
|
||||||
|
if(time_reg = 100, unix_timestamp(), time_reg) as time_reg,
|
||||||
|
align,
|
||||||
|
level,
|
||||||
|
name,
|
||||||
|
sex,
|
||||||
|
obraz,
|
||||||
|
stats,
|
||||||
|
upLevel,
|
||||||
|
itemsUse
|
||||||
|
from test_bot where id = ?', [$bot['id_bot']]);
|
||||||
|
|
||||||
|
if (!$addBot) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($loginsBot[$addBot['login']])) {
|
||||||
|
$loginsBot[$addBot['login']]++;
|
||||||
|
$addBot['login'] = $addBot['login'] . ' (' . $loginsBot[$addBot['login']] . ')';
|
||||||
|
} else {
|
||||||
|
$loginsBot[$addBot['login']] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'insert into users (align, login, level, pass, city, cityreg, name, sex, timereg, obraz, bot_id) values (?,?,?,?,?,?,?,?,?,?,?)';
|
||||||
|
$args = [
|
||||||
|
$addBot['align'],
|
||||||
|
$addBot['login'],
|
||||||
|
$addBot['level'],
|
||||||
|
password_hash($addBot['login'] . mt_rand(10, 99), PASSWORD_DEFAULT),
|
||||||
|
'Городские трущобы',
|
||||||
|
'Городские трущобы',
|
||||||
|
$addBot['name'],
|
||||||
|
$addBot['sex'],
|
||||||
|
$addBot['time_reg'],
|
||||||
|
$addBot['obraz'],
|
||||||
|
$bot['id_bot'],
|
||||||
|
];
|
||||||
|
Db::sql($sql, $args);
|
||||||
|
|
||||||
|
# Если бот успешно создан.
|
||||||
|
$botid = Db::lastInsertId();
|
||||||
|
Db::sql('insert into stats (id, stats, hpNow, upLevel, bot) values (?,?,1000000,?,1)', [$botid, $addBot['stats'], $addBot['upLevel']]);
|
||||||
|
|
||||||
|
//Добавляем значения не из базы.
|
||||||
|
$addBot['id'] = $botid;
|
||||||
|
$addBot['logins_bot'] = $loginsBot;
|
||||||
|
|
||||||
|
//Выдаем предметы
|
||||||
|
self::botWearItems(explode(',', $addBot['itemsUse']), $botid);
|
||||||
|
return $addBot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Одеваем предметы в слоты бота.
|
||||||
|
* @param array $items
|
||||||
|
* @param int $botid
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function botWearItems(array $items, int $botid)
|
||||||
|
{
|
||||||
|
$w3b = 0;
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$idiu = self::botAddItem($item, $botid);
|
||||||
|
(int)$islot = Db::getValue('select inslot from items_main where id = ?', [$item]);
|
||||||
|
if (empty($islot)) {
|
||||||
|
$islot = 2000;
|
||||||
|
} else {
|
||||||
|
if ($islot === 3) {
|
||||||
|
if ($w3b === 1) {
|
||||||
|
$islot = 14;
|
||||||
|
} else {
|
||||||
|
$w3b = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($idiu, $islot)) {
|
||||||
|
Db::sql('update items_users set inOdet = ? where id = ?', [$islot, $idiu]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Выдаем предметы Боту.
|
||||||
|
* @param $itemId
|
||||||
|
* @param $botUid
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private static function botAddItem($itemId, $botUid): int
|
||||||
|
{
|
||||||
|
$item = Db::getRow('select overTypei, data, iznosMAXi, magic_inci from items_main left join items_main_data on items_id = items_main.id where items_main.id = ?', [$itemId]);
|
||||||
|
if (!$item) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$sql = 'insert into items_users (overType, item_id, uid, data, iznosMAX, magic_inc, lastUPD, time_create) values (?,?,?,?,?,?,unix_timestamp(),unix_timestamp())';
|
||||||
|
$args = [
|
||||||
|
$item['overTypei'],
|
||||||
|
$itemId,
|
||||||
|
$botUid,
|
||||||
|
$item['data'],
|
||||||
|
$item['iznosMAXi'],
|
||||||
|
$item['magic_inci'],
|
||||||
|
];
|
||||||
|
Db::sql($sql, $args);
|
||||||
|
return (int)Db::lastInsertId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function queryUsersSetBattle(int $battleId, int $userId): void
|
||||||
|
{
|
||||||
|
Db::sql('update users set battle = ? where id = ?', [$battleId, $userId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function queryStatsSetTeam(int $team, int $id)
|
||||||
|
{
|
||||||
|
if (!in_array($team, [1, 2])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Db::sql('update stats set team = ? where id = ?', [$team, $id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Добавляем ботов.
|
||||||
|
* @param array $bot
|
||||||
|
* @param int $userid
|
||||||
|
* @param int $battleid
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function addBots(array $bot, int $userid, int $battleid)
|
||||||
|
{
|
||||||
|
$j = 0;
|
||||||
|
$jui = 1;
|
||||||
|
$loginsBot = [];
|
||||||
|
|
||||||
|
Db::sql('update dungeon_bots set inBattle = ? where id2 = ?', [$battleid, $bot['id2']]);
|
||||||
|
|
||||||
|
while ($jui <= $bot['colvo']) {
|
||||||
|
$k = self::botAddBattle($bot, $loginsBot);
|
||||||
|
$loginsBot = $k['logins_bot'];
|
||||||
|
if ($k) {
|
||||||
|
self::queryUsersSetBattle($battleid, $k['id']);
|
||||||
|
self::queryStatsSetTeam(2, $k['id']);
|
||||||
|
$j++;
|
||||||
|
}
|
||||||
|
$jui++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($j > 0) {
|
||||||
|
self::queryUsersSetBattle($battleid, $userid);
|
||||||
|
self::queryStatsSetTeam(1, $userid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Запуск раз в миниту
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Core\Db;
|
||||||
|
|
||||||
|
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
|
# Страница создана 0.0000
|
||||||
|
$mtime = explode(" ", microtime());
|
||||||
|
$tstart = $mtime[1] + $mtime[0];
|
||||||
|
|
||||||
|
# Запускаем выполнение процесса.
|
||||||
|
DungeonBotLogic::start();
|
||||||
|
|
||||||
|
$mtime = explode(" ", microtime());
|
||||||
|
$mtime = $mtime[1] + $mtime[0];
|
||||||
|
$totaltime = ($mtime - $tstart);
|
||||||
|
printf("Страница сгенерирована за %f секунд !", $totaltime);
|
53
_incl_data/crons/auction.php
Normal file
53
_incl_data/crons/auction.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Core\Db;
|
||||||
|
|
||||||
|
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CRON Комиссионного магазина
|
||||||
|
* Если предмет висит уже 2 и более недель, продавать предмет за 50% от его стоимости с учетом износа.
|
||||||
|
*
|
||||||
|
* Запуск раз в минуту.
|
||||||
|
*
|
||||||
|
* @author Insallah
|
||||||
|
*/
|
||||||
|
|
||||||
|
const TIME_LAST = 86400; // 1 day
|
||||||
|
const AUC = '<span style="color: #009966;">Филиал Аукциона</span>';
|
||||||
|
const AUC_WIN = 'Вы выиграли торги. Предмет "%s" за <b>%s кр.</b> был добавлен к вам в инвентарь.';
|
||||||
|
const AUC_SELL = 'Предмет "%s" был продан на торгах, <b>%s</b> кр. за товар отправлены вам по почте.';
|
||||||
|
const AUC_NOT_SELL = 'Предмет "%s" не был продан, он возвращен вам в инвентарь.';
|
||||||
|
|
||||||
|
function sendToChat(string $message, string $to = '', string $from = '')
|
||||||
|
{
|
||||||
|
$sql = 'insert into chat (new, login, `to`, text, time, type) values (1, ?, ?, ?, unix_timestamp(), 6)';
|
||||||
|
Db::sql($sql, [$from, $to, $message]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeOwner(int $userId, int $itemId)
|
||||||
|
{
|
||||||
|
$sql = 'update items_users set uid = ?, lastUPD = unix_timestamp() where (id = ? or inGroup = ?) and uid = 0';
|
||||||
|
Db::sql($sql, [$userId, $itemId, $itemId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = Db::getRow('select * from items_auc where time_end = 0 and time < unix_timestamp() - ? order by user_buy', [TIME_LAST]);
|
||||||
|
foreach ($items as $item) {
|
||||||
|
if ($item['x'] > 0) {
|
||||||
|
$item['name'] .= ' (x' . $item['x'] . ')';
|
||||||
|
}
|
||||||
|
$userLogin = Db::getValue('select login from users where id = ?', [$item['uid']]);
|
||||||
|
if ($item['user_buy'] && Db::getValue('select count(*) from users where id = ?', [$item['user_buy']])) {
|
||||||
|
changeOwner($item['user_buy'], $item['item_id']);
|
||||||
|
sendToChat(sprintf(AUC_WIN, $item['name'], $item['price']), $item['user_buy'], AUC);
|
||||||
|
if ($userLogin) {
|
||||||
|
sendToChat(sprintf(AUC_SELL, $item['name'], $item['price']), $userLogin, AUC);
|
||||||
|
Db::sql('insert into items_users (`delete`, item_id, 1price, uid, lastUPD, `data`) values (0, 1220, ?, ?, unix_timestamp(), ?)', [$item['price'], '-51' . $item['uid'], '']);
|
||||||
|
}
|
||||||
|
} elseif ($userLogin) {
|
||||||
|
changeOwner($item['uid'], $item['item_id']);
|
||||||
|
|
||||||
|
sendToChat(sprintf(AUC_NOT_SELL, $item['name']), $userLogin, AUC);
|
||||||
|
}
|
||||||
|
Db::sql('update items_auc set time_end = unix_timestamp() where id = ?', [$item['id']]);
|
||||||
|
}
|
122
_incl_data/crons/clear.php
Normal file
122
_incl_data/crons/clear.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
# Каждую полночь
|
||||||
|
use Core\Db;
|
||||||
|
|
||||||
|
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CRON Очистки сервера от ненужной информации
|
||||||
|
* Действия:
|
||||||
|
* 1. Очистка чата
|
||||||
|
* 2. Очистка заявок в поединки
|
||||||
|
* 3. Очистка заявок в пещеры
|
||||||
|
* 4. Очистка походов
|
||||||
|
* */
|
||||||
|
|
||||||
|
// ЕБИИИИИИИЧЕСКАЯ СИИИИЛА!!!!! (с) Инс.
|
||||||
|
// forign_keys! Никто не знает про foreign_keys!
|
||||||
|
|
||||||
|
function clearUsersFromDb(array $uidsArray, array $loginsArray)
|
||||||
|
{
|
||||||
|
$uids = implode(',', $uidsArray);
|
||||||
|
$logins = implode(',', $loginsArray);
|
||||||
|
Db::sql('delete from aaa_znahar where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from actions where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from add_smiles where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from a_com_act where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from bandit where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from bank_alh where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from battle_actions where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from battle_cache where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from battle_last where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from battle_users where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from battle_act where uid1 in (?) or uid2 in (?)', [$uids, $uids]);
|
||||||
|
Db::sql('delete from battle_stat where uid1 in (?) or uid2 in (?)', [$uids, $uids]);
|
||||||
|
Db::sql('delete from bs_actions where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from bs_zv where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from building where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from complects_priem where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from dialog_act where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from dump where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from dungeon_actions where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from eff_users where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from ekr_sale where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from feerverks where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from fontan where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from fontan_hp where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from fontan_text where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from friends where user in (?) or friend in (?) or enemy in (?) or notinlist in (?) or ignor in (?) or login_ignor in (?) or user_ignor in (?)',
|
||||||
|
[$uids, $uids, $uids, $uids, $uids, $logins, $logins]);
|
||||||
|
Db::sql('delete from house where owner in (?)', [$uids]);
|
||||||
|
Db::sql('delete from items_img where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from items_users where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from izlom_rating where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from laba_act where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from laba_itm where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from lastnames where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from logs_auth where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from loto_win where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from mults where uid in (?) or uid2 in (?)', [$uids, $uids]);
|
||||||
|
Db::sql('delete from notepad where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from obraz where uid in (?) or login in (?)', [$uids, $logins]);
|
||||||
|
Db::sql('delete from online where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from pirogi where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from reimage where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from rep where id in (?)', [$uids]);
|
||||||
|
Db::sql('delete from repass where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from ruletka_coin where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from save_com where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from stats where id in (?)', [$uids]);
|
||||||
|
Db::sql('delete from transfers where uid1 in (?) or uid2 in (?)', [$uids, $uids]);
|
||||||
|
Db::sql('delete from users where id in (?)', [$uids]);
|
||||||
|
Db::sql('delete from users_delo where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from users_animal where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from users_gifts where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from users_ico where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from users_reputation where user_id in (?)', [$uids]);
|
||||||
|
Db::sql('delete from users_turnirs where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from users_twink where uid in (?)', [$uids]);
|
||||||
|
Db::sql('delete from zayvki where creator in (?)', [$uids]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//1. Очистка чата, остается чат только за последние 3 дня
|
||||||
|
//Db::sql('delete from chat where time < unix_timestamp() - 86400 * 3');
|
||||||
|
|
||||||
|
//2. Очистка заявок в поединки
|
||||||
|
Db::sql('delete from zayvki where start > 0 or cancel > 0 or time < unix_timestamp() - 86400');
|
||||||
|
|
||||||
|
//3. Очистка заявок в пещеры
|
||||||
|
Db::sql('delete from dungeon_zv where `delete` > 0 or time < unix_timestamp() - 86400');
|
||||||
|
|
||||||
|
//4. Очистка походов
|
||||||
|
$idsArr = Db::getColumn('select id from dungeon_now where time_start < unix_timestamp() - 86400 or time_finish > 0');
|
||||||
|
$idsStr = implode(',', $idsArr);
|
||||||
|
Db::sql('delete from dungeon_actions where dn in (?)', [$idsStr]);
|
||||||
|
Db::sql('delete from dungeon_bots where dn in (?)', [$idsStr]);
|
||||||
|
Db::sql('delete from dungeon_items where dn in (?)', [$idsStr]);
|
||||||
|
Db::sql('delete from dungeon_obj where dn in (?)', [$idsStr]);
|
||||||
|
Db::sql('delete from dungeon_now where id in (?)', [$idsStr]);
|
||||||
|
|
||||||
|
//5. Очистка монстров
|
||||||
|
$botuids = [];
|
||||||
|
$botlogins = [];
|
||||||
|
|
||||||
|
$bots = Db::getRows('select users.id, login
|
||||||
|
from users
|
||||||
|
left join battle on users.battle = battle.id
|
||||||
|
where `real` = 0 and battle.id = 0 and team_win >= 0 and not exists(select 1 from users where inUser = users.id) order by id');
|
||||||
|
|
||||||
|
foreach ($bots as $bot) {
|
||||||
|
$botuids[] = $bot['id'];
|
||||||
|
$botlogins[] = $bot['login'];
|
||||||
|
}
|
||||||
|
|
||||||
|
clearUsersFromDb($botuids, $botlogins);
|
||||||
|
|
||||||
|
Db::sql('delete from stats where id not in (select id from users)');
|
||||||
|
Db::sql('delete from items_users where `delete` > time_create and `delete` > 0');
|
||||||
|
|
||||||
|
//6. Очистка личного дела
|
||||||
|
//mysql_query('DELETE FROM `users_delo` WHERE `time` < "'.(time()-86400*30).'" LIMIT 1000');
|
||||||
|
|
@ -9,7 +9,6 @@ require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
|
|||||||
* Если предмет висит уже 2 и более недель, продавать предмет за 50% от его стоимости с учетом износа.
|
* Если предмет висит уже 2 и более недель, продавать предмет за 50% от его стоимости с учетом износа.
|
||||||
* Деньги отсылаются на почту.
|
* Деньги отсылаются на почту.
|
||||||
* @author Insallah
|
* @author Insallah
|
||||||
* @todo проверить на конфликты с cshop_sellToShop.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# Каждый понедельник в 12 дня.
|
# Каждый понедельник в 12 дня.
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Core\Db;
|
|
||||||
|
|
||||||
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CRON Комиссионного магазина
|
|
||||||
* Если предмет висит уже 2 и более недель, продавать предмет за 50% от его стоимости с учетом износа.
|
|
||||||
* Деньги отсылаются на почту.
|
|
||||||
*
|
|
||||||
* Примерно вот так должен выглядеть нормальный крон. Меньше левых зависимостей, нет подтягиванию половины движка.
|
|
||||||
* Всё ещё не идеально, но уже неплохо.
|
|
||||||
*
|
|
||||||
* Запуск раз в минуту.
|
|
||||||
*
|
|
||||||
* @author Ivor Barhansky <me@lopar.space>
|
|
||||||
* @todo проверить на конфликты с cshop_returnToOwner.
|
|
||||||
* @todo Вернуть запросы взад и вывести их из циклов. "нормальный крон", ёпт, под какими веществами я это делал?
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TIME_LAST = 86400; // 1 day
|
|
||||||
const AUC = '<span style="color: #009966;">Филиал Аукциона</span>';
|
|
||||||
const AUC_WIN = 'Вы выиграли торги. Предмет "%s" за <b>%s кр.</b> был добавлен к вам в инвентарь.';
|
|
||||||
const AUC_SELL = 'Предмет "%s" был продан на торгах, <b>%s</b> кр. за товар отправлены вам по почте.';
|
|
||||||
const AUC_SELL_LOG = 'Филиал Аукциона: Предмет "%s" был продан за <b>%s кр</b>.';
|
|
||||||
const AUC_NOT_SELL = 'Предмет "%s" не был продан, он возвращен вам в инвентарь.';
|
|
||||||
|
|
||||||
$query = [ //all queries
|
|
||||||
'insert into chat (new, login, `to`, text, time, type) values (1, ?, ?, ?, unix_timestamp(), 6)',
|
|
||||||
'select * from items_auc where time_end = 0 and time < unix_timestamp() - ? order by user_buy',
|
|
||||||
'select login from users where id = ?',
|
|
||||||
'select count(*) from users where id = ?',
|
|
||||||
'update items_users set uid = ?, lastUPD = unix_timestamp() where (id = ? or inGroup = ?) and uid = 0',
|
|
||||||
'insert into items_users (`delete`, item_id, 1price, uid, lastUPD, `data`) values (0, 1220, ?, ?, unix_timestamp(), ?)',
|
|
||||||
'insert into post (uid, sender_id, time, money, text) values (?, 0, unix_timestamp(), ?, ?)',
|
|
||||||
'update items_auc set time_end = unix_timestamp() where id = ?',
|
|
||||||
];
|
|
||||||
|
|
||||||
$sp = Db::getRow($query[1], [TIME_LAST]);
|
|
||||||
foreach ($sp as $pl) {
|
|
||||||
if ($pl['x'] > 0) {
|
|
||||||
$pl['name'] .= ' (x' . $pl['x'] . ')';
|
|
||||||
}
|
|
||||||
$userLogin = Db::getValue($query[2], [$pl['uid']]);
|
|
||||||
if ($pl['user_buy'] && Db::getValue($query[3], [$pl['user_buy']])) {
|
|
||||||
Db::sql($query[4], [$pl['user_buy'], $pl['item_id'], $pl['item_id']]);
|
|
||||||
Db::sql($query[0], [AUC, $pl['user_buy'], sprintf(AUC_WIN, $pl['name'], $pl['price'])]);
|
|
||||||
if ($userLogin) {
|
|
||||||
Db::sql($query[0], [AUC, $userLogin, sprintf(AUC_SELL, $pl['name'], $pl['price'])]);
|
|
||||||
Db::sql($query[5], [$pl['price'], '-51' . $pl['uid'], '']);
|
|
||||||
Db::sql($query[6], [$pl['uid'], $pl['price'], sprintf(AUC_SELL_LOG, $pl['name'], $pl['price'])]);
|
|
||||||
}
|
|
||||||
} elseif ($userLogin) {
|
|
||||||
Db::sql($query[4], [$pl['uid'], $pl['item_id'], $pl['item_id']]);
|
|
||||||
Db::sql($query[0], [AUC, $userLogin, sprintf(AUC_NOT_SELL, $pl['name'])]);
|
|
||||||
}
|
|
||||||
Db::sql($query[7], [$pl['id']]);
|
|
||||||
}
|
|
@ -104,10 +104,17 @@ foreach ($keys as $key) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$prize = [
|
||||||
|
1 => $xu_list[0] * 0.3,
|
||||||
|
2 => $xu_list[1] * 0.2,
|
||||||
|
3 => $xu_list[2] * 0.1,
|
||||||
|
];
|
||||||
|
const RATING_MSG = 'Клан %s получает %s екр. в казну клана за %s-е место в рейтинге!';
|
||||||
|
|
||||||
$stmt = Db::prepare('update clan set money2 = money2 + ? where id = ?');
|
$stmt = Db::prepare('update clan set money2 = money2 + ? where id = ?');
|
||||||
$stmt->execute([$xu_list[0] * 0.3, $keys[0]]);
|
$stmt->execute([$prize[1], $keys[0]]);
|
||||||
$stmt->execute([$xu_list[1] * 0.2, $keys[1]]);
|
$stmt->execute([$prize[2], $keys[1]]);
|
||||||
$stmt->execute([$xu_list[2] * 0.1, $keys[2]]);
|
$stmt->execute([$prize[3], $keys[2]]);
|
||||||
|
|
||||||
Db::sql(
|
Db::sql(
|
||||||
'insert into chat (text, city, type, new, time) values
|
'insert into chat (text, city, type, new, time) values
|
||||||
@ -117,9 +124,9 @@ Db::sql(
|
|||||||
(?,\'capitalcity\',6,1,unix_timestamp())',
|
(?,\'capitalcity\',6,1,unix_timestamp())',
|
||||||
[
|
[
|
||||||
'<span style="color: red; font-weight: bold;">Рейтинг кланов ' . date('d-m-Y') . ' </span>',
|
'<span style="color: red; font-weight: bold;">Рейтинг кланов ' . date('d-m-Y') . ' </span>',
|
||||||
'Клан ' . $log_list[0] . ' получает ' . $xu_list[0] * 0.3 . ' Екр. в казну клана за 1-е место в рейтинге!',
|
sprintf(RATING_MSG, $log_list[0], $prize[1], 1),
|
||||||
'Клан ' . $log_list[1] . ' получает ' . $xu_list[1] * 0.2 . ' Екр. в казну клана за 2-е место в рейтинге!',
|
sprintf(RATING_MSG, $log_list[1], $prize[2], 2),
|
||||||
'Клан ' . $log_list[2] . ' получает ' . $xu_list[2] * 0.1 . ' Екр. в казну клана за 3-е место в рейтинге!',
|
sprintf(RATING_MSG, $log_list[2], $prize[3], 3),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -107,6 +107,8 @@ foreach ($keys as $key) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PRIZE_MSG = 'Игрок %s получает %s екр. за %s-е место в рейтинге!';
|
||||||
|
|
||||||
$stmt = Db::prepare('update users set money2 = money2 + ? where id = ?');
|
$stmt = Db::prepare('update users set money2 = money2 + ? where id = ?');
|
||||||
$stmt->execute([1, $keys[0]]);
|
$stmt->execute([1, $keys[0]]);
|
||||||
$stmt->execute([0.75, $keys[1]]);
|
$stmt->execute([0.75, $keys[1]]);
|
||||||
@ -124,10 +126,10 @@ Db::sql(
|
|||||||
(?,\'capitalcity\',6,1,unix_timestamp())',
|
(?,\'capitalcity\',6,1,unix_timestamp())',
|
||||||
[
|
[
|
||||||
'<span style="color: red; font-weight: bold;">Рейтинг игроков ' . date('d-m-Y') . ' </span>',
|
'<span style="color: red; font-weight: bold;">Рейтинг игроков ' . date('d-m-Y') . ' </span>',
|
||||||
'Игрок ' . $log_list[0] . ' получает 1 Екр. за 1-е место в рейтинге!',
|
sprintf(PRIZE_MSG, $log_list[0], 1, 1),
|
||||||
'Игрок ' . $log_list[1] . ' получает 0.75 Екр. за 2-е место в рейтинге!',
|
sprintf(PRIZE_MSG, $log_list[1], 0.75, 2),
|
||||||
'Игрок ' . $log_list[2] . ' получает 0.5 Екр. за 3-е место в рейтинге!',
|
sprintf(PRIZE_MSG, $log_list[2], 0.5, 3),
|
||||||
'Игрок ' . $log_list[3] . ' получает 0.25 Екр. за 4-е место в рейтинге!',
|
sprintf(PRIZE_MSG, $log_list[3], 0.25, 4),
|
||||||
'Игрок ' . $log_list[4] . ' получает 0.15 Екр. за 5-е место в рейтинге!',
|
sprintf(PRIZE_MSG, $log_list[4], 0.15, 5),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -1,152 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
# Каждую полночь
|
|
||||||
|
|
||||||
const GAME = true;
|
|
||||||
include('/home/newcom1/public_html/_incl_data/class/__db_connect.php');
|
|
||||||
|
|
||||||
if( isset($_GET['actions']) ) {
|
|
||||||
//
|
|
||||||
$data = array();
|
|
||||||
//
|
|
||||||
$sp = mysql_query('SELECT * FROM `actions`');
|
|
||||||
while( $pl = mysql_fetch_array($sp) ) {
|
|
||||||
$pl['vars'] = str_replace(0,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(1,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(2,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(3,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(4,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(5,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(6,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(7,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(8,'%',$pl['vars']);
|
|
||||||
$pl['vars'] = str_replace(9,'%',$pl['vars']);
|
|
||||||
$data[$pl['vars']]++;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
print_r($data);
|
|
||||||
//
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
CRON Очистки сервера от ненужной информации
|
|
||||||
Действия:
|
|
||||||
1. Очистка чата
|
|
||||||
2. Очистка заявок в поединки
|
|
||||||
3. Очистка заявок в пещеры
|
|
||||||
4. Очистка походов
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// ЕБИИИИИИИЧЕСКАЯ СИИИИЛА!!!!! (с) Инс.
|
|
||||||
// forign_keys! Никто не знает про foreign_keys!
|
|
||||||
|
|
||||||
function delete_user_all( $uid , $login ) {
|
|
||||||
mysql_query('DELETE FROM `aaa_znahar` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `actions` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `add_smiles` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `a_com_act` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `bandit` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `bank_alh` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `battle_act` WHERE `uid1` = "'.$uid.'" OR `uid2` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `battle_actions` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `battle_cache` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `battle_last` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `battle_stat` WHERE `uid1` = "'.$uid.'" OR `uid2` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `battle_users` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `bs_actions` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `bs_zv` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `building` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `buy_ekr` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `complects_priem` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `dialog_act` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `dump` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `dungeon_actions` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `ekr_sale` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `feerverks` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `fontan` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `fontan_hp` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `fontan_text` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `friends` WHERE `user` = "'.$uid.'"
|
|
||||||
OR `friend` = "'.$uid.'"
|
|
||||||
OR `enemy` = "'.$uid.'"
|
|
||||||
OR `notinlist` = "'.$uid.'"
|
|
||||||
OR `ignor` = "'.$uid.'"
|
|
||||||
OR `login_ignor` = "'.$login.'"
|
|
||||||
OR `user_ignor` = "'.$login.'"');
|
|
||||||
mysql_query('DELETE FROM `house` WHERE `owner` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `items_img` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `items_users` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `izlom_rating` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `laba_act` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `laba_itm` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `lastnames` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `logs_auth` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `loto_win` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `mults` WHERE `uid` = "'.$uid.'" OR `uid2` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `notepad` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `obraz` WHERE `uid` = "'.$uid.'" OR `login` = "'.$login.'"');
|
|
||||||
mysql_query('DELETE FROM `online` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `pirogi` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `reimage` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `rep` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `repass` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `ruletka_coin` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `save_com` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `stats` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `transfers` WHERE `uid1` = "'.$uid.'" OR `uid2` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `users` WHERE `id` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `stats` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `users_delo` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `users_animal` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `users_gifts` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `users_ico` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `users_reputation` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `users_turnirs` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `users_twink` WHERE `uid` = "'.$uid.'"');
|
|
||||||
mysql_query('DELETE FROM `zayavki` WHERE `creator` = "'.$uid.'"');
|
|
||||||
}
|
|
||||||
|
|
||||||
//1. Очистка чата, остается чат только за последние 3 дня
|
|
||||||
mysql_query('DELETE FROM `chat` WHERE `time` < '.(time()-86400*3).'');
|
|
||||||
|
|
||||||
//2. Очистка заявок в поединки
|
|
||||||
mysql_query('DELETE FROM `zayvki` WHERE `start` > 0 OR `cancel` > 0 OR `time` < "'.(time()-86400*1).'"');
|
|
||||||
|
|
||||||
//3. Очистка заявок в пещеры
|
|
||||||
mysql_query('DELETE FROM `dungeon_zv` WHERE `delete` > 0 OR `time` < "'.(time()-86400*1).'"');
|
|
||||||
|
|
||||||
//4. Очистка походов
|
|
||||||
$sp = mysql_query('SELECT * FROM `dungeon_now` WHERE `time_start` < "'.(time()-86400*1).'" OR `time_finish` > 0');
|
|
||||||
while( $pl = mysql_fetch_array($sp) ) {
|
|
||||||
mysql_query('DELETE FROM `dungeon_actions` WHERE `dn` = "'.$pl['id'].'"');
|
|
||||||
mysql_query('DELETE FROM `dungeon_bots` WHERE `dn` = "'.$pl['id'].'"');
|
|
||||||
mysql_query('DELETE FROM `dungeon_items` WHERE `dn` = "'.$pl['id'].'"');
|
|
||||||
mysql_query('DELETE FROM `dungeon_obj` WHERE `dn` = "'.$pl['id'].'"');
|
|
||||||
mysql_query('DELETE FROM `dungeon_now` WHERE `id` = "'.$pl['id'].'"');
|
|
||||||
}
|
|
||||||
|
|
||||||
//5. Очистка монстров
|
|
||||||
$i = 0;
|
|
||||||
$sp = mysql_query('SELECT * FROM `users` WHERE `real` = 0 ORDER BY `id` ASC LIMIT 100');
|
|
||||||
while( $pl = mysql_fetch_array($sp) ) {
|
|
||||||
$btl = mysql_fetch_array(mysql_query('SELECT * FROM `battle` WHERE `id` = "'.$pl['battle'].'" LIMIT 1'));
|
|
||||||
$clon = mysql_fetch_array(mysql_query('SELECT `id` FROM `users` WHERE `inUser` = "'.$pl['id'].'" LIMIT 1'));
|
|
||||||
if( (!isset($btl['id']) || $btl['team_win'] >= 0) && !isset($clon['id']) ) {
|
|
||||||
//Очищаем бота
|
|
||||||
delete_user_all( $pl['id'] , $pl['login'] );
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$x = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM `users` WHERE `real` = 0 LIMIT 1'));
|
|
||||||
$x = $x[0];
|
|
||||||
|
|
||||||
mysql_query('DELETE FROM `stats` WHERE `id` NOT IN (SELECT `id` FROM `users`);');
|
|
||||||
mysql_query('DELETE FROM `items_users` WHERE `delete` > `time_create` AND `delete` > 0');
|
|
||||||
|
|
||||||
//6. Очистка личного дела
|
|
||||||
mysql_query('DELETE FROM `users_delo` WHERE `time` < "'.(time()-86400*30).'" LIMIT 1000');
|
|
||||||
|
|
@ -1,492 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Скрипт отвечает за перемещения ботов по пещере и напедения, когда игрок рядом.
|
|
||||||
*
|
|
||||||
* Запуск раз в миниту
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
|
|
||||||
|
|
||||||
//todo: IN PROGRESS
|
|
||||||
|
|
||||||
# Совершаем действие -> Нападение на игрока.
|
|
||||||
function botAttack($bot, $user)
|
|
||||||
{
|
|
||||||
if ($user['userBattle'] > 0) {
|
|
||||||
$battleID = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT `id` FROM `battle` WHERE `id` = "' . $user['userBattle'] . '" AND `team_win` = "-1" LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!isset($battleID['id'])) { //Создаем поединок
|
|
||||||
$btl_id = 0;
|
|
||||||
$expB = 0;
|
|
||||||
$btl = ['players' => '', 'timeout' => 180, '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 (
|
|
||||||
"' . $bot['dn_id'] . '",
|
|
||||||
"' . $bot['this_dn'] . '",
|
|
||||||
"' . $bot['x'] . '",
|
|
||||||
"' . $bot['y'] . '",
|
|
||||||
"' . $bot['userCity'] . '",
|
|
||||||
"' . 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) { //Добавляем ботов
|
|
||||||
$j = 0;
|
|
||||||
$logins_bot = [];
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `dungeon_bots` SET `inBattle` = "' . $btl_id . '" WHERE `id2` = "' . $bot['id2'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
$jui = 1;
|
|
||||||
while ($jui <= $bot['colvo']) {
|
|
||||||
$k = botAddBattle($bot, $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 `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` = "' . $user['userId'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
mysql_query('UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $user['userId'] . '" LIMIT 1');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { # Вмешиваемся в поединок.
|
|
||||||
$j = 0;
|
|
||||||
$logins_bot = [];
|
|
||||||
$logins_bot_text = [];
|
|
||||||
$logins_bot_vars = ['time1=' . time() . ''];
|
|
||||||
$logins_bot_inBattle = mysql_query(
|
|
||||||
'SELECT SUBSTRING_INDEX(`login`, " (", 1) as login2, count(`login`) as count, `login` FROM `battle_users` WHERE `battle` = "' . $battleID['id'] . '" AND `team`=2 GROUP BY `login2`'
|
|
||||||
);
|
|
||||||
while ($row = mysql_fetch_array($logins_bot_inBattle)) {
|
|
||||||
$logins_bot[$row['login2']] = (int)$row['count'];
|
|
||||||
}
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `dungeon_bots` SET `inBattle` = "' . $battleID['id'] . '" WHERE `id2` = "' . $bot['id2'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
$jui = 1;
|
|
||||||
while ($jui <= $bot['colvo']) {
|
|
||||||
$k = botAddBattle($bot, $logins_bot);
|
|
||||||
$logins_bot = $k['logins_bot'];
|
|
||||||
|
|
||||||
$logins_bot_text[] = ' <strong>' . $k['login'] . '</strong>';
|
|
||||||
if ($k != false) {
|
|
||||||
$upd = mysql_query(
|
|
||||||
'UPDATE `users` SET `battle` = "' . $battleID['id'] . '" WHERE `id` = "' . $k['id'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
if ($upd) {
|
|
||||||
$upd = mysql_query('UPDATE `stats` SET `team` = "2" WHERE `id` = "' . $k['id'] . '" LIMIT 1');
|
|
||||||
if ($upd) {
|
|
||||||
$j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$jui++;
|
|
||||||
}
|
|
||||||
if ($j > 0) {
|
|
||||||
$logins_bot_text = '{tm1} В поединок вмешались: ' . implode(', ', $logins_bot_text) . '.';
|
|
||||||
$logins_bot_vars = implode('||', $logins_bot_vars);
|
|
||||||
$battle_log = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT * FROM `battle_logs` WHERE `battle`=' . $battleID['id'] . ' ORDER BY `id_hod` DESC LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if ($battle_log['id_hod'] > 0) {
|
|
||||||
mysql_query(
|
|
||||||
'INSERT INTO `battle_logs` (`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zonb1`,`zona2`,`zonb2`,`type`) VALUES ("' . time(
|
|
||||||
) . '","' . $battleID['id'] . '","' . ($battle_log['id_hod'] + 1) . '","' . $logins_bot_text . '","' . $logins_bot_vars . '","","","","",1)'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($logins_bot);
|
|
||||||
if ($j > 0) {
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `users` SET `battle` = "' . $battleID['id'] . '" WHERE `id` = "' . $user['id'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
mysql_query('UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $user['id'] . '" LIMIT 1');
|
|
||||||
}
|
|
||||||
unset($logins_bot_inBattle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Совершаем нападение -> Добавляем Ботов в поединок
|
|
||||||
function botAddBattle($bot, $logins_bot)
|
|
||||||
{
|
|
||||||
$add_bot = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT
|
|
||||||
`id`, `login`, `stats`, `obraz`, `level`, `sex`, `name`, `hobby`, `type`, `itemsUse`, `priemUse`, `align`, `clan`, `align_zvanie`, `bonus`, `clan_zvanie`, `time_reg`, `city_reg`, `upLevel`, `active`, `expB`, `p_items`, `agressor`, `priems`, `priems_z`, `award`
|
|
||||||
FROM `test_bot`
|
|
||||||
WHERE `id` = "' . $bot['id_bot'] . '"
|
|
||||||
LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isset($add_bot['id'])) {
|
|
||||||
if (isset($logins_bot[$add_bot['login']])) {
|
|
||||||
$logins_bot[$add_bot['login']]++;
|
|
||||||
$add_bot['login'] = $add_bot['login'] . ' (' . $logins_bot[$add_bot['login']] . ')';
|
|
||||||
} else {
|
|
||||||
$logins_bot[$add_bot['login']] = 1;
|
|
||||||
}
|
|
||||||
$ret = true;
|
|
||||||
if ($add_bot['time_reg'] == 100) {
|
|
||||||
$add_bot['time_reg'] = time();
|
|
||||||
}
|
|
||||||
if ($add_bot['city_reg'] == '{thiscity}') {
|
|
||||||
$add_bot['city_reg'] = $bot['userCity'];
|
|
||||||
}
|
|
||||||
$ins1 = mysql_query(
|
|
||||||
'INSERT INTO `users` (
|
|
||||||
`align`,
|
|
||||||
`login`,
|
|
||||||
`level`,
|
|
||||||
`pass`,
|
|
||||||
`city`,
|
|
||||||
`cityreg`,
|
|
||||||
`name`,
|
|
||||||
`sex`,
|
|
||||||
`hobby`,
|
|
||||||
`timereg`,
|
|
||||||
`obraz`,
|
|
||||||
`bot_id`
|
|
||||||
) VALUES (
|
|
||||||
"' . $add_bot['align'] . '",
|
|
||||||
"' . $add_bot['login'] . '",
|
|
||||||
"' . $add_bot['level'] . '",
|
|
||||||
"' . md5('bot_pass_' . $add_bot['login'] . '_') . '",
|
|
||||||
"' . $bot['userCity'] . '",
|
|
||||||
"' . $add_bot['city_reg'] . '",
|
|
||||||
"' . $add_bot['name'] . '",
|
|
||||||
"' . $add_bot['sex'] . '",
|
|
||||||
"' . $add_bot['hobby'] . '",
|
|
||||||
"' . $add_bot['time_reg'] . '",
|
|
||||||
"' . $add_bot['obraz'] . '",
|
|
||||||
"' . $bot['id_bot'] . '"
|
|
||||||
)'
|
|
||||||
);
|
|
||||||
|
|
||||||
# Если бот успешно создан.
|
|
||||||
if ($ins1) {
|
|
||||||
$uid = mysql_insert_id();
|
|
||||||
$ins2 = mysql_query(
|
|
||||||
'INSERT INTO `stats` (`id`,`stats`,`hpNow`,`upLevel`,`bot`) VALUES ("' . $uid . '","' . $add_bot['stats'] . '","1000000","' . $add_bot['upLevel'] . '","1")'
|
|
||||||
);
|
|
||||||
if ($ins2) {
|
|
||||||
$add_bot['id'] = $uid;
|
|
||||||
$add_bot['logins_bot'] = $logins_bot;
|
|
||||||
$ret = $add_bot;
|
|
||||||
|
|
||||||
//Выдаем предметы
|
|
||||||
//$this->addItem($item_id,$uid);
|
|
||||||
$iu = explode(',', $add_bot['itemsUse']);
|
|
||||||
$i = 0;
|
|
||||||
$w3b = 0;
|
|
||||||
while ($i < count($iu)) {
|
|
||||||
if ($iu[$i] > 0) {
|
|
||||||
$idiu = botAddItem($iu[$i], $add_bot['id'], $bot['userCity']);
|
|
||||||
$islot = mysql_fetch_array(
|
|
||||||
mysql_query('SELECT `id`,`inslot` FROM `items_main` WHERE `id` = "' . $iu[$i] . '" LIMIT 1')
|
|
||||||
);
|
|
||||||
if (isset($islot['id'])) {
|
|
||||||
if ($islot['inslot'] == 3) {
|
|
||||||
if ($w3b == 1) {
|
|
||||||
$islot = 14;
|
|
||||||
} else {
|
|
||||||
$islot = 3;
|
|
||||||
$w3b = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$islot = $islot['inslot'];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$islot = 2000;
|
|
||||||
}
|
|
||||||
if (isset($idiu, $islot)) {
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `items_users` SET `inOdet` = "' . $islot . '" WHERE `id` = "' . $idiu . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$ret = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$ret = false;
|
|
||||||
}
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Выдаем предметы Боту.
|
|
||||||
function botAddItem($item_id, $bot_uid, $city)
|
|
||||||
{
|
|
||||||
$i = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT `im`.`id`,`im`.`name`,`im`.`img`,`im`.`type`,`im`.`inslot`,`im`.`2h`,`im`.`2too`,`im`.`iznosMAXi`,`im`.`inRazdel`,`im`.`price1`,`im`.`price2`,`im`.`pricerep`,`im`.`magic_chance`,`im`.`info`,`im`.`massa`,`im`.`level`,`im`.`magic_inci`,`im`.`overTypei`,`im`.`group`,`im`.`group_max`,`im`.`geni`,`im`.`ts`,`im`.`srok`,`im`.`class`,`im`.`class_point`,`im`.`anti_class`,`im`.`anti_class_point`,`im`.`max_text`,`im`.`useInBattle`,`im`.`lbtl`,`im`.`lvl_itm`,`im`.`lvl_exp`,`im`.`lvl_aexp` FROM `items_main` AS `im` WHERE `im`.`id` = "' . mysql_real_escape_string(
|
|
||||||
$item_id
|
|
||||||
) . '" LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (isset($i['id'])) {
|
|
||||||
$d = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT `id`,`items_id`,`data` FROM `items_main_data` WHERE `items_id` = "' . $i['id'] . '" LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
//новая дата
|
|
||||||
$data = $d['data'];
|
|
||||||
$ins = mysql_query(
|
|
||||||
'
|
|
||||||
INSERT INTO `items_users` (
|
|
||||||
`overType`,`item_id`,`uid`,`data`,`iznosMAX`,`geniration`,`magic_inc`,`maidin`,`lastUPD`,`time_create`,`dn_delete`
|
|
||||||
) VALUES (
|
|
||||||
"' . $i['overTypei'] . '",
|
|
||||||
"' . $i['id'] . '",
|
|
||||||
"' . $bot_uid . '",
|
|
||||||
"' . $data . '",
|
|
||||||
"' . $i['iznosMAXi'] . '",
|
|
||||||
"' . $i['geni'] . '",
|
|
||||||
"' . $i['magic_inci'] . '",
|
|
||||||
"' . $city . '",
|
|
||||||
"' . time() . '",
|
|
||||||
"' . time() . '",
|
|
||||||
"' . $i['dn_delete'] . '"
|
|
||||||
)'
|
|
||||||
);
|
|
||||||
|
|
||||||
# Если предмет успешно добавлен в базу данных.
|
|
||||||
if ($ins) {
|
|
||||||
$rt = mysql_insert_id();
|
|
||||||
# отключена запись получения предмета в Дело.
|
|
||||||
} else {
|
|
||||||
$rt = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $rt;
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveBots($direction, $b)
|
|
||||||
{
|
|
||||||
$toGoX = 0;
|
|
||||||
$toGoY = 0;
|
|
||||||
|
|
||||||
if (isset($b['noBot']) && $b['noBot'] != '0000') {
|
|
||||||
if ($b['noBot'][0] != '0') {
|
|
||||||
$b['goTop'] = 0;
|
|
||||||
}
|
|
||||||
if ($b['noBot'][1] != '0') {
|
|
||||||
$b['goLeft'] = 0;
|
|
||||||
}
|
|
||||||
if ($b['noBot'][2] != '0') {
|
|
||||||
$b['goBottom'] = 0;
|
|
||||||
}
|
|
||||||
if ($b['noBot'][3] != '0') {
|
|
||||||
$b['goRight'] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$go = [
|
|
||||||
1 => ['d' => (int)$b['goTop'], 'go1' => (int)$b['goLeft'], 'go2' => (int)$b['goRight'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
|
||||||
2 => ['d' => (int)$b['goLeft'], 'go1' => (int)$b['goBottom'], 'go2' => (int)$b['goTop'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
|
||||||
3 => ['d' => (int)$b['goBottom'], 'go1' => (int)$b['goRight'], 'go2' => (int)$b['goLeft'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
|
||||||
4 => ['d' => (int)$b['goRight'], 'go1' => (int)$b['goTop'], 'go2' => (int)$b['goBottom'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
|
||||||
];
|
|
||||||
$dir = [
|
|
||||||
1 => ['moveForward' => ['x' => '0', 'y' => '1'], 'moveBack' => ['x' => '0', 'y' => '-1'], 'moveGo1' => ['x' => '-1', 'y' => '0'], 'moveGo2' => ['x' => '1', 'y' => '0']],
|
|
||||||
2 => ['moveForward' => ['x' => '-1', 'y' => '0'], 'moveBack' => ['x' => '1', 'y' => '0'], 'moveGo1' => ['x' => '0', 'y' => '-1'], 'moveGo2' => ['x' => '0', 'y' => '1']],
|
|
||||||
3 => ['moveForward' => ['x' => '0', 'y' => '-1'], 'moveBack' => ['x' => '0', 'y' => '1'], 'moveGo1' => ['x' => '1', 'y' => '0'], 'moveGo2' => ['x' => '-1', 'y' => '0']],
|
|
||||||
4 => ['moveForward' => ['x' => '1', 'y' => '0'], 'moveBack' => ['x' => '-1', 'y' => '0'], 'moveGo1' => ['x' => '0', 'y' => '1'], 'moveGo2' => ['x' => '0', 'y' => '-1']],
|
|
||||||
];
|
|
||||||
$go = $go[$direction];
|
|
||||||
$dir = $dir[$direction];
|
|
||||||
if ($go['d'] == 1) {
|
|
||||||
$toGoY = $dir['moveForward']['y'];
|
|
||||||
$toGoX = $dir['moveForward']['x'];
|
|
||||||
if (rand(1, 100) > 66) {
|
|
||||||
if ($go['go1'] == 1 && $go['go2'] == 0) {
|
|
||||||
$toGoY = $dir['moveGo1']['y'];
|
|
||||||
$toGoX = $dir['moveGo1']['x'];
|
|
||||||
} elseif ($go['go1'] == 0 && $go['go2'] == 1) {
|
|
||||||
$toGoY = $dir['moveGo2']['y'];
|
|
||||||
$toGoX = $dir['moveGo2']['x'];
|
|
||||||
} elseif ($go['go1'] == 1 && $go['go2'] == 1) {
|
|
||||||
$a = rand(1, 2);
|
|
||||||
$toGoY = $dir['moveGo' . $a]['y'];
|
|
||||||
$toGoX = $dir['moveGo' . $a]['x'];
|
|
||||||
}
|
|
||||||
} elseif (rand(1, 100) > 96) {
|
|
||||||
$toGoY = $dir['moveBack']['y'];
|
|
||||||
$toGoX = $dir['moveBack']['x'];
|
|
||||||
}
|
|
||||||
} elseif ($go['d'] == 0) {
|
|
||||||
if ($go['go1'] == 1 && $go['go2'] == 1) {
|
|
||||||
if (rand(0, 1) == 1) {
|
|
||||||
$toGoY = $dir['moveGo1']['y'];
|
|
||||||
$toGoX = $dir['moveGo1']['x'];
|
|
||||||
} else {
|
|
||||||
$toGoY = $dir['moveGo2']['y'];
|
|
||||||
$toGoX = $dir['moveGo2']['x'];
|
|
||||||
}
|
|
||||||
} elseif ($go['go1'] == 1 && $go['go2'] == 0) {
|
|
||||||
$toGoY = $dir['moveGo1']['y'];
|
|
||||||
$toGoX = $dir['moveGo1']['x'];
|
|
||||||
} elseif ($go['go1'] == 0 && $go['go2'] == 1) {
|
|
||||||
$toGoY = $dir['moveGo2']['y'];
|
|
||||||
$toGoX = $dir['moveGo2']['x'];
|
|
||||||
} elseif ($go['go1'] == 0 && $go['go2'] == 0) {
|
|
||||||
$toGoY = $dir['moveBack']['y'];
|
|
||||||
$toGoX = $dir['moveBack']['x'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($dir, $go, $direction, $a);
|
|
||||||
return ['x' => (int)$toGoX, 'y' => (int)$toGoY];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# запуск скрипта.
|
|
||||||
function start()
|
|
||||||
{
|
|
||||||
# Страница создана 0.0000
|
|
||||||
$mtime = microtime();
|
|
||||||
$mtime = explode(" ", $mtime);
|
|
||||||
$tstart = $mtime[1] + $mtime[0];
|
|
||||||
|
|
||||||
# Выбираем всех ботов.
|
|
||||||
# В выборку включено: Позиция бота, Направление куда он может идти, Существует ли рядом Игрок, его координаты и в поединке ли он.
|
|
||||||
$query = mysql_query(
|
|
||||||
"SELECT
|
|
||||||
`dn`.`id` as `this_dn`, `dn`.`id2` as `dn_id`, `db`.`id2`, `db`.`id_bot`, `tb`.`login` as login, `db`.`colvo`, `db`.`go_bot`, `db`.`x`, `db`.`y`, `db`.`s`, `db`.`atack`, `tb`.`agressor`,
|
|
||||||
`dm`.`go_1` as `goRight`, `dm`.`go_2` as `goLeft`, `dm`.`go_3` as `goTop`, `dm`.`go_4` as `goBottom`, `dm`.`no_bot` as `noBot`,
|
|
||||||
`user_info`.`id` as `userId`,
|
|
||||||
`user_info`.`login` as `userLogin`,
|
|
||||||
`user_stats`.`hpNow` as `userHP`,
|
|
||||||
`user_stats`.`x` as `userPosX`,
|
|
||||||
`user_stats`.`y` as `userPosY`,
|
|
||||||
`user_info`.`battle` as `userBattle`
|
|
||||||
FROM `dungeon_now` as `dn`
|
|
||||||
LEFT JOIN `dungeon_bots` as `db` ON `db`.`dn` = `dn`.`id`
|
|
||||||
LEFT JOIN `dungeon_map` as `dm` ON ( `dm`.`x` = `db`.`x` AND `dm`.`y` = `db`.`y` AND `dm`.`id_dng` = `dn`.`id2` )
|
|
||||||
LEFT JOIN `test_bot` AS `tb` ON `db`.`id_bot` = `tb`.`id`
|
|
||||||
LEFT JOIN `stats` AS `user_stats` ON ( ( `user_stats`.`x`+1 >= `db`.`x` AND `user_stats`.`x`-1 <= `db`.`x` ) AND ( `user_stats`.`y`+1 >= `db`.`y` AND `user_stats`.`y`-1 <= `db`.`y`) AND `user_stats`.`dnow` = `dn`.`id` )
|
|
||||||
LEFT JOIN `users` AS `user_info` ON ( `user_stats`.`id` = `user_info`.`id` )
|
|
||||||
|
|
||||||
WHERE
|
|
||||||
`dn`.`time_finish` = '0' AND
|
|
||||||
`db`.`atack` = '0' AND
|
|
||||||
`db`.`delete` = '0' AND
|
|
||||||
`db`.`for_dn` = '0' AND
|
|
||||||
( ( `db`.`go_bot` > '" . (time() - 32400) . "' AND `db`.`go_bot` < '" . (time()) . "') OR `db`.`go_bot`='1') AND
|
|
||||||
`db`.`inBattle`='0'
|
|
||||||
GROUP BY `db`.`id2`
|
|
||||||
ORDER BY `db`.`go_bot` ASC"
|
|
||||||
);
|
|
||||||
|
|
||||||
while ($bot = mysql_fetch_array($query)) {
|
|
||||||
if ($bot['go_bot'] > 0 && $bot['go_bot'] <= time()) {
|
|
||||||
$sNext = true;
|
|
||||||
$sTo = $bot['s'];
|
|
||||||
$xFrom = $bot['x']; # текущие координаты X
|
|
||||||
$yFrom = $bot['y']; # текущие координаты Y
|
|
||||||
|
|
||||||
$return = moveBots($bot['s'], $bot);
|
|
||||||
$xTo = $bot['x'] + $return['x'];
|
|
||||||
$yTo = $bot['y'] + $return['y'];
|
|
||||||
# Проверяем, имеется ли переход по клетке.
|
|
||||||
$inSight = 0;
|
|
||||||
if (isset($bot['id2'])) {
|
|
||||||
if ($xFrom == $xTo && $yFrom == $yTo) { # Если остаемся на месте.
|
|
||||||
$inSight = 1;
|
|
||||||
} elseif (isset($bot['goRight']) && $xFrom == $xTo - 1 && $bot['goRight'] == 1) { //право
|
|
||||||
$sTo = 4;
|
|
||||||
$inSight = 1;
|
|
||||||
} elseif (isset($bot['goLeft']) && $xFrom == $xTo + 1 && $bot['goLeft'] == 1) { //лево
|
|
||||||
$sTo = 2;
|
|
||||||
$inSight = 1;
|
|
||||||
} elseif (isset($bot['goTop']) && $yFrom == $yTo - 1 && $bot['goTop'] == 1) { //верх
|
|
||||||
$sTo = 1;
|
|
||||||
$inSight = 1;
|
|
||||||
} elseif (isset($bot['goBottom']) && $yFrom == $yTo + 1 && $bot['goBottom'] == 1) { //низ
|
|
||||||
$sTo = 3;
|
|
||||||
$inSight = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($bot['userId'], $bot['userPosY'], $bot['userPosX']) && $bot['userId'] != '' && $bot['agressor'] == 1 && (
|
|
||||||
($bot['userPosY'] == $bot['y'] + 1 && $bot['userPosX'] == $bot['x']) or
|
|
||||||
($bot['userPosY'] == $bot['y'] - 1 && $bot['userPosX'] == $bot['x']) or
|
|
||||||
($bot['userPosY'] == $bot['y'] && $bot['userPosX'] == $bot['x'] - 1) or
|
|
||||||
($bot['userPosY'] == $bot['y'] && $bot['userPosX'] == $bot['x'] + 1)
|
|
||||||
)) {
|
|
||||||
bot['userPosY'] = $yFrom;
|
|
||||||
$bot['userPosX'] = $xFrom;
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `stats` SET `x` = "' . $xFrom . '" , `y` = "' . $yFrom . '" WHERE `id` = "' . $bot['userId'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
botAttack($bot, $bot);
|
|
||||||
} elseif (isset($bot['userId'], $bot['userPosY'], $bot['userPosX']) && $bot['userId'] != '' && $inSight == 1 && $yTo == $bot['userPosY'] && $xTo == $bot['userPosX'] && $bot['atack'] == 1) {
|
|
||||||
botAttack($bot, $bot);
|
|
||||||
} elseif ($inSight == 1) { // Передвижение ботов.
|
|
||||||
$bot['go_bot'] = time() + rand(7, 15);
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `dungeon_bots` SET `x` = "' . $xTo . '",`y` = "' . $yTo . '", `s` = "' . $sTo . '", `go_bot` = "' . $bot['go_bot'] . '" WHERE `id2` = "' . $bot['id2'] . '" LIMIT 1 '
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unset($xFrom, $yFrom, $xTo, $yTo, $inSight, $sNext, $sTo);
|
|
||||||
}
|
|
||||||
unset($bot);
|
|
||||||
}
|
|
||||||
unset($query, $bot);
|
|
||||||
|
|
||||||
$mtime = microtime();
|
|
||||||
$mtime = explode(" ", $mtime);
|
|
||||||
$mtime = $mtime[1] + $mtime[0];
|
|
||||||
$totaltime = ($mtime - $tstart);
|
|
||||||
printf("Страница сгенерирована за %f секунд !", $totaltime);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Запускаем выполнение процесса.
|
|
||||||
start();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Для оптимизации запроса обновлений позиций
|
|
||||||
|
|
||||||
UPDATE dungeon_bots SET
|
|
||||||
x = CASE
|
|
||||||
WHEN id2 = '.$bot['id2'].' THEN "test2"
|
|
||||||
WHEN id2 = '.$bot['id2'].' THEN "test1" END
|
|
||||||
WHERE id2 IN ('.$bot['id2'].', 2, 3, 4)
|
|
||||||
|
|
||||||
*/
|
|
213
cron/clear.php
213
cron/clear.php
@ -2,28 +2,28 @@
|
|||||||
const GAME = true;
|
const GAME = true;
|
||||||
include('/home/newcom1/public_html/_incl_data/class/__db_connect.php');
|
include('/home/newcom1/public_html/_incl_data/class/__db_connect.php');
|
||||||
|
|
||||||
if( isset($_GET['actions']) ) {
|
if (isset($_GET['actions'])) {
|
||||||
//
|
//
|
||||||
$data = array();
|
$data = [];
|
||||||
//
|
//
|
||||||
$sp = mysql_query('SELECT * FROM `actions`');
|
$sp = mysql_query('SELECT * FROM `actions`');
|
||||||
while( $pl = mysql_fetch_array($sp) ) {
|
while ($pl = mysql_fetch_array($sp)) {
|
||||||
$pl['vars'] = str_replace(0,'%',$pl['vars']);
|
$pl['vars'] = str_replace(0, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(1,'%',$pl['vars']);
|
$pl['vars'] = str_replace(1, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(2,'%',$pl['vars']);
|
$pl['vars'] = str_replace(2, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(3,'%',$pl['vars']);
|
$pl['vars'] = str_replace(3, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(4,'%',$pl['vars']);
|
$pl['vars'] = str_replace(4, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(5,'%',$pl['vars']);
|
$pl['vars'] = str_replace(5, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(6,'%',$pl['vars']);
|
$pl['vars'] = str_replace(6, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(7,'%',$pl['vars']);
|
$pl['vars'] = str_replace(7, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(8,'%',$pl['vars']);
|
$pl['vars'] = str_replace(8, '%', $pl['vars']);
|
||||||
$pl['vars'] = str_replace(9,'%',$pl['vars']);
|
$pl['vars'] = str_replace(9, '%', $pl['vars']);
|
||||||
$data[$pl['vars']]++;
|
$data[$pl['vars']]++;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
print_r($data);
|
print_r($data);
|
||||||
//
|
//
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -40,103 +40,104 @@ if( isset($_GET['actions']) ) {
|
|||||||
// ЕБИИИИИИИЧЕСКАЯ СИИИИЛА!!!!! (с) Инс.
|
// ЕБИИИИИИИЧЕСКАЯ СИИИИЛА!!!!! (с) Инс.
|
||||||
// forign_keys! Никто не знает про foreign_keys!
|
// forign_keys! Никто не знает про foreign_keys!
|
||||||
|
|
||||||
function delete_user_all( $uid , $login ) {
|
function delete_user_all($uid, $login)
|
||||||
mysql_query('DELETE FROM `aaa_znahar` WHERE `uid` = "'.$uid.'"');
|
{
|
||||||
mysql_query('DELETE FROM `actions` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `aaa_znahar` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `add_smiles` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `actions` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `a_com_act` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `add_smiles` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `bandit` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `a_com_act` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `bank_alh` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `bandit` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `battle_act` WHERE `uid1` = "'.$uid.'" OR `uid2` = "'.$uid.'"');
|
mysql_query('DELETE FROM `bank_alh` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `battle_actions` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `battle_act` WHERE `uid1` = "' . $uid . '" OR `uid2` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `battle_cache` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `battle_actions` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `battle_last` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `battle_cache` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `battle_stat` WHERE `uid1` = "'.$uid.'" OR `uid2` = "'.$uid.'"');
|
mysql_query('DELETE FROM `battle_last` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `battle_users` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `battle_stat` WHERE `uid1` = "' . $uid . '" OR `uid2` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `bs_actions` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `battle_users` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `bs_zv` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `bs_actions` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `building` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `bs_zv` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `buy_ekr` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `building` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `complects_priem` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `buy_ekr` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `dialog_act` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `complects_priem` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `dump` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `dialog_act` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `dungeon_actions` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `dump` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `dungeon_actions` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `ekr_sale` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `feerverks` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `ekr_sale` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `fontan` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `feerverks` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `fontan_hp` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `fontan` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `fontan_text` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `fontan_hp` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `friends` WHERE `user` = "'.$uid.'"
|
mysql_query('DELETE FROM `fontan_text` WHERE `uid` = "' . $uid . '"');
|
||||||
OR `friend` = "'.$uid.'"
|
mysql_query('DELETE FROM `friends` WHERE `user` = "' . $uid . '"
|
||||||
OR `enemy` = "'.$uid.'"
|
OR `friend` = "' . $uid . '"
|
||||||
OR `notinlist` = "'.$uid.'"
|
OR `enemy` = "' . $uid . '"
|
||||||
OR `ignor` = "'.$uid.'"
|
OR `notinlist` = "' . $uid . '"
|
||||||
OR `login_ignor` = "'.$login.'"
|
OR `ignor` = "' . $uid . '"
|
||||||
OR `user_ignor` = "'.$login.'"');
|
OR `login_ignor` = "' . $login . '"
|
||||||
mysql_query('DELETE FROM `house` WHERE `owner` = "'.$uid.'"');
|
OR `user_ignor` = "' . $login . '"');
|
||||||
mysql_query('DELETE FROM `items_img` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `house` WHERE `owner` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `items_users` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `items_img` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `izlom_rating` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `items_users` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `laba_act` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `izlom_rating` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `laba_itm` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `laba_act` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `lastnames` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `laba_itm` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `logs_auth` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `lastnames` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `loto_win` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `logs_auth` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `mults` WHERE `uid` = "'.$uid.'" OR `uid2` = "'.$uid.'"');
|
mysql_query('DELETE FROM `loto_win` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `notepad` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `mults` WHERE `uid` = "' . $uid . '" OR `uid2` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `obraz` WHERE `uid` = "'.$uid.'" OR `login` = "'.$login.'"');
|
mysql_query('DELETE FROM `notepad` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `online` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `obraz` WHERE `uid` = "' . $uid . '" OR `login` = "' . $login . '"');
|
||||||
mysql_query('DELETE FROM `pirogi` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `online` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `reimage` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `pirogi` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `rep` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `reimage` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `repass` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `rep` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `ruletka_coin` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `repass` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `save_com` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `ruletka_coin` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `stats` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `save_com` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `transfers` WHERE `uid1` = "'.$uid.'" OR `uid2` = "'.$uid.'"');
|
mysql_query('DELETE FROM `stats` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `users` WHERE `id` = "'.$uid.'"');
|
mysql_query('DELETE FROM `transfers` WHERE `uid1` = "' . $uid . '" OR `uid2` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `stats` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `users` WHERE `id` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `users_delo` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `stats` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `users_animal` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `users_delo` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `users_gifts` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `users_animal` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `users_ico` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `users_gifts` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `users_reputation` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `users_ico` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `users_turnirs` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `users_reputation` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `users_twink` WHERE `uid` = "'.$uid.'"');
|
mysql_query('DELETE FROM `users_turnirs` WHERE `uid` = "' . $uid . '"');
|
||||||
mysql_query('DELETE FROM `zayavki` WHERE `creator` = "'.$uid.'"');
|
mysql_query('DELETE FROM `users_twink` WHERE `uid` = "' . $uid . '"');
|
||||||
|
mysql_query('DELETE FROM `zayavki` WHERE `creator` = "' . $uid . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
//1. Очистка чата, остается чат только за последние 3 дня
|
//1. Очистка чата, остается чат только за последние 3 дня
|
||||||
mysql_query('DELETE FROM `chat` WHERE `time` < '.(time()-86400*3).'');
|
mysql_query('DELETE FROM `chat` WHERE `time` < ' . (time() - 86400 * 3) . '');
|
||||||
|
|
||||||
//2. Очистка заявок в поединки
|
//2. Очистка заявок в поединки
|
||||||
mysql_query('DELETE FROM `zayvki` WHERE `start` > 0 OR `cancel` > 0 OR `time` < "'.(time()-86400*1).'"');
|
mysql_query('DELETE FROM `zayvki` WHERE `start` > 0 OR `cancel` > 0 OR `time` < "' . (time() - 86400 * 1) . '"');
|
||||||
|
|
||||||
//3. Очистка заявок в пещеры
|
//3. Очистка заявок в пещеры
|
||||||
mysql_query('DELETE FROM `dungeon_zv` WHERE `delete` > 0 OR `time` < "'.(time()-86400*1).'"');
|
mysql_query('DELETE FROM `dungeon_zv` WHERE `delete` > 0 OR `time` < "' . (time() - 86400 * 1) . '"');
|
||||||
|
|
||||||
//4. Очистка походов
|
//4. Очистка походов
|
||||||
$sp = mysql_query('SELECT * FROM `dungeon_now` WHERE `time_start` < "'.(time()-86400*1).'" OR `time_finish` > 0');
|
$sp = mysql_query('SELECT * FROM `dungeon_now` WHERE `time_start` < "' . (time() - 86400 * 1) . '" OR `time_finish` > 0');
|
||||||
while( $pl = mysql_fetch_array($sp) ) {
|
while ($pl = mysql_fetch_array($sp)) {
|
||||||
mysql_query('DELETE FROM `dungeon_actions` WHERE `dn` = "'.$pl['id'].'"');
|
mysql_query('DELETE FROM `dungeon_actions` WHERE `dn` = "' . $pl['id'] . '"');
|
||||||
mysql_query('DELETE FROM `dungeon_bots` WHERE `dn` = "'.$pl['id'].'"');
|
mysql_query('DELETE FROM `dungeon_bots` WHERE `dn` = "' . $pl['id'] . '"');
|
||||||
mysql_query('DELETE FROM `dungeon_items` WHERE `dn` = "'.$pl['id'].'"');
|
mysql_query('DELETE FROM `dungeon_items` WHERE `dn` = "' . $pl['id'] . '"');
|
||||||
mysql_query('DELETE FROM `dungeon_obj` WHERE `dn` = "'.$pl['id'].'"');
|
mysql_query('DELETE FROM `dungeon_obj` WHERE `dn` = "' . $pl['id'] . '"');
|
||||||
mysql_query('DELETE FROM `dungeon_now` WHERE `id` = "'.$pl['id'].'"');
|
mysql_query('DELETE FROM `dungeon_now` WHERE `id` = "' . $pl['id'] . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
//5. Очистка монстров
|
//5. Очистка монстров
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$sp = mysql_query('SELECT * FROM `users` WHERE `real` = 0 ORDER BY `id` ASC LIMIT 100');
|
$sp = mysql_query('SELECT * FROM `users` WHERE `real` = 0 ORDER BY `id` ASC LIMIT 100');
|
||||||
while( $pl = mysql_fetch_array($sp) ) {
|
while ($pl = mysql_fetch_array($sp)) {
|
||||||
$btl = mysql_fetch_array(mysql_query('SELECT * FROM `battle` WHERE `id` = "'.$pl['battle'].'" LIMIT 1'));
|
$btl = mysql_fetch_array(mysql_query('SELECT * FROM `battle` WHERE `id` = "' . $pl['battle'] . '" LIMIT 1'));
|
||||||
$clon = mysql_fetch_array(mysql_query('SELECT `id` FROM `users` WHERE `inUser` = "'.$pl['id'].'" LIMIT 1'));
|
$clon = mysql_fetch_array(mysql_query('SELECT `id` FROM `users` WHERE `inUser` = "' . $pl['id'] . '" LIMIT 1'));
|
||||||
if( (!isset($btl['id']) || $btl['team_win'] >= 0) && !isset($clon['id']) ) {
|
if ((!isset($btl['id']) || $btl['team_win'] >= 0) && !isset($clon['id'])) {
|
||||||
//Очищаем бота
|
//Очищаем бота
|
||||||
delete_user_all( $pl['id'] , $pl['login'] );
|
clearUsersFromDb($pl['id'], $pl['login']);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$x = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM `users` WHERE `real` = 0 LIMIT 1'));
|
$x = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM `users` WHERE `real` = 0 LIMIT 1'));
|
||||||
$x = $x[0];
|
$x = $x[0];
|
||||||
@ -145,5 +146,5 @@ mysql_query('DELETE FROM `stats` WHERE `id` NOT IN (SELECT `id` FROM `users`);')
|
|||||||
mysql_query('DELETE FROM `items_users` WHERE `delete` > `time_create` AND `delete` > 0');
|
mysql_query('DELETE FROM `items_users` WHERE `delete` > `time_create` AND `delete` > 0');
|
||||||
|
|
||||||
//6. Очистка личного дела
|
//6. Очистка личного дела
|
||||||
mysql_query('DELETE FROM `users_delo` WHERE `time` < "'.(time()-86400*30).'" LIMIT 1000');
|
mysql_query('DELETE FROM `users_delo` WHERE `time` < "' . (time() - 86400 * 30) . '" LIMIT 1000');
|
||||||
|
|
||||||
|
@ -1,491 +0,0 @@
|
|||||||
<?php
|
|
||||||
# Скрипт отвечает за
|
|
||||||
# перемещения ботов по пещере
|
|
||||||
# а так-же напедения, когда игрок рядом
|
|
||||||
|
|
||||||
const GAME = true;
|
|
||||||
|
|
||||||
|
|
||||||
include('_incl_data/__config.php');
|
|
||||||
include('_incl_data/class/__db_connect.php');
|
|
||||||
|
|
||||||
# Совершаем действие -> Нападение на игрока.
|
|
||||||
function botAttack($bot, $user)
|
|
||||||
{
|
|
||||||
if ($user['userBattle'] > 0) {
|
|
||||||
$battleID = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT `id` FROM `battle` WHERE `id` = "' . $user['userBattle'] . '" AND `team_win` = "-1" LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!isset($battleID['id'])) { //Создаем поединок
|
|
||||||
$btl_id = 0;
|
|
||||||
$expB = 0;
|
|
||||||
$btl = ['players' => '', 'timeout' => 180, '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 (
|
|
||||||
"' . $bot['dn_id'] . '",
|
|
||||||
"' . $bot['this_dn'] . '",
|
|
||||||
"' . $bot['x'] . '",
|
|
||||||
"' . $bot['y'] . '",
|
|
||||||
"' . $bot['userCity'] . '",
|
|
||||||
"' . 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) { //Добавляем ботов
|
|
||||||
$j = 0;
|
|
||||||
$logins_bot = [];
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `dungeon_bots` SET `inBattle` = "' . $btl_id . '" WHERE `id2` = "' . $bot['id2'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
$jui = 1;
|
|
||||||
while ($jui <= $bot['colvo']) {
|
|
||||||
$k = botAddBattle($bot, $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 `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` = "' . $user['userId'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
mysql_query('UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $user['userId'] . '" LIMIT 1');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { # Вмешиваемся в поединок.
|
|
||||||
$j = 0;
|
|
||||||
$logins_bot = [];
|
|
||||||
$logins_bot_text = [];
|
|
||||||
$logins_bot_vars = ['time1=' . time() . ''];
|
|
||||||
$logins_bot_inBattle = mysql_query(
|
|
||||||
'SELECT SUBSTRING_INDEX(`login`, " (", 1) as login2, count(`login`) as count, `login` FROM `battle_users` WHERE `battle` = "' . $battleID['id'] . '" AND `team`=2 GROUP BY `login2`'
|
|
||||||
);
|
|
||||||
while ($row = mysql_fetch_array($logins_bot_inBattle)) {
|
|
||||||
$logins_bot[$row['login2']] = (int)$row['count'];
|
|
||||||
}
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `dungeon_bots` SET `inBattle` = "' . $battleID['id'] . '" WHERE `id2` = "' . $bot['id2'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
$jui = 1;
|
|
||||||
while ($jui <= $bot['colvo']) {
|
|
||||||
$k = botAddBattle($bot, $logins_bot);
|
|
||||||
$logins_bot = $k['logins_bot'];
|
|
||||||
|
|
||||||
$logins_bot_text[] = ' <strong>' . $k['login'] . '</strong>';
|
|
||||||
if ($k != false) {
|
|
||||||
$upd = mysql_query(
|
|
||||||
'UPDATE `users` SET `battle` = "' . $battleID['id'] . '" WHERE `id` = "' . $k['id'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
if ($upd) {
|
|
||||||
$upd = mysql_query('UPDATE `stats` SET `team` = "2" WHERE `id` = "' . $k['id'] . '" LIMIT 1');
|
|
||||||
if ($upd) {
|
|
||||||
$j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$jui++;
|
|
||||||
}
|
|
||||||
if ($j > 0) {
|
|
||||||
$logins_bot_text = '{tm1} В поединок вмешались: ' . implode(', ', $logins_bot_text) . '.';
|
|
||||||
$logins_bot_vars = implode('||', $logins_bot_vars);
|
|
||||||
$battle_log = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT * FROM `battle_logs` WHERE `battle`=' . $battleID['id'] . ' ORDER BY `id_hod` DESC LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if ($battle_log['id_hod'] > 0) {
|
|
||||||
mysql_query(
|
|
||||||
'INSERT INTO `battle_logs` (`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zonb1`,`zona2`,`zonb2`,`type`) VALUES ("' . time(
|
|
||||||
) . '","' . $battleID['id'] . '","' . ($battle_log['id_hod'] + 1) . '","' . $logins_bot_text . '","' . $logins_bot_vars . '","","","","",1)'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($logins_bot);
|
|
||||||
if ($j > 0) {
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `users` SET `battle` = "' . $battleID['id'] . '" WHERE `id` = "' . $user['id'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
mysql_query('UPDATE `stats` SET `team` = "1" WHERE `id` = "' . $user['id'] . '" LIMIT 1');
|
|
||||||
}
|
|
||||||
unset($logins_bot_inBattle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Совершаем нападение -> Добавляем Ботов в поединок
|
|
||||||
function botAddBattle($bot, $logins_bot)
|
|
||||||
{
|
|
||||||
$add_bot = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT
|
|
||||||
`id`, `login`, `stats`, `obraz`, `level`, `sex`, `name`, `hobby`, `type`, `itemsUse`, `priemUse`, `align`, `clan`, `align_zvanie`, `bonus`, `clan_zvanie`, `time_reg`, `city_reg`, `upLevel`, `active`, `expB`, `p_items`, `agressor`, `priems`, `priems_z`, `award`
|
|
||||||
FROM `test_bot`
|
|
||||||
WHERE `id` = "' . $bot['id_bot'] . '"
|
|
||||||
LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isset($add_bot['id'])) {
|
|
||||||
if (isset($logins_bot[$add_bot['login']])) {
|
|
||||||
$logins_bot[$add_bot['login']]++;
|
|
||||||
$add_bot['login'] = $add_bot['login'] . ' (' . $logins_bot[$add_bot['login']] . ')';
|
|
||||||
} else {
|
|
||||||
$logins_bot[$add_bot['login']] = 1;
|
|
||||||
}
|
|
||||||
$ret = true;
|
|
||||||
if ($add_bot['time_reg'] == 100) {
|
|
||||||
$add_bot['time_reg'] = time();
|
|
||||||
}
|
|
||||||
if ($add_bot['city_reg'] == '{thiscity}') {
|
|
||||||
$add_bot['city_reg'] = $bot['userCity'];
|
|
||||||
}
|
|
||||||
$ins1 = mysql_query(
|
|
||||||
'INSERT INTO `users` (
|
|
||||||
`align`,
|
|
||||||
`login`,
|
|
||||||
`level`,
|
|
||||||
`pass`,
|
|
||||||
`city`,
|
|
||||||
`cityreg`,
|
|
||||||
`name`,
|
|
||||||
`sex`,
|
|
||||||
`hobby`,
|
|
||||||
`timereg`,
|
|
||||||
`obraz`,
|
|
||||||
`bot_id`
|
|
||||||
) VALUES (
|
|
||||||
"' . $add_bot['align'] . '",
|
|
||||||
"' . $add_bot['login'] . '",
|
|
||||||
"' . $add_bot['level'] . '",
|
|
||||||
"' . md5('bot_pass_' . $add_bot['login'] . '_') . '",
|
|
||||||
"' . $bot['userCity'] . '",
|
|
||||||
"' . $add_bot['city_reg'] . '",
|
|
||||||
"' . $add_bot['name'] . '",
|
|
||||||
"' . $add_bot['sex'] . '",
|
|
||||||
"' . $add_bot['hobby'] . '",
|
|
||||||
"' . $add_bot['time_reg'] . '",
|
|
||||||
"' . $add_bot['obraz'] . '",
|
|
||||||
"' . $bot['id_bot'] . '"
|
|
||||||
)'
|
|
||||||
);
|
|
||||||
|
|
||||||
# Если бот успешно создан.
|
|
||||||
if ($ins1) {
|
|
||||||
$uid = mysql_insert_id();
|
|
||||||
$ins2 = mysql_query(
|
|
||||||
'INSERT INTO `stats` (`id`,`stats`,`hpNow`,`upLevel`,`bot`) VALUES ("' . $uid . '","' . $add_bot['stats'] . '","1000000","' . $add_bot['upLevel'] . '","1")'
|
|
||||||
);
|
|
||||||
if ($ins2) {
|
|
||||||
$add_bot['id'] = $uid;
|
|
||||||
$add_bot['logins_bot'] = $logins_bot;
|
|
||||||
$ret = $add_bot;
|
|
||||||
|
|
||||||
//Выдаем предметы
|
|
||||||
//$this->addItem($item_id,$uid);
|
|
||||||
$iu = explode(',', $add_bot['itemsUse']);
|
|
||||||
$i = 0;
|
|
||||||
$w3b = 0;
|
|
||||||
while ($i < count($iu)) {
|
|
||||||
if ($iu[$i] > 0) {
|
|
||||||
$idiu = botAddItem($iu[$i], $add_bot['id'], $bot['userCity']);
|
|
||||||
$islot = mysql_fetch_array(
|
|
||||||
mysql_query('SELECT `id`,`inslot` FROM `items_main` WHERE `id` = "' . $iu[$i] . '" LIMIT 1')
|
|
||||||
);
|
|
||||||
if (isset($islot['id'])) {
|
|
||||||
if ($islot['inslot'] == 3) {
|
|
||||||
if ($w3b == 1) {
|
|
||||||
$islot = 14;
|
|
||||||
} else {
|
|
||||||
$islot = 3;
|
|
||||||
$w3b = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$islot = $islot['inslot'];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$islot = 2000;
|
|
||||||
}
|
|
||||||
if (isset($idiu, $islot)) {
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `items_users` SET `inOdet` = "' . $islot . '" WHERE `id` = "' . $idiu . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$ret = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$ret = false;
|
|
||||||
}
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Выдаем предметы Боту.
|
|
||||||
function botAddItem($item_id, $bot_uid, $city)
|
|
||||||
{
|
|
||||||
$i = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT `im`.`id`,`im`.`name`,`im`.`img`,`im`.`type`,`im`.`inslot`,`im`.`2h`,`im`.`2too`,`im`.`iznosMAXi`,`im`.`inRazdel`,`im`.`price1`,`im`.`price2`,`im`.`pricerep`,`im`.`magic_chance`,`im`.`info`,`im`.`massa`,`im`.`level`,`im`.`magic_inci`,`im`.`overTypei`,`im`.`group`,`im`.`group_max`,`im`.`geni`,`im`.`ts`,`im`.`srok`,`im`.`class`,`im`.`class_point`,`im`.`anti_class`,`im`.`anti_class_point`,`im`.`max_text`,`im`.`useInBattle`,`im`.`lbtl`,`im`.`lvl_itm`,`im`.`lvl_exp`,`im`.`lvl_aexp` FROM `items_main` AS `im` WHERE `im`.`id` = "' . mysql_real_escape_string(
|
|
||||||
$item_id
|
|
||||||
) . '" LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (isset($i['id'])) {
|
|
||||||
$d = mysql_fetch_array(
|
|
||||||
mysql_query(
|
|
||||||
'SELECT `id`,`items_id`,`data` FROM `items_main_data` WHERE `items_id` = "' . $i['id'] . '" LIMIT 1'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
//новая дата
|
|
||||||
$data = $d['data'];
|
|
||||||
$ins = mysql_query(
|
|
||||||
'
|
|
||||||
INSERT INTO `items_users` (
|
|
||||||
`overType`,`item_id`,`uid`,`data`,`iznosMAX`,`geniration`,`magic_inc`,`maidin`,`lastUPD`,`time_create`,`dn_delete`
|
|
||||||
) VALUES (
|
|
||||||
"' . $i['overTypei'] . '",
|
|
||||||
"' . $i['id'] . '",
|
|
||||||
"' . $bot_uid . '",
|
|
||||||
"' . $data . '",
|
|
||||||
"' . $i['iznosMAXi'] . '",
|
|
||||||
"' . $i['geni'] . '",
|
|
||||||
"' . $i['magic_inci'] . '",
|
|
||||||
"' . $city . '",
|
|
||||||
"' . time() . '",
|
|
||||||
"' . time() . '",
|
|
||||||
"' . $i['dn_delete'] . '"
|
|
||||||
)'
|
|
||||||
);
|
|
||||||
|
|
||||||
# Если предмет успешно добавлен в базу данных.
|
|
||||||
if ($ins) {
|
|
||||||
$rt = mysql_insert_id();
|
|
||||||
# отключена запись получения предмета в Дело.
|
|
||||||
} else {
|
|
||||||
$rt = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $rt;
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveBots($direction, $b)
|
|
||||||
{
|
|
||||||
$toGoX = 0;
|
|
||||||
$toGoY = 0;
|
|
||||||
|
|
||||||
if (isset($b['noBot']) && $b['noBot'] != '0000') {
|
|
||||||
if ($b['noBot'][0] != '0') {
|
|
||||||
$b['goTop'] = 0;
|
|
||||||
}
|
|
||||||
if ($b['noBot'][1] != '0') {
|
|
||||||
$b['goLeft'] = 0;
|
|
||||||
}
|
|
||||||
if ($b['noBot'][2] != '0') {
|
|
||||||
$b['goBottom'] = 0;
|
|
||||||
}
|
|
||||||
if ($b['noBot'][3] != '0') {
|
|
||||||
$b['goRight'] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$go = [
|
|
||||||
1 => ['d' => (int)$b['goTop'], 'go1' => (int)$b['goLeft'], 'go2' => (int)$b['goRight'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
|
||||||
2 => ['d' => (int)$b['goLeft'], 'go1' => (int)$b['goBottom'], 'go2' => (int)$b['goTop'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
|
||||||
3 => ['d' => (int)$b['goBottom'], 'go1' => (int)$b['goRight'], 'go2' => (int)$b['goLeft'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
|
||||||
4 => ['d' => (int)$b['goRight'], 'go1' => (int)$b['goTop'], 'go2' => (int)$b['goBottom'], 'x' => (int)$b['x'], 'y' => (int)$b['y'], 's' => (int)$b['s']],
|
|
||||||
];
|
|
||||||
$dir = [
|
|
||||||
1 => ['moveForward' => ['x' => '0', 'y' => '1'], 'moveBack' => ['x' => '0', 'y' => '-1'], 'moveGo1' => ['x' => '-1', 'y' => '0'], 'moveGo2' => ['x' => '1', 'y' => '0']],
|
|
||||||
2 => ['moveForward' => ['x' => '-1', 'y' => '0'], 'moveBack' => ['x' => '1', 'y' => '0'], 'moveGo1' => ['x' => '0', 'y' => '-1'], 'moveGo2' => ['x' => '0', 'y' => '1']],
|
|
||||||
3 => ['moveForward' => ['x' => '0', 'y' => '-1'], 'moveBack' => ['x' => '0', 'y' => '1'], 'moveGo1' => ['x' => '1', 'y' => '0'], 'moveGo2' => ['x' => '-1', 'y' => '0']],
|
|
||||||
4 => ['moveForward' => ['x' => '1', 'y' => '0'], 'moveBack' => ['x' => '-1', 'y' => '0'], 'moveGo1' => ['x' => '0', 'y' => '1'], 'moveGo2' => ['x' => '0', 'y' => '-1']],
|
|
||||||
];
|
|
||||||
$go = $go[$direction];
|
|
||||||
$dir = $dir[$direction];
|
|
||||||
if ($go['d'] == 1) {
|
|
||||||
$toGoY = $dir['moveForward']['y'];
|
|
||||||
$toGoX = $dir['moveForward']['x'];
|
|
||||||
if (rand(1, 100) > 66) {
|
|
||||||
if ($go['go1'] == 1 && $go['go2'] == 0) {
|
|
||||||
$toGoY = $dir['moveGo1']['y'];
|
|
||||||
$toGoX = $dir['moveGo1']['x'];
|
|
||||||
} elseif ($go['go1'] == 0 && $go['go2'] == 1) {
|
|
||||||
$toGoY = $dir['moveGo2']['y'];
|
|
||||||
$toGoX = $dir['moveGo2']['x'];
|
|
||||||
} elseif ($go['go1'] == 1 && $go['go2'] == 1) {
|
|
||||||
$a = rand(1, 2);
|
|
||||||
$toGoY = $dir['moveGo' . $a]['y'];
|
|
||||||
$toGoX = $dir['moveGo' . $a]['x'];
|
|
||||||
}
|
|
||||||
} elseif (rand(1, 100) > 96) {
|
|
||||||
$toGoY = $dir['moveBack']['y'];
|
|
||||||
$toGoX = $dir['moveBack']['x'];
|
|
||||||
}
|
|
||||||
} elseif ($go['d'] == 0) {
|
|
||||||
if ($go['go1'] == 1 && $go['go2'] == 1) {
|
|
||||||
if (rand(0, 1) == 1) {
|
|
||||||
$toGoY = $dir['moveGo1']['y'];
|
|
||||||
$toGoX = $dir['moveGo1']['x'];
|
|
||||||
} else {
|
|
||||||
$toGoY = $dir['moveGo2']['y'];
|
|
||||||
$toGoX = $dir['moveGo2']['x'];
|
|
||||||
}
|
|
||||||
} elseif ($go['go1'] == 1 && $go['go2'] == 0) {
|
|
||||||
$toGoY = $dir['moveGo1']['y'];
|
|
||||||
$toGoX = $dir['moveGo1']['x'];
|
|
||||||
} elseif ($go['go1'] == 0 && $go['go2'] == 1) {
|
|
||||||
$toGoY = $dir['moveGo2']['y'];
|
|
||||||
$toGoX = $dir['moveGo2']['x'];
|
|
||||||
} elseif ($go['go1'] == 0 && $go['go2'] == 0) {
|
|
||||||
$toGoY = $dir['moveBack']['y'];
|
|
||||||
$toGoX = $dir['moveBack']['x'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($dir, $go, $direction, $a);
|
|
||||||
return ['x' => (int)$toGoX, 'y' => (int)$toGoY];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# запуск скрипта.
|
|
||||||
function start()
|
|
||||||
{
|
|
||||||
# Страница создана 0.0000
|
|
||||||
$mtime = microtime();
|
|
||||||
$mtime = explode(" ", $mtime);
|
|
||||||
$tstart = $mtime[1] + $mtime[0];
|
|
||||||
|
|
||||||
# Выбираем всех ботов.
|
|
||||||
# В выборку включено: Позиция бота, Направление куда он может идти, Существует ли рядом Игрок, его координаты и в поединке ли он.
|
|
||||||
$query = mysql_query(
|
|
||||||
"SELECT
|
|
||||||
`dn`.`id` as `this_dn`, `dn`.`id2` as `dn_id`, `db`.`id2`, `db`.`id_bot`, `tb`.`login` as login, `db`.`colvo`, `db`.`go_bot`, `db`.`x`, `db`.`y`, `db`.`s`, `db`.`atack`, `tb`.`agressor`,
|
|
||||||
`dm`.`go_1` as `goRight`, `dm`.`go_2` as `goLeft`, `dm`.`go_3` as `goTop`, `dm`.`go_4` as `goBottom`, `dm`.`no_bot` as `noBot`,
|
|
||||||
`user_info`.`id` as `userId`,
|
|
||||||
`user_info`.`login` as `userLogin`,
|
|
||||||
`user_stats`.`hpNow` as `userHP`,
|
|
||||||
`user_stats`.`x` as `userPosX`,
|
|
||||||
`user_stats`.`y` as `userPosY`,
|
|
||||||
`user_info`.`battle` as `userBattle`
|
|
||||||
FROM `dungeon_now` as `dn`
|
|
||||||
LEFT JOIN `dungeon_bots` as `db` ON `db`.`dn` = `dn`.`id`
|
|
||||||
LEFT JOIN `dungeon_map` as `dm` ON ( `dm`.`x` = `db`.`x` AND `dm`.`y` = `db`.`y` AND `dm`.`id_dng` = `dn`.`id2` )
|
|
||||||
LEFT JOIN `test_bot` AS `tb` ON `db`.`id_bot` = `tb`.`id`
|
|
||||||
LEFT JOIN `stats` AS `user_stats` ON ( ( `user_stats`.`x`+1 >= `db`.`x` AND `user_stats`.`x`-1 <= `db`.`x` ) AND ( `user_stats`.`y`+1 >= `db`.`y` AND `user_stats`.`y`-1 <= `db`.`y`) AND `user_stats`.`dnow` = `dn`.`id` )
|
|
||||||
LEFT JOIN `users` AS `user_info` ON ( `user_stats`.`id` = `user_info`.`id` )
|
|
||||||
|
|
||||||
WHERE
|
|
||||||
`dn`.`time_finish` = '0' AND
|
|
||||||
`db`.`atack` = '0' AND
|
|
||||||
`db`.`delete` = '0' AND
|
|
||||||
`db`.`for_dn` = '0' AND
|
|
||||||
( ( `db`.`go_bot` > '" . (time() - 32400) . "' AND `db`.`go_bot` < '" . (time()) . "') OR `db`.`go_bot`='1') AND
|
|
||||||
`db`.`inBattle`='0'
|
|
||||||
GROUP BY `db`.`id2`
|
|
||||||
ORDER BY `db`.`go_bot` ASC"
|
|
||||||
);
|
|
||||||
|
|
||||||
while ($bot = mysql_fetch_array($query)) {
|
|
||||||
if ($bot['go_bot'] > 0 && $bot['go_bot'] <= time()) {
|
|
||||||
$sNext = true;
|
|
||||||
$sTo = $bot['s'];
|
|
||||||
$xFrom = $bot['x']; # текущие координаты X
|
|
||||||
$yFrom = $bot['y']; # текущие координаты Y
|
|
||||||
|
|
||||||
$return = moveBots($bot['s'], $bot);
|
|
||||||
$xTo = $bot['x'] + $return['x'];
|
|
||||||
$yTo = $bot['y'] + $return['y'];
|
|
||||||
# Проверяем, имеется ли переход по клетке.
|
|
||||||
$inSight = 0;
|
|
||||||
if (isset($bot['id2'])) {
|
|
||||||
if ($xFrom == $xTo && $yFrom == $yTo) { # Если остаемся на месте.
|
|
||||||
$inSight = 1;
|
|
||||||
} elseif (isset($bot['goRight']) && $xFrom == $xTo - 1 && $bot['goRight'] == 1) { //право
|
|
||||||
$sTo = 4;
|
|
||||||
$inSight = 1;
|
|
||||||
} elseif (isset($bot['goLeft']) && $xFrom == $xTo + 1 && $bot['goLeft'] == 1) { //лево
|
|
||||||
$sTo = 2;
|
|
||||||
$inSight = 1;
|
|
||||||
} elseif (isset($bot['goTop']) && $yFrom == $yTo - 1 && $bot['goTop'] == 1) { //верх
|
|
||||||
$sTo = 1;
|
|
||||||
$inSight = 1;
|
|
||||||
} elseif (isset($bot['goBottom']) && $yFrom == $yTo + 1 && $bot['goBottom'] == 1) { //низ
|
|
||||||
$sTo = 3;
|
|
||||||
$inSight = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($bot['userId'], $bot['userPosY'], $bot['userPosX']) && $bot['userId'] != '' && $bot['agressor'] == 1 && (
|
|
||||||
($bot['userPosY'] == $bot['y'] + 1 && $bot['userPosX'] == $bot['x']) or
|
|
||||||
($bot['userPosY'] == $bot['y'] - 1 && $bot['userPosX'] == $bot['x']) or
|
|
||||||
($bot['userPosY'] == $bot['y'] && $bot['userPosX'] == $bot['x'] - 1) or
|
|
||||||
($bot['userPosY'] == $bot['y'] && $bot['userPosX'] == $bot['x'] + 1)
|
|
||||||
)) {
|
|
||||||
bot['userPosY'] = $yFrom;
|
|
||||||
$bot['userPosX'] = $xFrom;
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `stats` SET `x` = "' . $xFrom . '" , `y` = "' . $yFrom . '" WHERE `id` = "' . $bot['userId'] . '" LIMIT 1'
|
|
||||||
);
|
|
||||||
botAttack($bot, $bot);
|
|
||||||
} elseif (isset($bot['userId'], $bot['userPosY'], $bot['userPosX']) && $bot['userId'] != '' && $inSight == 1 && $yTo == $bot['userPosY'] && $xTo == $bot['userPosX'] && $bot['atack'] == 1) {
|
|
||||||
botAttack($bot, $bot);
|
|
||||||
} elseif ($inSight == 1) { // Передвижение ботов.
|
|
||||||
$bot['go_bot'] = time() + rand(7, 15);
|
|
||||||
mysql_query(
|
|
||||||
'UPDATE `dungeon_bots` SET `x` = "' . $xTo . '",`y` = "' . $yTo . '", `s` = "' . $sTo . '", `go_bot` = "' . $bot['go_bot'] . '" WHERE `id2` = "' . $bot['id2'] . '" LIMIT 1 '
|
|
||||||
);
|
|
||||||
}
|
|
||||||
unset($xFrom, $yFrom, $xTo, $yTo, $inSight, $sNext, $sTo);
|
|
||||||
}
|
|
||||||
unset($bot);
|
|
||||||
}
|
|
||||||
unset($query, $bot);
|
|
||||||
|
|
||||||
$mtime = microtime();
|
|
||||||
$mtime = explode(" ", $mtime);
|
|
||||||
$mtime = $mtime[1] + $mtime[0];
|
|
||||||
$totaltime = ($mtime - $tstart);
|
|
||||||
printf("Страница сгенерирована за %f секунд !", $totaltime);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Запускаем выполнение процесса.
|
|
||||||
start();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Для оптимизации запроса обновлений позиций
|
|
||||||
|
|
||||||
UPDATE dungeon_bots SET
|
|
||||||
x = CASE
|
|
||||||
WHEN id2 = '.$bot['id2'].' THEN "test2"
|
|
||||||
WHEN id2 = '.$bot['id2'].' THEN "test1" END
|
|
||||||
WHERE id2 IN ('.$bot['id2'].', 2, 3, 4)
|
|
||||||
|
|
||||||
*/
|
|
Loading…
Reference in New Issue
Block a user