<?php
define('PROTECTOR', 1);
include('files/path.php');
include($path . 'files/db.php');
include($path . 'files/auth.php');
include($path . 'files/func.php');
$textl = 'Долина бессмертных';
include($path . 'files/core.php');
include($path . 'files/head.php');
include($path . 'files/zag.php');
echo '<div class="main"><div class="block_zero center"><span style="color: #9bc;">Бой с ордами врагов!</span></div><div class="mini-line"></div>';
if ($udata['lvl'] > 4) {
    $opponent_str = rand(10, 100);
    $opponent_vit = rand(10, 100);
    $opponent_agi = rand(10, 100);
    $opponent_def = rand(10, 100);
    $opponent_hp  = $opponent_vit * 2;
    $member       = mysql_query('SELECT * FROM `undying_member` WHERE `user` = "' . $udata['id'] . '" ORDER BY `id` DESC LIMIT 1');
    $member       = mysql_fetch_array($member);
    $battle       = mysql_query('SELECT * FROM `undying` WHERE `id` = "' . $member['battle'] . '"');
    $battle       = mysql_fetch_array($battle);
    if ($member['exit'] == 0 && $battle['start'] == 1 && $battle['end'] == 0) {
        $titans = mysql_result(mysql_query('SELECT COUNT(*) FROM `undying_member` WHERE `dead` = "0" AND `battle` = "' . $battle['id'] . '"'), 0);
        if ($titans == 0 OR $battle['opponents'] == 0) {
            mysql_query('UPDATE `undying` SET `end` = "1" WHERE `id` = "' . $battle['id'] . '"');
            header('location: undying.php');
            exit;
        }
        if ($battle['time'] < time()) {
            mysql_query('UPDATE `undying` SET `end` = "1" WHERE `id` = "' . $battle['id'] . '"');
            header('location: undying.php');
            exit;
        }
        if ($member['dead'] == 0) {
            if ($_GET['attack'] == true && $battle['opponents']) {
            mysql_query('UPDATE `undying_member` SET `mana` = "1" WHERE `user` = "' . $udata['id'] . '"');
                if ($member['time'] > time() OR $udata['mp'] < 50) {
                    header('location: undying.php');
                    exit;
                }
                $mag = mysql_fetch_array(mysql_query("SELECT * FROM `mag` WHERE `usr` = '$log'"));
                if ($mag['yarost'] > 0) {
                    switch ($mag['yarost']) {
                        case 5:
                            $a_1_bonus  = 45;
                            $a_1_chanse = 8;
                            break;
                        case 10:
                            $a_1_bonus  = 50;
                            $a_1_chanse = 8;
                            break;
                        case 15:
                            $a_1_bonus  = 55;
                            $a_1_chanse = 8;
                            break;
                        case 20:
                            $a_1_bonus  = 60;
                            $a_1_chanse = 8;
                            break;
                        case 25:
                            $a_1_bonus  = 65;
                            $a_1_chanse = 8;
                            break;
                        case 30:
                            $a_1_bonus  = 65;
                            $a_1_chanse = 11;
                            break;
                        case 35:
                            $a_1_bonus  = 70;
                            $a_1_chanse = 11;
                            break;
                        case 40:
                            $a_1_bonus  = 75;
                            $a_1_chanse = 11;
                            break;
                        case 45:
                            $a_1_bonus  = 80;
                            $a_1_chanse = 11;
                            break;
                        case 50:
                            $a_1_bonus  = 85;
                            $a_1_chanse = 11;
                            break;
                        case 55:
                            $a_1_bonus  = 85;
                            $a_1_chanse = 14;
                            break;
                        case 60:
                            $a_1_bonus  = 90;
                            $a_1_chanse = 14;
                            break;
                        case 65:
                            $a_1_bonus  = 95;
                            $a_1_chanse = 14;
                            break;
                        case 70:
                            $a_1_bonus  = 100;
                            $a_1_chanse = 14;
                            break;
                        case 75:
                            $a_1_bonus  = 105;
                            $a_1_chanse = 14;
                            break;
                        case 80:
                            $a_1_bonus  = 105;
                            $a_1_chanse = 17;
                            break;
                        case 85:
                            $a_1_bonus  = 145;
                            $a_1_chanse = 20;
                            break;
                        case 90:
                            $a_1_bonus  = 165;
                            $a_1_chanse = 23;
                            break;
                        case 95:
                            $a_1_bonus  = 165;
                            $a_1_chanse = 23;
                            break;
                        case 100:
                            $a_1_bonus  = 200;
                            $a_1_chanse = 25;
                            break;
                            }
                    if (isset($a_1_chanse) AND mt_rand(0, 100) <= $a_1_chanse) {
                        $a_1 = true;
                    }
                }
                if ($mag['bronya'] > 0) {
                    switch ($mag['bronya']) {
                        case 5:
                            $a_1_bonus  = 45;
                            $a_1_chanse = 8;
                            break;
                        case 10:
                            $a_1_bonus  = 50;
                            $a_1_chanse = 8;
                            break;
                        case 15:
                            $a_1_bonus  = 55;
                            $a_1_chanse = 8;
                            break;
                        case 20:
                            $a_1_bonus  = 60;
                            $a_1_chanse = 8;
                            break;
                        case 25:
                            $a_1_bonus  = 65;
                            $a_1_chanse = 8;
                            break;
                        case 30:
                            $a_1_bonus  = 65;
                            $a_1_chanse = 11;
                            break;
                        case 35:
                            $a_1_bonus  = 70;
                            $a_1_chanse = 11;
                            break;
                        case 40:
                            $a_1_bonus  = 75;
                            $a_1_chanse = 11;
                            break;
                        case 45:
                            $a_1_bonus  = 80;
                            $a_1_chanse = 11;
                            break;
                        case 50:
                            $a_1_bonus  = 85;
                            $a_1_chanse = 11;
                            break;
                        case 55:
                            $a_1_bonus  = 85;
                            $a_1_chanse = 14;
                            break;
                        case 60:
                            $a_1_bonus  = 90;
                            $a_1_chanse = 14;
                            break;
                        case 65:
                            $a_1_bonus  = 95;
                            $a_1_chanse = 14;
                            break;
                        case 70:
                            $a_1_bonus  = 100;
                            $a_1_chanse = 14;
                            break;
                        case 75:
                            $a_1_bonus  = 105;
                            $a_1_chanse = 14;
                            break;
                        case 80:
                            $a_1_bonus  = 105;
                            $a_1_chanse = 17;
                            break;
                        case 85:
                            $a_1_bonus  = 145;
                            $a_1_chanse = 20;
                            break;
                        case 90:
                            $a_1_bonus  = 165;
                            $a_1_chanse = 23;
                            break;
                        case 95:
                            $a_1_bonus  = 165;
                            $a_1_chanse = 23;
                            break;
                        case 100:
                            $a_1_bonus  = 200;
                            $a_1_chanse = 25;
                            break;
                    }
                    if (isset($a_2_chanse) AND mt_rand(0, 100) <= $a_2_chanse) {
                        $a_2 = true;
                    }
                }
                if ($mag['vihr'] > 0) {
                    switch ($mag['vihr']) {
                        case 0:
                            $a_3_bonus       = 5;
                            $a_3_crit_chanse = 5;
                            $a_3_chanse      = 20;
                            break;
                        case 1:
                            $a_3_bonus       = 5;
                            $a_3_crit_chanse = 5;
                            $a_3_chanse      = 20;
                            break;
                        case 2:
                            $a_3_bonus       = 8;
                            $a_3_crit_chanse = 5;
                            $a_3_chanse      = 20;
                            break;
                        case 3:
                            $a_3_bonus       = 11;
                            $a_3_crit_chanse = 5;
                            $a_3_chanse      = 20;
                            break;
                        case 4:
                            $a_3_bonus       = 14;
                            $a_3_crit_chanse = 5;
                            $a_3_chanse      = 20;
                            break;
                        case 5:
                            $a_3_bonus       = 17;
                            $a_3_crit_chanse = 5;
                            $a_3_chanse      = 20;
                            break;
                        case 6:
                            $a_3_bonus       = 17;
                            $a_3_crit_chanse = 7;
                            $a_3_chanse      = 25;
                            break;
                        case 7:
                            $a_3_bonus       = 20;
                            $a_3_crit_chanse = 7;
                            $a_3_chanse      = 25;
                            break;
                        case 8:
                            $a_3_bonus       = 23;
                            $a_3_crit_chanse = 7;
                            $a_3_chanse      = 25;
                            break;
                        case 9:
                            $a_3_bonus       = 26;
                            $a_3_crit_chanse = 7;
                            $a_3_chanse      = 25;
                            break;
                        case 10:
                            $a_3_bonus       = 29;
                            $a_3_crit_chanse = 7;
                            $a_3_chanse      = 25;
                            break;
                        case 11:
                            $a_3_bonus       = 29;
                            $a_3_crit_chanse = 9;
                            $a_3_chanse      = 30;
                            break;
                        case 12:
                            $a_3_bonus       = 32;
                            $a_3_crit_chanse = 9;
                            $a_3_chanse      = 30;
                            break;
                        case 13:
                            $a_3_bonus       = 35;
                            $a_3_crit_chanse = 9;
                            $a_3_chanse      = 30;
                            break;
                        case 14:
                            $a_3_bonus       = 38;
                            $a_3_crit_chanse = 9;
                            $a_3_chanse      = 30;
                            break;
                        case 15:
                            $a_3_bonus       = 41;
                            $a_3_crit_chanse = 9;
                            $a_3_chanse      = 30;
                            break;
                        case 16:
                            $a_3_bonus       = 41;
                            $a_3_crit_chanse = 11;
                            $a_3_chanse      = 35;
                            break;
                        case 17:
                            $a_3_bonus       = 44;
                            $a_3_crit_chanse = 11;
                            $a_3_chanse      = 35;
                            break;
                        case 18:
                            $a_3_bonus       = 47;
                            $a_3_crit_chanse = 11;
                            $a_3_chanse      = 35;
                            break;
                        case 19:
                            $a_3_bonus       = 50;
                            $a_3_crit_chanse = 11;
                            $a_3_chanse      = 35;
                            break;
                        case 20:
                            $a_3_bonus       = 53;
                            $a_3_crit_chanse = 11;
                            $a_3_chanse      = 35;
                            break;
                        case 21:
                            $a_3_bonus       = 53;
                            $a_3_crit_chanse = 13;
                            $a_3_chanse      = 40;
                            break;
                        case 22:
                            $a_3_bonus       = 77;
                            $a_3_crit_chanse = 15;
                            $a_3_chanse      = 45;
                            break;
                        case 23:
                            $a_3_bonus       = 89;
                            $a_3_crit_chanse = 17;
                            $a_3_chanse      = 50;
                            break;
                        case 24:
                            $a_3_bonus       = 89;
                            $a_3_crit_chanse = 17;
                            $a_3_chanse      = 50;
                            break;
                    }
                    if (isset($a_3_chanse) AND mt_rand(0, 100) <= $a_3_chanse) {
                        $a_3 = true;
                    }
                }
                if ($mag['stoika'] > 0) {
                    switch ($mag['stoika']) {
                        case 0:
                            $a_4_bonus  = 20;
                            $a_4_chanse = 5;
                            break;
                        case 1:
                            $a_4_bonus  = 20;
                            $a_4_chanse = 5;
                            break;
                        case 2:
                            $a_4_bonus  = 22;
                            $a_4_chanse = 5;
                            break;
                        case 3:
                            $a_4_bonus  = 24;
                            $a_4_chanse = 5;
                            break;
                        case 4:
                            $a_4_bonus  = 26;
                            $a_4_chanse = 5;
                            break;
                        case 5:
                            $a_4_bonus  = 28;
                            $a_4_chanse = 5;
                            break;
                        case 6:
                            $a_4_bonus  = 28;
                            $a_4_chanse = 10;
                            break;
                        case 7:
                            $a_4_bonus  = 30;
                            $a_4_chanse = 10;
                            break;
                        case 8:
                            $a_4_bonus  = 32;
                            $a_4_chanse = 10;
                            break;
                        case 9:
                            $a_4_bonus  = 34;
                            $a_4_chanse = 10;
                            break;
                        case 10:
                            $a_4_bonus  = 36;
                            $a_4_chanse = 10;
                            break;
                        case 11:
                            $a_4_bonus  = 36;
                            $a_4_chanse = 15;
                            break;
                        case 12:
                            $a_4_bonus  = 38;
                            $a_4_chanse = 15;
                            break;
                        case 13:
                            $a_4_bonus  = 40;
                            $a_4_chanse = 15;
                            break;
                        case 14:
                            $a_4_bonus  = 42;
                            $a_4_chanse = 15;
                            break;
                        case 15:
                            $a_4_bonus  = 44;
                            $a_4_chanse = 15;
                            break;
                        case 16:
                            $a_4_bonus  = 44;
                            $a_4_chanse = 20;
                            break;
                        case 17:
                            $a_4_bonus  = 46;
                            $a_4_chanse = 20;
                            break;
                        case 18:
                            $a_4_bonus  = 48;
                            $a_4_chanse = 20;
                            break;
                        case 19:
                            $a_4_bonus  = 50;
                            $a_4_chanse = 20;
                            break;
                        case 20:
                            $a_4_bonus  = 52;
                            $a_4_chanse = 20;
                            break;
                        case 21:
                            $a_4_bonus  = 52;
                            $a_4_chanse = 25;
                            break;
                        case 22:
                            $a_4_bonus  = 68;
                            $a_4_chanse = 30;
                            break;
                        case 23:
                            $a_4_bonus  = 76;
                            $a_4_chanse = 35;
                            break;
                        case 24:
                            $a_4_bonus  = 76;
                            $a_4_chanse = 35;
                            break;
                    }
                    if (isset($a_4_chanse) AND mt_rand(0, 100) <= $a_4_chanse) {
                        $a_4 = true;
                    }
                }
                $dmg = round(rand(($udata['sila'] / 6), ($udata['sila'] / 4)));
                $dmg = $dmg + round(rand(($udata['sila'] / 6), ($udata['sila'] / 4)));
                if (isset($a_1) AND $a_1 == true) {
                    $dmg += round(($dmg / 100) * $a_1_bonus);
                }
                $dmg -= round(rand(($opponent_def / 12), ($opponent_def / 7)));
                if ($dmg < 0) {
                    $dmg = 0;
                }
                if (isset($a_3) AND $a_3 == true) {
                    $crit = ((rand(1, 2) * ($udata['lovk'] / 100) + $a_3_crit_chanse) - (rand(1, 2) * ($opponent_agi / 100)));
                } else {
                    $crit = ((rand(1, 2) * ($udata['lovk'] / 100)) - (rand(1, 2) * ($opponent_agi / 100)));
                }
                if (mt_rand(0, 100) <= $crit) {
                    $dmg *= 2;
                    if (isset($a_3) AND $a_3 == true) {
                        $dmg += round(($dmg / 100) * $a_3_bonus);
                    }
                    $_crit = true;
                }
                $dodge = ((rand(1, 2) * ($opponent_agi / 100)) - (rand(1, 2) * ($udata['lovk'] / 100)));
                if (mt_rand(0, 100) <= $dodge) {
                    $dmg = 0;
                }
                $opponent_dmg = round(rand(($opponent_str / 6), ($opponent_str / 4)));
                $opponent_dmg = $opponent_dmg + round(rand(($opponent_str / 6), ($opponent_str / 4)));
                if (isset($a_2) AND $a_2 == true) {
                    $opponent_dmg -= round(($opponent_dmg / 100) * $a_2_bonus);
                }
                $opponent_dmg -= round(rand(($udata['prot'] / 12), ($udata['prot'] / 7)));
                if ($opponent_dmg < 0) {
                    $opponent_dmg = 0;
                }
                $opponent_crit = ((rand(1, 2) * ($opponent_agi / 100)) - (rand(1, 2) * ($udata['lovk'] / 100)));
                if (mt_rand(0, 100) <= $opponent_crit) {
                    $opponent_dmg *= 2;
                    if (isset($a_4) AND $a_4 == true) {
                        $opponent_dmg -= round(($opponent_dmg / 100) * $a_4_bonus);
                    }
                    $_opponent_crit = true;
                }
                $opponent_dodge = ((rand(1, 2) * ($udata['lovk'] / 100)) - (rand(1, 2) * ($opponent_agi / 100)));
                if (mt_rand(0, 100) <= $opponent_dodge) {
                    $opponent_dmg = 0;
                }
                if ($dmg > $opponent_hp) {
                    mysql_query('UPDATE `undying_member` SET `kills` = "' . ($member['kills'] + 1) . '" WHERE `user` = "' . $udata['id'] . '" AND `battle` = "' . $battle['id'] . '"');
                    mysql_query('UPDATE `undying` SET `opponents` = "' . ($battle['opponents'] - 1) . '" WHERE `id` = "' . $battle['id'] . '"');
                    if ($battle['opponents'] - 1 == 0) {
                        header('location: undying.php');
                    }
                }
                mysql_query('UPDATE `undying_member` SET `time` = "' . (time() + 10) . '", `dmg` = "' . ($member['dmg'] + $dmg) . '" WHERE `user` = "' . $udata['id'] . '" AND `battle` = "' . $battle['id'] . '"');
                if ($opponent_dmg > $udata['hp']) {
                    $_hp = $udata['hp'];
                } else {
                    $_hp = $opponent_dmg;
                }
                if ($opponent_dmg > 0) {
                    mysql_query('UPDATE `users` SET `hp` = "' . ($udata['hp'] - $_hp) . '" WHERE `id` = "' . $udata['id'] . '"');
                }
                mysql_query('UPDATE `users` SET `mp` = "' . ($udata['mp'] - 5) . '" WHERE `id` = "' . $udata['id'] . '"');
                if ($opponent_dmg > $udata['hp']) {
                    mysql_query('UPDATE `undying_member` SET `dead` = "1" WHERE `user` = "' . $udata['id'] . '" AND `battle` = "' . $battle['id'] . '"');
                    if ($titans - 1 == 0) {
                        header('location: undying.php');
                    }
                }
?> </div></div><div class='block_zero center'><img src='/image/icon/hit.png' alt='*'/><font color='#9c9'> Нанесено урона: <b><?= $dmg ?> </b> <?
                if (isset($_crit) AND $_crit == true) {
                    echo '(крит)';
                }
?> </font><br/> <?
                if ((isset($a_1) AND $a_1 == true) OR (isset($a_2) AND $a_2 == true) OR (isset($a_3) AND $a_3 == true) OR (isset($a_4) AND $a_4 == true)) {
?>  <div class='separ'></div>  <?
                    if (isset($a_1) AND $a_1 == true) {
                        if ($mag['yarost'] == 0) {
                            $pic = 0;
                        }
                        if ($mag['yarost'] >= 1) {
                            $pic = 1;
                        }
                        if ($mag['yarost'] >= 20) {
                            $pic = 2;
                        }
                        if ($mag['yarost'] >= 40) {
                            $pic = 3;
                        }
                        if ($mag['yarost'] >= 60) {
                            $pic = 4;
                        }
                        if ($mag['yarost'] >= 80) {
                            $pic = 5;
                        }
                        if ($mag['yarost'] == 100) {
                            $pic = 6;
                        }
                        echo ' <img src=\'/image/umehi/1.' . $pic . '.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';
                    }
                    if (isset($a_2) AND $a_2 == true) {
                        if ($mag['bronya'] == 0) {
                            $pic2 = 0;
                        }
                        if ($mag['bronya'] >= 1) {
                            $pic2 = 1;
                        }
                        if ($mag['bronya'] >= 20) {
                            $pic2 = 2;
                        }
                        if ($mag['bronya'] >= 40) {
                            $pic2 = 3;
                        }
                        if ($mag['bronya'] >= 60) {
                            $pic2 = 4;
                        }
                        if ($mag['bronya'] >= 80) {
                            $pic2 = 5;
                        }
                        if ($mag['bronya'] == 100) {
                            $pic2 = 6;
                        }
                        echo ' <img src=\'/image/umehi/2.' . $pic2 . '.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';
                    }
                    if (isset($a_3) AND $a_3 == true) {
                        if ($mag['vihr'] == 0) {
                            $pic3 = 0;
                        }
                        if ($mag['vihr'] >= 1) {
                            $pic3 = 1;
                        }
                        if ($mag['vihr'] >= 20) {
                            $pic3 = 2;
                        }
                        if ($mag['vihr'] >= 40) {
                            $pic3 = 3;
                        }
                        if ($mag['vihr'] >= 60) {
                            $pic3 = 4;
                        }
                        if ($mag['vihr'] >= 80) {
                            $pic3 = 5;
                        }
                        if ($mag['vihr'] == 100) {
                            $pic3 = 6;
                        }
                        echo ' <img src=\'/image/umehi/3.' . $pic3 . '.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';
                    }
                    if (isset($a_4) AND $a_4 == true) {
                        if ($mag['stoika'] == 0) {
                            $pic4 = 0;
                        }
                        if ($mag['stoika'] >= 1) {
                            $pic4 = 1;
                        }
                        if ($mag['stoika'] >= 20) {
                            $pic4 = 2;
                        }
                        if ($mag['stoika'] >= 40) {
                            $pic4 = 3;
                        }
                        if ($mag['stoika'] >= 60) {
                            $pic4 = 4;
                        }
                        if ($mag['stoika'] >= 80) {
                            $pic4 = 5;
                        }
                        if ($mag['stoika'] == 100) {
                            $pic4 = 6;
                        }
                        echo ' <img src=\'/image/umehi/4.' . $pic4 . '.png\' width=\'25px\' height=\'25px\' alt=\'*\'/> ';
                    }
                }
                if ($dmg > $opponent_hp) {
?> <div class='separ'></div><img src='/image/icon/rip.png' alt='*'/> <font color='#9bc'>Вы убили одного <img src='/image/icon/bot.png' alt='*'/> врага!</font><br/> <?
                }
                if ($opponent_dmg > 0) {
?> <div class='separ'></div> <img src='/image/icon/bot.png' alt='*'/> <font color='#c66'>Получено урона: <b><?= $opponent_dmg ?></b> <?
                    if (isset($_opponent_crit) AND $_opponent_crit == true) {
                        echo '(крит)';
                    }
?></font> <?
                }
                } else {
            }
?> </div><div class='dot-line'></div><div class='main'><div class='block_zero center'><img src='/image/icon/0.png' alt='*'/><img src='/image/icon/1.png' alt='*'/> Бессмертные: <b><?= $titans ?></b> <img src='/image/icon/vs.png' alt='*'/> <img src='/image/icon/bot.png' alt='*'/> Враги: <b><?= $battle['opponents'] ?></b> <?
            if ($udata['mp'] < $udata['mpall']  AND $member['mana']=='0') {
                if ($_GET['mana'] == true) {
                    mysql_query('UPDATE `users` SET `mp` = "' . $udata['mpall'] . '" WHERE `id` = "' . $udata['id'] . '"');
                    mysql_query('UPDATE `undying_member` SET `mana` = "1" WHERE `user` = "' . $udata['id'] . '"');
                    header('location: undying.php');
                }
?> </div><div class='dot-line'></div><div class='block_zero center'><a href='undying.php?mana=true' class='btn'><span class='end'><span class='label'>Пополнить ману</span></span></a></div><div class='dot-line'></div><div class='block_zero center'> <?
            } else {
?> </div><div class='dot-line'></div><div class='block_zero center'><a href='undying.php?attack=true' class='btn'><span class='end'><span class='label'>Атаковать</span></span></a></div><div class='dot-line'></div><div class='block_zero center'> <?
            }
            if ($member['time'] > time()) {
?> <font color='#999'>До удара <?= ($member['time'] - time()) ?> сек</font> <?
            }
            $timerboya = Sec2time($battle['time'] - time());
            echo "<br><font color='#999'>Бой закончится через $timerboya</font></div></div>";
         if($udata['mp']<50) {
?> </b></div><div class='dot-line'></div><div class='main'><div class='block_zero center'><font color='#999'>У Вас не достаточно маны,<br>необходимо минимум 50 маны</font></div></div></div> <?      
        }
        } else {
?> <div class='block_zero center'><img src='/image/icon/0.png' alt='*'/><img src='/image/icon/1.png' alt='*'/> Бессмертные: <b><?= $titans ?></b><img src='/image/icon/vs.png' alt='*'/><img src='/image/icon/bot.png' alt='*'/> Враги: <b><?= $battle['opponents'] ?></b></div><div class='dot-line'></div><div class='main'><div class='block_zero center'><a href='?' class='btn'><span class='end'><span class='label'>Обновить</span></span></a></div><div class='dot-line'></div><div class='block_zero center'><font color='#999'>Вы были убиты во время сражения,<br> ожидайте окончания боя</font></div></div></div> <?
        }
    } else {
        if ($member['exit'] == 0 && $battle['start'] == 1 && $battle['end'] == 1) {
            $titans = mysql_result(mysql_query('SELECT COUNT(*) FROM `undying_member` WHERE `dead` = "0" AND `battle` = "' . $battle['id'] . '"'), 0);
            if ($titans == 0 && $battle['opponents'] > 0 OR $battle['opponents'] > 0) {
                $_g   = round($member['kills'] / 2);
                $_s   = rand(1, 1000) + round(rand(($member['dmg'] / 100), $member['dmg']) / 2);
                $_exp = rand(1, 100) + round(round(round($member['dmg'] / 100) * 10) / 2);
?> <div class='block_zero center'> <img src='/image/icon/2hit.png' alt='*'/> <font color='#c66'>Поражение!</font> <img src='/image/icon/2hit.png' alt='*'/></div><div class='dot-line'></div> <?
            } else {
                $_g   = $member['kills'];
                $_s   = rand(1, 10000) + round(rand(($member['dmg'] / 100), $member['dmg']));
                $_exp = rand(1, 1000) + round(round($member['dmg'] / 100) * 10);
?> <div class='block_zero center'><img src='/image/icon/2hit.png' alt='*'/> <font color='#9c9'>Победа</font> <img src='/image/icon/2hit.png' alt='*'/> <br /><a href='sunduki.php'>Вы получили <img src='image/icon/key.png'/> 1 ключ от сундука</a></div><div class='dot-line'></div> <?
mysql_query("UPDATE `users` SET `key`= `key`+'1' WHERE `id`='$udata[id]'");
            }
?> <div class='block_zero center'><div class='separator'></div><font color='#9bc'>Награда:</font><br/><img src='/image/icon/almaz.png' alt='*'/> <?= $_g ?> золота <img src='/image/icon/money.png' alt='*'/> <?= $_s ?> серебра <img src='/image/icon/exp.png' alt='*'/> <?= $_exp ?> опыта </div><div class='dot-line'></div> <?
            
            $req = mysql_query("SELECT * FROM `clan` where `lider`='$udata[clan]'");
            $avto=mysql_num_rows($req);
            $clan = mysql_fetch_array($req);
            if($avto==1){
            $_exp += round($_exp / 1000);
            }
            
            if ($set['vip'] == 'on') {
                $_exp += round($_exp / 100) * 50;
            }
            
            mysql_query("UPDATE `clan` SET `exp` = `exp`+'$_exp' WHERE `lider` = '$udata[clan]'");
            mysql_query("UPDATE `users` SET `clanexp` = `clanexp`+'$_exp' WHERE `usr` = '$log'");
            
            mysql_query('UPDATE `users` SET `almaz` = "' . ($udata['almaz'] + $_g) . '", `money` = "' . ($udata['money'] + $_s) . '", `exp` = "' . ($udata['exp'] + $_exp) . '" WHERE `id` = "' . $udata['id'] . '"');
            mysql_query('UPDATE `undying_member` SET `exit` = "1" WHERE `battle` = "' . $battle['id'] . '" AND `user` = "' . $udata['id'] . '"');
        } else {
        }
?> <div class='block_zero center'> <img src='/image/logo/<?= (($member['exit'] == 0 && $battle['start'] == 1 && $battle['end'] == 1) ? (($titans == 0 && $battle['opponents'] > 0 OR $battle['opponents'] > 0) ? 'vragi.png' : 'bogi.png') : 'dolina.png') ?>' alt='*'/> <?
        echo '</div><div class="dot-line"></div>';
        if ($member['exit'] == 0 && $battle['start'] == 1 && $battle['end'] == 1) {
?> <div class='block_zero center'> <font color='#90b0c0'>Ваши достижения:</font><br/> <img src='/image/icon/bot.png' alt='*'/> Убито врагов: <font color='#9c9'><?= $member['kills'] ?></font><br/> <img src='/image/icon/hit.png' alt='*'/> Нанесено урона: <font color='#9c9'><?= $member['dmg'] ?></font></div><div class='dot-line'></div> <?
} else {
        }
        $battle = mysql_query('SELECT * FROM `undying` WHERE `start` = "0"');
        $battle = mysql_fetch_array($battle);
        if (!$battle) {
            $h = date('H', time());
            if ($h > 22 && $h < 6) {
                $time = 3600 * 6;
            } else {
                $time = 3600 * 6;
            }
            mysql_query('INSERT INTO `undying` (`time`) VALUES ("' . (time() + $time) . '")');
        }
        if ($battle['time'] <= time()) {
            mysql_query('UPDATE `undying` SET `start` = "1", `time` = "' . (time() + (60 * 5)) . '" WHERE `id` = "' . $battle['id'] . '"');
            header('location: undying.php');
        }
?> <div class='block_zero center'> <img src='/image/icon/0.png' alt='*'/><img src='/image/icon/1.png' alt='*'/> Бессмертные:<b> <?= mysql_result(mysql_query('SELECT COUNT(*) FROM `undying_member` WHERE `battle` = "' . $battle['id'] . '"'), 0) ?></b><br/>Битва начнется через: <?= Sec2time($battle['time'] - time()) ?> <?
        if ($member['battle'] != $battle['id']) {
            if ($_GET['enter'] == true) {
                mysql_query('UPDATE `undying_member` SET `mana` = "0" WHERE `user` = "' . $udata['id'] . '"');
                mysql_query('INSERT INTO `undying_member` (`battle`, `user`, `time`) VALUES ("' . $battle['id'] . '", "' . $udata['id'] . '", "' . time() . '")');
                mysql_query('UPDATE `undying` SET `opponents` = "' . ($battle['opponents'] + rand(1, 5)) . '" WHERE `id` = "' . $battle['id'] . '"');
                $_SESSION['message']="Заявка на участие в битве подана!";
                header('location: undying.php');
            }
?> </div><div class='dot-line'></div> <div class='block_zero center'> <a href='undying.php?enter=true' class='btn'><span class='end'><span class='label'><img src='/image/icon/hit.png' alt='*'/> Подать заявку</span></span></a></div><div class='mini-line'> </div><ul class='hint'><li>Ваш герой будет сражаться сам, даже если Вы не пришли на битву, но награда будет меньше</li></ul></div></div></div> <?
        } else {
?> </div><div class='dot-line'></div> <div class='block_zero center'> <a href='undying.php' class='btn'><span class='end'><span class='label'>Обновить</span></span></a></div></div> <?
        }
    }
} else {
?>  <div class='content' align='center'> <div class='block_zero center'>  Для участии в <img src='/image/icon/bar.png' alt='*'/> Долине бессмертных требуется <img src='/image/icon/level.png' alt='*'/> 5 уровень </div> </div> </div> <?
}
include($path . 'files/down.php');
?>