u = User::start();
unset($_POST['kingfight'], $_POST['nobot'], $_POST['mut_clever']);
$this->u->info['no_zv_key'] = true;
if (!empty($_GET['del_z_time'])) {
$zay = Db::getValue(
'select count(*) from zayvki where id = ? and creator = ? and start = 0 and cancel = 0 and btl_id = 0 and priz = 0',
[$this->u->info['zv'], $this->u->info['id']]
);
if ($zay) {
$cols = $this->countUsersAll($this->u->info['zv']);
if ($cols === 1) {
Db::sql('update stats set zv = 0 where id = ?', [$this->u->info['id']]);
Db::sql('delete from zayvki where id = ?', [$this->u->info['zv']]);
}
}
}
$this->test(); //проверяем заявки
}
/** Считаем количество людей в конкретной заявке.
* @param int $frId id заявки
* @return int
*/
private function countUsersAll(int $frId): int
{
return Db::getValue('select count(*) from stats where zv = ?', [$frId]);
}
/** Проверяем заявки
* @return void
*/
private function test()
{
if ($this->u->info['zv'] > 0) {
$z = Db::getValue(
'select count(*) from zayvki where id = ? and (cancel > 0 or btl_id >0 or time < unix_timestamp() - 3600)',
[$this->u->info['zv']]
);
if ($z > 0) {
$this->u->info['zv'] = 0;
Db::sql('update stats set zv = 0 where id = ?', [$this->u->info['id']]);
}
}
$this->testGroupAndChaotic();
}
private function testGroupAndChaotic()
{
//Проверяем хаотичные и групповые бои [в этом городе ?]
$sp = Db::getRows(
'select * from zayvki where btl_id = 0 and cancel = 0 and start = 0 and razdel in (4,5) order by id desc limit 22'
);
foreach ($sp as $pl) {
$uz = Db::getRow(
'select * from users left join stats on users.id = stats.id where zv = ?',
[$pl['id']]
);
$i = [];
$toChat = '';
$toWhere = '';
if (is_iterable($uz)) {
foreach ($uz as $t) {
${'tm' . $t['team']} ??= [];
$i[$t['team']] ??= 0;
${'tm' . $t['team']}[$i[$t['team']]] = $t;
$toChat .= '' . $t['login'] . ',';
$toWhere .= 'OR `id` = "' . $t['id'] . '" ';
$i[$t['team']]++;
}
}
if ($pl['razdel'] == self::BATTLE_RAZDEL_CHAOTIC) {
$cols = $this->countUsersAll($pl['id']);
if ($cols >= $pl['maxplayers']) {
$pl['time_start'] = time() - $pl['time'] - 1;
}
}
if (
$pl['time_start'] >= time() - $pl['time'] &&
($pl['razdel'] != self::BATTLE_RAZDEL_GROUP || $i[1] < $pl['tm1max'] || $i[2] < $pl['tm2max'])
) {
continue;
}
$toChat = rtrim($toChat, ',');
$toWhere = ltrim($toWhere, 'OR ');
if ($pl['razdel'] == self::BATTLE_RAZDEL_GROUP) {
$this->testGroup($i, $pl, $toChat, $toWhere);
} else {
$this->testCronChaotic($pl, $toChat, $toWhere);
}
}
}
private function testGroup($groups, $zayavka, $toChat, $toWhere)
{
if ($zayavka['razdel'] != 4) {
return;
}
if (
empty($groups[1]) ||
empty($groups[2]) ||
(
empty($groups[3]) &&
$zayavka['teams'] == 3
)
) {
//группа не набрана
$this->cancelGroup($zayavka, $toChat);
} else {
//Начинаем поединок
$this->startBattle($zayavka['id'], $toChat . '|-|' . $toWhere);
}
}
private function cancelGroup($zv, $uids, $debug = null)
{
Db::sql('update stats set zv = default where zv = ?', [$zv['id']]);
Db::sql('update zayvki set cancel = unix_timestamp() where id = ?', [$zv['id']]);
if (empty($uids)) {
return;
}
$text = ' Не удалось начать поединок по причине: Группа не набрана!';
if ($zv['priz'] > 0) {
$pg = $this->cancelPrizedChaotic($zv);
if (!empty($pg[0])) {
$uids = $pg[0];
}
$text .= $pg[1];
}
$chat = new Chat();
$chat->sendsys($text . $debug, $uids);
}
private function cancelPrizedChaotic(array $zv): array
{
$stmt = Db::getRows('select id from stats where zv = ?', [$zv['id']]);
foreach ($stmt as $user) {
if ($zv['type'] === self::CHAOTIC_TYPE_PRIZED) {
$stmt2 = Db::getValue('select id from users where inUser = ?', [$user['id']]);
if (!empty($stmt2)) {
Db::sql('update users set inUser = 0 where id = ?', [$stmt2]);
Db::sql('delete from users where id = ?', [$user['id']]);
Db::sql('delete from stats where id = ?', [$user['id']]);
Db::sql('delete from items_users where uid = ?', [$user['id']]);
Db::sql('delete from eff_users where uid = ?', [$user['id']]);
// \Core\ConversionHelper::dataStringToArray(4754, $user['id']);
}
} else {
// \Core\ConversionHelper::dataStringToArray(4754, $user['id']); реликвии ангела
}
}
return [
$stmt2 ?? 0,
' Вы получаете Призовой Жетон (х1)',
];
}
public function startBattle($id, $vars = null)
{
// что это?
$z = Db::getRow(
'select * from zayvki where id = ? and start = 0 and cancel = 0 and (time > unix_timestamp() - 60*60*2 or razdel > 3)',
[$id]
);
if (!isset($z['id'])) {
return;
}
$vars = explode('|-|', $vars);
if ($z['razdel'] == self::BATTLE_RAZDEL_GROUP || $z['razdel'] == self::BATTLE_RAZDEL_CHAOTIC) {
if ($z['razdel'] == self::BATTLE_RAZDEL_CHAOTIC) {
$sp = Db::getRows(
'select id, team, upLevel, btl_cof, exp from stats where zv = ? order by btl_cof desc', [$z['id']]
);
// Разбивка на команды раньше зависела от равной суммы btl_cof в командах, но как это должно было
// работать никто не знал. Теперь просто пул игроков мешается и бьётся пополам. Ins.
$pld2 = [];
$team1IdsArr = [];
$team2IdsArr = [];
foreach ($sp as $pl) {
$pld2[] = $pl;
}
shuffle($pld2);
$pieces = array_chunk($pld2, ceil(count($pld2) / 2));
foreach ($pieces[0] as $team1) {
$team1IdsArr[] = $team1['id'];
}
foreach ($pieces[1] as $team2) {
$team2IdsArr[] = $team2['id'];
}
$team1Ids = implode($team1IdsArr);
$team2Ids = implode($team2IdsArr);
Db::sql('update stats set team = 1 where id in (?)', [$team1Ids]);
Db::sql('update stats set team = 2 where id in (?)', [$team2Ids]);
}
$args = [
$z['otmorozok'],
$z['priz'],
$z['smert'],
$z['noart'],
$z['noeff'],
$z['noatack'],
$z['arand'],
$z['kingfight'],
$z['nobot'],
$z['fastfight'],
$z['razdel'],
$z['city'],
$z['timeout'],
$z['type'],
$z['invise'],
$z['travmChance'],
$z['exp'],
];
$q = 'insert into battle (
otmorozok,
priz,
smert,
noart,
noeff,
noatack,
arand,
kingfight,
nobot,
fastfight,
razdel,
city,
time_start,
timeout,
type,
invis,
travmChance,
addExp
) values (?,?,?,?,?,?,?,?,?,?,?,?,unix_timestamp(),?,?,?,?,?)';
//ТУТ старт боя
Db::sql($q, $args);
unset($q, $args);
$btl_id = Db::lastInsertId();
if ($btl_id) {
if ($z['type'] == self::BATTLE_TYPE_MELEE) {
Db::sql(
'update items_users set inOdet = 0 where uid in (select id from stats where zv = ?)', [$z['id']]
);
} elseif ($z['type'] == self::BATTLE_TYPE_NO_EKR_ITEMS) {
Db::sql(
'update items_users set inOdet = 0 where uid in (select id from stats where zv = ?) and 2price > 0',
[$z['id']]
);
}
//обновляем данные о поединке
Db::sql('update stats set zv = 0 where zv = ?', [$z['id']]);
$q = 'update users set battle = ' . $btl_id . ' where ' . $vars[1];
Db::sql($q);
unset($q);
//обновляем заявку, что бой начался
Db::sql('update zayvki set start = unix_timestamp(), btl_id = ? where id = ?', [$btl_id, $z['id']]);
$this->u->info['battle'] = $btl_id;
//Отправляем сообщение в чат всем бойцам
$this->sendSysChatSound($vars[0], -1);
}
} elseif ($z['razdel'] >= 1 && $z['razdel'] <= 3) {
//начало PvP
if ($this->u->info['team'] != 1 || $this->u->info['zv'] != $z['id']) {
$this->error = 'Вы не можете начать поединок.';
} else {
$enemyId = Db::getValue('select id from stats where zv = ? and team = 2 limit 1', [$z['id']]);
if (!$enemyId) {
$this->error = 'Вы не можете начать поединок, вашу заявку никто не принял.';
} else {
$enemy = Db::getRow('select login, money from users where id = ?', [$enemyId]);
//создаем поединок
if (
$enemy['money'] < $z['money'] ||
$this->u->info['money'] < $z['money']
) {
$z['money'] = 0.00;
}
$args = [
$z['otmorozok'],
$z['smert'],
$z['noart'],
$z['noeff'],
$z['noatack'],
$z['arand'],
$z['kingfight'],
$z['nobot'],
$z['fastfight'],
$this->u->info['city'],
$z['timeout'],
$z['type'],
$z['travmChance'],
$z['money'],
];
$q = 'insert into battle (
otmorozok,
smert,
noart,
noeff,
noatack,
arand,
kingfight,
nobot,
fastfight,
city,
time_start,
timeout,
type,
travmChance,
money
) values (?,?,?,?,?,?,?,?,?,?,unix_timestamp(),?,?,?,?)';
Db::sql($q, $args);
$btl_id = Db::lastInsertId();
unset($q, $args);
if (!$btl_id) {
$this->error = 'Ошибка создания битвы.';
} else {
//обновляем данные о поединке
Db::sql('update stats set zv = 0 where zv = ?', [$z['id']]);
Db::sql(
'update users set battle = ? where id = ? or id = ?',
[$btl_id, $this->u->info['id'], $enemyId]
);
//Если бой кулачный, то снимаем вещи
if ($z['type'] == self::BATTLE_TYPE_MELEE) {
Db::sql(
'update items_users set inOdet = 0 where uid in (?,?) ',
[$this->u->info['id'], $enemyId]
);
}
//обновляем заявку, что бой начался
Db::sql(
'update zayvki set start = unix_timestamp(), btl_id = ? where id = ?', [$btl_id, $z['id']]
);
$this->u->info['battle'] = $btl_id;
//Отправляем сообщение в чат всем бойцам
$this->sendSysChatSound($enemy['login']);
die('');
}
}
}
}
}
/**
* Звуковой пинг в чат?
* @return void
* @todo убрать колхоз с условиями когда станет ясно как оно работает.
*/
private function sendSysChatSound(string $to = '', int $room = 0)
{
$cmsg = new ChatMessage();
if (empty($to)) {
$cmsg->setTo($this->u->info['login']);
} else {
$cmsg->setTo($to);
}
if (empty($room)) {
$cmsg->setRoom($this->u->info['room']);
} else {
$cmsg->setRoom($room);
}
$cmsg->setCity($this->u->info['city']);
$cmsg->setType(11);
$cmsg->setSound(117);
(new Chat())->sendMsg($cmsg);
}
private function testCronChaotic($zayavka, $toChat, $toWhere)
{
$chat = new Chat();
$levelToExp = [
0 => 0,
1 => 110,
2 => 420,
3 => 1300,
4 => 2500,
5 => 5000,
6 => 12500,
7 => 30000,
8 => 300000,
9 => 3000000,
10 => 10000000,
11 => 52000000,
12 => 63000000,
13 => 182000000,
14 => 212000000,
15 => 352000000,
16 => 504000000,
17 => 1187000000,
18 => 2455000000,
19 => 4387000000,
20 => 6355000000,
21 => 15500000000,
22 => 755500000000,
];
$botUsers = [];
define('FAST_FIGHT_REQUIRED_FIGHTERS_COUNT', 2);
define('FIGHT_REQUIRED_FIGHTERS_COUNT', 6);
$requiredFightersToStartBattle = FIGHT_REQUIRED_FIGHTERS_COUNT;
if ($zayavka['fastfight'] > 0) {
$requiredFightersToStartBattle = FAST_FIGHT_REQUIRED_FIGHTERS_COUNT;
}
$pendingFightersCount = $this->countUsersAll($zayavka['id']);
if ($pendingFightersCount < $requiredFightersToStartBattle) {
//группа не набрана
//Добавляем недостающих игроков
if (!$zayavka['nobot']) { // Если нет запрета на ботов.
//$getRealPlayersQuery = 'select * from stats left join users on stats.id = users.id where exp >= ? and exp < ? and bot = 0 order by btl_cof desc limit 50';
$getBotsQuery = 'select * from stats left join users on stats.id = users.id where bot = 2 and exp >= ? and exp < ?';
$botUsers = Db::getRows(
$getBotsQuery,
[$levelToExp[$zayavka['min_lvl_1']], $levelToExp[$zayavka['max_lvl_1'] + 1]]
);
}
if (empty($botUsers)) {
$text = ' Не удалось начать поединок по причине: Группа не набрана. (' . $zayavka['id'] . ': 0 ' . $levelToExp[$zayavka['min_lvl_1']] . '-' . $levelToExp[$zayavka['max_lvl_1'] + 1] . ')';
$chat->sendsys($text, 'Merlin');
$this->cancelGroup($zayavka, $toChat, ' Боты проспали.');
} else {
$pendingBotsCount = 0;
for ($i = 0; $i < $requiredFightersToStartBattle - $pendingFightersCount; $i++) {
shuffle($botUsers);
$botInfo = array_shift($botUsers);
$botData = [
'id' => $botInfo['id'],
'login' => $botInfo['login'],
'level' => $botInfo['level'],
'city' => $botInfo['city'],
'cityreg' => $botInfo['city'],
'name' => $botInfo['login'],
'sex' => $botInfo['sex'],
'hobby' => '',
'time_reg' => time(),
'obraz' => $botInfo['obraz'],
'stats' => $botInfo['stats'],
'upLevel' => $botInfo['upLevel'],
'priems' => $botInfo['priems'],
'loclon' => true,
];
$bot = $this->u->addNewbot(1, null, $botData, null, true);
if (!$bot) {
continue;
}
Db::sql(
'update stats set btl_cof = ?, zv = ?, hpNow = 1000000, mpNow = 1000000 where id = ?',
[$botInfo['btl_cof'], $zayavka['id'], $bot]
);
Db::sql('update users set room = 303, battle = 0 where id = ?', [$bot]);
$pendingBotsCount++;
}
unset($botUsers, $botInfo, $botData, $bot);
if ($pendingBotsCount + $pendingFightersCount >= $requiredFightersToStartBattle) {
$this->backTest = true;
self::$bcktst = true;
}
}
} else {
//Начинаем поединок
$this->startBattle($zayavka['id'], $toChat . '|-|' . $toWhere);
}
}
public function testCronZv()
{
$this->testCronGroupAndChaotic();
if ($this->backTest || self::$bcktst) {
self::$bcktst = false;
$this->testCronZv();
}
}
/** Проверяем хаотичные и групповые бои [в этом городе ?] */
private function testCronGroupAndChaotic(): void
{
$zv1k = Db::getRows(
'select * from zayvki where btl_id = 0 and cancel = 0 and start = 0 and razdel in (4, 5) order by id desc'
);
foreach ($zv1k as $zv) {
$i = [];
$toChat = $toWhere = '';
$users = Db::getRows(
'select * from stats left join users on stats.id = users.id where zv = ?',
[$zv['id']]
);
foreach ($users as $user) {
${'tm' . $user['team']} ??= [];
$i[$user['team']] ??= 0;
${'tm' . $user['team']}[$i[$user['team']]] = $user;
$toChat .= $user['login'] . ',';
$toWhere .= 'OR id = ' . $user['id'] . ' ';
$i[$user['team']]++;
}
if (
$zv['time_start'] > time() - $zv['time'] &&
($zv['razdel'] != self::BATTLE_RAZDEL_GROUP || $i[1] < $zv['tm1max'] || $i[2] < $zv['tm2max'])
) {
continue;
}
$toChat = rtrim($toChat, ',');
$toWhere = ltrim($toWhere, 'OR ');
if ($zv['razdel'] == self::BATTLE_RAZDEL_GROUP) {
$this->testGroup($i, $zv, $toChat, $toWhere);
} else {
$this->testCronChaotic($zv, $toChat, $toWhere);
}
}
}
public function addGroupOrChaoticRequest(int $r)
{
if (!in_array($r, [self::BATTLE_RAZDEL_GROUP, self::BATTLE_RAZDEL_CHAOTIC])) {
return;
}
$k = (int)$_POST['k'];
$az = 1;
if ($this->testTravm() == 1 && $k !== 1) {
$this->error = 'Вы травмированы. С такими увечьями доступны кулачные бои.';
$az = 0;
} elseif ($this->testTravm() == 2) {
$this->error = 'Вы травмированы. С такими увечьями невозможно сражаться.';
$az = 0;
} elseif ($this->u->isWeakened()) {
$this->error = 'Вы еще слишком ослаблены чтобы начать новый бой';
$az = 0;
}
if ($this->u->info['zv'] > 0) {
$this->error = 'Вы уже находитесь в заявке.';
$az = 0;
}
if ($az === 0) {
return;
}
$timeout = (int)$_POST['timeout'];
$nz = [];
$nz['travmaChance'] = 0;
$nz['time_start'] = 0;
$nz['tm1max'] = 0;
$nz['tm2max'] = 0;
$nz['invise'] = 0;
$nz['tm1'] = 0;
$nz['tm2'] = 0;
$nz['otmorozok'] = 0;
$nz['fastfight'] = 0;
$nz['noinc'] = 0;
$nz['type'] = 0;
if ($k === 1) {
$nz['type'] = 1;
}
if ($k === 2) {
$nz['type'] = 6;
$nz['travmaChance'] = 100;
}
if (!in_array($timeout, [1, 2, 3, 4, 5])) {
$timeout = 3;
}
$nz['timeout'] = $timeout * 60;
$nz['razdel'] = $r;
$nz['comment'] = substr($_POST['cmt'], 0, 40);
$nz['comment'] = str_replace('"', '"', $nz['comment']);
$gad = 1;
if ($r == self::BATTLE_RAZDEL_CHAOTIC) {
//хаотичный бой
if ($_POST['startime2']) {
$nz['time_start'] = (int)$_POST['startime2'];
if (!in_array($nz['time_start'], [60, 180, 300])) {
$nz['time_start'] = 600;
}
if (isset($_POST['mut_hidden'])) {
$nz['invise'] = 1;
}
if (isset($_POST['noinc'])) {
$nz['noinc'] = 1;
}
if (isset($_POST['fastfight'])) {
$nz['fastfight'] = 1;
}
if (isset($_POST['otmorozok'])) {
$nz['otmorozok'] = 1;
}
if (isset($_POST['nobot'])) {
$nz['nobot'] = 1;
}
if (isset($_POST['kingfight'])) {
$nz['kingfight'] = 1;
}
if (isset($_POST['arand'])) {
$nz['arand'] = 1;
}
if (isset($_POST['travma'])) {
$nz['travmaChance'] = 100;
}
if (isset($_POST['noatack'])) {
$nz['noatack'] = 1;
}
if (isset($_POST['noeff'])) {
$nz['noeff'] = 1;
}
if (isset($_POST['smert'])) {
$nz['smert'] = 1;
}
if (isset($_POST['noart'])) {
$nz['noart'] = 1;
}
if ($nz['kingfight'] == 1 && $nz['fastfight'] == 1) {
$nz['kingfight'] = 0;
}
//Генерируем уровни
$levels = FRHelper::getChaoticTeammatesLevel($_POST['levellogin1'], $this->u->info['level']);
$nz['min_lvl_1'] = $levels->min;
$nz['max_lvl_1'] = $levels->max;
$nz['min_lvl_2'] = $levels->min;
$nz['max_lvl_2'] = $levels->max;
$nz['tm1'] = $this->u->stats['reting'];
if (
!$this->u->info['no_zv_key'] &&
(
$_POST['code21'] == 0 ||
$_POST['code21'] != $_SESSION['code2'] ||
$_SESSION['code2'] == 0 ||
!isset($_SESSION['code2'])
)
) {
$this->error = 'Неправильный код подтверждения';
$gad = 0;
}
} else {
$gad = 0;
$this->error = 'Что-то не так...
';
}
} elseif ($r == self::BATTLE_RAZDEL_GROUP) {
//групповой бой
//здесь заносим и проверяем данные на гурпповой бой
if ($_POST['startime']) {
$nz['time_start'] = (int)$_POST['startime'];
if (!in_array($nz['time_start'], [300, 600, 900, 1200, 1800])) {
$nz['time_start'] = 600;
}
$nz['tm1max'] = Comparsion::minimax((int)$_POST['nlogin1'], 1, 99);
$nz['tm2max'] = Comparsion::minimax((int)$_POST['nlogin2'], 1, 99);
//Генерируем уровни союзника
$levels = FRHelper::getTeammatesLevel($_POST['levellogin1'], $this->u->info['level']);
$nz['min_lvl_1'] = $levels->min;
$nz['max_lvl_1'] = $levels->max;
//Генерируем уровни противника
$levels = FRHelper::getTeammatesLevel($_POST['levellogin2'], $this->u->info['level']);
$nz['min_lvl_2'] = $levels->min;
$nz['max_lvl_2'] = $levels->max;
} else {
$gad = 0;
$this->error = 'Что-то не так...
';
}
}
$bt2 = (int)$_POST['bots2'];
if ($bt2 != 0 && $r == self::BATTLE_RAZDEL_GROUP) {
$bt2 = 1;
$nz['min_lvl_2'] = $this->u->info['level'];
$nz['max_lvl_2'] = $this->u->info['level'];
$nz['min_lvl_1'] = $this->u->info['level'];
$nz['max_lvl_1'] = $this->u->info['level'];
} else {
$bt2 = 0;
}
if ($gad == 1) {
if ($nz['razdel'] == self::BATTLE_RAZDEL_CHAOTIC) {
$nz['maxplayers'] = (int)$_POST['players'];
}
$dbvalues = [
$nz['maxplayers'],
$nz['otmorozok'],
$nz['smert'],
$nz['noart'],
$nz['noeff'],
$nz['noatack'],
$nz['arand'],
$nz['kingfight'],
$nz['nobot'],
$nz['fastfight'],
$nz['noinc'],
$bt2,
strtotime(date('d.m.Y H:i:00')),
$this->u->info['city'],
$this->u->info['id'],
$nz['type'],
$nz['time_start'],
$nz['timeout'],
$nz['min_lvl_1'],
$nz['min_lvl_2'],
$nz['max_lvl_1'],
$nz['max_lvl_2'],
$nz['tm1max'],
$nz['tm2max'],
$nz['travmaChance'],
$nz['invise'],
$nz['razdel'],
$nz['comment'],
$nz['tm1'],
$nz['tm2'],
];
$dbquery = 'insert into zayvki (`maxplayers`,`otmorozok`,`smert`,`noart`,`noeff`,`noatack`,`arand`,`kingfight`,`nobot`,`fastfight`,`noinc`,`bot2`,`time`,`city`,`creator`,`type`,`time_start`,`timeout`,`min_lvl_1`,`min_lvl_2`,`max_lvl_1`,`max_lvl_2`,`tm1max`,`tm2max`,`travmaChance`,`invise`,`razdel`,`comment`,`tm1`,`tm2`) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
Db::run($dbquery, $dbvalues);
$zid = Db::lastInsertId();
if ($zid) {
Db::sql('update stats set zv = ?, team = 1 where id = ?', [$zid, $this->u->info['id']]);
$this->u->info['zv'] = $zid;
$this->error = 'Заявка на бой подана';
} else {
$this->error = 'Ошибка: Заявка не подана!';
}
}
}
private function testTravm()
{
$tr = Db::getValue(
'select v1 from eff_users where id_eff = 4 and `delete` = 0 and uid = ? order by v1 desc limit 1',
[$this->u->info['id']]
);
return $tr ? $tr - 1 : 0;
}
public function getCurrentStatus(array $zi, int $r)
{
// нахуй статус
// если у меня нет заявки
// если я в бою
// если я не в тех категориях
if (
!$this->u->info['zv'] || $this->u->info['battle'] > 0 ||
!in_array($r, [self::BATTLE_RAZDEL_GROUP, self::BATTLE_RAZDEL_CHAOTIC, self::BATTLE_RAZDEL_TOURNAMENTS])
) {
return;
}
$battleType = [
self::BATTLE_RAZDEL_GROUP => 'группового',
self::BATTLE_RAZDEL_CHAOTIC => 'хаотичного',
];
$tm_start = floor(($zi['time'] + $zi['time_start'] - time()) / 6) / 10;
$tm_start = $this->rzv($tm_start);
echo 'Ожидаем начала ' . $battleType[$zi['razdel']] . ' боя';
echo '
Ваш бой начнется через ' . $tm_start . ' мин.';
}
/** Дописывает значение после точки, если такового нет. 1 -> 1.0, 1.1 -> 1.1
* @param string $str
* @return string
*/
public function rzv(string $str): string
{
$symbols = explode('.', $str);
return isset($symbols[1]) ? $symbols[0] . '.' . $symbols[1] : $symbols[0] . '.0';
}
public function getEndedBattlesList(string $slogin, int $dt)
{
$code = PassGen::intCode();
$btl = '';
$see = '';
$usr = Db::getRow('select id, login, level, city from users where login = ? limit 1', [$slogin]);
if (isset($usr['id'])) {
$tms = $dt;
$tmf = $dt + 86400;
$sp = Db::getRows(
'select * from battle_last where time >= ? and time < ? and uid = ? order by id desc ',
[$tms, $tmf, $usr['id']]
);
$jk = 0;
$btl_lst = [];
foreach ($sp as $pl) {
$b = Db::getRow('select * from battle_end where battle_id = ? limit 1', [$pl['battle_id']]);
$tm = '';
if (isset($b['id'])) {
$tms = [];
$ts = [];
$spi = Db::getRows('select * from battle_last where battle_id = ?', [$pl['battle_id']]);
foreach ($spi as $pli) {
if (!isset($tms[$pli['team']])) {
$ts[] = $pli['team'];
}
$tms[$pli['team']][count($tms[$pli['team']])] = $pli;
}
$k = 0;
while ($k < count($ts)) {
$g = $ts[$k];
$h = 0;
$tm2 = '';
while ($h < count($tms[$g])) {
if ($tms[$g][$h]['uid'] > 0) {
if ($tms[$g][$h]['align'] > 0) {
$tm2 .= '';
}
$tm2 .= '' . $tms[$g][$h]['login'] . ' [' . $tms[$g][$h]['lvl'] . ']
, ';
}
$h++;
}
$tm2 = rtrim($tm2, ', ');
$btlg = Db::getValue('select id, team_win from battle where id = ?', [$pl['battle_id']]);
if (isset($btlg['id']) && $g == $btlg['team_win']) {
$tm2 .= ' ';
}
$tm .= $tm2;
if ($k + 1 < count($ts) && $tm2 != '' && $ts[$k + 1] > 0) {
$tm .= ' против ';
}
$k++;
}
}
if (!isset($btl_lst[$b['id']])) {
$btl_lst[$b['id']] = true;
if ($tm == '') {
$tm = 'Данные поединка потеряны';
}
$jk++;
$btl .= $jk . '. ' . date(
'd.m.y H:i', $pl['time']
) . ' ' . $tm . ' »»
';
}
}
}
$see .= empty($btl) ? '