game/_incl_data/class/Battle/Finish.php

1916 lines
102 KiB
PHP
Raw Normal View History

2023-12-19 01:58:37 +00:00
<?php
namespace Battle;
use Actions;
use Battle;
use Chat;
use ChatMessage;
use Core\Config;
use Core\Db;
use Delo;
use ItemModel;
use User;
use User\Clan;
use User\Effects;
use User\ItemsModel;
use User\Reputation;
use User\StatsModel;
class Finish
{
private array $ainm = [];
private int $expCoef = 0; # % опыта в бою
private int $aBexp = 0; //Добавочный опыт в боях
private Battle $battle;
public function __construct(Battle $battle)
{
$this->battle = $battle;
}
public function finishBattle(?array $t, ?array $v, ?int $nl): void
{
global $u;
$injuryName = [1 => 'легкую', 2 => 'среднюю', 3 => 'тяжелую', 4 => 'неизлечимую',];
$dnr = 0; //???
$chat = new Chat();
mysql_query('LOCK TABLES users,stats,battle,battle_last,battle_end,chat WRITE');
$test = Db::getRow('select id, team_win, testfinish from battle where id = ? and team_win != -1', [$this->battle->info['id']]);
if ($test['testfinish'] == -1) {
sleep(2);
} else {
Db::sql('update battle set testfinish = -1 where id = ?', [$this->battle->info['id']]);
if ($nl != 10 && $this->battle->info['team_win'] == -1) {
$this->battle->info['team_win'] = 0;
if (is_array($v) && is_array($t)) {
foreach ($v as $vs) {
if ($vs < 1 || $t[$vs] <= 0) {
continue;
}
$this->battle->info['team_win'] = $vs;
}
}
}
//данные о игроках в бою
$t = Db::getRows(
"select
*,
users.id as id,
users.level as level,
users.align as align,
users.sex as sex,
users.clan as clan,
stats.timeGo as timeGo,
users.name as name,
stats.lider as lider,
if(login2 = '',login,login2) as login2
from users
left join stats on users.id = stats.id
where battle = ?", [$this->battle->info['id']]
);
foreach ($t as $userInBattle) {
$this->battle->users[] = $userInBattle;
end($this->battle->users);
$this->battle->uids[$userInBattle['id']] = key($this->battle->users);
if ($userInBattle['bot'] > 0) {
$this->battle->bots[] = $userInBattle;
end($this->battle->bots);
$this->battle->setIBotsValue($userInBattle['id'], key($this->battle->bots));
}
$this->battle->stats[key($this->battle->users)] = $u->getStats(uid: $userInBattle['id'], minimal: true);
}
if ($this->battle->info['time_over'] == 0) {
$tststrt = Db::getRow('select * from battle where id = ? and time_over = 0', [$this->battle->info['id']]);
if (isset($tststrt['id'])) {
if ($this->battle->info['inTurnir'] == 0 || $this->battle->info['type'] == 500) {
Db::sql('update battle set time_over = unix_timestamp(), team_win = ? where id = ?', [$this->battle->info['team_win'], $this->battle->info['id']]);
}
//Заносим данные о завершении боя
$queryValues = '';
$vtvl = '';
foreach ($this->battle->users as $user) {
$inner = implode(
"','",
[
$user['login'],
$user['city'],
$this->battle->info['id'],
$user['id'],
$user['team'],
$user['level'],
$user['align'],
$user['clan'],
$user['exp'],
$user['bot'],
$user['money'],
$user['money2'],
$user['money3'],
]
);
$queryValues .= "('$inner',unix_timestamp()),";
if ($user['team'] == $this->battle->info['team_win'] && $this->battle->info['team_win'] > 0) {
$vtvl .= '<strong>' . $user['login'] . '</strong>, ';
}
}
$this->battle->info['players_c'] = Db::getValue("select count(id) from users where login not like '%(зверь%' and battle = ?", [$this->battle->info['id']]);
Db::sql('update battle set players_c = ? where id = ?', [$this->battle->info['players_c'], $this->battle->info['id']]);
if (!empty($vtvl)) {
$vtvl = rtrim($vtvl, ', ');
$vtvl = str_replace('"', '\\\\\"', $vtvl);
$logtext = "Бой закончен, победа за $vtvl.";
} else {
$this->battle->info['players_cc'] = $this->battle->info['players_cc2'] = 0;
$logtext = 'Бой закончен, ничья.';
}
$this->battle->hodID++;
Log::add(
[
'battle' => $this->battle->info['id'],
'id_hod' => $this->battle->hodID,
'text' => $logtext,
'vars' => 'time1=' . time(),
'type' => 1,
]
);
unset($logtext);
$this->saveLogs();
if ($this->battle->info['type'] == 99) {
$logarray = [
'battle' => $this->battle->info['id'],
'id_hod' => $this->battle->hodID,
'text' => 'И победители стали калечить проигравших...',
'vars' => 'time1=' . time(),
'type' => '1',
];
Log::add($logarray);
$vtvl = '';
foreach ($this->battle->users as $userToInjure) {
if ($userToInjure['team'] == $this->battle->info['team_win']) {
continue;
}
$injuryCaster = Db::getRow('select id, v1 from eff_users where id_eff = 4 and uid = ? order by v1 desc limit 1');
if (!empty($injuryCaster['id']) && $injuryCaster['v1'] >= 3) {
continue;
}
$a = $userToInjure['sex'] == 1 ? 'а' : '';
$injuryType = $this->battle->info['smert'] == 1 ? 4 : mt_rand(1, 3);
if (!empty($injuryCaster['id'])) {
$injuryType = mt_rand($injuryCaster['v1'] + 1, 3);
}
$vtvl = "<strong>{$userToInjure['login']}</strong> получил$a повреждение:" .
" <span style='color: crimson;'>$injuryName[$injuryType]</span>.<br>$vtvl";
$this->battle->addTravm($userToInjure['id'], $injuryType, rand(3, 5));
}
$logarray['text'] = $vtvl;
Log::add($logarray);
}
if (!empty($queryValues)) {
$queryValues = rtrim($queryValues, ',');
Db::sql("insert into battle_last (login,city,battle_id,uid,team,lvl,align,clan,exp,bot,money,money2,money3,time) values $queryValues");
}
Db::sql(
'insert into battle_end (battle_id, city, time, team_win) values (?,?,?,?)',
[$this->battle->info['id'], $this->battle->info['city'], $this->battle->info['time_start'], $this->battle->info['team_win']]
);
}
$logarray = [
'battle' => $this->battle->info['id'],
'id_hod' => $this->battle->hodID,
'vars' => 'time1=' . time(),
'type' => '1',
];
$vtvl = '';
foreach ($this->battle->users as $userToInjure) {
if ($userToInjure['team'] == $this->battle->info['team_win'] || $this->battle->info['team_win'] == 0) {
continue;
}
$injuryCaster = Db::getRow("select id, v1, data, user_use from eff_users where v1 = 'priem' and v2 = 292 and uid = ? limit 1");
if (empty($injuryCaster['id']) || mt_rand(0, 100) >= $injuryCaster['data']) {
continue;
}
$a = $userToInjure['sex'] == 1 ? 'а' : '';
$injuryType = mt_rand($injuryCaster['v1'] + 1, 3);
$injuryCasterLogin = $this->battle->users[$this->battle->uids[$injuryCaster['user_use']]]['login'];
$vtvl = "<strong>{$userToInjure['login']}</strong> получил$a повреждение" .
" (Искалечить, автор: <strong>$injuryCasterLogin</strong>):" .
" <span style='color: crimson;'>$injuryName[$injuryType]</span>.<br>$vtvl";
$this->battle->addTravm($userToInjure['id'], $injuryType, rand(3, 5));
}
if (!empty($vtvl)) {
if ($this->battle->info['type'] != 99) {
$logarray['text'] = 'И победители стали калечить проигравших...';
Log::add($logarray);
}
$logarray['text'] = $vtvl;
Log::add($logarray);
}
//Турнир БС
if ($this->battle->info['inTurnir'] > 0 && $this->battle->info['dungeon'] != 15 && $u->info['room'] != 413) {
$bs = mysql_fetch_array(
mysql_query('SELECT * FROM `bs_turnirs` WHERE `id` = "' . $this->battle->info['inTurnir'] . '" LIMIT 1')
);
$i = 0;
$j = 0;
while ($i < count($this->battle->users)) {
$text = '';
if ($this->battle->stats[$i]['hpNow'] < 1 && $this->battle->users[$i]['clone'] == 0 && $this->battle->stats[$i]['clone'] == 0) {
//Добавляем в лог БС
if ($this->battle->users[$i]['sex'] == 0) {
$text .= '{u1} повержен и выбывает из турнира';
} else {
$text .= '{u1} повержена и выбывает из турнира';
}
//Выкидываем предметы с персонажа
$spik = mysql_query(
'SELECT `id`,`item_id` FROM `items_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" AND `delete` ="0"'
);
while ($plik = mysql_fetch_array($spik)) {
mysql_query(
'INSERT INTO `dungeon_items` (`dn`,`item_id`,`time`,`x`,`y`) VALUES (
"' . $this->battle->users[$i]['dnow'] . '","' . $plik['item_id'] . '","' . (time(
) - 600) . '","' . $this->battle->users[$i]['x'] . '","' . $this->battle->users[$i]['y'] . '"
)'
);
}
unset($spik, $plik);
//
$usrreal = '';
$usr_real = mysql_fetch_array(
mysql_query(
'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `login` = "' . $this->battle->users[$i]['login'] . '" AND `inUser` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
)
);
if (!isset($usr_real['id'])) {
$usr_real = $this->battle->users[$i];
}
if (isset($usr_real['id'])) {
if ($usr_real['align'] > 0) {
$usrreal .= '<img src=//img.new-combats.tech/i/align/align' . $usr_real['align'] . '.gif width=12 height=15 >';
}
if ($usr_real['clan'] > 0) {
$usrreal .= '<img src=//img.new-combats.tech/i/clan/' . $usr_real['clan'] . '.gif width=24 height=15 >';
}
$usrreal .= '<strong>' . $usr_real['login'] . '</strong>[' . $usr_real['level'] . ']<a target=_blank href=/info/' . $usr_real['id'] . ' ><img src=//img.new-combats.tech/i/inf_capitalcity.gif alt=""></a>';
}
$text = str_replace('{u1}', $usrreal, $text);
mysql_query(
'INSERT INTO `bs_logs` (`type`,`text`,`time`,`id_bs`,`count_bs`,`city`,`m`,`u`) VALUES (
"1", "' . mysql_real_escape_string($text) . '", "' . time() . '", "' . $bs['id'] . '", "' . $bs['count'] . '", "' . $bs['city'] . '",
"' . round($bs['money'] * 0.85, 2) . '","' . $i . '"
)'
);
//
//Удаление клона
mysql_query('DELETE FROM `users` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1');
mysql_query('DELETE FROM `stats` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1');
mysql_query('DELETE FROM `actions` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '"');
mysql_query('DELETE FROM `items_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '"');
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '"');
mysql_query('DELETE FROM `users_delo` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '"');
//Обновление персонажа
mysql_query(
'UPDATE `users` SET `inUser` = "0" WHERE `login` = "' . $this->battle->users[$i]['login'] . '" OR `inUser` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
//Обновляем заявку
mysql_query(
'UPDATE `bs_zv` SET `off` = "' . time() . '" WHERE `inBot` = "' . $this->battle->users[$i]['id'] . '" AND `off` = "0" LIMIT 1'
);
unset($text, $usrreal, $usr_real);
if ($this->battle->users[$i]['pass'] != 'bstowerbot') {
$bs['users']--;
$bs['users_finish']++;
} else {
$bs['arhiv']--;
}
$j++;
}
$i++;
}
if ($j > 0) {
mysql_query(
'UPDATE `bs_turnirs` SET `arhiv` = "' . $bs['arhiv'] . '",`users` = "' . $bs['users'] . '",`users_finish` = "' . $bs['users_finish'] . '" WHERE `id` = "' . $bs['id'] . '" LIMIT 1'
);
}
unset($bs, $j);
}
//Награда за события
if ($this->battle->info['type'] == 500 && isset($tststrt['id'])) {
//Предметы которые выпадают в центр
$i = 0;
while ($i < count($this->battle->users)) {
$cmsg = new ChatMessage();
$cmsg->setType(6);
$cmsg->setIsAlert(true);
if ($this->battle->users[$i]['no_ip'] == 'trupojor') {
$mon = mysql_fetch_array(
mysql_query(
'SELECT * FROM `aaa_monsters` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
)
);
if (isset($mon['id'])) {
if ($this->battle->info['team_win'] == 0) {
//Ничья
mysql_query(
'UPDATE `stats` SET `hpNow` = "' . $this->battle->stats[$i]['hpAll'] . '",`mpNow` = "' . $this->battle->stats[$i]['mpAll'] . '" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
$cmsg->setText(
str_replace(
'{b}',
'<strong>' . $this->battle->users[$i]['login'] . '</strong> [' . $this->battle->users[$i]['level'] . ']<a target=_blank href=info/' . $this->battle->users[$i]['id'] . ' ><img alt="" src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>',
$mon['nich_text']
)
);
$chat->sendMsg($cmsg);
} elseif ($this->battle->info['team_win'] != $this->battle->users[$i]['team']) {
//Выиграли
$j = 0;
$usrwin = '';
while ($j < count($this->battle->users)) {
if ($this->battle->users[$j]['no_ip'] != 'trupojor' && $this->battle->users[$j]['bot'] == 0 && $this->battle->stats[$j]['hpNow'] > 0) {
$usrwin .= ', ';
if ($this->battle->users[$j]['align'] > 0) {
$usrwin .= '<img width=12 height=15 src=//img.new-combats.tech/i/align/align' . $this->battle->users[$j]['align'] . '.gif >';
}
if ($this->battle->users[$j]['clan'] > 0) {
$usrwin .= '<img width=24 height=15 src=//img.new-combats.tech/i/clan/' . $this->battle->users[$j]['clan'] . '.gif >';
}
$usrwin .= '<strong>' . $this->battle->users[$j]['login'] . '</strong> [' . $this->battle->users[$j]['level'] . ']<a target=_blank href=info/' . $this->battle->users[$j]['id'] . ' ><img alt="" src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
}
$j++;
}
if ($usrwin != '') {
$usrwin = ltrim($usrwin, ', ');
} else {
$usrwin = '<i>Команда героев</i>';
}
mysql_query(
'UPDATE `users` SET `room` = "303" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
$truptimelast = time() + rand(1800, 3600);
mysql_query(
'UPDATE `stats` SET `res_x` = "' . $truptimelast . '" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
$cmsg->setText(
str_replace(
'{b}',
'<strong>' . $this->battle->users[$i]['login'] . '</strong> [' . $this->battle->users[$i]['level'] . ']<a target=_blank href=info/' . $this->battle->users[$i]['id'] . ' ><img alt="" src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>',
str_replace('{u}', $usrwin, $mon['win_text'])
)
);
$chat->sendMsg($cmsg);
unset($usrwin);
} else {
//Проиграли
if ($mon['win_back'] == 1) {
mysql_query(
'UPDATE `users` SET `room` = "303" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
}
mysql_query(
'UPDATE `stats` SET `hpNow` = "' . $this->battle->stats[$i]['hpAll'] . '",`mpNow` = "' . $this->battle->stats[$i]['mpAll'] . '" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
$cmsg->setText(
str_replace(
'{b}',
'<strong>' . $this->battle->users[$i]['login'] . '</strong> [' . $this->battle->users[$i]['level'] . ']<a target=_blank href=info/' . $this->battle->users[$i]['id'] . ' ><img alt="" src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>',
$mon['lose_text']
)
);
$chat->sendMsg($cmsg);
}
}
}
$i++;
}
}
}
// выкидываем ботов из боя
$i = 0;
$botsi = 0;
if (isset($tststrt['id'])) {
while ($i < count($this->battle->users)) {
//Тут выкидываем юзеров из Призавого хаота
if ($this->battle->info['type'] == 33) {
$plde = mysql_fetch_array(
mysql_query('SELECT * FROM `users` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1')
);
if (isset($plde['mail']) && $plde['mail'] == "haot@new-combats.com") {
$pld = mysql_fetch_array(
mysql_query(
'SELECT * FROM `users` WHERE `inUser` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
)
);
if (isset($pld['id'])) {
if ($this->battle->users[$i]['battle_yron'] >= 500) {
mysql_query(
'UPDATE `users_achiv` SET `pg`= `pg`+1 WHERE `id` = "' . $pld['id'] . '" LIMIT 1'
);
if ($this->battle->users[$i]['team'] == $this->battle->info['team_win'] && rand(1, 100) <= 5) {
ItemsModel::addItem(10020, $pld['id'], '');
$pld['battle_text'] .= ' За Героическое Сражение вы получаете <strong>Жетон Успеха</strong>. ';
}
} else {
$pld['battle_text'] .= ' Вы ничего не получили. <strong>Нужно набить больше 500 урона урона</strong> .';
}
$cmsg = new ChatMessage();
$cmsg->setRoom($pld['room']);
$cmsg->setTo($pld['login']);
$cmsg->setText($pld['battle_text']);
$cmsg->setType(6);
$chat->sendMsg($cmsg);
mysql_query(
'DELETE FROM `stats` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
mysql_query(
'DELETE FROM `items_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" LIMIT 100'
);
mysql_query(
'DELETE FROM `eff_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" LIMIT 100'
);
mysql_query(
'UPDATE `users` SET `inUser` = "0" WHERE `inUser` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
mysql_query(
'DELETE FROM `users` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
}
}
unset ($plde, $pld);
}
if ($this->battle->users[$i]['bot'] == 1) {
$botsi++;
mysql_query('DELETE FROM `users` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1');
mysql_query('DELETE FROM `stats` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1');
mysql_query(
'DELETE FROM `items_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" LIMIT 100'
);
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" LIMIT 100');
} elseif ($this->battle->users[$i]['bot'] == 2 || $this->battle->users[$i]['bot'] > 0) {
$this->battle->users[$i]['battle'] = 0;
mysql_query(
'UPDATE `users` SET `battle` = "0" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
mysql_query(
'UPDATE `stats` SET `zv` = "0",`team` = "0",`exp` = `exp` + `battle_exp`,`battle_exp` = "0",`battle_yron` = "0",`enemy` = "0", `timeGo` = "' . time(
) . '" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" LIMIT 100');
}
if ($this->battle->users[$i]['clone'] > 0 && $this->battle->users[$i]['bot'] > 0 && isset($this->battle->users[$this->battle->uids[$this->battle->users[$i]['clone']]]['id']) && $this->battle->users[$this->battle->uids[$this->battle->users[$i]['clone']]]['team'] != $this->battle->users[$i]['team']) {
//Добавляем что клон побежден
if ($this->battle->users[$this->battle->uids[$this->battle->users[$i]['clone']]]['team'] == $this->battle->info['team_win']) {
$u->addAction(time(), 'win_bot_clone', '', $this->battle->users[$i]['clone']);
} elseif ($this->battle->info['team_win'] == 0) {
$u->addAction(time(), 'nich_bot_clone', '', $this->battle->users[$i]['clone']);
} else {
$u->addAction(time(), 'lose_bot_clone', '', $this->battle->users[$i]['clone']);
}
} elseif ($this->battle->users[$i]['bot'] > 0 && $this->battle->users[$i]['bot_id'] > 0) {
//Добавляем что бота победили
$j = 0;
while ($j < count($this->battle->users)) {
if ($this->battle->users[$j]['bot'] == 0 && $this->battle->users[$j]['team'] != $this->battle->users[$i]['team']) {
if ($this->battle->users[$j]['team'] == $this->battle->info['team_win']) { // if($this->battle->users[$j]['team']==$this->battle->info['team_win']){
$u->addAction(
time(), 'win_bot_' . $this->battle->users[$i]['bot_id'], '',
$this->battle->users[$j]['id']
);
//
mysql_query(
'UPDATE `dialog_act` SET `now` = `now` + 1 WHERE `uid` = "' . $this->battle->users[$j]['id'] . '" AND
( `btl_bot` LIKE "' . $this->battle->users[$i]['bot_id'] . '!%" OR `btl_bot` LIKE "%!' . $this->battle->users[$i]['bot_id'] . '!%" )
AND `val` != 1
LIMIT 1'
);
//
} elseif ($this->battle->info['team_win'] == 0) {
$u->addAction(
time(), 'nich_bot_' . $this->battle->users[$i]['bot_id'], '',
$this->battle->users[$j]['id']
);
} else {
$u->addAction(
time(), 'lose_bot_' . $this->battle->users[$i]['bot_id'], '',
$this->battle->users[$j]['id']
);
}
}
$j++;
}
}
$i++;
}
}
//Из бота падают предметы
if ($nl != 10 && $this->battle->info['dungeon'] > 0) {
if ($this->battle->info['team_win'] == $u->info['team'] && $this->battle->info['dungeon'] == 102) {
$j1 = mysql_fetch_array(
mysql_query(
'SELECT * FROM `laba_obj` WHERE `type` = 2 AND `lib` = "' . $this->battle->info['dn_id'] . '" AND `x` = "' . $this->battle->info['x'] . '" AND `y` = "' . $this->battle->info['y'] . '" LIMIT 1'
)
);
if (isset($j1['id'])) {
mysql_query('DELETE FROM `laba_obj` WHERE `id` = "' . $j1['id'] . '" LIMIT 1');
//Выпадает шмотка
mysql_query(
'INSERT INTO `laba_obj` (`use`,`lib`,`time`,`type`,`x`,`y`,`vars`) VALUES (
"0","' . $j1['lib'] . '","' . time() . '","6","' . $j1['x'] . '","' . $j1['y'] . '","' . ($botsi) . '"
)'
);
}
} elseif ($this->battle->info['team_win'] == $u->info['team']) {
//выйграли люди, выкидываем предметы из мобов
$j1 = mysql_query(
'SELECT * FROM `dungeon_bots` WHERE `dn` = "' . $this->battle->info['dn_id'] . '" AND `for_dn` = "0" AND `x` = "' . $this->battle->info['x'] . '" AND `delete` = "0" AND `y`= "' . $this->battle->info['y'] . '" LIMIT 100'
);
while ($tbot = mysql_fetch_array($j1)) {
$cmsg = new ChatMessage();
$cmsg->setDn($this->battle->info['dn_id']);
$cmsg->setRoom($this->battle->users[0]['room']);
$cmsg->setType(6);
$cmsg->setTypeTime(1);
$tbot2 = mysql_fetch_array(
mysql_query(
'SELECT * FROM `test_bot` WHERE `id` = "' . $tbot['id_bot'] . '" LIMIT 1'
)
);
$j2 = 0;
while ($j2 < $tbot['colvo']) {
if (isset($tbot['id2'])) {
$itms = explode('|', $tbot2['p_items']);
$tii = 0;
$testdrop = 0;
while ($tii < count($itms) && $testdrop == 0) {
$itmz = explode('=', $itms[$tii]);
if ($itmz[0] > 0) {
if (isset($itmz[2]) && $itmz[2] != '') { // $itmz[2] == quest888
$questDrop = mysql_fetch_array(
mysql_query(
'SELECT * FROM `actions` WHERE `vars` LIKE "%' . $itmz[2] . '%" AND `vals` = "go" AND `uid` = "' . $u->info['id'] . '" LIMIT 1'
)
);
}
if (!isset($questDrop['id']) && isset($itmz[2]) && $itmz[2] != '') {
$itmz[1] = 0;
} // Если предмет квестовый, а квеста у игрока нет, то предмет выпадет с вероятностью 0
//Добавляем этот предмет в зону Х и У
if ($itmz[1] * 100000 >= rand(1, 10000000)) {
$tou = 0; //какому юзеру предназначено
/* выделяем случайного юзера из команды */
$cmsg->setText(
'У <strong>' . $tbot2['login'] . '</strong> был предмет &quot;' . ItemModel::getNameById($itmz[0]) . '&quot; и кто угодно может поднять его'
);
$chat->sendMsg($cmsg);
mysql_query(
'INSERT INTO `dungeon_items` (`dn`,`user`,`item_id`,`time`,`x`,`y`) VALUES (
"' . $this->battle->info['dn_id'] . '",
"' . $tou . '",
"' . $itmz[0] . '",
"' . time() . '",
"' . $this->battle->info['x'] . '",
"' . $this->battle->info['y'] . '")'
);
if (!isset($questDrop['id'])) {
$testdrop = 1; //ТУТ drop-drop //quest
}
}
}
$tii++;
}
}
$j2++;
}
//
//Квест 1-15 сентября,
if (
date('m') == 9 &&
date('d') < 15 &&
!Helper::getChanse(99) &&
($this->battle->info['dungeon'] == 12 || $this->battle->info['dungeon'] == 101)
) {
$tou = 0; //какому юзеру предназначено
/* выделяем случайного юзера из команды */
$itmz = [
mt_rand(4745, 4751),
100,
];
$cmsg->setText(
'У <strong>' . $tbot2['login'] . '</strong> был предмет &quot;' . ItemModel::getNameById(mt_rand(4745, 4751)) . '&quot; и кто угодно может поднять его'
);
$chat->sendMsg($cmsg);
mysql_query(
'INSERT INTO `dungeon_items` (`dn`,`user`,`item_id`,`time`,`x`,`y`) VALUES (
"' . $this->battle->info['dn_id'] . '",
"' . $tou . '",
"' . $itmz[0] . '",
"' . time() . '",
"' . $this->battle->info['x'] . '",
"' . $this->battle->info['y'] . '")'
);
}
//
//Странички саныча,
if (rand(1, 100) > 99) {
continue;
}
if (
$this->battle->info['dungeon'] == 12 || $this->battle->info['dungeon'] == 3 ||
$this->battle->info['dungeon'] == 101 || $this->battle->info['dungeon'] == 16 ||
$this->battle->info['dungeon'] == 9 || $this->battle->info['dungeon'] == 10 ||
$this->battle->info['dungeon'] == 13 || $this->battle->info['dungeon'] == 106
) {
$tou = 0; //какому юзеру предназначено
// выделяем случайного юзера из команды
$itmz = mt_rand(3143, 3192);
$cmsg->setText(
'У <strong>' . $tbot2['login'] . '</strong> был предмет &quot;' . ItemModel::getNameById($itmz) . '&quot; и кто угодно может поднять его'
);
$chat->sendMsg($cmsg);
mysql_query(
'INSERT INTO `dungeon_items` (`dn`,`user`,`item_id`,`time`,`x`,`y`) VALUES (
"' . $this->battle->info['dn_id'] . '",
"' . $tou . '",
"' . $itmz . '",
"' . time() . '",
"' . $this->battle->info['x'] . '",
"' . $this->battle->info['y'] . '")'
);
}
}
mysql_query(
'UPDATE `dungeon_bots` SET `delete` = "' . time(
) . '" AND `inBattle` = "' . $this->battle->info['id'] . '" WHERE `dn` = "' . $this->battle->info['dn_id'] . '" AND `for_dn` = "0" AND `delete` = "0" '
);
} else {
//выкидываем всех игроков в клетку RESTART
$dnr = 1;
if ($this->battle->info['dungeon'] != 102) {
mysql_query(
'UPDATE `dungeon_bots` SET `inBattle` = "0" WHERE `dn` = "' . $this->battle->info['dn_id'] . '" AND `for_dn` = "0" AND `x` = "' . $this->battle->info['x'] . '" AND `y`= "' . $this->battle->info['y'] . '"'
);
}
}
}
$gm = [];
$gms = [];
$bm = [];
$bms = [];
//Квестовый раздел
//Квестовый раздел
//завершаем поединок
$i = $this->battle->uids[$u->info['id']];
if ($this->battle->info['team_win'] >= 0) {
$cmsg = new ChatMessage();
$cmsg->setRoom($this->battle->users[$i]['room']);
$cmsg->setType(6);
if ($this->battle->stats[$i]['pbe'] > 0) {
//Бонус покупателя
$this->expCoef += $this->battle->stats[$i]['pbe'];
}
if ($this->battle->info['razdel'] == 5 && (Config::get('m') >= 6 && Config::get('m') <= 8 || Config::get('w') == 0 || Config::get('w') == 6)) {
$this->expCoef += 5;
}
$this->battle->stats[$i]['exp'] += $this->expCoef;
$this->battle->stats[$i]['exp'] += $this->aBexp * Config::get('exp');
if ($this->battle->stats[$i]['os4'] > 0) {
$this->battle->stats[$i]['exp'] += $this->battle->stats[$i]['os4'];
}
$act01 = 0;
$this->battle->users[$i]['battle_exp'] = round(
$this->battle->users[$i]['battle_exp'] + ($this->battle->users[$i]['battle_exp'] / 100 * (1 + $this->battle->info['addExp'] + $this->battle->stats[$i]['exp']))
);
if ($this->battle->info['type'] == 564) {
//Бой с копией
$this->battle->users[$i]['battle_exp'] = 0;
}
if ($this->battle->info['dungeon'] == 104) {
$this->battle->users[$i]['battle_exp'] = ($u->info['level'] * 2) * (count($this->battle->uids) - 1);
} elseif ($this->battle->info['dungeon'] > 0 && $this->battle->users[$i]['dnow'] != 0 && $this->battle->info['dungeon'] != 1 && $this->battle->users[$i]['team'] == $this->battle->info['team_win']) {
$dun_limitForLevel = [
4 => 750,
5 => 1500,
6 => 3500,
7 => 8000,
8 => 25000,
9 => 50000,
10 => 75000,
11 => 100000,
12 => 100000,
13 => 100000,
14 => 100000,
];
// Максимум для каждого уровня.
if ($this->battle->users[$i]['battle_exp'] > 0) {
$dun_exp = []; // Текущий лимит опыта игрока в подземельях.
$rep = mysql_fetch_array(
mysql_query(
'SELECT `dungeonexp`,`id` FROM `rep` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
)
);
$rep = explode(',', $rep['dungeonexp']);
foreach ($rep as $val) {
$val = explode('=', $val); // текущий лимит опыта в подземке
if (isset($val[0]) && isset($val[1]) && $val[0] != '' && $val[1] != 0) {
$dun_exp[(int)$val[0]] = (int)$val[1];
}
}
unset($rep);
}
if (!isset($dun_exp[$this->battle->info['dungeon']])) {
$dun_exp[$this->battle->info['dungeon']] = 0;
}
if (!isset($dun_limitForLevel[(int)$this->battle->users[$i]['level']])) { // Если лимит не задан, опыт не даем.
$this->battle->users[$i]['battle_exp'] = 0;
} elseif (
isset($dun_exp[$this->battle->info['dungeon']]) &&
$dun_exp[$this->battle->info['dungeon']] >= $dun_limitForLevel[(int)$this->battle->users[$i]['level']]
) { // Если лимит уже достигнут, опыт не даем.
$this->battle->users[$i]['battle_exp'] = 0;
} elseif (
isset($dun_exp[$this->battle->info['dungeon']]) &&
$dun_limitForLevel[(int)$this->battle->users[$i]['level']] > $dun_exp[$this->battle->info['dungeon']]
) { // Если текущая репутация не достигла лимита.
if (($dun_exp[$this->battle->info['dungeon']] + $this->battle->users[$i]['battle_exp']) > $dun_limitForLevel[(int)$this->battle->users[$i]['level']]) {
// Если опыта набрано достаточно, для достижения лимита.
$this->battle->users[$i]['battle_exp'] = abs(
$this->battle->users[$i]['battle_exp'] - abs(
$dun_limitForLevel[(int)$this->battle->users[$i]['level']] - ($this->battle->users[$i]['battle_exp'] + $dun_exp[$this->battle->info['dungeon']])
)
);
$dun_exp[$this->battle->info['dungeon']] += $this->battle->users[$i]['battle_exp'];
} elseif ($dun_limitForLevel[(int)$this->battle->users[$i]['level']] > ($dun_exp[$this->battle->info['dungeon']] + $this->battle->users[$i]['battle_exp'])) {
// Если опыта недостаточно, для достижения лимита.
$dun_exp[$this->battle->info['dungeon']] += $this->battle->users[$i]['battle_exp'];
} else {
$this->battle->users[$i]['battle_exp'] = 0;
}
} else { // В любой непонятной ситуцаии.
$this->battle->users[$i]['battle_exp'] = 0;
}
if ($this->battle->users[$i]['battle_exp'] > 0 && isset($dun_exp[$this->battle->info['dungeon']]) && $dun_exp[$this->battle->info['dungeon']] > 0) {
$dunexp = [];
foreach ($dun_exp as $key => $val) {
$dunexp[$key] = $key . '=' . $val; // текущий лимит опыта в подземке
}
$dun_exp = implode(",", $dunexp);
mysql_query(
'UPDATE `rep` SET `dungeonexp` = "' . $dun_exp . '" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
unset($dunexp, $dun_exp);
}
unset($dun_limitForLevel);
}
$sinf = '';
if (Config::get('exp_mega')) {
$this->battle->users[$i]['battle_exp'] += floor(
$this->battle->users[$i]['battle_exp'] / 100 * Config::get('exp_mega_val')[$this->battle->users[$i]['level']]
);
}
if ($this->battle->info['team_win'] == 0 && $this->battle->info['type'] != 564) {
if ($this->battle->users[$i]['level'] <= 1) {
$this->battle->users[$i]['battle_exp'] = floor($this->battle->users[$i]['battle_exp'] * 0.50);
} else {
$this->battle->users[$i]['battle_exp'] = ceil($this->battle->users[$i]['battle_exp'] * 0.10);
}
$this->battle->users[$i]['nich'] += 1;
} elseif ($this->battle->users[$i]['team'] == $this->battle->info['team_win'] && $this->battle->info['type'] != 564) {
$gm[$i] = $this->battle->info['money'];
$gms[$i] = $this->battle->info['money3'];
$this->battle->users[$i]['win'] += 1;
$act01 = 1;
} elseif ($this->battle->info['type'] != 564) {
if ($this->battle->users[$i]['level'] <= 1) {
$this->battle->users[$i]['battle_exp'] = ceil($this->battle->users[$i]['battle_exp'] * 0.33);
} else {
$this->battle->users[$i]['battle_exp'] = ceil($this->battle->users[$i]['battle_exp'] * 0.10);
}
$bm[$i] = $this->battle->info['money'];
$bms[$i] = $this->battle->info['money3'];
$this->battle->users[$i]['lose'] += 1;
$act01 = 2;
}
//Рассчитываем кол-во выигрышных сумм и кто сколько получил (для екр.)
if ($this->battle->info['money3'] > 0 && isset($gms[$i]) && $this->battle->info['type'] != 564) {
$mn = [
'l' => 0, //сколько проигравших игроков
'w' => 0, //сколько выигрывших игроков
'm' => 0, //сумма выигрыша (общая)
];
if ($act01 == 1) {
$mn['l'] = mysql_fetch_array(
mysql_query(
'SELECT COUNT(`id`) FROM `battle_users` WHERE `battle` = "' . $this->battle->info['id'] . '" AND `team` != "' . $this->battle->users[$i]['team'] . '" LIMIT 1'
)
);
$mn['l'] = $mn['l'][0];
$mn['w'] = mysql_fetch_array(
mysql_query(
'SELECT COUNT(`id`) FROM `battle_users` WHERE `battle` = "' . $this->battle->info['id'] . '" AND `team` = "' . $this->battle->users[$i]['team'] . '" LIMIT 1'
)
);
$mn['w'] = $mn['w'][0];
$mn['m'] = round(($mn['l'] * $this->battle->info['money3']) / 100 * 87, 2);
$gms[$i] = round(($mn['m'] / $mn['w']), 2);
}
}
//заносим данные в БД
//Поломка предметов
$lom = 0;
if ($act01 == 1) {
//победа
if ($this->battle->users[$i]['dnow'] == 0 && $this->battle->users[$i]['hpNow'] < 1) {
$lom = 0.05;
}
} elseif ($act01 == 2) {
//поражение
$lom = 0.55;
} else {
//ничья
$lom = 0.05;
}
$nlom = [0 => rand(0, 18), 1 => rand(0, 18), 2 => rand(0, 18), 3 => rand(0, 18)];
if ($this->battle->info['type'] == 564 || $this->battle->stats[$i]['silver']) {
$lom = 0;
}
mysql_query(
'UPDATE `items_users` SET `iznosNOW` = `iznosNOW`+' . $lom . ' WHERE `inOdet` < "18" AND `inOdet` > "0" AND `uid` = "' . $this->battle->users[$i]['id'] . '" AND `inOdet`!="0" AND `inOdet`!=' . $nlom[0] . ' AND `inOdet`!=' . $nlom[1] . ' AND `inOdet`!=' . $nlom[2] . ' AND `inOdet`!=' . $nlom[3] . ' LIMIT 18'
);
$prc = '';
if ($this->battle->users[$i]['align'] == 2) {
$this->battle->users[$i]['battle_exp'] = floor($this->battle->users[$i]['battle_exp'] / 2);
}
if ($this->battle->users[$i]['animal'] > 0) {
$ulan = $u->testAction(
'`uid` = "' . $this->battle->users[$i]['id'] . '" AND `vars` = "animal_use' . $this->battle->info['id'] . '" LIMIT 1',
1
);
if (isset($ulan['id']) && $this->battle->users[$i]['team'] == $this->battle->info['team_win'] && $this->battle->users[$i]['level'] > $ulan['vals']) {
$a004 = mysql_fetch_array(
mysql_query(
'SELECT `max_exp`,`name` FROM `users_animal` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" AND `id` = "' . $this->battle->users[$i]['animal'] . '" AND `pet_in_cage` = "0" AND `delete` = "0" LIMIT 1'
)
);
//33% от опыта переходит зверю, но не более максимума
$aexp = (round($this->battle->users[$i]['battle_exp'] / 100 * 33));
if ($aexp > $a004['max_exp']) {
$aexp = $a004['max_exp'];
}
unset($ulan);
//
$cmsg->setTo($this->battle->users[$i]['login']);
$cmsg->setText("Ваш питомец «{$a004['name']}» получил опыт: <strong>$aexp</strong>");
$chat->sendMsg($cmsg);
//
$upd = mysql_query(
'UPDATE `users_animal` SET `exp` = `exp` + ' . $aexp . ' WHERE `id` = "' . $this->battle->users[$i]['animal'] . '" AND `level` < ' . $this->battle->users[$i]['level'] . ' LIMIT 1'
);
if ($upd) {
$this->battle->users[$i]['battle_exp'] = round($this->battle->users[$i]['battle_exp'] / 100 * 67);
$this->battle->info['addExp'] -= 33.333;
}
}
}
$prsusers = mysql_fetch_array(
mysql_query(
'SELECT SUM(`price1`) FROM `battle_users` WHERE `battle` = "' . $this->battle->info['id'] . '" LIMIT 1'
)
);
$btlstatus = $this->typeBattle($prsusers[0]);
if ($this->battle->info['smert'] == 1) {
$btlstatus = [150, 150, 'Жесточайшее Сражение', 'Жесточайшее Сражение'];
}
//
if ($this->battle->stats[$i]['clanpos'] > 0 && ($this->battle->stats[$i]['clanpos'] == 1 || $this->battle->stats[$i]['clanpos'] == 2 || $this->battle->stats[$i]['clanpos'] == 3)) {
$this->battle->info['addExp'] += 0;
}
unset($r1);
//Статусная битва
if ($btlstatus[0] > 0) {
if ($this->battle->info['type'] == 99) {
$this->battle->info['addExp'] += $btlstatus[1];
} else {
$this->battle->info['addExp'] += $btlstatus[0];
}
}
if ($this->battle->users[$i]['align'] == 2 || $this->battle->users[$i]['haos'] > time()) {
$this->battle->stats[$i]['exp'] = -($this->battle->info['addExp'] + 50);
}
if ($this->battle->info['addExp'] + $this->battle->stats[$i]['exp'] != 0) {
$prc = ' (' . (100 + $this->battle->info['addExp'] + $this->battle->stats[$i]['exp']) . '%)';
}
if ($this->battle->info['money'] > 0) {
if (isset($gm[$i])) {
$prc .= ' Вы выйграли <strong>' . $gm[$i] . ' кр.</strong> за этот бой.';
Delo::add(
4,
'System.battle',
$this->battle->users[$i]['id'],
'&quot;<span style="color: olive; ">System.battle</span>&quot;: Персонаж выйграл <strong>' . $gm[$i] . ' кр.</strong> (В бою №' . $this->battle->info['id'] . ').',
);
$this->battle->users[$i]['money'] += $gm[$i];
} elseif (isset($bm[$i])) {
$prc .= ' Вы заплатили <strong>' . $bm[$i] . ' кр.</strong> за этот бой.';
Delo::add(
4,
'System.battle',
$this->battle->users[$i]['id'],
'&quot;<span style="color: olive; ">System.battle</span>&quot;: Персонаж <i>проиграл</i> <strong>' . $gm[$i] . ' кр.</strong> (В бою №' . $this->battle->info['id'] . ').',
);
$this->battle->users[$i]['money'] -= $bm[$i];
}
}
if (Config::get('money_haot') && $this->battle->users[$i]['exp'] <= 200000000 && $act01 == 1 && $this->battle->info['razdel'] == 5 && $this->battle->users[$i]['level'] >= 8) {
//Сколько нужно опыта набить
$trexp = [
8 => 1200,
9 => 3000,
10 => 4500,
11 => 12000,
12 => 20000,
13 => 30000,
14 => 30000,
15 => 30000,
16 => 30000,
17 => 30000,
18 => 30000,
19 => 30000,
20 => 30000,
21 => 30000,
];
$trexp = $trexp[$this->battle->users[$i]['level']];
//Сколько екр дается
$admn = [
8 => 0.05, //0.05
9 => 0.065, //0.065
10 => 0.075, //0.075
11 => 0.085, //0.085
12 => 0.1, //0.1
13 => 0.1,
14 => 0.1,
15 => 0.1,
16 => 0.1,
17 => 0.1,
18 => 0.1,
19 => 0.1,
20 => 0.1,
21 => 0.1,
];
$admn = $admn[$this->battle->users[$i]['level']];
if (Config::get('m') >= 6 && Config::get('m') <= 8) {
//Летний период
if (Config::get('w') == 0 || Config::get('w') == 5 || Config::get('w') == 6) {
//Выходные дни
$admn = $admn * 2;
}
} elseif (Config::get('w') == 0 || Config::get('w') == 5 || Config::get('w') == 6) {
//Выходные дни
$admn = $admn * 2;
}
if ($this->battle->users[$i]['battle_exp'] < $trexp) {
$prc .= ', Награда <strong>0 ЕКР</strong> за этот бой (Мало опыта набили).';
} elseif ($admn > 0) {
if ($this->battle->info['type'] != 33) {
$prc .= ', Награда <strong>' . $admn . ' ЕКР</strong> за этот бой.';
}
Delo::add(
4,
'System.battle',
$this->battle->users[$i]['id'],
'&quot;<span style="color: olive; ">System.battle</span>&quot;: Персонаж получил <strong>' . $admn . ' ЕКР</strong> (В бою №' . $this->battle->info['id'] . ').',
);
$this->battle->users[$i]['money2'] += $admn;
}
}
if ($this->battle->info['money3'] > 0) {
if (isset($gms[$i])) {
$prc .= ' Вы выйграли <strong>' . $gms[$i] . ' $.</strong> за этот бой.';
Delo::add(
4,
'System.battle',
$this->battle->users[$i]['id'],
'&quot;<span style="color: olive; ">System.battle</span>&quot;: Персонаж выйграл <strong>' . $gms[$i] . ' $.</strong> (В бою №' . $this->battle->info['id'] . ').',
);
$this->battle->users[$i]['money3'] += $gms[$i];
mysql_query(
'UPDATE `users` SET `money3` = `money3` + "' . $gms[$i] . '" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
} elseif (isset($bms[$i])) {
$prc .= ' Вы заплатили <strong>' . $bms[$i] . ' $.</strong> за этот бой.';
Delo::add(
4,
'System.battle',
$this->battle->users[$i]['id'],
'&quot;<span style="color: olive; ">System.battle</span>&quot;: Персонаж <i>проиграл</i> <strong>' . $gms[$i] . ' $.</strong> (В бою №' . $this->battle->info['id'] . ').',
);
$this->battle->users[$i]['money3'] -= $bms[$i];
mysql_query(
'UPDATE `users` SET `money3` = `money3` - "' . $bms[$i] . '" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
}
}
$lime = [
8 => 18000,
9 => 28000,
10 => 84000,
11 => 100,
12 => 100,
13 => 100,
14 => 100,
15 => 100,
16 => 100,
17 => 100,
18 => 100,
19 => 100,
20 => 100,
21 => 100,
];
if ($this->battle->users[$i]['level'] < 8) {
$lime = 5400;
} else {
$lime = $lime[$this->battle->users[$i]['level']];
}
if ($this->battle->stats[$i]['silver'] >= 5) {
$lime += round($lime);
}
if ($this->battle->users[$i]['stopexp'] == 1) {
$lime = 0;
$this->battle->users[$i]['battle_exp'] = 0;
}
if ($lime < $this->battle->users[$i]['battle_exp'] && Config::get('limitedexp')) {
$this->battle->users[$i]['battle_exp'] = $lime;
}
unset($lime);
if ($btlstatus[0] > 0) {
if ($this->battle->info['type'] == 99) {
$prc .= ' (' . $btlstatus[3] . ')';
} else {
$prc .= ' (' . $btlstatus[2] . ')';
}
}
if ($this->battle->info['dungeon'] == 1 && $this->battle->users[$i]['team'] == $this->battle->info['team_win']) {
//канализация лимит
$rep = mysql_fetch_array(
mysql_query(
'SELECT `dl1`,`id` FROM `rep` WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
)
);
if ($rep['dl' . $this->battle->info['dungeon']] > 0) {
$this->battle->users[$i]['battle_exp'] += 3 * count($this->battle->users);
if ($rep['dl' . $this->battle->info['dungeon']] > $this->battle->users[$i]['battle_exp']) {
$rep['dl' . $this->battle->info['dungeon']] -= $this->battle->users[$i]['battle_exp'];
} else {
$this->battle->users[$i]['battle_exp'] = $rep['dl' . $this->battle->info['dungeon']];
$rep['dl' . $this->battle->info['dungeon']] = 0;
}
mysql_query(
'UPDATE `rep` SET `dl' . $this->battle->info['dungeon'] . '` = "' . $rep['dl' . $this->battle->info['dungeon']] . '" WHERE `id` = "' . $rep['id'] . '" LIMIT 1'
);
} else {
$this->battle->users[$i]['battle_exp'] = 0;
}
}
if ($this->battle->users[$i]['battle_exp'] < 1) {
$this->battle->users[$i]['battle_exp'] = 0;
}
if (
$this->battle->users[$i]['battle_exp'] < 1 &&
$this->battle->users[$i]['twink'] == 0 &&
$this->battle->info['money'] == 0 &&
$this->battle->info['money3'] == 0 &&
$this->battle->info['kingfight'] == 0 &&
(!isset($admnb) || $admnb == 0)
) {
$prc = '';
}
if ($this->battle->users[$i]['host_reg'] == 'real_bot_user') {
$this->battle->users[$i]['battle_exp'] = round($this->battle->users[$i]['battle_exp'] / 3);
}
if ($sinf != '') {
$sinf = ' ( ' . $sinf . ' )';
}
//--------------Лимит 8-9--------------
if ($this->battle->users[$i]['level'] == 8 && $this->battle->users[$i]['battle_exp'] >= 23000) {
$this->battle->users[$i]['battle_exp'] = 23000;
}
if ($this->battle->users[$i]['level'] == 9 && $this->battle->users[$i]['battle_exp'] >= 31000) {
$this->battle->users[$i]['battle_exp'] = 31000;
}
if ($this->battle->users[$i]['level'] == 10 && $this->battle->users[$i]['battle_exp'] >= 52000) {
$this->battle->users[$i]['battle_exp'] = 52000;
}
if ($this->battle->users[$i]['level'] >= 11 && $this->battle->users[$i]['battle_exp'] >= 75000) {
$this->battle->users[$i]['battle_exp'] = 75000;
}
//-------------------------------------
if ($this->battle->info['type'] != 33) {
$this->battle->users[$i]['battle_text'] = 'Бой закончен. Всего вами нанесено урона: <strong>' . floor(
$this->battle->users[$i]['battle_yron']
) . ' HP</strong>. Получено опыта: <strong>' . (0 + $this->battle->users[$i]['battle_exp']) . '</strong>' . $prc . '.' . $sinf; //stats
}
//Снижение времени Право на подвиг Титул за победу в хаоте
if ($this->battle->info['dungeon'] == 0 && $this->battle->info['razdel'] == 5 && $this->battle->users[$i]['team'] == $this->battle->info['team_win']) {
//ТУТ2
StatsModel::addRepexpById($this->battle->users[$i]['id'], 2); //Репутация за поб в хаоте +2
$check = mysql_fetch_array(
mysql_query(
'SELECT * FROM `eff_users` WHERE `id_eff` = 478 AND `uid` = "' . $this->battle->users[$i]['id'] . '" AND `delete` = 0 ORDER BY `overType` DESC LIMIT 1;'
)
);
if (isset($check['id'])) {
$urcheck = 10000;
if ($this->battle->users[$i]['level'] == 8) {
$urcheck = 3000;
} elseif ($this->battle->users[$i]['level'] == 9) {
$urcheck = 7000;
} elseif ($this->battle->users[$i]['level'] == 10) {
$urcheck = 12000;
} elseif ($this->battle->users[$i]['level'] >= 11) {
$urcheck = 18000;
}
if ($this->battle->users[$i]['battle_yron'] >= $urcheck) {
mysql_query(
'UPDATE `eff_users` SET `timeUse` = `timeUse` - 300 WHERE `id_eff`=478 AND `delete` = 0 AND `uid` =' . $this->battle->users[$i]['id'] . ' LIMIT 1'
);
$this->battle->users[$i]['battle_text'] .= ' За победу в хаоте и нанесение урона в <strong>' . $urcheck . '</strong> и более вы получаете <strong>-5 мин.</strong> к праву на подвиг!';
}
}
mysql_query(
'UPDATE `users_achiv` SET `vx`= `vx`+1 WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
); //
}
//Награда за клан вар
if ($this->battle->info['dungeon'] == 0 && $this->battle->info['type'] == 250 && $this->battle->users[$i]['team'] == $this->battle->info['team_win']) {
mysql_query(
'UPDATE `users_achiv` SET `kw`= `kw`+1 WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
if (date('w') == 0 || date('w') == 6 || date('w') == 4) {
StatsModel::addRepexpById($this->battle->users[$i]['id'], 25); //Клановые войны(победа) 25
}
}
//Награда за клан вар
if (
$this->battle->info['dungeon'] == 0 &&
$this->battle->info['type'] == 99 &&
$this->battle->users[$i]['team'] == $this->battle->info['team_win'] &&
(date('w') == 0 || date('w') == 6 || date('w') == 5)
) {
StatsModel::addRepexpById($this->battle->users[$i]['id'], 10); //Кровавые войны(победа) 10
}
//Новая выдача на трупожора
if ($this->battle->info['dungeon'] == 0 && $this->battle->info['type'] == 500 && $this->battle->users[$i]['team'] == $this->battle->info['team_win'] && $this->battle->users[$i]['no_ip'] != 'trupojor' && $this->battle->users[$i]['bot'] == 0) {
if ($this->battle->users[$i]['level'] > 9) {
$mid = 903093;
} else {
$mid = 89489;
}
$mon = mysql_fetch_array(
mysql_query('SELECT * FROM `aaa_monsters` WHERE `uid` = "' . $mid . '" LIMIT 1')
);
if ($this->battle->users[$i]['battle_yron'] >= 1500) {
$ritem = rand(1, 100);
if ($ritem <= 20) {
$mon['win_itm'] = '4459@1';
} elseif ($ritem <= 40) {
$mon['win_itm'] = '4460@1';
} elseif ($ritem <= 60) {
$mon['win_itm'] = '4461@1';
} elseif ($ritem <= 80) {
$mon['win_itm'] = '4462@1';
} else {
$mon['win_itm'] = '4463@1';
}
} elseif ($this->battle->users[$i]['battle_yron'] >= 1000) {
$ritem = rand(1, 100);
if ($ritem <= 25) {
$mon['win_itm'] = '4460@1';
} elseif ($ritem <= 50) {
$mon['win_itm'] = '4461@1';
} elseif ($ritem <= 75) {
$mon['win_itm'] = '4462@1';
} else {
$mon['win_itm'] = '4463@1';
}
} else {
$mon['win_itm'] = '4392@1';
}
if ($this->battle->users[$i]['battle_yron'] > 0) {
mysql_query(
'INSERT INTO `eff_users` (`no_Ace`,`id_eff`,`overType`,`uid`,`name`,`data`,`timeUse`) VALUES ("1","478","111","' . $this->battle->users[$i]['id'] . '","Право на подвиг","pravonapodvig=1","' . time(
) . '")'
);
}
mysql_query(
'INSERT INTO `actions`(`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`, `val`) VALUES ("' . $this->battle->users[$i]['id'] . '","' . time(
) . '","capitalcity","' . $this->battle->users[$i]['room'] . '","end_trup"," ","","")'
);
mysql_query(
'INSERT INTO `eff_users` (`no_Ace`,`id_eff`,`overType`,`uid`,`name`,`data`,`timeUse`) VALUES ("1","479","112","' . $u->info['id'] . '","Защита от нападения","zashitatk=1","' . time(
) . '")'
);
$ritem = rand(1, 1000);
if ($ritem == 555) {
$mon['win_itm'] = $mon['win_itm'] . ',5022@1';
}
//
$this->addGlobalItems(
$mid,
$this->battle->users[$i]['id'],
$mon['win_itm'],
$mon['win_ico'],
1,
$mon['win_money1'],
$mon['win_money2']
);
}
if (
($this->battle->info['razdel'] == 5 || $this->battle->info['razdel'] == 4) &&
(date('d.m') == '31.10' || (date('m') == 11 && date('d') < 7))
) {
//Хэллоуин 4504
$this->battle->users[$i]['battle_text'] .= ' Вы получаете <strong>Тыква (x1)</strong>.';
ItemsModel::addItem(4504, $this->battle->users[$i]['id'], '|sudba=1');
}
//Добавляем воинственность
if (
$this->battle->info['dungeon'] == 0 &&
$this->battle->info['razdel'] == 5 &&
$this->battle->users[$i]['exp'] >= 1500 &&
$this->battle->users[$i]['battle_exp'] > 100 * $this->battle->users[$i]['level']
) {
$rzbvo = $this->battle->users[$i]['battle_exp'] * 6 / 1000;
if ($this->battle->users[$i]['level'] == 8 && $rzbvo >= 100) {
$rzbvo = 100;
}
if ($this->battle->users[$i]['level'] == 9 && $rzbvo >= 150) {
$rzbvo = 150;
}
if ($this->battle->users[$i]['level'] == 10 && $rzbvo >= 200) {
$rzbvo = 200;
}
if ($this->battle->users[$i]['level'] == 11 && $rzbvo >= 250) {
$rzbvo = 250;
}
if ($this->battle->users[$i]['level'] == 12 && $rzbvo >= 250) {
$rzbvo = 250;
}
if ($this->battle->info['type'] != 33) {
$this->battle->users[$i]['battle_text'] .= ' Вы получили ' . $rzbvo . ' воинственности за этот бой.';
}
mysql_query(
'UPDATE `rep` SET `rep3` = `rep3` + "' . $rzbvo . '" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
mysql_query(
'INSERT INTO `actions`(`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`, `val`) VALUES ("' . $this->battle->users[$i]['id'] . '","' . time(
) . '","capitalcity","' . $this->battle->users[$i]['room'] . '","end_xaot"," ","","")'
);
}
if ($this->battle->stats[$i]['hpNow'] >= 1) {
$this->battle->stats[$i]['test_heal'] = mysql_fetch_array(
mysql_query(
'SELECT SUM(`yrn`) FROM `battle_stat` WHERE `uid2` = "' . $this->battle->users[$i]['id'] . '" AND `battle` = "' . $this->battle->info['id'] . '" LIMIT 1'
)
);
$this->battle->stats[$i]['test_heal'] = $this->battle->stats[$i]['test_heal'][0];
$this->battle->stats[$i]['test_start'] = mysql_fetch_array(
mysql_query(
'SELECT `hpStart` FROM `battle_users` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" AND `battle` = "' . $this->battle->info['id'] . '" LIMIT 1'
)
);
$this->battle->stats[$i]['test_start'] = $this->battle->stats[$i]['test_start']['hpStart'];
//
$this->battle->stats[$i]['hpNow'] = ($this->battle->stats[$i]['test_start'] - $this->battle->stats[$i]['test_heal']);
if ($this->battle->stats[$i]['hpNow'] < 1) {
$this->battle->stats[$i]['hpNow'] = 1;
}
} else {
$this->battle->stats[$i]['hpNow'] = 0;
}
unset($this->battle->stats[$i]['test_heal']);
$this->battle->users[$i]['last_b'] = $this->battle->info['id']; //stats
$this->battle->users[$i]['last_a'] = $act01;
$this->battle->users[$i]['battle'] = -1; //users
$this->battle->users[$i]['battle_yron'] = 0; //stats
$this->battle->users[$i]['exp'] += $this->battle->users[$i]['battle_exp']; //users
//Добавляем клан опыт (Все кроме пещер)
if ($this->battle->users[$i]['clan'] > 0) {
$cpr = 1;
if ($this->battle->info['typeBattle'] == 9) {
$cpr = 25;
} elseif ($this->battle->info['typeBattle'] == 50) {
$cpr = 65;
}
if ($this->battle->stats[$i]['silver'] >= 5) {
$cpr = floor($cpr / 100 * 150);
}
Clan::addExp(
round($this->battle->users[$i]['battle_exp'] / 100 * $cpr),
$this->battle->users[$i]['clan']
);
}
$this->battle->users[$i]['battle_exp'] = 0; //stats
if ($this->battle->users[$i]['team'] == $this->battle->info['team_win']) {
$r = new Reputation($this->battle->users[$i]['id']);
$r->addRep('n_capitalcity', $this->battle->users[$i]['bn_capitalcity']);
$r->addRep('n_demonscity', $this->battle->users[$i]['bn_demonscity']);
$r->addRep('n_suncity', $this->battle->users[$i]['bn_suncity']);
}
//репутация
$this->battle->users[$i]['bn_demonscity'] = 0;
$this->battle->users[$i]['bn_capitalcity'] = 0;
$this->battle->users[$i]['bn_suncity'] = 0;
//обновляем данные
Effects::removePriems($this->battle->users[$i]['id']);
$this->dieInDungeon($dnr, $i, $u, $cmsg, $chat);
Db::sql('update users set login2 = default where battle = ?', [$this->battle->info['id']]);
Db::sql(
'update users set login2 = default, money = ?, money2 = ?, win = ?, lose = ?, nich = ?, battle = -1 where id = ?',
[
$this->battle->users[$i]['money'],
$this->battle->users[$i]['money2'],
$this->battle->users[$i]['win'],
$this->battle->users[$i]['lose'],
$this->battle->users[$i]['nich'],
$this->battle->users[$i]['id'],
]
);
if ($u->info['id'] == $this->battle->users[$i]['id']) {
$u->info['battle_text'] = $this->battle->users[$i]['battle_text'];
}
Db::sql(
'update stats set hpNow = ?, mpNow = ?, tactic7 = 10, x = ?, y = ?, exp = ?, battle_exp = ?, battle_text = ?, last_b = ?, regHP = unix_timestamp(), regMP = unix_timestamp()
where id = ?',
[
$this->battle->stats[$i]['hpNow'],
$this->battle->stats[$i]['mpNow'],
$this->battle->users[$i]['x'],
$this->battle->users[$i]['y'],
$this->battle->users[$i]['exp'],
$this->battle->users[$i]['battle_exp'],
$this->battle->users[$i]['battle_text'],
$this->battle->info['id'],
$this->battle->users[$i]['id'],
]
);
if ($this->battle->info['turnir'] == 0) {
//пишем в чат
$cmsg->setTo($this->battle->users[$i]['login']);
$cmsg->setText($this->battle->users[$i]['battle_text']);
$chat->sendMsg($cmsg);
} else {
Db::sql('update turnirs set winner = ? where id = ?', [$this->battle->info['team_win'], $this->battle->info['turnir']]);
}
//завершаем сам бой
Db::sql('update battle set time_over = unix_timestamp(), team_win = ? where id = ?', [$this->battle->info['team_win'], $this->battle->info['id']]);
// Жрать хочет
if ($this->battle->users[$i]['animal'] > 0) {
$a = mysql_fetch_array(
mysql_query(
'SELECT * FROM `users_animal` WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" AND `id` = "' . $this->battle->users[$i]['animal'] . '" AND `pet_in_cage` = "0" AND `delete` = "0" LIMIT 1'
)
);
if (isset($a['id']) && $a['eda'] < 1) {
$cmsg = new ChatMessage();
$cmsg->setRoom($this->battle->users[$i]['room']);
$cmsg->setTo($this->battle->users[$i]['login']);
$cmsg->setText('<strong>' . $a['name'] . '</strong> нуждается в еде...');
$cmsg->setType(6);
$chat->sendMsg($cmsg);
}
}
mysql_query(
'UPDATE `stats` SET `battle_text` = "",`last_b`="0" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
mysql_query('UPDATE `battle_users` SET `finish` = 1 WHERE `uid` = "' . $this->battle->users[$i]['id'] . '"');
$this->saveLogs();
if ($u->info['battle'] != 0 && !isset($u->info['battle_lsto'])) {
echo '<script>document.getElementById(\'teams\').style.display=\'none\';var battleFinishData = "' . $u->info['battle_text'] . '";</script>';
}
}
}
mysql_query('UPDATE `battle` SET `testfinish` = "0" WHERE `id` = "' . $this->battle->info['id'] . '" LIMIT 1');
mysql_query('UNLOCK TABLES');
}
private function addItemToItemsLocal(int $itemId, int $uid, string $data = ''): void
{
Db::sql(
"insert into items_local (room, time, item_id, data, tr_login, colvo) values (?,unix_timestamp(),?,?,?,1)",
[
$this->battle->users[$this->battle->uids[$uid]]['room'],
$itemId,
$data,
$this->battle->users[$this->battle->uids[$uid]]['login'],
]
);
}
private function addGlobalItems($bid, $uid, $itm, $ico, $exp, $cr, $ecr): void
{
global $u;
$chat = new Chat();
$cmsg = new ChatMessage();
$cmsg->setType(6);
$cmsg->setRoom($this->battle->users[$this->battle->uids[$uid]]['room']);
$cmsg->setTo($this->battle->users[$this->battle->uids[$uid]]['login']);
$cmsg->setColor('#cb0000');
$this->addGlobalItemsDropsOnMainStreet($bid, $uid);
if ($exp >= 0) {
//added if, was division by zero. 27.08.22, ins.
$this->battle->users[$this->battle->uids[$uid]]['battle_exp'] += round(
$this->battle->stats[$this->battle->uids[$bid]]['hpAll'] > 0 ?
$exp * $this->battle->users[$this->battle->uids[$uid]]['battle_yron'] / $this->battle->stats[$this->battle->uids[$bid]]['hpAll'] :
$exp * $this->battle->users[$this->battle->uids[$uid]]['battle_yron']
);
Db::sql(
'update stats set battle_exp = ? where id = ?',
[
$this->battle->users[$this->battle->uids[$uid]]['battle_exp'],
$uid,
]
);
}
if (!empty($cr) && $this->battle->stats[$this->battle->uids[$uid]]['hpNow'] > 0) {
$this->battle->users[$this->battle->uids[$uid]]['money'] += (int)$cr;
$u->addKr((int)$cr, $uid);
$cmsg->setText("<strong>Вы получили кредиты: $cr кр.</strong>");
$chat->sendMsg($cmsg);
}
if (!empty($ecr) && $this->battle->stats[$this->battle->uids[$uid]]['hpNow'] > 0) {
$this->battle->users[$this->battle->uids[$uid]]['money2'] += (int)$ecr;
$u->addEkr((int)$ecr, $uid);
$cmsg->setText("<strong>Вы получили еврокредиты: $ecr екр.</strong>");
$chat->sendMsg($cmsg);
Delo::add(
4,
'System.battle',
$this->battle->users[$this->battle->uids[$uid]]['id'],
'&quot;<span style="color: olive; ">System.battle</span>&quot;: Персонаж получил <strong>' . $ecr . ' ЕКР</strong> (В бою трупожор), сейчас: <strong>' .
$this->battle->users[$this->battle->uids[$uid]]['money2'] . ' ЕКР</strong>',
);
}
$this->addGlobalItemsIco($ico, $uid, $cmsg, $chat);
$this->addGlobalItemItm($itm, $uid, $cmsg, $chat);
}
/**
* Сохраняем лог в архив
* @return void
*/
private function saveLogs(): void
{
Db::sql(
'insert into battle_logs_save select id, time, battle, id_hod, text, vars, zona1, zonb1, zona2, zonb2, type from battle_logs where battle = ? and id_hod <= ?',
[$this->battle->info['id'], $this->battle->hodID]
);
Db::sql('delete from battle_logs where battle = ?', [$this->battle->info['id']]);
Db::sql('delete from battle_stat where battle < ?', [$this->battle->info['id'] - 100]);
Db::sql('delete from battle_actions where btl = ?', [$this->battle->info['id']]);
}
private function typeBattle(int $x): array
{
$r = [0, 0, 'Обычный поединок', 'Кровавый Поединок'];
if ($x >= 50000 && $x < 100000) {
$r = [25, 50, 'Великая Битва', 'Кровавая Битва'];
} elseif ($x < 500000) {
$r = [50, 75, 'Величайшая Битва', 'Кровавая Резня'];
} elseif ($x < 1000000) {
$r = [75, 100, 'Историческая Битва', 'Кровавая Сеча'];
} elseif ($x < 2500000) {
$r = [100, 125, 'Эпохальная Битва', 'Кровавое Побоище'];
} elseif ($x >= 5000000) {
$r = [150, 150, 'Судный День', 'Судный День'];
}
return $r;
}
private function dieInDungeon(int $dnr, int $i, User $u, ChatMessage $cmsg, Chat $chat): void
{
if ($dnr != 1) {
return;
}
$vars = $this->battle->users[$i]['room'] == 370 ? 'dielaba' : 'die';
$dies = Actions::countDungeon(
$this->battle->users[$i]['dnow'],
$this->battle->users[$i]['id'],
$vars
);
Actions::addDungeon(
$this->battle->users[$i]['dnow'],
$this->battle->users[$i]['id'],
$this->battle->users[$i]['x'],
$this->battle->users[$i]['y'],
$vars
);
$la = $this->battle->users[$i]['sex'] == 1 ? 'ла' : '';
if ($dies < 2 || $this->battle->info['dungeon'] == 15) {
$shaibaItemId = Db::getValue('select id from items_users where uid = ? and item_id = 4910 limit 1', [$this->battle->users[$i]['id']]);
if ($shaibaItemId) {
//выбрасываем шайбу
ItemsModel::delete($shaibaItemId);
Db::sql(
"insert into dungeon_obj (name, dn, x, y, img, action, w, h, os1, os2, os3, date)
values ('Шайба',?,?,?,'shaiba.png','fileact:15/shaiba',120,220,5,8,12,?)",
[
$this->battle->info['dn_id'],
$this->battle->users[$i]['x'],
$this->battle->users[$i]['y'],
"{use:'takeit',rt1:69,rl1:-47,rt2:74,rl2:126,rt3:76,rl3:140,rt4:80,rl4:150}",
]
);
}
//телепортируем в рестарт (координата 0х0)
$this->battle->users[$i]['x'] = $this->battle->users[$i]['res_x'];
$this->battle->users[$i]['y'] = $this->battle->users[$i]['res_y'];
$this->battle->users[$i]['s'] = $this->battle->users[$i]['res_s'];
$roomName = Db::getValue('select name from room where id = ?', [(int)$this->battle->users[$i]['room']]);
$reviveRoomName = $this->battle->users[$i]['room'] == 370 ? 'начале лабиринта' : "комнате «{$roomName}»";
$rtxt = "<strong>{$this->battle->users[$i]['login']}</strong> трагически погиб$la и находится в $reviveRoomName";
} elseif ($this->battle->info['dungeon'] == 102) {
$nld = '';
$lab = Db::getRow('select id, users from laba_now where id = ?', [$this->battle->users[$i]['id']]);
if ($lab['users'] < 2) {
//Удаляем подземелье
Db::sql('delete from laba_now where id = ?', [$lab['id']]);
Db::sql('delete from laba_map where id = ?', [$lab['id']]);
Db::sql('delete from laba_obj where lib = ?', [$lab['id']]);
Db::sql('delete from laba_act where lib = ?', [$lab['id']]);
Db::sql('delete from laba_itm where lib = ?', [$lab['id']]);
} else {
$lab['users']--;
mysql_query(
'UPDATE `laba_now` SET `users` = "' . $lab['users'] . '" WHERE `id` = "' . $lab['id'] . '" LIMIT 1'
);
}
mysql_query(
'UPDATE `stats` SET `dnow` = "0" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
mysql_query(
'UPDATE `users` SET `room` = "369" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
//удаляем все предметы которые пропадают после выхода из пещеры
mysql_query(
'UPDATE `items_users` SET `delete` = "' . time(
) . '" WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" AND `delete` < 1234567890 AND `inShop` = "0" AND (`dn_delete` = "1" OR `data` LIKE "%fromlaba=1%")'
);
if ($this->battle->users[$i]['login'] != '') {
if ($this->battle->users[$i]['sex'] == 0) {
$rtxt = '<strong>' . $this->battle->users[$i]['login'] . '</strong> трагически погиб без права на воскрешение и покидает подземелье' . $nld;
} else {
$rtxt = '<strong>' . $this->battle->users[$i]['login'] . '</strong> трагически погибла без права на воскрешение и покидает подземелье' . $nld;
}
}
} else {
$tinf = mysql_fetch_array(
mysql_query(
'SELECT `uid` FROM `dungeon_now` WHERE `id` = "' . $this->battle->info['dn_id'] . '" LIMIT 1'
)
);
$nld = '';
if ($tinf['uid'] == $this->battle->users[$i]['id']) {
$tinf = mysql_fetch_array(
mysql_query(
'SELECT `id` FROM `stats` WHERE `dnow` = "' . $this->battle->info['dn_id'] . '" AND `hpNow` >= 1 LIMIT 1'
)
);
if (isset($tinf['id'])) {
$tinf = mysql_fetch_array(
mysql_query(
'SELECT `id`,`login` FROM `users` WHERE `id` = "' . $tinf['id'] . '" LIMIT 1'
)
);
$nld .= ', новым лидером становится &quot;' . $tinf['login'] . '&quot;';
mysql_query(
'UPDATE `dungeon_now` SET `uid` = "' . $tinf['id'] . '" WHERE `id` = "' . $this->battle->info['dn_id'] . '" LIMIT 1'
);
}
}
mysql_query(
'UPDATE `stats` SET `dnow` = "0" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
mysql_query(
'UPDATE `users` SET `room` = "321" WHERE `id` = "' . $this->battle->users[$i]['id'] . '" LIMIT 1'
);
//удаляем все предметы которые пропадают после выхода из пещеры
mysql_query(
'UPDATE `items_users` SET `delete` = "' . time() . '" WHERE `uid` = "' . $this->battle->users[$i]['id'] . '" AND `dn_delete` = "1" LIMIT 1000'
);
mysql_query(
'UPDATE `items_users` SET `delete` = "' . time() . '" WHERE `uid` = "' . $u->info['id'] . '" AND `item_id` = "1189" OR `item_id` = "4447" OR `item_id` = "1174") LIMIT 1000'
);
if ($this->battle->users[$i]['sex'] == 0) {
$rtxt = '<strong>' . $this->battle->users[$i]['login'] . '</strong> трагически погиб без права на воскрешение и покидает подземелье' . $nld;
} else {
$rtxt = '<strong>' . $this->battle->users[$i]['login'] . '</strong> трагически погибла без права на воскрешение и покидает подземелье' . $nld;
}
}
if (!empty($rtxt)) {
$cmsg->setDn($this->battle->info['dn_id']);
$cmsg->setText($rtxt);
$cmsg->setTypeTime(1);
$chat->sendMsg($cmsg);
}
}
private function addGlobalItemsIco(string $ico, int $uid, ChatMessage $cmsg, Chat $chat): void
{
if (empty($ico)) {
return;
}
/**
** $exploded[]:
* 0 (тип, 1 - значок, 2 - подвиг)@
* 1 (время в минутах)@
* 2 (название картинки)@
* 3 (название)@
* 4 (требует остаться в живых 0 или 1, либо игрок умер -1)@
* 5 (требует набить с ботам урона в % Например 0.001)@
* 6 (действия например: add_s1=5|add_hpAll=50)@
* 7 (Требует другой значок, название картинки)@
* 8 (плюсует значок 0 или 1)@
* 9 (удаляем прошлый значок 0 or 1)
*/
$txt = '';
foreach (explode('#', $ico) as $icon) {
$exploded = explode('@', $icon);
if (empty($exploded[3])) {
continue;
}
$add = 1;
if ($exploded[4] == 1 && floor($this->battle->stats[$this->battle->uids[$uid]]['hpNow']) < 1) {
$add = 0;
}
if ($add != 1) {
continue;
}
$ins = false;
if ($exploded[8] == 0) {
$ins = true;
if ($exploded[9] == 1) {
Db::sql('delete from users_ico where uid = ? and img = ?', [$uid, $exploded[2]]);
}
} else {
$oldIcoId = Db::getValue(
'select id from users_ico where uid = ? and img = ? and (endTime > unix_timestamp() or endTime = 0)',
[$uid, $exploded[2]]
);
if (!$oldIcoId || $oldIcoId < 1) {
$ins = true;
} else {
$txt .= ", «$exploded[3] (<small>Обновление</small>)»";
Db::sql(
'update users_ico set x = x + 1, endTime = unix_timestamp() + ? * 60 where id = ?',
[$exploded[1], $oldIcoId]
);
}
}
if (!$ins) {
continue;
}
if ($exploded[9] == 1) {
Db::sql('delete from users_ico where uid = ? and img = ?', [$uid, $exploded[2]]);
}
Db::sql(
'insert into users_ico (uid, time, text, img, endTime, type, bonus) values (?,unix_timestamp(),?,?,unix_timestamp() + ? * 60,?,?)',
[
$uid,
$exploded[3],
$exploded[2],
$exploded[1],
$exploded[0],
$exploded[6],
]
);
$txt .= ", «$exploded[3]»";
}
if (!empty($txt)) {
$txt = ltrim($txt, ', ');
$cmsg->setText("<strong>Вы совершили подвиг:</strong> $txt");
$chat->sendMsg($cmsg);
}
}
private function addGlobalItemItm($itm, $uid, ChatMessage $cmsg, Chat $chat): void
{
if (empty($itm)) {
return;
}
/**
** $exploded[]:
* 0 (id предмета)@
* 1 (количество предметов)@
* 2 (data предмета |add_s1=5|add_hpAll=50)@
*/
$txt = '';
foreach (explode(',', $itm) as $item) {
$exploded = explode('@', $item);
if ($exploded[0] < 1) {
continue;
}
for ($i = 0; $i < $exploded[1]; $i++) {
ItemsModel::addItem($exploded[0], $uid, "|$exploded[2]");
}
if (empty($this->ainm[$exploded[0]])) {
$this->ainm[$exploded[0]] =
Db::getRow('select id, name from items_main where id = ?', [$exploded[0]]);
}
if (empty($this->ainm[$exploded[0]]['id'])) {
continue;
}
$txt .= ", <strong>{$this->ainm[$exploded[0]]['name']}</strong>";
if ($exploded[1] > 1) {
$txt .= ", <strong>(x$exploded[1])</strong>";
}
}
if ($txt != '') {
$txt = ltrim($txt, ', ');
$cmsg->setText("<strong>Вы получили предметы:</strong> $txt");
$chat->sendMsg($cmsg);
}
}
private function addGlobalItemsDropsOnMainStreet(int $bid, int $uid): void
{
//Выпадение дропа на ЦП
$mf = Db::getValue('select floor(count(id) / 20) as c from users where online > unix_timestamp() - 120');
$mf = mt_rand(1, max($mf, 1));
if ($bid == 1008) {
//Старый Новый Год
for ($i = 0; $i < $mf; $i++) {
if (mt_rand(0, 1) === 1) {
continue;
}
if (mt_rand(0, 86) <= 71) {
for ($j = 1; $j <= 7; $j++) {
$this->addItemToItemsLocal(1000, $uid, '|nosale=1|srok=259200');
}
} else {
$customs = [911, 1172, 1173, 1461, 1462, 1463, 2141, 2142, 2143, 2144, 2870, 4037, 4038, 4039, 4040];
$this->addItemToItemsLocal($customs[array_rand($customs)], $uid, '|nosale=1|srok=259200');
}
}
} elseif ($bid == 1007) {
//Хэллоуин, Тыквоголовый CAPITAL CITY
for ($i = 0; $i < $mf; $i++) {
if (mt_rand(0, 1) === 1) {
continue;
}
$this->addItemToItemsLocal(4504, $uid);
}
} elseif ($bid == 1006 && mt_rand(1, 10) === 1 || in_array($bid, range(1000, 1004))) {
//Трупожор CAPITAL CITY
$this->addItemToItemsLocal(4451, $uid, 'srok=2592000');
}
}
}