game/_incl_data/crons/bot_calls.php

110 lines
3.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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=//img.new-combats.tech/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);
}