Вход Регистрация
Файл: public_html/modules/dungeon/battle.php
Строк: 345
<?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']."'");
if(
$myPlayer->num_rows == 0) redirect('/dungeon');
$myPlayer = $myPlayer->fetch_object();
$dungeon = $db->query("SELECT * FROM `dungeons` WHERE `id` = '".$btl->dungeon."'")->fetch_object();
if(
$btl->status == 'prepare') redirect('/dungeon/battle/'.$id);
$playersCount = $db->query("SELECT * FROM `dungeon_players` WHERE `battle` = '".$btl->id."'")->num_rows;
$stageMobs = $db->query("SELECT * FROM `dungeon_mobs` WHERE `battle` = '".$id."' AND `health` > '0' AND `stage` = 
'"
.$btl->stage."'");
$stageMobsInfo = $db->query("SELECT * FROM `dungeon_stages` WHERE `stage` = '".$btl->stage."' AND `dungeon` = '"
        
.$btl->dungeon."'")->fetch_object();
$alivePlayers = $db->query("SELECT * FROM `dungeon_players` WHERE `battle` = '".$id."' AND `health` > '0' AND `user` != '".$u['id']."'");
$aP = $db->query("SELECT * FROM `dungeon_players` WHERE `battle` = '".$id."' AND `health` > '0'")->num_rows;
if(
$myPlayer->opponent > 0)
{
    
$opponent = $db->query("SELECT * FROM `dungeon_mobs` WHERE `id` = '".$myPlayer->opponent."'")->fetch_object();
    if(
$opponent->health <= 0)
    {
        
$db->query("UPDATE `dungeon_players` SET `opponent` = '0' WHERE `id` = '".$myPlayer->id."'");
        
redirect('/dungeon/battle/'.$id.'/battle');
    }
}
if(
$btl->stage < 4)
{
    if(
$stageMobs->num_rows == 0)
    {
        
addStageMobs($id, $btl->dungeon, $btl->stage+1);
        
$db->query("UPDATE `dungeon_battles` SET `stage` = `stage` + '1' WHERE `id` = '".$id."'");
        
redirect('/dungeon/battle/'.$id.'/battle');
    }
}
if(isset(
$_GET['send']))
{
    
$msg = fl($_POST['msg']);
    
$finalMsg = who($u['id']).':'.$msg;
    
$db->query("INSERT INTO `battle_logs` (`type`,`battle`,`msg`,`time`) VALUES ('dungeon', '".$btl->id."', '".$finalMsg."', '".time()."')");
    
redirect('/dungeon/battle/'.$btl->id.'/battle');
}
if(
$btl->stage == 4 && $stageMobs->num_rows == 0 && $aP > 0)
{
    
$db->query("UPDATE `dungeon_battles` SET `status` = 'result-win' WHERE `id` = '".$id."'");
    
redirect('/dungeon/result/'.$id);
}
if((
$stageMobs->num_rows > 0 && $aP == 0) || ($stageMobs->num_rows == 0 && $aP == 0))
{
    
$db->query("UPDATE `dungeon_battles` SET `status` = 'result-lose' WHERE `id` = '".$id."'");
    
redirect('/dungeon/result/'.$id);
}
$attacks = [' ударил', ' ударил', ' ударил'];
if(isset(
$_GET['rand']))
{
    if(
$stageMobs->num_rows == 0) redirect('/dungeon/battle/'.$id.'/battle');
    
$randOpponent = $db->query("SELECT * FROM `dungeon_mobs` WHERE `battle` = '".$id."' AND `stage` = '".$btl->stage."' AND `health` > '0' ORDER BY RAND() LIMIT 1")->fetch_object();
    if(
$myPlayer->health <= 0) redirect('/dungeon/battle/'.$id.'/battle');
    
$damage = getDamage(get_power($u['id']), $stageMobsInfo->defense);
    
$cooldown_time = $myPlayer->attack_cd-time();
    if(
$cooldown_time >= 2) $finalDamage = 0;
    elseif(
$cooldown_time == 0 && $cooldown_time == 1) $finalDamage = round($damage*(rand(1,50)/100));
    else 
$finalDamage = $damage;
    if(
$finalDamage != 0) $db->query("UPDATE `dungeon_players` SET `attack_cd` = '".(time()+3)."', `opponent` = '".$randOpponent->id."', `damage` = `damage` + '".$finalDamage."' WHERE `id` = '".$myPlayer->id."'");
    
$db->query("UPDATE `dungeon_mobs` SET `health` = `health` - '".$finalDamage."' WHERE `id` = '".$randOpponent->id."'");
    if(
$finalDamage == 0) $logMsg = name($u['id']).' промахнулся по '.$stageMobsInfo->mob_name.'.';
    else 
$logMsg = name($u['id']).$attacks[rand(0,2)].' '.$stageMobsInfo->mob_name.' на '.$damage.'.';
    
$db->query("INSERT INTO `battle_logs` (`type`,`battle`,`msg`,`time`) VALUES ('dungeon', '".$id."', '".$logMsg."', '".time()."')");
    
redirect('/dungeon/battle/'.$id.'/battle');
}
if(isset(
$_GET['attack']))
{
    if(!empty(
$_GET['attack']))
    {
        
$attack = fl($_GET['attack']);
        
$attackMob = $db->query("SELECT * FROM `dungeon_mobs` WHERE `id` = '".$attack."'")->num_rows;
        if(
$attackMob == 0) redirect('/dungeon/battle/'.$id.'/battle');
    }
    else 
$attack = 0;
    if(
$stageMobs->num_rows == 0) redirect('/dungeon/battle/'.$id.'/battle');
    if(
$myPlayer->health <= 0) redirect('/dungeon/battle/'.$id.'/battle');
    
$damage = getDamage(get_power($u['id']), $stageMobsInfo->defense);
    
$cooldown_time = $myPlayer->attack_cd-time();
    if(
$cooldown_time >= 2) $finalDamage = 0;
    elseif(
$cooldown_time == 0 && $cooldown_time == 1) $finalDamage = round($damage*(rand(1,50)/100));
    else 
$finalDamage = $damage;
    if(
$finalDamage != 0) $db->query("UPDATE `dungeon_players` SET `attack_cd` = '".(time()+3)."', `damage` = `damage` + '".$finalDamage."' WHERE `id` = '".$myPlayer->id."'");
    if(
$attack > 0) $db->query("UPDATE `dungeon_players` SET `opponent` = '".$attack."' WHERE `id` = '".$myPlayer->id."'");
    
$db->query("UPDATE `dungeon_mobs` SET `health` = `health` - '".$finalDamage."' WHERE `id` = '".$randOpponent->id."'");
    if(
$attack == 0) $db->query("UPDATE `dungeon_mobs` SET `health` = `health` - '".$finalDamage."' WHERE `id` = '".$myPlayer->opponent."'");
    else 
$db->query("UPDATE `dungeon_mobs` SET `health` = `health` - '".$finalDamage."' WHERE `id` = '".$attack."'");
    if(
$finalDamage == 0) $logMsg = name($u['id']).' промахнулся по '.$stageMobsInfo->mob_name.'.';
    else 
$logMsg = name($u['id']).$attacks[rand(0,2)].' '.$stageMobsInfo->mob_name.' на '.$damage.'.';
    
$db->query("INSERT INTO `battle_logs` (`type`,`battle`,`msg`,`time`) VALUES ('dungeon', '".$id."', '".$logMsg."', '".time()."')");
    
redirect('/dungeon/battle/'.$id.'/battle');
}
if(isset(
$_GET['heal']))
{
    if(
$stageMobs->num_rows == 0) redirect('/dungeon/battle/'.$id.'/battle');
    if(
$myPlayer->health <= 0) redirect('/dungeon/battle/'.$id.'/battle');
    if(
$myPlayer->heal_cd > time()) redirect('/dungeon/battle/'.$id.'/battle');
    if(
$myPlayer->health >= get_health($u['id'])) redirect('/dungeon/battle/'.$id.'/battle');
    
$healBonus = getSkillBonus('heal');
    if(
$healBonus+$myPlayer->health > get_health($u['id'])) $hp = get_health($u['id']);
    else 
$hp = $myPlayer->health+$healBonus;
    
$db->query("UPDATE `dungeon_players` SET `health` = '".$hp."', `heal_cd` = '".(time()+30)."' WHERE `id` = '".$myPlayer->id."'");
    
redirect('/dungeon/battle/'.$id.'/battle');
}
if(isset(
$_GET['arrow']))
{
    if(
$stageMobs->num_rows == 0) redirect('/dungeon/battle/'.$id.'/battle');
    if(
$myPlayer->health <= 0) redirect('/dungeon/battle/'.$id.'/battle');
    if(
$myPlayer->opponent == 0)
    {
        
$randOpponent = $db->query("SELECT * FROM `dungeon_mobs` WHERE `battle` = '".$id."' AND `stage` = '".$btl->stage."' AND `health` > '0' ORDER BY RAND() LIMIT 1")->fetch_object();
        
$opponentArrow = $randOpponent->id;
    }
    else 
$opponentArrow = $myPlayer->opponent;
    
$damage = getDamage(getSkillBonus('arrow'), $stageMobsInfo->defense);
    if(
$myPlayer->arrow_cd > time()) redirect('/dungeon/battle/'.$id.'/battle');
    
$finalDamage = $damage;
    if(
$opponentArrow != $myPlayer->opponent) $db->query("UPDATE `dungeon_players` SET `opponent` = '".$opponentArrow."' WHERE `id` = '".$myPlayer->id."'");
    
$db->query("UPDATE `dungeon_players` SET `arrow_cd` = '".(time()+40)."', `damage` = `damage` + '".$finalDamage."' WHERE `id` = '".$myPlayer->id."'");
    
$db->query("UPDATE `dungeon_mobs` SET `health` = `health` - '".$finalDamage."' WHERE `id` = '".$opponentArrow."'");
    
$logMsg = name($u['id']).$attacks[rand(0,2)].' '.$stageMobsInfo->mob_name.' навыком "Разряд" на '.$damage.'.';
    
$db->query("INSERT INTO `battle_logs` (`type`,`battle`,`msg`,`time`) VALUES ('dungeon', '".$id."', '".$logMsg."', '".time()."')");
    
redirect('/dungeon/battle/'.$id.'/battle');
}
?>
<style>
    .exam {
    display: inline-block;
    position: relative;
}
.exam .exam_text {
    display: block;
    position: absolute;
    left: 15px;
    height: 45px;
    bottom: -13px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #fff;
    padding: 0px;
}
</style>
<?
if($myPlayer->health > 0)
{
    
$arrow_cd = $myPlayer->arrow_cd-time();
    
$heal_cd = $myPlayer->heal_cd-time();
    echo 
'<div class="b"><center><big>Мое здоровье <img src="/images/health.png" width="25" heigth="25"><font color="orange">'.$myPlayer->health.'</font></big></center>';
    if(
$myPlayer->opponent > 0)
    {
        echo 
'</br><center><img src="/images/dungeons/mobs/'.$stageMobsInfo->image.'.png" width="100"></center></br>';
        echo 
'<a href="/dungeon/battle/'.$id.'/battle/attack" class="clicker">Добивать '.$stageMobsInfo->mob_name.' ('.$opponent->health.' хп)</a>';
    }
    echo 
'<a href="/dungeon/battle/'.$id.'/battle/rand" class="clicker">Бить любого</a></br>';
    echo
"<center>";
    echo 
'<div class  ="exam"><a href="/dungeon/battle/'.$id.'/battle/arrow"> <img width="50px" src="/images/skills/2.png"><div class="exam_text"><center>'.($arrow_cd > 0 ? '<b><big>'.$arrow_cd.'</center></big></b>' : '').' </div> </a> </div> ';
    echo 
'<div class  ="exam"><a href="/dungeon/battle/'.$id.'/battle/heal"> <img width="50px" src="/images/skills/1.png"><div class="exam_text"><center>'.($heal_cd > 0 ? '<b><big>'.$heal_cd.'</big></b>' : '').'</center></div></a></div></div>';
    echo
"</center>";
   
// echo '<a href="/dungeon/battle/'.$id.'/battle/arrow" class="clicker">Огненная стрела '.($arrow_cd > 0 ? '('.$arrow_cd.' сек)' : '').'</a>';
   // echo '<a href="/dungeon/battle/'.$id.'/battle/heal" class="clicker">Исцеление </a>';
}
echo 
'<div class="b">';
echo 
'Противники: ';
$countE = 0;
$allEnemies = $stageMobs->num_rows;
while(
$sM = $stageMobs->fetch_object())
{
    
$enemy = '<a 
href="/dungeon/battle/'
.$id.'/battle/attack/'.$sM->id.'"><ins><font color="yellow">'.$stageMobsInfo->mob_name.'</font></ins></a>';
    
$countE++;
    if(
$countE < $allEnemies) $enemy .= ', ';
    echo 
$enemy;
}
echo 
'</div>';
echo 
'<div class="line"></div>';
if(
$alivePlayers->num_rows > 0)
{
    echo 
'<div class="b">';
    echo 
'Союзники: ';
    
$countT = 0;
    
$allTeammates = $alivePlayers->num_rows;
    while(
$t = $alivePlayers->fetch_object())
    {
        
$teammate = name($t->user);
        
$countT++;
        if(
$countT < $allTeammates) $teammate .= ', ';
        echo 
$teammate;
    }
    echo 
'</div>';
    echo 
'<div class="line"></div>';
}
$log = $db->query("SELECT * FROM `battle_logs` WHERE `type` = 'dungeon' AND `battle` = '".$id."' ORDER BY `time` DESC LIMIT 10");
if(
$log->num_rows > 0)
{
    echo 
'<div class="b">';
    while(
$l = $log->fetch_object())
    {
        echo 
$l->msg.'<br>';
    }
    echo 
'</div>';
}
echo 
'<div class="line"></div><div class="b">
    <center>
        <form action="?send" method="post">
            <input type="text" name="msg" required><br>
            <input type="submit" name="send" value="Отправить">
        </form>
    </center>
</div>'
;
include_once (
$root.'/core/foot.php');
Онлайн: 0
Реклама