Файл: public_html/modules/battleground/result.php
Строк: 57
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include_once ($root.'/core/base.php');
falseauth();
$header = "Поле боя";
include_once ($root.'/core/head.php');
$btl = $db->query("SELECT * FROM `battleground_battles` WHERE `id` = '".$u['battleground_id']."'");
if($btl->num_rows == 0) redirect('/battleground');
$btl = $btl->fetch_object();
if($btl->status == 'prepare') redirect('/battleground');
if($btl->status == 'battle') redirect('/battleground/battle');
if($btl->status == 'end') redirect('/battleground');
$alivePlayer = $db->query("SELECT * FROM `battleground_players` WHERE `battle` = '".$btl->id."' AND `health` > '0'")->fetch_object();
$alivePlayerUser = $db->query("SELECT * FROM `users` WHERE `id` = '".$alivePlayer->user."'")->fetch_object();
$alivePlayerRating = rand(15,30);
$alivePlayerExp = rand($alivePlayerUser->level*5, $alivePlayerUser->level*10);
$alivePlayerSilver = ceil($alivePlayerExp*1.5);
$alivePlayerResultMsg = 'Вы победили! Награда: +'.$alivePlayerRating.' рейтинга, '.$alivePlayerExp.' опыта и '.$alivePlayerSilver.' серебра!';
updateUserStats($alivePlayerUser->id, $alivePlayerExp, $alivePlayerSilver, 0);
updateBattleGroundRating($alivePlayerUser->id, $alivePlayerRating, '+');
$db->query("UPDATE `users` SET `battleground_result` = '".$alivePlayerResultMsg."' WHERE `id` = '".$alivePlayerUser->id."'");
$players = $db->query("SELECT * FROM `battleground_players` WHERE `battle` = '".$btl->id."' AND `user` != '".$alivePlayer->user."' ORDER BY `damage` DESC");
$position = 2;
while($pl = $players->fetch_object())
{
$vipBoost = getVipBoost($pl->user);
$leagueBoost = getLeagueBonus($pl->user);
if($position == 2) $results = [rand(5,15), rand(5,50), rand(10,100), $position, '+'];
elseif($position == 3) $results = [rand(0,2), rand(2,20), rand(4,80), $position, '+'];
elseif($position == 4) $results = [rand(5,15), rand(2,10), rand(4,40), $position, '-'];
elseif($position == 5) $results = [rand(15,30), rand(2,5), rand(4,20), $position, '-'];
$resultMsg = 'Вы заняли '.$results[3].' место! Результат: '.$results[4].$results[0].' рейтинга, '.round($results[1]*$vipBoost->exp*$leagueBoost['exp']).' опыта и '.round($results[2]*$vipBoost->silver*$leagueBoost['exp']).' серебра!';
$db->query("UPDATE `users` SET `battleground_result` = '".$resultMsg."' WHERE `id` = '".$pl->user."'");
updateUserStats($pl->user, $results[1], $results[2], 0);
updateBattleGroundRating($pl->user, $results[0], $results[4]);
questUpdate($pl->user,3);
$position++;
}
$db->query("UPDATE `battleground_battles` SET `status` = 'end' WHERE `id` = '".$btl->id."'");
header("Location: /battleground");
exit;
include_once ($root.'/core/foot.php');