game/_incl_data/crons/bot_calls.php
2022-12-30 21:03:50 +02:00

110 lines
3.5 KiB
PHP

<?php
/**
* Âûçîâ áîòîâ â èãðîâûå êîìíàòû.
*
* Çàïóñê ðàç â ìèíóòó.
*/
use Core\Db;
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
function makeLogin(int $id, string $login, int $level): string
{
return <<<HTML
<strong>$login</strong>&nbsp;[$level]&nbsp;
<a target='_blank' href='inf.php?$id'>
<img src=https://img.new-combats.com/i/inf_capitalcity.gif alt='inf'>
</a>
HTML;
}
function testMonster(array $mon): bool // ×ÒÎ ÒÛ ÁËßÒÜ ÒÀÊÎÅ? ×ÒÎ ÒÛ ÏÐÎÂÅÐßÅØÜ? ÊÀÊ ÒÛ ÐÀÁÎÒÀÅØÜ?
{
return
(
$mon['back_day'] === -1 ||
(
$mon['back_day'] === 7 ||
$mon['back_day'] === idate('w')
) &&
$mon['back_day'] === 7
) &&
(
$mon['back_dd'] === -1 ||
$mon['back_dd'] === idate('j')
) &&
(
$mon['back_mm'] === -1 ||
$mon['back_mm'] === idate('n')
) &&
(
$mon['back_hh'] === -1 ||
$mon['back_hh'] === idate('H') &&
(
$mon['back_min'] === -1 ||
$mon['back_min'] >= idate('i')
)
);
}
$rows = Db::getRows('select * from users left join stats on users.id = stats.id where no_ip = \'trupojor\' limit 100');
foreach ($rows as $row) {
$act = 0;
if ($row['online'] < time() - 60) {
$row['online'] = time();
Db::sql('update users set online = ? where id = ?', [$row['online'], $row['id']]);
}
$mon = Db::getRow('select * from aaa_monsters where uid = ?', [$row['id']]);
if ($row['res_x'] < time()) {
if (isset($mon['id'])) { //åñëè áîò â ñïåöèàëüíîì ñïèñêå
// åñëè áîò ñïðÿòàí â äîìèêå (303) - âûïóñêàåì è ëå÷èì åãî
if (testMonster($mon) && $row['room'] == 303) {
Db::sql('update users set room = ? where id = ?', [$mon['start_room'], $row['id']]);
Db::sql('update stats set hpNow = hpAll, mpNow = mpAll where id = ?', [$row['id']]);
if ($mon['start_text']) {
$str = '<span style="color: red">Âíèìàíèå!</span> ';
$str .= str_replace('{b}', makeLogin($row['id'], $row['login'], $row['level']), $mon['start_text']);
Db::sql(
'insert into chat (text, city, type, new, time) values (?,?,6,1,unix_timestamp())',
[$str, $row['city']]
);
}
$act = 1;
}
} else {
//+1hour
Db::sql('update stats set res_x = unix_timestamp() + 3600 where id = ?', [$row['id']]);
}
}
if (
$act == 0 &&
$row['room'] != 303 &&
$row['battle'] == 0 &&
isset($mon['id']) &&
testMonster($mon)
) {
// åñëè áîò íå â äîìèêå, îòïðàëÿåì â äîìèê (303).
Db::sql('update users set room = 303 where id = ?', [$row['id']]);
if ($mon['back_text']) {
$str = '<span style="color: red">Âíèìàíèå!</span> ';
$str .= str_replace('{b}', makeLogin($row['id'], $row['login'], $row['level']), $mon['back_text']);
Db::sql(
'insert into chat (text, city, type, new, time)
values
(?,?,6,1,unix_timestamp()),
(?,?,1,1,unix_timestamp())',
[$str, $row['city'], $str, $row['city']]
);
}
$act = 2;
}
sleep(1);
}