<?php
require_once('system/func.php');
$title = 'Умения';

auth(); // 
require_once('system/header.php');


$ability = mysql_fetch_assoc(mysql_query("SELECT * FROM `ability` WHERE  `id_user` = '$myID'"));
//Если у игрока нету умений 
if (!$ability) {
    mysql_query("INSERT INTO `ability` SET `id_user` = '$myID'");
    header('Location: /ability/');
    exit();
}

function cost($i) {

    switch ($i) {
        case 0:
            $cost = 1000;
            break;

        case 1:
            $cost = 5000;
            break;

        case 2:
            $cost = 15000;
            break;

        case 3:
            $cost = 30000;
            break;

        case 4:
            $cost = 1000;
            break;

        case 5:
            $cost = 80000;
            break;

        case 6:
            $cost = 110000;
            break;

        case 7:
            $cost = 170000;
            break;

        case 8:
            $cost = 3000;
            break;

        case 9:
            $cost = 250000;
            break;

        case 10:
            $cost = 310000;
            break;

        case 11:
            $cost = 380000;
            break;

        case 12:
            $cost = 5000;
            break;

        case 13:
            $cost = 470000;
            break;

        case 14:
            $cost = 560000;
            break;

        case 15:
            $cost = 640000;
            break;

        case 16:
            $cost = 10000;
            break;

        case 17:
            $cost = 750000;
            break;

        case 18:
            $cost = 900000;
            break;

        case 19:
            $cost = 1500000;
            break;

        case 20:
            $cost = 15000;
            break;


    }


    return $cost * 5;

}

function value($i) {

    switch ($i) {
        case 0:
            $value = 'gold';
            break;

        case 1:
            $value = 'gold';
            break;

        case 2:
            $value = 'gold';
            break;

        case 3:
            $value = 'gold';
            break;

        case 4:
            $value = 'almaz';
            break;

        case 5:
            $value = 'gold';
            break;

        case 6:
            $value = 'gold';
            break;

        case 7:
            $value = 'gold';
            break;

        case 8:
            $value = 'almaz';
            break;

        case 9:
            $value = 'gold';
            break;

        case 10:
            $value = 'gold';
            break;

        case 11:
            $value = 'gold';
            break;

        case 12:
            $value = 'almaz';
            break;

        case 13:
            $value = 'gold';
            break;

        case 14:
            $value = 'gold';
            break;

        case 15:
            $value = 'gold';
            break;

        case 16:
            $value = 'almaz';
            break;

        case 17:
            $value = 'gold';
            break;

        case 18:
            $value = 'gold';
            break;

        case 19:
            $value = 'gold';
            break;

        case 20:
            $value = 'almaz';
            break;

    }


    return $value;

}

//Бонус 
function bonus($i) {
    switch ($i) {
        case 0 :
            $resphP = 15;
            break;

        case 1 :
            $resphP = 16;
            break;
        case 2 :
            $resphP = 17;
            break;
        case 3 :
            $resphP = 18;
            break;
        case 4 :
            $resphP = 22;
            break;
        case 5 :
            $resphP = 24;
            break;

        case 6 :
            $resphP = 26;
            break;

        case 7 :
            $resphP = 28;
            break;

        case 8 :
            $resphP = 34;
            break;

        case 9 :
            $resphP = 36;
            break;

        case 10 :
            $resphP = 38;
            break;

        case 11 :
            $resphP = 40;
            break;
        case 12 :
            $resphP = 45;
            break;
        case 13 :
            $resphP = 47;
            break;
        case 14 :
            $resphP = 49;
            break;
        case 15 :
            $resphP = 51;
            break;

        case 16 :
            $resphP = 56;
            break;

        case 17 :
            $resphP = 58;
            break;

        case 18 :
            $resphP = 60;
            break;

        case 19 :
            $resphP = 62;
            break;

        case 20 :
            $resphP = 67;
            break;


    }
    return $resphP;

}

//Умения сила жизни             
if (isset($_GET['AbilityHp'])) {
    if ($ability['spellHpLvl'] != 20) {
        if (value($ability['spellHpLvl']) == 'gold') {
            if ($user['gold'] < cost($ability['spellHpLvl'])) {
                $_SESSION['msg'] = "Не хватает " . ico('icons', 'gold.png') . " " . (cost($ability['spellHpLvl']) - $user['gold']) . " золота";
                header('Location: /ability/?' . $random);
                exit();
            } else {
                mysql_query('UPDATE `ability` SET `spellHpLvl` =   `spellHpLvl` + 1 ,   `spellHpResp` =   `spellHpResp` + ' . bonus($ability['spellHpLvl']) . '  WHERE `id_user` = "' . $user['id'] . '" LIMIT 1 ');
                mysql_query('UPDATE `users` SET `gold` = `gold` - ' . cost($ability['spellHpLvl']) . ' WHERE `id` = "' . $user['id'] . '"');
                $_SESSION['msg'] = "<div class='wrapper'>Умения Сила жизни  улучшено </div> ";
                header('Location: /ability/?' . $random);
                exit();
            }
        } elseif (value($ability['spellHpLvl'] == 'almaz')) {
            if ($user['almaz'] < cost($ability['spellHpLvl'])) {
                $_SESSION['msg'] = " <div class='block_lose'> Не хватает " . ico('icons', 'almaz.png') . " " . (cost($ability['spellHpLvl']) - $user['almaz']) . " алмазов</div>";
                header('Location: /ability/?' . $random);
                exit();
            } else {
                mysql_query('UPDATE `ability` SET `spellHpLvl` =   `spellHpLvl` + 1 ,   `spellHpResp` =   `spellHpResp` + ' . bonus($ability['spellHpLvl']) . '  WHERE `id_user` = "' . $user['id'] . '" LIMIT 1 ');
                mysql_query('UPDATE `users` SET `almaz` = `almaz` - ' . cost($ability['spellHpLvl']) . ' WHERE `id` = "' . $user['id'] . '"');
                $_SESSION['msg'] = " <div class='wrapper'> Умения Сила жизни улучшено</div> ";
                header('Location: /ability?' . $random);
                exit();
            }
        }
    }
}

//Сила удара             
if (isset($_GET['AbilityStr'])) {
    if ($ability['spellStrLvl'] != 20) {
        if (value($ability['spellStrLvl']) == 'gold') {
            if ($user['gold'] < cost($ability['spellStrLvl'])) {
                $_SESSION['msg'] = "Не хватает " . ico('icons', 'gold.png') . " " . (cost($ability['spellStrLvl']) - $user['gold']) . " золота";
                header('Location: /ability/?' . $random);
                exit();
            } else {
                mysql_query('UPDATE `ability` SET `spellStrLvl` =   `spellStrLvl` + 1 ,   `spellStrDmg` =   `spellStrDmg` + ' . bonus($ability['spellStrLvl']) . '  WHERE `id_user` = "' . $user['id'] . '" LIMIT 1 ');
                mysql_query('UPDATE `users` SET `gold` = `gold` - ' . cost($ability['spellStrLvl']) . ' WHERE `id` = "' . $user['id'] . '"');
                $_SESSION['msg'] = "<div class='wrapper'>Умения улучшено </div> ";
                header('Location: /ability/?' . $random);
                exit();
            }
        } elseif (value($ability['spellStrLvl'] == 'almaz')) {
            if ($user['almaz'] < cost($ability['spellStrLvl'])) {
                $_SESSION['msg'] = " <div class='block_lose'> Не хватает " . ico('icons', 'almaz.png') . " " . (cost($ability['spellStrLvl']) - $user['almaz']) . " алмазов</div>";
                header('Location: /ability/?' . $random);
                exit();
            } else {
                mysql_query('UPDATE `ability` SET `spellStrLvl` =   `spellStrLvl` + 1 ,   `spellStrDmg` =   `spellStrDmg` + ' . bonus($ability['spellStrLvl']) . '  WHERE `id_user` = "' . $user['id'] . '" LIMIT 1 ');
                mysql_query('UPDATE `users` SET `almaz` = `almaz` - ' . cost($ability['spellStrLvl']) . ' WHERE `id` = "' . $user['id'] . '"');
                $_SESSION['msg'] = " <div class='wrapper'> Умения Сила удара  улучшено</div> ";
                header('Location: /ability?' . $random);
                exit();
            }
        }
    }
}


//Крепкая броня             
if (isset($_GET['AbilityDef'])) {
    if ($ability['spellDefLvl'] != 20) {
        if (value($ability['spellDefLvl']) == 'gold') {
            if ($user['gold'] < cost($ability['spellDefLvl'])) {
                $_SESSION['msg'] = "Не хватает " . ico('icons', 'gold.png') . " " . (cost($ability['spellDefLvl']) - $user['gold']) . " золота";
                header('Location: /ability/?' . $random);
                exit();
            } else {
                mysql_query('UPDATE `ability` SET `spellDefLvl` =   `spellDefLvl` + 1 ,   `spellDefAbsorb` =   `spellDefAbsorb` + ' . bonus($ability['spellDefLvl']) . '  WHERE `id_user` = "' . $user['id'] . '" LIMIT 1 ');
                mysql_query('UPDATE `users` SET `gold` = `gold` - ' . cost($ability['spellDefLvl']) . ' WHERE `id` = "' . $user['id'] . '"');
                $_SESSION['msg'] = "<div class='block_win'>Умения Крепкая броня </div> ";
                header('Location: /ability/?' . $random);
                exit();
            }
        } elseif (value($ability['spellDefLvl'] == 'almaz')) {
            if ($user['almaz'] < cost($ability['spellDefLvl'])) {
                $_SESSION['msg'] = " <div class='block_lose'> Не хватает " . ico('icons', 'almaz.png') . " " . (cost($ability['spellDefLvl']) - $user['almaz']) . " алмазов</div>";
                header('Location: /ability/?' . $random);
                exit();
            } else {
                mysql_query('UPDATE `ability` SET `spellDefLvl` =   `spellDefLvl` + 1 ,   `spellDefAbsorb` =   `spellDefAbsorb` + ' . bonus($ability['spellDefLvl']) . '  WHERE `id_user` = "' . $user['id'] . '" LIMIT 1 ');
                mysql_query('UPDATE `users` SET `almaz` = `almaz` - ' . cost($ability['spellDefLvl']) . ' WHERE `id` = "' . $user['id'] . '"');
                $_SESSION['msg'] = " <div class='block_win'> Умения Крепкая броня  улучшено</div> ";
                header('Location: /ability?' . $random);
                exit();
            }
        }
    }
}


if ($ability['spellHpLvl'] < 20) {
    $AbilityHp = color('green') . " + " . bonus($ability['spellHpLvl']);

    $LinkHp = "<br><center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?AbilityHp'>" . span('white') . "Улучшить  за " . (value($ability['spellHpLvl']) == 'almaz' ? ico('icons', 'almaz.png') : ico('icons', 'gold.png')) . " " . cost($ability['spellHpLvl']) . "</div></span></span></a>";
} else {
    $LinkHp = "<br><center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?'>" . span('white') . "Масимальний уровень </div></span></span></a>";
}


if ($ability['spellDefLvl'] < 20) {
    $AbilityDef = color('green') . " + " . bonus($ability['spellDefLvl']);
    $LinkDef = "<br><center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?AbilityDef'>" . span('white') . "Улучшить  за " . (value($ability['spellDefLvl']) == 'almaz' ? ico('icons', 'almaz.png') : ico('icons', 'gold.png')) . " " . cost($ability['spellDefLvl']) . "</div></span></span></a>";
} else {
    $LinkDef = "<br><center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?'>" . span('white') . "Масимальний уровень </div></span></span></a>";
}


if ($ability['spellStrLvl'] < 20) {
    $AbilityStr = color('green') . " + " . bonus($ability['spellStrLvl']);
    $LinkStr = "<br><center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?AbilityStr'>" . span('white') . "Улучшить  за " . (value($ability['spellStrLvl']) == 'almaz' ? ico('icons', 'almaz.png') : ico('icons', 'gold.png')) . " " . cost($ability['spellStrLvl']) . "</div></span></span></a>";
} else {
    $LinkStr = "<br><center><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?'>" . span('white') . "Масимальний уровень </div></span></span></a>";
}


//view
echo div('wrapper') . "   " . div('oh') . " " . img('ability', 'spell_health.png') . "</div> <span class='lime'> Сила жизни  </span><br>
 " . ico('icons', 'level.png') . "  Уровень: $ability[spellHpLvl] из 20  </font>  " . color('green') . "     </font><br> 
" . ico('icons', 'health.png') . "  Исцеление: " . ceil($ability['spellHpResp'] + ($user['max_health'] / 100 * 10)) . "    $AbilityHp    </font>  ";
echo $LinkHp;

echo " </div>";


//view
echo div('wrapper') . "   " . div('oh') . " " . img('ability', 'double_attack.jpg') . "</div> <span class='gold'> Сила удара   </span><br>
 " . ico('icons', 'level.png') . "  Уровень: $ability[spellStrLvl] из 20  </font>  " . color('green') . "   </font><br> 
" . ico('icons', 'str.png') . "  Урон: " . ceil($ability['spellStrDmg'] + ($user['str'] / 15)) . "      $AbilityStr    </font>  ";
echo $LinkStr;

echo " </div>";


//view
echo div('wrapper') . "   " . div('oh') . " " . img('ability', 'spell_defence.png') . "</div> <span class='lime'> Крепкая броня  </span><br>
 " . ico('icons', 'level.png') . "  Уровень: $ability[spellDefLvl] из 20  </font>  " . color('green') . "   </font><br> 
" . ico('icons', 'def.png') . "  Снижение урона: " . ceil($ability['spellDefAbsorb'] + ($user['def'] / 20)) . "      $AbilityDef    </font>  ";
echo $LinkDef;

echo " </div>";

require_once('system/footer.php');


