<?php
require_once 'h_func.php';
if (!isset($t)) $t = 'FactionWar (RU)';
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
echo '<meta charset="utf-8">';
echo '<link rel="stylesheet" href="/fawa.css">';
echo '<link rel="shortcut icon" href="favicon.png" type="image/png">';
echo '<script type="text/javascript">
setInterval(function(){
    document.getElementById("updatetime").innerHTML = (new Date()).toLocaleTimeString();
}, 1000);
</script>';
echo '<title>' . $t . '</title>';

if (isset($ank)){
	
    if($_SERVER['SCRIPT_FILENAME'] != WCORE_ROOT."/power.php"){if($ank['power'] == "none"){go('/power.php');exit;}}
	echo '<div class="header_game">
	<table width="100%">
	<tbody>
	<tr>
	<td width="50%"><center><img src="/img/icons/200164.png" width="16px"><div class="header_res">'. $ank['gold'] .'</div></center></td>
	<td width="50%"><center><img src="/img/icons/200135.png" width="16px"><div class="header_res">'. $ank['diamond'] .'</div></center></td>
	</tr>
	</tbody>
	</table>
	</div>';

	if($ank['level'] < 159) $exp_progress = ($ank['exp'] == 0) ? 0 : round(100 / ( $exps / $ank['exp'] ) );
	else $exp_progress = 0;
	if($ank['level'] < 159){
		if($exp_progress >= 100){
			$bonp_1 = round($ank['param_1']*0.002); $bonp_2 = round($ank['param_2']*0.002); $bonp_3 = round($ank['param_3']*0.002); $bonp_4 = round($ank['param_4']*0.002);
			mysqli_query($mysqli,"UPDATE `users` SET `level` = `level` + 1, `exp` = '". ($ank['exp'] - $exp) ."', `param_1` = '". ($bonp_1 + $ank['param_1']) ."', `param_2` = '". ($bonp_2 + $ank['param_2']) ."', `param_3` = '". ($bonp_3 + $ank['param_3']) ."', `param_4` = '". ($bonp_4 + $ank['param_4']) ."' WHERE `id` = '". $ank['id'] ."'");
			$_SESSION['new_level'] = '<center><b>Новый уровень!</b><br>
			Здоровье <font color="lime">+'. $bonp_1 .'</font> :: 
			Сила <font color="lime">+'. $bonp_2 .'</font><br>
			Защита <font color="lime">+'. $bonp_3 .'</font> ::
			Скорость <font color="lime">+'. $bonp_4 .'</font></center>';
			header('Location: #new_level');
			exit;
		}
	}

	echo '<table width="100%" class="info_bar">
	<tbody>
	<tr>
	<td width="75px" style="text-align: center;background: #282828;border-radius: 5px;">Lv. '. $reincarnation . $ank['level'] .'</td>
	<td width="250px"><div class="exp_bar"><div class="exp_progress" style="width: '. ($exp_progress >= 100 ? '100' : $exp_progress) .'%;"></div></div></td>
	<td width="75px" style="text-align: center;background: #282828;border-radius: 5px;">'. ($exp_progress >= 100 ? '100' : $exp_progress) .'%</td>
	</tr>
	</tbody>
	</table>';
	
	echo $_SESSION['new_level'];
	$_SESSION['new_level'] = NULL;
	
	echo '<div class="game">';

} else {
	
	echo '<header>';
	echo '<a href="/" style="float: left;"><img src="/img/logo.png" width="132px"></a>';
	if($_SERVER['SCRIPT_FILENAME'] == WCORE_ROOT."/index.php") echo '<a href="/auth.php" style="display: inline-block;float: right;margin-right: 20px;margin-top: 10px;padding: 3px 10px 3px 10px;color: white;background: linear-gradient(to bottom, #921519, #57342E);border-radius: 10px;border: 1px solid darkred;box-shadow: 0 0 5px red;color: #DD2127;text-shadow: 0 0 1px red;">Авторизация</a>';
	echo '</header>';
	
	echo '<div class="game">';

}
?>