Файл: 3/arena_pit.php
Строк: 166
<?php
require_once ('system/func.php');
auth(); // Закроем от не авторизованных
$title = 'Арена питомцев';
require_once ('system/header.php');
echo'<div class="lent mlra w80">
<div class="bl-ttl"><div class="te"><div class="ttl">
Арена питомцев
</div></div></div>';
$tren = $db->query("SELECT * FROM `trenirovka` WHERE `user` = '".$user["id"]."' LIMIT 1")->fetch_assoc();
if(isset($_SESSION['battle'])){
echo $_SESSION['battle'];
$_SESSION['battle']=NULL;}
$my_pets = $db->query("SELECT * FROM `pit_users` WHERE `id_user` = '".$user['id']."'")->fetch_assoc();;
//////////////////////
if($my_pets['time'] < time()){
$db->query("UPDATE `pit_users` SET `arena_battle` = '200', `time` = '".(time() + 86000)."' WHERE `id_user` = '".$user['id']."'");
}
/////////////////////
if($my_pets == false){echo'<div class="block">У вас нет питомца!</div></div>';
require_once ('system/footer.php');
exit();}
if(isset($_GET['attack']) && $my_pets['arena_battle'] > '0'){
if(($my_pets['last']+2)>time()){echo'<div class="block">Не бейте так часто!</div><a class="link" href=/arena_pit.php>Вернуться</a></div>';
require_once ('system/footer.php');
exit();}
$vs = $db->query("SELECT * FROM `pit_users` WHERE `id_user` = '".num($_GET['attack'])."'")->fetch_assoc();
$my_crit = ($my_pets['str']+$my_pets['health']+$my_pets['def'])/2;
$vs_crit = ($vs['str']+$vs['health']+$vs['def'])/2;
$rand_s = rand(20,200);
if($user[vip]==1){$rand_s=ceil($rand_s*1.5);}
$battle = $my_pets['arena_battle']-1;
if($my_crit >= $vs_crit){
$sob=$db->query("SELECT * FROM `sobytia_log` WHERE `id_user`=".$user['id']." LIMIT 1")->fetch_assoc();
if($sob['g_arena_pit']==1 and $sob['arena_pit']<50 and $sob['k_arena_pit']>0)
{
$db->query("UPDATE `sobytia_log` SET `arena_pit`=`arena_pit`+'1' WHERE `id_user`=".$myID."");
}
$db->query("UPDATE `users` SET `silver` = `silver` + '$rand_s' WHERE `id` = '$user[id]'");
$db->query("UPDATE `pit_users` SET `arena_battle` = `arena_battle` - '1', `last` = ".time()." WHERE `id_user` = '$user[id]'");
if($tren['shag'] == 5){
if($tren['arena_pit'] < 50){
$db->query("UPDATE `trenirovka` SET `arena_pit`=`arena_pit`+'1' WHERE `user`='$user[id]'");
}}
if($my_pets['arena_battle'] == '1') $db->query("UPDATE `users` SET `gold` = `gold` + '10' WHERE `id` = '$user[id]'");
$_SESSION['battle'] = '<div class="block"><b><center><font color="green"> Победа! </font></b></center>
Получено: '.ico('icons','silver.png').' '.$rand_s.' серебра
'.($my_pets['arena_battle'] == '1'?' и '.ico('icons','gold.png').' 10 золота':'').'<br/>
<font color="#90b0c0">Осталось боёв:</font> '.ico('icons','2hit.png').' <b> '.$battle.' из 200</b>
</div>';
header('Location:/arena_pit.php');
}
elseif($vs_crit >= $my_crit){
$rand_s = rand(1,20);
if($user[vip]==1){$rand_s=ceil($rand_s*1.5);}
$sob=$db->query("SELECT * FROM `sobytia_log` WHERE `id_user`=".$user['id']." LIMIT 1")->fetch_assoc();
if($sob['g_arena_pit']==1 and $sob['arena_pit']<50 and $sob['k_arena_pit']>0)
{
$db->query("UPDATE `sobytia_log` SET `arena_pit`=`arena_pit`+'1' WHERE `id_user`=".$myID."");
}
$db->query("UPDATE `users` SET `silver` = `silver` + '$rand_s' WHERE `id` = '$user[id]'");
$db->query("UPDATE `pit_users` SET `arena_battle` = `arena_battle` - '1', `last` = ".time()." WHERE `id_user` = '$user[id]'");
if($tren['shag'] == 5){
if($tren['arena_pit'] < 50){
$db->query("UPDATE `trenirovka` SET `arena_pit`=`arena_pit`+'1' WHERE `user`='$user[id]'");
}}
if($my_pets['arena_battle'] == '1') $db->query("UPDATE `users` SET `gold` = `gold` + '10' WHERE `id` = '$user[id]'");
$_SESSION['battle'] = '<div class="block"><b><center><font color="#900"> Поражение! </font></b></center>
Получено: '.ico('icons','silver.png').' '.$rand_s.' серебра
'.($my_pets['arena_battle'] == '1'?' и '.ico('icons','gold.png').' 10 золота':'').'<br/>
<font color="#90b0c0">Осталось боёв:</font> '.ico('icons','2hit.png').' <b> '.$battle.' из 200</b>
</div>';
header('Location:/arena_pit.php');
}
}
$opponent = $db->query('SELECT * FROM `pit_users` WHERE `str` + `health` + `def` >= "'.(($my_pets['str'] + $my_pets['health'] + $my_pets['def'])).'" AND `id_user` != "'.$user['id'].'" OR `str` + `health` + `def` <= "'.($my_pets['str'] + $my_pets['health'] + $my_pets['def']).'" AND `id_user` != "'.$user['id'].'" ORDER BY RAND() LIMIT 1')->fetch_assoc();
$pets_user = $db->query("SELECT * FROM `users` WHERE `id` = '$opponent[id_user]'")->fetch_assoc();
if($opponent==0){echo'<div class="block">Нет доступных противников</div></div>';
require_once ('system/footer.php');
exit();
}
echo'
<div class="block">
<table style="width:100%" cellspacing="0" cellpadding="0">
<tbody><tr><td style="text-align:center;width:40%;">
<img src="/images/pits/'.$my_pets[item].'.png" width="40" height="40" alt="">
<br>
'.$my_pets['name'].'<br>
<font color="gold"><b>Наставник: Я</b></font><br>
<span style="color:#6f6f6f;"><small> <img src="/images/icons/str.png" alt="*"/> '.$my_pets['str'].' <img src="/images/icons/health.png" alt="*"/> '.$my_pets['health'].' <img src="/images/icons/def.png" alt="*"/> '.$my_pets['def'].'<br/>
</span>
</td>
<td style="text-align:center;width:20%;">
<h1><font color="green">VS</font></h1>
</td><td style="text-align:center;width:40%;"><img src="/images/pits/'.$opponent[item].'.png" width="40" height="40" alt="">
<br>
'.$opponent['name'].'<br>
<font color="gold"><b>Наставник: '.$pets_user['login'].'</b></font><br>';
echo "<span style='color:#6f6f6f;'><small> <img src='/images/icons/str.png' alt='*'/> ".$opponent['str']." <img src='/images/icons/health.png' alt='*'/> ".$opponent['health']." <img src='/images/icons/def.png' alt='*'/> ".$opponent['def']."<br/>
</td></tr></tbody></table><br>";
echo'<table style="width:100%" cellspacing="0" cellpadding="0">
<tbody><tr><td style="vertical-align:submit;width:50%;white-space:nowrap;">
<center><a href="?"><input type="submit" class="btn" value="Искать" style="width:130px;"/></a></center>
</td>
<td style="vertical-align:submit;width:50%;white-space:nowrap;">
<center><a href="?attack='.$opponent['id_user'].'">
<input type="submit" class="btn" value="Битва" style="width:130px;"/></a></center></td></tr>
</tbody>
</table>
<br/> <br/>
</div>
<div class="block2">
<b>Арена питомцев -</b> место, где ваш питомец сражается с питомцем другого наставника. Здесь вы сможете заработать золото и серебро <br/>Каждые 24 часа вам доступны 200 боев<br/>
<br/>
<center> <font color="#90b0c0">Доступно боёв:</font> '.ico('icons','2hit.png').' <b>'.$my_pets['arena_battle'].' из 200</b><br/>
Следующее обновление боёв <b>'.vremja($my_pets['time']).'</b>
</center>
</div></div>';
require_once ('system/footer.php');
?>