Файл: public_html/modules/dungeon/result.php
Строк: 113
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include_once ($root.'/core/base.php');
falseauth();
$header = "Подземелья";
include_once ($root.'/core/head.php');
$id = fl($_GET['id']);
$btl = $db->query("SELECT * FROM `dungeon_battles` WHERE `id` = '".$id."'");
if($btl->num_rows == 0) redirect('/dungeon');
$btl = $btl->fetch_object();
$myPlayer = $db->query("SELECT * FROM `dungeon_players` WHERE `user` = '".$u['id']."'")->num_rows;
if($myPlayer == 0) redirect('/dungeon');
$dungeon = $db->query("SELECT * FROM `dungeons` WHERE `id` = '".$btl->dungeon."'")->fetch_object();
if($btl->status == 'battle') redirect('/dungeon/battle/'.$id.'/battle');
if($btl->status == 'prepare') redirect('/dungeon/battle/'.$id);
if($btl->status == 'end') redirect('/dungeon');
if($btl->status == 'result-win')
{
$players = $db->query("SELECT * FROM `dungeon_players` WHERE `battle` = '".$id."'");
while($pl = $players->fetch_object())
{
$randItem = $db->query("SELECT * FROM `subject` WHERE `id` IN (".$dungeon->items.") ORDER BY RAND() LIMIT 1")->fetch_object();
$db->query("INSERT INTO `inventory` (`user`,`item`,`type`,`buytime`) VALUES ('".$pl->user."', '".$randItem->id."', '".$randItem->clothing_type."', '".time()."')");
updateUserStats($pl->user, $dungeon->exp, $dungeon->silver, $dungeon->gems);
$result = 'Подземелье пройдено! Награда: '.$randItem->name.', '.$dungeon->exp.' опыта, '.$dungeon->silver.' серебра и '.$dungeon->gems.' гемов!';
$db->query("UPDATE `users` SET `dungeon_result` = '".$result."', `dungeon_count` = `dungeon_count` - '1' WHERE `id` = '".$pl->user ."'");
}
$db->query("DELETE FROM `battle_logs` WHERE `battle` = '".$id."' AND `type` IN ('dungeon-prepare','dungeon')");
$db->query("UPDATE `dungeon_battles` SET `status` = 'end' WHERE `id` = '".$id."'");
$db->query("DELETE FROM `dungeon_mobs` WHERE `battle` = '".$id."'");
$db->query("DELETE FROM `dungeon_players` WHERE `battle` = '".$id."'");
$db->query("DELETE FROM `dungeon_battles` WHERE `id` = '".$id."'");
}
if($btl->status == 'result-lose')
{
$players = $db->query("SELECT * FROM `dungeon_players` WHERE `battle` = '".$id."'");
while($pl = $players->fetch_object())
{
updateUserStats($pl->user, round($dungeon->exp/10), round($dungeon->silver/10), 0);
$result = 'Подземелье не пройдено! Поощрительный приз: '.round($dungeon->exp/10).' опыта и '.round($dungeon->silver/10).' серебра';
$db->query("UPDATE `users` SET `dungeon_result` = '".$result."', `dungeon_count` = `dungeon_count` - '1' WHERE `id` = '".$pl->user."'");
}
$db->query("DELETE FROM `battle_logs` WHERE `battle` = '".$id."' AND `type` IN ('dungeon-prepare','dungeon')");
$db->query("UPDATE `dungeon_battles` SET `status` = 'end' WHERE `id` = '".$id."'");
$db->query("DELETE FROM `dungeon_mobs` WHERE `battle` = '".$id."'");
$db->query("DELETE FROM `dungeon_players` WHERE `battle` = '".$id."'");
$db->query("DELETE FROM `dungeon_battles` WHERE `id` = '".$id."'");
}
redirect('/dungeon');
include_once ($root.'/core/foot.php');