<?php
include ('inc/base.php');
include ('inc/functions.php');
include ('inc/user.php');
if(!$user) {
header('location: /');
exit();
}
if($user['rabota_time'] > time()) {
$title = 'Граница';
include ('inc/header.php');
echo '<div class="main center">Нельзя покидать рабочее место!</div>';
echo '<a href="/" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($_GET['my_loc'] == 'exit' and $user['location'] != 'world') {
$title = 'Окраина';
include ('inc/header.php');
mysql_query("update `accounts` set `location` = 'world' where `id` = '".$user['id']."'");
mysql_query("update `acc_heroes` set `location` = 'world' where `user_id` = '".$user['id']."'");
echo '<div class="main center">Покинута опасная зона!</div>';
echo '<a href="/" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$id = num($_GET['id']);
if($id) {
$location = mysql_fetch_array(mysql_query('SELECT * FROM `locations` WHERE `id` = "'.$id.'" LIMIT 1'));
mysql_free_result($location);
}
if(!$location or $id == '0') {
$title = 'Переход';
include ('inc/header.php');
echo '<div class="main center">Локация не найдена!</div>';
echo '<a href="/" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$title = $location['ru_name'];
include ('inc/header.php');
if($location['rating'] > $user['rating']) {
echo '<div class="main center">Для входа на эту локацию не хватает '.($location['rating']- $user['rating']).' рейтинга!</div>';
include ('inc/footer.php');
exit();
}
$weapon = mysql_fetch_array(mysql_query('SELECT * FROM `acc_weapon` WHERE `user` = "'.$user['id'].'" and `active` = "1" LIMIT 1'));
mysql_free_result($weapon);
if(!$weapon) {
echo '<div class="main center">Без оружия сюда идти не стоит!</div>';
echo '<a href="/weapon.php" class="link center">Оружие</a>';
include ('inc/footer.php');
exit();
}
if($user['bullets'] < $weapon['consumption']) {
echo '<div class="main center">Не хватает '.($weapon['consumption']- $user['bullets']).' патронов!</div>';
echo '<a href="/shop.php?bullets" class="link center">Патроны</a>';
include ('inc/footer.php');
exit();
}
if($weapon['wear'] == '100') {
echo '<div class="main center">Нельзя использовать сломанное оружие!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if(mysql_result(mysql_query('SELECT COUNT(*) FROM `acc_heroes` WHERE `user_id` = \''.$user['id'].'\''),0) == 0) {
mysql_query('INSERT INTO `acc_heroes` (`user_id`, `health`, `location`) VALUEs ("'.$user['id'].'", "50000", "'.$location['name'].'")');
echo '<div class="main center">Произошел вход на локацию '.$location['ru_name'].'!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$hero = mysql_fetch_array(mysql_query('SELECT * FROM `acc_heroes` WHERE `user_id` = "'.$user['id'].'" LIMIT 1'));
mysql_free_result($hero);
if($_GET['death'] == '0' and $hero['death'] == '1') {
if($user['cash'] < '5000') {
echo '<div class="main center">Не хватает '.(5000- $user['cash']).' рублей!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `acc_heroes` set `death` = '0', `health` = '50000' where `user_id` = '".$user['id']."'");
mysql_query("update `accounts` set `cash` = `cash` - '5000' where `id` = '".$user['id']."'");
echo '<div class="main center">Идёт воскрешение!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($hero['death'] == '1') {
echo '<div class="main center">Смерть!</div>';
echo '<a href="?id='.$location['id'].'&death=0" class="link center">Воскрешение за 5000 <img src="/style/src/cash.png" height="14"></a>';
include ('inc/footer.php');
exit();
}
if($user['location'] != $location['name'] or $hero['location'] != $location['name']) {
mysql_query("update `accounts` set `location` = '".$location['name']."' where `id` = '".$user['id']."'");
mysql_query("update `acc_heroes` set `location` = '".$location['name']."' where `user_id` = '".$user['id']."'");
echo '<div class="main center">Произошел переход на локацию '.$location['ru_name'].'!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($_GET['active'] == 'first') {
if($user['first'] == '0') {
echo '<div class="main center">Аптечки закончились!</div>';
echo '<a href="/shop.php?first" class="link center">Аптечки</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `acc_heroes` set `health` = `health` + '10000' where `user_id` = '".$hero['user_id']."'");
mysql_query("update `accounts` set `first` = `first` - '1' where `id` = '".$user['id']."'");
header('location: ?id='.$location['id'].'');
exit();
}
$attack = text(num($_GET['attack']));
if($attack) {
if($user['group'] != '0') {
$gr = mysql_fetch_array(mysql_query('SELECT * FROM `groups` WHERE `id` = "'.$user['group'].'" LIMIT 1'));
}
$m_dam = $user['damage']+$weapon['damage'];
$rand_dam = round($weapon['accuracy']/100*$m_dam);
$damage = rand($rand_dam,$weapon['damage']);
$consumption = $weapon['consumption'];
$enemy_damage = $enemy['damage'];
if($user['attack_time'] > time()) {
echo '<div class="main center">Перезарядка!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$enemy = mysql_fetch_array(mysql_query('SELECT * FROM `acc_heroes` WHERE `id` = "'.$attack.'" LIMIT 1'));
mysql_free_result($enemy);
$enem = mysql_fetch_array(mysql_query('SELECT * FROM `accounts` WHERE `id` = "'.$enemy['user_id'].'" LIMIT 1'));
mysql_free_result($enem);
if(!$enemy or $enemy['user_id'] == $user['id'] or $enemy['location'] != $hero['location']) {
echo '<div class="main center">Противник не найден!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($enem['defence'] == '1') {
echo '<div class="main center">У этого игрока включена защита от нападений!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($enemy['type'] == 'user') {
if($user['defence'] == '1') {
echo '<div class="main center">Чтобы атаковать игроков нужно выключить защиту от нападений!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
}
if($gr) {
if($enemy['type'] == 'mob') {
$cash = rand(1,$gr['bonus']+150);
if($user['rating'] < '100') {
$rating = rand(1,50);
}
if($user['rating'] >= '100') {
$rating = rand(1,$gr['bonus']+100);
}
}
if($enemy['type'] == 'user') {
$cash = rand(1,$gr['bonus']+300);
if($user['rating'] < '100') {
$rating = rand (1,$gr['bonus']+70);
}
if($user['rating'] >= '100') {
$rating = rand(1,$gr['bonus']+140);
}
}
}else{
if($enemy['type'] == 'mob') {
$cash = rand(1,150);
if($user['rating'] < '100') {
$rating = rand(1,50);
}
if($user['rating'] >= '100') {
$rating = rand(1,100);
}
}
if($enemy['type'] == 'user') {
$cash = rand(1,300);
if($user['rating'] < '100') {
$rating = rand (1,70);
}
if($user['rating'] >= '100') {
$rating = rand(1,140);
}
}
}
if($enemy['death'] == '1') {
echo '<div class="main center">Противник уже убит!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($hero['health'] <= '1' or $enemy['damage'] > $hero['health']) {
mysql_query("update `acc_heroes` set `health` = `health` - '0', `death` = '1' where `user_id` = '".$hero['user_id']."'");
}
if($enemy['health'] <= '1' or $damage > $enemy['health']) {
mysql_query("update `acc_heroes` set `health` = '0', `death` = '1' where `id` = '".$enemy['id']."'");
mysql_query("update `accounts` set `cash` = `cash` + '10000', `nagrads` = `nagrads` + '1' where `id` = '".$user['id']."'");
echo '<div class="main center">Противник убит!<br>Получено 10000 <img src="/style/src/cash.png" height="14"> и награда!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($enemy['type'] == 'mob') {
mysql_query("update `acc_heroes` set `health` = `health` - '".$enemy['damage']."' where `user_id` = '".$hero['user_id']."'");
$enemy_name = 'Существо';
}
if($enemy['type'] == 'user') {
if($enem['rating'] > '100') {
$damage_rating = rand(1,130);
if($damage_rating > $enem['rating']) {
$u_rating = $enem['rating'];
}else{
$u_rating = $damage_rating;
}
mysql_query("update `accounts` set `rating` = `rating` - '".$u_rating."' where `id` = '".$enem['id']."'");
}
}
mysql_query("update `accounts` set `cash` = `cash` + '".$cash."', `rating` = `rating` + '".$rating."', `attack_time` = '".(time()+1)."', `bullets` = `bullets` - '".$weapon['consumption']."' where `id` = '".$user['id']."'");
if($gr) {
mysql_query("update `groups` set `rating` = `rating` + '".$rating."' where `id` = '".$user['group']."'");
}
mysql_query("update `acc_heroes` set `health` = `health` - '".$damage."' where `id` = '".$enemy['id']."'");
if($enemy['type'] == 'mob') {
$name = 'Существо';
}else{
$name = $enem['name'];
}
$text = 'атаковал(а) '.$name.' на '.$damage.' урона на локации '.$location['ru_name'].'';
mysql_query('INSERT INTO `location_logs` (`user`, `text`, `time`) VALUEs ("'.$user['id'].'", "'.$text.'", "'.time().'")');
if($weapon['wear'] < '100') {
if($weapon['damage'] >= '5' and $weapon['damage'] <= '120') {
$rand_wear = rand(1,5);
$r_wear = 5;
}
if($weapon['damage'] >= '240' and $weapon['damage'] <= '480') {
$rand_wear = rand(1,10);
$r_wear = 10;
}
if($weapon['damage'] >= '960' and $weapon['damage'] <= '1920') {
$rand_wear = rand(1,20);
$r_wear = 20;
}
if($weapon['damage'] >= '1920' and $weapon['damage'] <= '3840') {
$rand_wear = rand(1,30);
$r_wear = 30;
}
if($weapon['damage'] >= '7680' and $weapon['damage'] <= '15360') {
$rand_wear = rand(1,40);
$r_wear = 40;
}
if($weapon['damage'] >= '30720' and $weapon['damage'] <= '61440') {
$rand_wear = rand(1,100);
$r_wear = 100;
}
if($rand_wear == $r_wear) {
mysql_query("update `acc_weapon` set `wear` = `wear` + '1' where `user` = '".$user['id']."'");
}
}
$rand_drop = rand(0,3000);
if($rand_drop == '2999') {
$weapon_d = mysql_fetch_array(mysql_query('SELECT * FROM `unique_weapon` WHERE `location` = "'.$user['location'].'" ORDER BY rand() LIMIT 1'));
mysql_free_result($weapon_d);
mysql_query('INSERT INTO `acc_weapon` (`name`, `damage`, `img`, `user`, `accuracy`, `active`, `consumption`) VALUEs ("'.$weapon_d['name'].'", "'.$weapon_d['damage'].'", "'.$weapon_d['img'].'", "'.$user['id'].'", "'.$weapon_d['accuracy'].'", "0", "'.$weapon_d['consumption'].'")');
echo '<div class="main center">Найдено оружие!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
header('location: ?id='.$location['id'].'');
exit();
}
if($_GET['search'] == 'ok') {
if(isset($_POST['search'])) {
$opponent = text($_POST['opponent']);
if(!$opponent) {
echo '<div class="main center">Заполните все поля!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if(strlen($opponent) < 2 or strlen($opponent) > 16) {
echo '<div class="main center">Допустимая длина ника 2-16 символов!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$oppon = mysql_fetch_array(mysql_query('SELECT * FROM `accounts` WHERE `name` = "'.$opponent.'" LIMIT 1'));
mysql_free_result($oppon);
if(!$oppon or $oppon['id'] == $user['id']) {
echo '<div class="main center">Противник не найден!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($oppon['location'] != $hero['location']) {
echo '<div class="main center">Противник не найден на этой локации!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$opponen = mysql_fetch_array(mysql_query('SELECT * FROM `acc_heroes` WHERE `user_id` = "'.$oppon['id'].'" LIMIT 1'));
mysql_free_result($opponen);
if($opponen['death'] == '1' or !$opponen) {
echo '<div class="main center">Противник уже убит!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `accounts` set `opponent` = '".$opponen['id']."', `opponent_type` = '".$opponen['type']."' where `id` = '".$user['id']."'");
echo '<div class="main center">Противник обнаружен!</div>';
echo '<a href="?id='.$location['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if(!isset($_POST['search'])) {
$sq = mysql_query("SELECT * FROM `acc_heroes` where `location` = '".$location['name']."' and `user_id` != '".$user['id']."' and `death` = '0' and `id` != '".$user['opponent']."' ORDER BY rand() LIMIT 1");
while($opp = mysql_fetch_assoc($sq)) {
mysql_query("update `accounts` set `opponent` = '".$opp['id']."', `opponent_type` = '".$opp['type']."' where `id` = '".$user['id']."'");
mysql_free_result($opp);
}
header('location: ?id='.$location['id'].'');
exit();
}
}
echo '<table class="main" width="100%"><tr><td style="width: 90%"><img src="/style/src/health.png"> Мои жизни: '.$hero['health'].'</td><td style="width: 10%"><a href="?id='.$location['id'].'&active=first" class="none"><img src="/style/src/first.png"></a></td></tr></table>';
$sql = mysql_query("SELECT * FROM `acc_heroes` where `id` = '".$user['opponent']."' and `type` = '".$user['opponent_type']."' LIMIT 1");
while($object = mysql_fetch_assoc($sql)) {
if($object['death'] == '1' or $object['health'] <= '1') {
header('location: ?id='.$location['id'].'&search=ok');
exit();
}
if($object['location'] != $location['name']) {
header('location: ?id='.$location['id'].'&search=ok');
exit();
}
if($object['type'] == 'user') {
$account = mysql_fetch_array(mysql_query('SELECT * FROM `accounts` WHERE `id` = "'.$object['user_id'].'" LIMIT 1'));
mysql_free_result($account);
echo '<table class="main" width="100%"><tr><td style="width: 20%"><img src="/style/src/avatars/'.$account['avatar'].'" width="60"></td><td style="width: 10%"></td><td style="width: 70%"><img src="/style/src/info.png"> Ник: '.$account['name'].'<br><img src="/style/src/health.png"> Жизни: '.$object['health'].'<br><img src="/style/src/damage.png"> Урон: '.$account['damage'].'</td></tr></table>';
}else{
echo '<table class="main" width="100%"><tr><td style="width: 20%"><img src="/style/src/mobs/'.$object['avatar'].'.png"></td><td style="width: 10%"></td><td style="width: 70%"><img src="/style/src/info.png"> Существо<br><img src="/style/src/health.png"> Жизни: '.$object['health'].'<br><img src="/style/src/damage.png"> Урон: '.$object['damage'].'</td></tr></table>';
}
mysql_free_result($object);
echo '<a href="?id='.$location['id'].'&attack='.$object['id'].'" class="link center"><img src="/style/src/damage.png" height="20"></a>';
}
echo '<a href="?id='.$location['id'].'&search=ok" class="link center">Искать</a>';
echo '<form action="?id='.$location['id'].'&search=ok" method="POST" class="main center">Ник:<br><input type="text" name="opponent"><input type="submit" name="search" value="Найти" class="input_send"><div class="new-line"></div></form>';
echo '<a href="?my_loc=exit" class="link center">Покинуть локацию</a>';
$sql_s = mysql_query("SELECT * FROM `location_logs` where `time` > '".(time() - 60)."' ORDER BY `id` DESC LIMIT 5");
while($log = mysql_fetch_assoc($sql_s)) {
$acc_log = mysql_fetch_array(mysql_query('SELECT * FROM `accounts` WHERE `id` = "'.$log['user'].'" LIMIT 1'));
mysql_free_result($acc_log);
echo '<div class="main"><a href="/private.php?id='.$acc_log['id'].'"><img src="/style/src/arrow.png"></a> '.$acc_log['name'].' <span style="float: right"><small>» Логи '.vremja($log['time']).'</small></span> <br> <font color="#517878">'.text($log['text']).'</font></div>';
mysql_free_result($log);
}
include ('inc/footer.php');
?>