Файл: public_html/modules/demons/boss.php
Строк: 162
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include_once ($root.'/core/base.php');
falseauth();
$header = "Вторжение демонов";
include_once ($root.'/core/head.php');
?>
<style>
.example3 .examples_text-1 {
    display: block;
    position: absolute;
    font-size: 20px;
    left: 0;
    bottom: 31%;
    width: 100%;
    height: 10%;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #fff;
    padding: 0px;
}
.example3 {
    display: inline-block;
    position: relative;
    width: 100%;
}
</style>
<?
$btl = $db->query("SELECT * FROM `demons_battles` WHERE `status` = 'battle' ORDER BY `id` DESC LIMIT 1");
if($btl->num_rows == 0) redirect('/demons');
$btl = $btl->fetch_object();
if($btl->stage == 'mobs') redirect('/demons/mobs');
if($btl->stage == 'players') redirect('/demons/players');
$myPlayer = $db->query("SELECT * FROM `demons_players` WHERE `user` = '".$u['id']."' AND `battle` = '".$btl->id."'");
if($myPlayer->num_rows == 0) redirect('/demons');
$myPlayer = $myPlayer->fetch_object();
$players = $db->query("SELECT * FROM `demons_players` WHERE `battle` = '".$btl->id."'")->num_rows;
$mobs = $db->query("SELECT * FROM `demons_mobs` WHERE `battle` = '".$btl->id."' AND `stage` = 'boss'")->num_rows;
$alivePlayers = $db->query("SELECT * FROM `demons_players` WHERE `battle` = '".$btl->id."' AND `health` > '0'")->num_rows;
$aliveMobs = $db->query("SELECT * FROM `demons_mobs` WHERE `battle` = '".$btl->id."' AND `health` > '0' AND `stage` = 'boss'")->num_rows;
if($alivePlayers > 0 && $aliveMobs <= 0)
{
    setStage('players', $btl->id);
    redirect('/demons/players');
}
elseif($alivePlayers <= 0 && $aliveMobs > 0)
{
    $db->query("UPDATE `demons_battles` SET `status` = 'result-lose-boss' WHERE `id` = '".$btl->id."'");
    redirect('/demons/result');
}
elseif($alivePlayers <= 0 && $aliveMobs <= 0)
{
    $db->query("UPDATE `demons_battles` SET `status` = 'result-lose-boss' WHERE `id` = '".$btl->id."'");
    redirect('/demons/result');
}
if($myPlayer->opponent == 0)
{
    $randOpponent = $db->query("SELECT * FROM `demons_mobs` WHERE `battle` = '".$btl->id."' AND `stage` = 'boss' AND `health` > '0' ORDER BY RAND() LIMIT 1")->fetch_object();
    $db->query("UPDATE `demons_players` SET `opponent` = '".$randOpponent->id."' WHERE `id` = '".$myPlayer->id."'");
    redirect('/demons/boss');
}
$opponent = $db->query("SELECT * FROM `demons_mobs` WHERE `id` = '".$myPlayer->opponent."'")->fetch_object();
if($opponent->health <= 0)
{
    $db->query("UPDATE `demons_players` SET `opponent` = '0' WHERE `id` = '".$myPlayer->id."'");
    redirect('/demons/boss');
}
if(isset($_GET['attack']))
{
    if($myPlayer->health <= 0) redirect('/demons/boss');
    $damage = getDamage(get_power($u['id']), $opponent->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 `demons_players` SET `attack_cd` = '".(time()+3)."', `damage` = `damage` + '".$finalDamage."' WHERE `id` = '".$myPlayer->id."'");
    $db->query("UPDATE `demons_mobs` SET `health` = `health` - '".$finalDamage."' WHERE `id` = '".$opponent->id."'");
    if($finalDamage == 0) $logMsg = name($u['id']).' промахнулся по Демону.';
    else
    {
        if($finalDamage >= $opponent->health)
        {
            $db->query("UPDATE `demons_battles` SET `killboss` = '".$u['id']."' WHERE `id` = '".$btl->id."'");
            $logMsg = name($u['id']).' убил Демона.';
        }
        else $logMsg = name($u['id']).' ударил Демона на '.$finalDamage.'.';
    }
    $db->query("INSERT INTO `battle_logs` (`type`,`battle`,`msg`,`time`) VALUES ('demons-boss', '".$btl->id."', '".$logMsg."', '".time()."')");
    redirect('/demons/boss');
}
if(isset($_GET['heal']))
{
    if($myPlayer->health <= 0) redirect('/demons/boss');
    if($myPlayer->heal_cd > time()) redirect('/demons/boss');
    if($myPlayer->health >= get_health($u['id'])) redirect('/demons/boss');
    $healBonus = getSkillBonus('heal');
    if($healBonus+$myPlayer->health > get_health($u['id'])) $hp = get_health($u['id']);
    else $hp = $myPlayer->health+$healBonus;
    $db->query("UPDATE `demons_players` SET `health` = '".$hp."', `heal_cd` = '".(time()+30)."' WHERE `id` = '".$myPlayer->id."'");
    redirect('/demons/boss');
}
if(isset($_GET['arrow']))
{
    if($myPlayer->health <= 0) redirect('/demons/boss');
    $damage = getDamage(getSkillBonus('arrow'), $opponent->defense);
    if($myPlayer->arrow_cd > time()) redirect('/demons/boss');
    $finalDamage = $damage;
    $db->query("UPDATE `demons_players` SET `arrow_cd` = '".(time()+40)."', `damage` = `damage` + '".$finalDamage."' WHERE `id` = '".$myPlayer->id."'");
    $db->query("UPDATE `demons_mobs` SET `health` = `health` - '".$finalDamage."' WHERE `id` = '".$opponent->id."'");
    if($finalDamage >= $opponent->health)
    {
        $db->query("UPDATE `demons_battles` SET `killboss` = '".$u['id']."' WHERE `id` = '".$btl->id."'");
        $logMsg = name($u['id']).' убил Демона навыком "Разряд".';
    }
    else $logMsg = name($u['id']).' ударил Демона навыком "Разряд" на '.$finalDamage.'.';
    $db->query("INSERT INTO `battle_logs` (`type`,`battle`,`msg`,`time`) VALUES ('demons-boss', '".$btl->id."', '".$logMsg."', '".time()."')");
    redirect('/demons/boss');
}
echo '<div class="example3">
    
            <div class="b">
                <div class="examples_text-1">
        
                    <center>
                            
                            <a href="?attack"><img src="/images/b-ok.png" width="17%"></a>
                    </center>
            
            </div>
            
<center>
    <font color = "red"><b><big>
            
            Демон <img src="/images/health.png" width="35" height="30"> '.$opponent->health.'
    </b></big></font>
</center>
    <center><img src="/modules/demons/demon-min.png" width="50%"></center>
    
    </div>';
    
        echo '<div class="b"><center><big>Живых игроков: <img src="/images/users.png" width="35px"> '.$alivePlayers.'</center></big></div>';
        
                
                    echo '<div class="b-mini"><center>
                    
                                <font color = "lime"><b><big><img src="/images/users.png" width="35px"> Вы
                                        
                                        <img src="/images/health.png" width="35" height="30">
                                        
            '.$myPlayer->health.'              </font>  
            
            </b></big></center>
                
       <div style="height: 8px; border: 1px solid #000; position:relative; border-radius: 4px">
                                        <div style="height: 8px; background: #00A4D9; width:56%; position: absolute; left: 0px; top: 0px; border-radius: 2px; border-bottom-right-radius: 1px;border-top-right-radius: 1px;">
                                        </div>
                                    </div>
        </div>
                                        ';
                                        echo'<div class = "b-mini">';
                                        echo'
    <table style="width:100%;">
    
            <tr>
            
                    <td style="width: 33%;" class="center">';
                    
if($myPlayer->heal_cd > time())
{
    echo'
    <input type="submit" value="Исцеление ('.tl($myPlayer->heal_cd-time()).')">
    </td>';
}
else
{
    echo '<a href="?heal"><input type="submit" value="Исцеление"></a>
    </td>';
}
    echo'
    <td style="width:33%;" class="center">';
    if($myPlayer->arrow_cd > time())
{
    echo '<input type="submit" value="Разряд ('.tl($myPlayer->arrow_cd-time()).')">
    </td>
    </tr>
    </table>
    ';
}
else
{
    echo '<a href="?arrow"><input type="submit" value="Разряд"></a>
    </td>
    </tr>
    </table>
    ';
}
    echo'</td>
    </tr>
    </table>';
echo '</div></div>
';
$log = $db->query("SELECT * FROM `battle_logs` WHERE `type` = 'demons-boss' AND `battle` = '".$btl->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>';
}
include_once ($root.'/core/foot.php');