
<?
    
    
require_once ('system/func.php');
$title = 'Охота';
require_once ('system/header.php');
auth(); // 
        
    

    





 

	$next = array (200,500,800,2000,2500,7000,7000,8000,9000,15000,10000);


	$rod = array ('Простой лук','Необычный лук','Редкий лук','Элитный лук');

	$sha = array (0,5,10,20); //добавление шанса от удочки


	$xs = array (0,2,3,4); // умножение награды от удочки, отсчет с 0




















$fish = mysql_query('SELECT * FROM `fish` WHERE `user` = "'.$myID.'"');      

    $fish = mysql_fetch_array($fish);

if(!$fish) {

  mysql_query('INSERT INTO `fish` (`user`) VALUES ("'.$myID.'")');

header('location:fish.php');exit;

} 



if (isset($_GET['sell'])){


if($fish['level']<5){ header('location:fish.php');exit;}
if($fish['total']<=0){ header('location:fish.php');exit;}
mysql_query('UPDATE `users` SET `almaz` = `almaz` + '.$fish['total'].' WHERE `id` = "'.$myID.'"');   




mysql_query('UPDATE `fish` SET `total` = 0 WHERE `user` = "'.$myID.'"');   


$_SESSION['notic']='<center><font color=green>Вся добыча продана</font></center>'; header('location:fish.php');exit;

}
$bon = $fish['level']*10;//количество добавленных параметров  

if($fish['level']<=0){ $ch=10; }else{ $ch=10; $ch=$ch+2*$fish['level'];}



$ch = $ch + $sha[$fish['udo4ka']];

if($fish['udo4ka']!=0){ $iznos=''.$fish['iznos'].''; }else{ $iznos='отсутвует'; }







if($fish['status']==1 && $fish['time']<=time()){

$rand = mt_rand(1,100);




if($ch<=$rand){


if($fish['udo4ka']>0){ $rand_exp=mt_rand(10,20); $rand_exp = $rand_exp*$xs[$fish['udo4ka']];   $rand_mon=mt_rand(12,22); $rand_mon = $rand_mon*$xs[$fish['udo4ka']]; }else{ $rand_exp=mt_rand(10,20);   $rand_mon=mt_rand(12,22); }





$inf_fish = array('Заяц','Кабан','Волк','Лиса','Медведь'); 
shuffle($inf_fish);



if($fish['level']<10){      mysql_query('UPDATE `fish` SET `pop` = `pop` + '.$rand_exp.',`total`=`total`+1, `iznos`=`iznos`-1 WHERE `user` = "'.$myID.'"');   







}else{ mysql_query('UPDATE `fish` SET `total`=`total`+1, `iznos`=`iznos`-1 WHERE `user` = "'.$myID.'"'); }  






     mysql_query('UPDATE `users` SET `gold` = `gold` + '.$rand_mon.',`exp`=`exp`+'.$rand_exp.' WHERE `id` = "'.$myID.'"');  



$_SESSION['inf']='<center> <span class=white>Ваша добыча:</span>  <font color=green>'.$inf_fish[0].'</font> <span class=white><img src="/images/icons/exp.png"> '.$rand_exp.' <img src="images/icons/gold.png"> '.$rand_mon.'</span></center>';























}else{
mysql_query('UPDATE `fish` SET `iznos`=`iznos`-2 WHERE `user` = "'.$myID.'"');  


$_SESSION['inf']='<center><img src="fish/fish.png" width="12"> <font color=red>Вы вернулись с охоты без добычи!!</font></center>';





}
mysql_query('UPDATE `fish` SET `status` = "0" WHERE `user` = "'.$myID.'"');

header('location:fish.php');exit;


}




if (isset($_GET['go'])){


if($fish['status']==1){ header('location:fish.php');exit;}

mysql_query('UPDATE `fish` SET `status` = "1",
`time` = "'.(time() + 1800).'" WHERE `user` = "'.$myID.'"');










  
  header('location: fish.php');exit;

  
  

}





if($fish['udo4ka']>0 and $fish['iznos']<=0){


mysql_query('UPDATE `fish` SET `udo4ka` = 0 WHERE `user` = "'.$myID.'"');   



$_SESSION['notic']='<font color=red>Лук полностью сломан</font>'; }

if($fish['level']<10){





if($fish['pop']>=$next[$fish['level']]){




mysql_query('UPDATE `fish` SET `pop` = 0,`level`=`level`+1 WHERE `user` = "'.$myID.'"');   


mysql_query('UPDATE `users` SET `str` = `str`+10,`def`=`def`+10,`max_health`=`max_health`+10,`max_energy`=`max_energy`+10 WHERE `id` = "'.$myID.'"');   


$_SESSION['notic']='<center> <font color=green>Навык Повышен</font></center>';


}

 } 













  if (isset($_SESSION['notic'])){?><?=$_SESSION['notic']?><?   $_SESSION['notic']=NULL; }
?><center><img src="/fish/old.png " width="100%"></center><?

  if (isset($_SESSION['inf'])){?><?=$_SESSION['inf']?><?   $_SESSION['inf']=NULL; }
if($fish['status']==0){
?><div class='wrapper'><center>


<a class="btn_grey" href='fish.php?go' data-ajax=''>Отправиться на охоту</a><br/>




 </center><?

}else{
?><div class='wrapper'><center> <font color=green>Вы на охоте, дождитесь окончания <br/>(Осталось: <?=tl($fish['time'] - time())?>) </font></center><? }






?><center><a class="btn_grey" href='/fish.php?' data-ajax''>Обновить</a></center></div><?




if($fish['level']>4 and $fish['total']>10){ ?> <center><a class="btn_grey" href='fish.php?sell' data-ajax''>Продать всю добычу <img src='/images/icons/almaz.png' alt='*'/> <?=$fish['total']?> алмазов</a></center></div> <? }







?><div class='wrapper'>



<table>
        <tr>
            <td style="width: 45px;"><img src="fish/ud/<?=$fish['udo4ka']?>.jpg"></td>



<td>
<span class="white"><?=$rod[$fish['udo4ka']]?></span><font color='#90c090'><b>(Прочность:  <?=$iznos?>) </b>    </a>

















            </td>
        </tr></table















 

<div class='wrapper'><?
if($fish['level']<10){ $prog =' <span class="white">Прогресс '.$fish['pop'].'/'.$next[$fish['level']].' </span>';}else{ $prog=' <span class="white">Всего добыто: '.$fish['total'].'</span>';}





?><div class='line'></div><table>



        <tr>
            <td style="width: 45px;"><img src="fish/lvl.png"></td>



<td>
<span class="white">Навык охотника(<?=$fish['level']?>) </br>  Бонус ко всем параметрам  </span><font color='#90c090'><b>+<?=$bon?> </b></font><br> <font color=green>Шанс найти добычу: <?=$ch?>%</font>  <br><?=$prog?>
















            </td>
        </tr>
</table><?



















require_once ('system/footer.php');
