<?php
/**
 * Created by PhpStorm.
 * User: alex_moor
 * Date: 20.01.2018
 * Time: 12:37
 */

$ArenaEnemyHp = round($btl['mob_health'] / $btl['mob_max_health'] * 100, 1);
if ($btl['stage'] == 'boss') {
    $ArenaEnemyHp = round($btl['health'] / $btl['max_health'] * 100, 1);
}

?>
<style>
    .wrapper1 {
        color: #ffffff;
        font-size: 13px;
        text-shadow: 1px 1px 0 black;
        font-weight: bold;
        padding: 5px 10px;
        border-top: 1px #979898 solid;
        border-bottom: 1px #979898 solid;
        background: -webkit-linear-gradient(top, #5bc4ff, #5c798a);
    }

    .wrapper2 {
        color: #ffffff;
        font-size: 13px;
        text-shadow: 1px 1px 0 black;
        font-weight: bold;
        padding: 5px 10px;
        border-top: 1px #979898 solid;
        border-bottom: 1px #979898 solid;
        background: -webkit-linear-gradient(top, #b8ff5b, #5c798a);
    }

    .wrapper3 {
        color: #ffffff;
        font-size: 13px;
        text-shadow: 1px 1px 0 black;
        font-weight: bold;
        padding: 5px 10px;
        border-top: 1px #979898 solid;
        border-bottom: 1px #979898 solid;
        background: -webkit-linear-gradient(top, #bd3e0e, #5c798a);
    }

</style>

    <div class="header" style="text-align: center;">
        <img src='<?= $mobs['img']; ?>' width='180'>
    </div>


<?php


echo div('header') . " " . $mobs['name'] . " <br> "

 ;
echo "<div class='life_bar'><div class='life_bar-red' style='width:$ArenaEnemyHp%'></div></div></div>";


if ($ability) {
    echo div('header center');
    echo " <a href='?attack'>" . img('ability', 'spell_attack.png') . "</a>";
    if ($ability['statusHp'] == 1 or $ability['energy'] < 1) {
        echo " <a href='?'>" . spell('ability', 'spell_health.png ') . "</a>";
    } else {
        echo " <a href='?UseSpellHp'>" . img('ability', 'spell_health.png ') . "</a>";
    }


    if ($ability['statusDef'] == 1 or $ability['energy'] < 1) {
        echo " <a href='?'>" . spell('ability', 'spell_defence.png ') . "</a>";
    } else {
        echo " <a href='?UseSpellDef'>" . img('ability', 'spell_defence.png ') . "</a>";
    }


    if ($ability['statusStr'] == 1 or $ability['energy'] < 1) {
        echo " <a href='?'>" . spell('ability', 'double_attack.jpg ') . "</a>";
    } else {
        echo " <a href='?UseSpellStr'>" . img('ability', 'double_attack.jpg ') . "</a>";
    }

    echo "</div>";

} else {
    echo "<div class='main_link'><a href='?attack'>" . img('ability', 'spell_attack.png') . "</a></div>";

}

if (filter_has_var(INPUT_POST, 'message')) {
    if (strlen($_POST['message']) == true) {
        $msg = mysql_real_escape_string($_POST['message']);
        mysql_query("INSERT INTO `avenax_demon_chat`(`id_user`, `message`, `time_msg`) VALUES ('" . $user['id'] . "', '" . $msg . "', '" . time() . "')");
        Invasion::redirect('?');
    }
}

echo '<div class="wrapper"><form method="post">';
echo '<textarea style="width: 100%" name="message" placeholder="Сообщение"></textarea>';
echo '<center><input type="submit" name="go" class="btn_grey" value="Отправить"></center>';
echo '</form></div>';


if (mysql_result(mysql_query("SELECT COUNT(*) FROM `avenax_demon_chat`"), 0) == false) {
    echo '<div class="text_p1">Чат пуст</div>';
} else {
    $q = mysql_query("SELECT avenax_demon_chat.*,users.login FROM avenax_demon_chat, users WHERE users.id = avenax_demon_chat.id_user ORDER BY avenax_demon_chat.id DESC LIMIT 5");
    while ($post = mysql_fetch_assoc($q)) {
        echo div('text_p1');
        echo icons_user($post['id_user'])." <font color='grey'> <a href='/profile/$post[id_user]'> <font color='white'> $post[login]</font></a><span style ='float:right;'>" . tl(time() - $post['time_msg']) . " </span> ";
        echo "<br>" . text_msg($post['message']) . "";
        echo "</div>";


    }
}


$userList = Invasion::getUserBattle($user['id'], ['login' => $user['login'], 'id_user' => $user['id'], 'damage' => $myBattle['damage']], $btl['id']);
echo '<div class="wrapper center" style="text-align: center;">Кто в бою:</div>';

foreach ($userList as $item => $value) {
    $div = 'wrapper';
    if ($item == 1) {
        $div = 'wrapper1';
    } else if ($item == 2) {
        $div = 'wrapper2';
    } else if ($item == 3) {
        $div = 'wrapper3';
    }
    echo '<div class="' . $div . '">';

    echo icons_user($value['id_user']) . "  <a href='/profile/$value[id_user]'>" . htmlspecialchars($value['login']) . "</a>, <img src='/images/icons/str.png'> $value[damage]</div>";
    echo '</div>';
}

require_once(ROOT . '/system/footer.php');

