Файл: public_html/modules/demons/result.php
Строк: 86
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include_once ($root.'/core/base.php');
falseauth();
$header = "Вторжение демонов";
include_once ($root.'/core/head.php');
$btl = $db->query("SELECT * FROM `demons_battles` WHERE `status` IN ('result-win', 'result-lose-boss', 'result-lose-mobs') ORDER BY `id` DESC LIMIT 1");
if($btl->num_rows == 0) redirect('/demons');
$btl = $btl->fetch_object();
$myPlayer = $db->query("SELECT * FROM `demons_players` WHERE `user` = '".$u['id']."' AND `battle` = '".$btl->id."'");
if($myPlayer->num_rows == 0) redirect('/demons');
if($btl->status == 'result-win')
{
$topPlayer = $db->query("SELECT * FROM `demons_players` WHERE `battle` = '".$btl->id."' AND `health` > '0'")->fetch_object();
$db->query("UPDATE `users` SET `demonstime` = '".(time()+86400)."' WHERE `id` = '".$topPlayer->user."'");
updateUserStats($topPlayer->user, 0, 0, 200);
$db->query("UPDATE `demons_battles` SET `firstinfo` = '".$topPlayer->user."' WHERE `id` = '".$btl->id."'");
$top23Player = $db->query("SELECT * FROM `demons_players` ORDER BY `deathtime` DESC LIMIT 2");
$countT23 = 1;
while($t23p = $top23Player->fetch_object())
{
if($countT23 == 1)
{
updateUserStats($t23p->user, 0, 0, 100);
$db->query("UPDATE `demons_battles` SET `secondinfo` = '".$t23p->user."' WHERE `id` = '".$btl->id."'");
}
else
{
$db->query("UPDATE `demons_battles` SET `thirdinfo` = '".$t23p->user."' WHERE `id` = '".$btl->id."'");
updateUserStats($t23p->user, 0, 0, 50);
}
$countT23++;
}
$bossKiller = $db->query("SELECT * FROM `demons_players` WHERE `user` = '".$btl->killboss."' AND `battle` = '".$btl->id."'")->fetch_object();
$item = $db->query("SELECT * FROM `subject` WHERE `clothing_mark` = '2' ORDER BY RAND() LIMIT 1")
->fetch_object();
$db->query("INSERT INTO `inventory` (`user`,`item`,`type`,`buytime`) VALUES ('".$bossKiller->user."', '".$item->id."', '".$item->clothing_type."', '".time()."')");
$players = $db->query("SELECT * FROM `demons_players` WHERE `battle` = '".$btl->id."'");
while($pl = $players->fetch_object())
{
$exp = round($pl->damage/5);
$silver = round($pl->damage/4);
if($pl->id == $btl->firstinfo) $resultMsg = 'Вы заняли 1-е место!<br> Награда: 200 гемов, '.$exp.' опыта, '.$silver.' серебра и +10% к параметрам до начала следующей битвы!';
elseif($pl->id == $btl->secondinfo) $resultMsg = 'Вы заняли 2-е место!<br> Награда: 100 гемов, '.$exp.' опыта и '.$silver.' серебра!';
elseif($pl->id == $btl->thirdinfo) $resultMsg = 'Вы заняли 3-е место!<br> Награда: 50 гемов, '.$exp.' опыта и '.$silver.' серебра!';
else $resultMsg = '<center>
<center><img src="/images/campaign/win.png" width="100%"></center>
Награда: <img src="/images/ic-experience-flat.png" width="20" height="20"> '.$exp.' и <img src="/images/silver.png" width="20" height="20"> '.$silver.'</center>';
updateUserStats($pl->user, $exp, $silver, 0);
$db->query("UPDATE `users` SET `demons_result` = '".$resultMsg."' WHERE `id` = '".$pl->user."'");
}
$db->query("UPDATE `demons_battles` SET `status` = 'end-win' WHERE `id` = '".$btl->id."'");
}
elseif($btl->status = 'result-lose-mobs')
{
while($pl = $players->fetch_object())
{
$exp = 50;
$silver = 100;
$resultMsg = '<center>
<center><img src="/images/campaign/notwin.png" width="100%"></center>
Награда: <img src="/images/ic-experience-flat.png" width="20" height="20"> '.$exp.' и <img src="/images/silver.png" width="20" height="20"> '.$silver.'</center>';
updateUserStats($pl->user, $exp, $silver, 0);
$db->query("UPDATE `users` SET `demons_result` = '".$resultMsg."' WHERE `id` = '".$pl->user."'");
}
$db->query("UPDATE `demons_battles` SET `status` = 'end-mobs' WHERE `id` = '".$btl->id."'");
}
elseif($btl->status == 'result-lose-boss')
{
while($pl = $players->fetch_object())
{
$exp = 500;
$silver = 1000;
$resultMsg = '<center>
<center><img src="/images/campaign/notwin.png" width="100%"></center>
Награда: <img src="/images/ic-experience-flat.png" width="20" height="20"> '.$exp.' и <img src="/images/silver.png" width="20" height="20"> '.$silver.'</center>';
updateUserStats($pl->user, $exp, $silver, 0);
$db->query("UPDATE `users` SET `demons_result` = '".$resultMsg."' WHERE `id` = '".$pl->user."'");
}
$db->query("UPDATE `demons_battles` SET `status` = 'end-boss' WHERE `id` = '".$btl->id."'");
}
$db->query("DELETE FROM `battle_logs` WHERE `type` IN ('demons-mobs','demons-boss','demons-players') AND `battle` = '".$btl->id."'");
redirect('/demons/last');
include_once ($root.'/core/foot.php');