<?php
$user_id = abs(intval($_SESSION['id']));
$query = "Select gruppa, hp, max_hp, last_active, radiation, antirad_time, regen, opit, aptechki, speed_p, speed_w, antirad_time, antirad, location, time_apt from users where id = '$user_id' limit 1";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД1');
$row = mysqli_fetch_array($result);
  if (empty($err)) {
$err = filter($_GET['err']);
  }
  if (!empty($err)) {
echo'<div id="error">';
	  if ($err == 8) {echo "Нельзя использовать аптечки так часто";}
	  if ($err == 7) {echo "Нужно захватить Лагерь чтобы двигаться дальше";}
	  if ($err == 6) {echo "Нет оружия данного типа";}
	  if ($err == 5) {echo "У вас сломано оружиe";}
	  if ($err == 4) {echo "Своих атаковать нельзя";}
	  if ($err == 3) {echo "не льзя так часто бить";}
	  if ($err == 2) {echo "У вас нет аптечек";}
	  if ($err == 1) {echo "Вы не можете телепортироваться";}
echo'</div>';
  }
$attack = filter($_GET['attack']);
$re_p = filter($_GET['re_p']);
  if ($lok_out <> 1) {
  if ($row_loc['bp_gruppa'] <> $us_gruppa) {
echo'<p>';
if($row_loc['bp_gruppa'] == 'svoboda') {echo'<img src="img/ico/svobodaon.png" width="12" height="12" alt="s"/>';}
if($row_loc['bp_gruppa'] == 'dolg') {echo'<img src="img/ico/dolgon.png" width="12" height="12" alt="d"/>'; }
if ($row_loc['bp_gruppa'] == 'naemniki') {?><img src="img/ico/naemniki.png" width="12" height="12" alt="o"/><?php }
if ($row_loc['bp_gruppa'] == 'renegat') {?><img src="img/ico/renegat.png" width="12" height="12" alt="s"/><?php }
if ($row_loc['bp_gruppa'] == 'chistoenebo') {?><img src="img/ico/chistoenebo.png" width="12" height="12" alt="s"/><?php }
echo'<a href="attack.php?attack=bp">Атаковать Лагерь </a>';
  if ($row_loc['bp_gruppa'] == 'dolg') { echo 'Армия Тьмы '; }
  if ($row_loc['bp_gruppa'] == 'naemniki') { echo ' Воины Ада '; }
if ($row_loc['bp_gruppa'] == 'svoboda') { echo ' Империя Людей '; }
if($row_loc['bp_count_grouppa'] == $us_gruppa and $row_loc['bp_count_now'] <>0) {echo'('.$row_loc['bp_count_now'].'/'.$row_loc['bp_count'].')';}
if ($row_loc['bp_count_grouppa'] <> $us_gruppa and $row_loc['bp_count_now'] <>0 ) {echo'(-'.filter($row_loc['bp_count_now']).'/'.filter($row_loc['bp_count']).')';}
if($row_loc['bp_count_now'] == 0 ){echo'(0/'.$row_loc['bp_count'].')';}
echo'</p>';
  }
  if (isset($attack)) {
$gruppa = $row['gruppa'];
$query_att = $pdo->query("Select id, nick, hp, gruppa, max_hp, last_active, radiation, regen, antirad_time from users where id = '$attack' and location = '$location' and last_active > NOW() - (60*5) and hp != 0 and gruppa != '$gruppa' and ban != 1 limit 1");
$row_att = $query_att->fetch();
    if ($row_att != 0) {
$gruppa_us = filter($row_att['gruppa']);
$hp_us = abs(intval($row_att['hp']));
$max_hp_us = abs(intval($row_att['max_hp']));
$last_active_us = filter($row_att['last_active']);
$regen_us = filter($row_att['regen']);
$nick_us =  filter($row_att['nick']);
$radiation_us =  filter($row_att['radiation']);
$antirad_time_us =  filter($row_att['antirad_time']);
	  $now = (date("Y-m-d H:i:s"));
      $now = strtotime("$now");
   //HP атакованного
   $last_active_us = strtotime("$last_active_us");
   $hp_time_us = ($now - $last_active_us);
   if ($hp_time_us !=0) {
    $antirad_time_us = strtotime("$antirad_time_us");
    $time = (date("Y-m-d H:i:s"));
    $time = strtotime("$time");
    $antirad_time_us = ($time - $antirad_time_us);
    $hp_down_rad = ($radiation_us - $radiation_loc);
	if ($hp_down_rad < 0 and $antirad_time_us > 7200) { 
	  $regen_us = ($regen_us + $hp_down_rad);
	}
	$hp_up_us = ($hp_time_us * $regen_us);
    $hp_up_us = ($hp_us + $hp_up_us);
    if (($max_hp_us > $hp_up_us) and ($hp_up_us > 0)) {
	  $hp_us = $hp_up_us;
    }
    if ($hp_up_us > $max_hp_us) {
      $hp_us = $max_hp_us;
    }
  }
	  if ($row['speed_p'] != 0) {				
echo'<p><img src="img/ico/pistol.png" alt="p" width="12" height="12"/> <a href="attack.php?rand=0&weapon=pistol&attack='.$attack.'">Напасть на </a>';
if ($gruppa_us == 'svoboda') {echo'<img src="img/ico/svoboda.png" width="12" height="12" alt="s"/>';}
if($gruppa_us == 'dolg') {echo'<img src="img/ico/dolg.png" width="12" height="12" alt="d"/>';}
if($gruppa_us == 'naemniki') {echo'<img src="img/ico/naemniki.png" width="12" height="12" alt="n"/>';}
if($gruppa_us == 'renegat') {echo'<img src="img/ico/renegat.png" width="12" height="12" alt="d"/>';}
if($gruppa_us == 'chistoenebo') {echo'<img src="img/ico/chistoenebo.png" width="12" height="12" alt="n"/>';}
echo'<a href="profile.php?id='.$attack.'">['.$nick_us.']</a>';
echo"($hp_us)";
echo'</p>';
	  }
$user_id = abs(intval($_SESSION['id']));
$query = "Select gruppa, hp, max_hp, last_active, radiation, antirad_time, regen, opit, aptechki, speed_p, speed_w, antirad_time, antirad, location, time_apt from users where id = '$user_id' limit 1";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД1');
$row = mysqli_fetch_array($result);
if ($row['speed_w'] != 0) {
echo'<p><img src="img/ico/avtomat.png" alt="a" width="12" height="12"/><a href="attack.php?rand=0&weapon=avtomat&attack='.$attack.'">Напасть на </a>';
if ($gruppa_us == 'svoboda') {echo'<img src="img/ico/svoboda.png" width="12" height="12" alt="s"/>';}
if($gruppa_us == 'dolg'){echo'<img src="img/ico/dolg.png" width="12" height="12" alt="d"/>';}
if($gruppa_us == 'naemniki') {echo'<img src="img/ico/naemniki.png" width="12" height="12" alt="n"/>';}
if($gruppa_us == 'renegat') {echo'<img src="img/ico/renegat.png" width="12" height="12" alt="d"/>';}
if($gruppa_us == 'chistoenebo') {echo'<img src="img/ico/chistoenebo.png" width="12" height="12" alt="n"/>';}
echo'<a href="profile.php?id='.$attack.'">['.$nick_us.']</a>';
echo " ($hp_us)</p>";
	  }
	}  
  }
$user_id = abs(intval($_SESSION['id']));
$query = "Select gruppa, hp, max_hp, last_active, radiation, antirad_time, regen, opit, aptechki, speed_p, speed_w, antirad_time, antirad, location, time_apt from users where id = '$user_id' limit 1";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД1');
$row = mysqli_fetch_array($result);
    if ($number_naim != 0 and $row['gruppa'] != 'naemniki') {
echo'<p><img src="img/ico/to4nost.png" width="12" height="12"/> <a href="attack.php?group=naemniki&rand=1">Напасть на "Воины Ада"</a></p>';
  }
  if ($number_dolg != 0 and $row['gruppa'] != 'dolg') {
echo'<p><img src="img/ico/to4nost.png" width="12" height="12"/> <a href="attack.php?group=dolg&rand=1">Напасть на "Армия Тьмы"</a></p>';
  }
  if ($number_svoboda != 0 and $row['gruppa'] != 'svoboda') {
echo'<p><img src="img/ico/to4nost.png" width="12" height="12"/> <a href="attack.php?group=svoboda&rand=1">Напасть на "Империя Людей"</a></p>';
  }
$query_number_mytants = "Select id from users where gruppa = 'mytants' and location = '$location' and  hp != 0 and ban != 1 limit 1";
$result_number_mytants = mysqli_query($dbc, $query_number_mytants) or die('Ошибка передачи запроса к БД');
  $number_mytants = mysqli_num_rows ($result_number_mytants);
  if (!empty($number_mytants)) {
	$number_mytants = mysqli_num_rows ($result_number_mytants);
echo'<p><img src="img/ico/mytants.png" width="12" height="12" alt="m"/> <a href="attack.php?group=mytants&rand=1">Напасть на монстров</a></p>';
  }
  $query_number_bandits = "Select id from users where gruppa = 'bandits' and location = '$location' and hp != 0 and ban != 1 limit 1";
  $result_number_bandits = mysqli_query($dbc, $query_number_bandits) or die ('Ошибка передачи запроса к БД'); 
  $number_bandits = mysqli_num_rows ($result_number_bandits);
  if (!empty($number_bandits)) {
	$number_bandits = mysqli_num_rows ($result_number_bandits);
echo'<p><img src="img/ico/mytants.png" width="12" height="12" alt="m"/> <a href="attack.php?group=bandits&rand=1">Напасть на зомби</a></p>';
  }
  $query_number_bandits = "Select id from users where gruppa = 'monolits' and location = '$location' and hp != 0 and ban != 1 limit 1";
  $result_number_bandits = mysqli_query($dbc, $query_number_bandits) or die ('Ошибка передачи запроса к БД'); 
  $number_bandits = mysqli_num_rows ($result_number_bandits);
  if (!empty($number_bandits)) {
	$number_bandits = mysqli_num_rows ($result_number_bandits);
echo'<p><img src="img/ico/mytants.png" width="12" height="12" alt="m"/> <a href="attack.php?group=monolits&rand=1">Напасть на Рамиала</a></p>';
  }
   $query_number_bandits = "Select id from users where gruppa = 'zombie' and location = '$location' and hp != 0 and ban != 1 limit 1";
  $result_number_bandits = mysqli_query($dbc, $query_number_bandits) or die ('Ошибка передачи запроса к БД'); 
  $number_bandits = mysqli_num_rows ($result_number_bandits);
  if (!empty($number_bandits)) {
	$number_bandits = mysqli_num_rows ($result_number_bandits);
echo'<p><img src="img/ico/mytants.png" width="12" height="12" alt="m"/> <a href="attack.php?group=zombie&rand=1">Напасть на Ищадье Ада</a></p>';
  }
  }
  $need_health = ($max_health * 0.6);
  if (($health < $need_health) and (!empty($aptechki))) {
$apt_time = filter($row['time_apt']);
    $apt_time = strtotime("$apt_time");
    $time = (date("Y-m-d H:i:s"));
    $time = strtotime("$time");
	$apt_time = ($time - $apt_time);
echo'<p><img src="img/ico/apte4ka.png" width="12" height="12"/> <a href="uphealth.php">Использовать аптечку ';
	if ($apt_time <=60) { 
	$ttt = (60-$apt_time);
	echo "($ttt сек)"; }
echo'</a></p>';
  }
$antirad_time = filter($row['antirad_time']);
  $antirad_time = strtotime("$antirad_time");
  $time = (date("Y-m-d H:i:s"));
  $time = strtotime("$time");
  $antirad_time = ($time - $antirad_time);
  if ($hp_down_rad < 0 and $antirad_time > 7200 and $row['antirad'] <> 0) { 
echo'<p><img src="img/ico/antirad.png" width="12" height="12"/> <a href="useantirad.php">Использовать зелье</a></p>';
  }
?>