<?php
define('PROTECTOR', 1);
include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
$textl='Работа';
going();
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');

if($set['shahter']==0){
echo'<div class="main"><div class="block_zero center"><img src="/image/!.png" alt=""/> Для начала изучите талант "Трудяга"</div></div>';
include($path.'files/down.php');exit;
}

$rand=rand(1000,9999);

$rydnik=mysql_fetch_array(mysql_query("SELECT * FROM `rydnik` WHERE `usr`='$log'"));

echo'<div class="main"><div class="block_zero center"><span style="color: #9bc;">Добудь ресурсы для улучшения вещей!</span></div><div class="mini-line"></div><div class="block_zero center"><img src="image/logo/cave.png" width="120" height="60" alt="logo"></div><div class="dot-line"></div>';

switch($_GET['mod']){
default:

echo'<div class="block_zero center">';

echo'<span style="color: #9c9;">Работать весело, когда платят!</span></div><div class="dot-line"></div><div class="block_zero center">';

if(isset($rydnik['udar']) AND $rydnik['udar']<9){
echo"<a href=\"rydnik.php?mod=udar\"><span class='btn'><span class='end'><input class='label' type=\"submit\" value=\"Ударить киркой\" /></a></span></span>";
}else{
echo'Начните поиск Инструманта!';
}
if(isset($rydnik['udar']) AND $rydnik['udar']>9){
echo"<a href=\"rydnik.php?mod=osmotr\"><span class='btn'><span class='end'><input class='label' type=\"submit\" value=\"Забрать добычу\" /></a></span></span>";
}
break;

case 'udar':
$zarp=rand(0,$set['shahter']);
$shahter=$set['shahter']/5;
//echo'Ваш уровень шахтёра: '.$shahter.'<br/>';
if($udata['mp']<50){
header('Location: rydnik.php?');
$_SESSION['err'] = 'Не хватает энергии, отдохните!';
exit();
}else{
mysql_query("UPDATE `dost` SET `prorud` = `prorud`+'1' WHERE `usr` = '$log'");
mysql_query("UPDATE `users` SET `money` = `money`+'$zarp', `mp` = `mp`-'50' WHERE `usr` = '$log'");
mysql_query("UPDATE `rydnik` SET `udar`=`udar`+1 WHERE `usr` = '$log'");
}
echo'</div><div class="block_zero center">';
//echo"Кол-во ударов: $rydnik[udar]</br>";
echo"Награда: <img src='/image/icon/money.png'/> $zarp сигарет";
echo'</div><div class="dot-line"></div><div class="main">';
echo'<div class="block_zero center">';
if($rydnik['udar']<9){
echo"<a href=\"rydnik.php?mod=udar\"><span class='btn'><span class='end'><input class='label' type=\"submit\" value=\"Ударить киркой\" /></a></span></span>";
}else{
echo"<a href=\"rydnik.php?mod=osmotr\"><span class='btn'><span class='end'><input class='label' type=\"submit\" value=\"Забрать добычу\" /></a></span></span>";
}
break; 

case 'osmotr':
$shahter=$set['shahter']/5;
//echo'Ваш уровень шахтёра: '.$shahter.'<br/>';

if($rydnik['udar']<9){
header('Location: rydnik.php?');
$_SESSION['err'] = 'Вам нечего забирать!';
exit();
break;
}

$nef=$set['shahter']+50;
$obs=$set['shahter']+50;
$kam=$set['shahter']+50;
$jel=$set['shahter']+50;
$ser=$set['shahter']+50;

echo'<div class="block_zero">';

$gora=rand(0,100);
if($gora>$nef){
echo'<img class="float-left" src="image/resurs/nef.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Нефрит<br><span style="color: #ff3434;">Не добыто!</span>';
}else{
$nk=$set['shahter']/5;
mysql_query("UPDATE `res` SET `kol` = `kol`+'$nk' WHERE `usr` = '$log' and `lat_name` = 'nefrit'");
echo'<img class="float-left" src="image/resurs/nef.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Нефрит<br><span style="color: #3c3;">Добыто!</span>';
}
echo'</div><div class="dot-line"></div>';

echo'<div class="block_zero">';

$gora=rand(0,100);

if($gora>$obs){
echo'<img class="float-left" src="image/resurs/obs.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Обсидиан<br><span style="color: #ff3434;">Не добыто!</span>';
}else{
$nk=$set['shahter']/5;
mysql_query("UPDATE `res` SET `kol` = `kol`+'$nk' WHERE `usr` = '$log' and `lat_name` = 'obsidian'");
echo'<img class="float-left" src="image/resurs/obs.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Обсидиан<br><span style="color: #3c3;">Добыто!</span>';
}
echo'</div><div class="dot-line"></div>';

echo'<div class="block_zero">';

$gora=rand(0,100);

if($gora>$kam){
echo'<img class="float-left" src="image/resurs/kam.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Камень<br><span style="color: #ff3434;">Не добыто!</span>';
}else{
$nk=$set['shahter']/5;
mysql_query("UPDATE `res` SET `kol` = `kol`+'$nk' WHERE `usr` = '$log' and `lat_name` = 'kamen'");
echo'<img class="float-left" src="image/resurs/kam.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Камень<br><span style="color: #3c3;">Добыто!</span>';
}
echo'</div><div class="dot-line"></div>';

echo'<div class="block_zero">';

$gora=rand(0,100);
if($gora>$jel){
echo'<img class="float-left" src="image/resurs/jel.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Железо<br><span style="color: #ff3434;">Не добыто!</span>';
}else{
$nk=$set['shahter']/5;
mysql_query("UPDATE `res` SET `kol` = `kol`+'$nk' WHERE `usr` = '$log' and `lat_name` = 'jelezo'");
echo'<img class="float-left" src="image/resurs/jel.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Железо<br><span style="color: #3c3;">Добыто!</span>';
}
echo'</div><div class="dot-line"></div>';

echo'<div class="block_zero">';

$gora=rand(0,100);
if($gora>$ser){
echo'<img class="float-left" src="image/resurs/ser.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Оникс<br><span style="color: #ff3434;">Не добыто!</span>';
}else{
$nk=$set['shahter']/5;
mysql_query("UPDATE `res` SET `kol` = `kol`+'$nk' WHERE `usr` = '$log' and `lat_name` = 'serebro'");
echo'<img class="float-left" src="image/resurs/ser.png" width="50" height="50" style="margin-left:1px; margin-right:10px;" alt="*"><br>Оникс<br><span style="color: #3c3;">Добыто!</span>';
}
echo'</div><div class="dot-line"></div>';

mysql_query("UPDATE `rydnik` SET `udar`='0' WHERE `usr` = '$log'");
echo'<div class="block_zero center">';
echo"<a href=\"rydnik.php?mod=udar\"><span class='btn'><span class='end'><input class='label' type=\"submit\" value=\"Ударить киркой\" /></a></span></span>";
break; 
}

echo'</div><div class="mini-line"></div><div class="main"><ul class="hint"><li>Бей киркой и собирай награду! Количество добытых ресурсов равно уровню таланта - Работяга!</a></li></ul></div></div></div>';

//************ПОИСК АРТЕФАКТА***********
echo'</div><div class="mini-line"></div><div class="main"><div class="block_zero center"><span style="color: #9bc;">Найди Инструменты для улучшения вещей!</span></div><div class="mini-line"></div><div class="block_zero center"><img src="image/logo/fights.png" width="120" height="60" alt="logo"></div><div class="dot-line"></div>';

echo'<div class="block_zero center">';

if($udata['klas']=='wizard'){
$kln='';
$txt='Тиски закалки';
$pic='<img src="image/resurs/zak.png" width="50" height="50" alt="*">';
}
if($udata['klas']=='fighert'){
$kln='';
$txt='Молоток ремонта';
$pic='<img src="image/resurs/rem.png" width="50" height="50" alt="*">';
}

echo'<span style="color: #9c9;">Можно найти инструменты для закалки или ремонта!</span></div><div class="dot-line"></div><div class="block_zero center">'.$pic.'</div><div class="dot-line"></div><div class="block_zero center">';

if(!empty($rydnik['usr'])){
if($rydnik['last']<time()-43200){
mysql_query("DELETE FROM `rydnik` WHERE usr='$log'");
header('Location: rydnik.php?r='.$rand.'');
$_SESSION['err'] = 'Вы заблудились и ничего не нашли!';
exit();
include('files/down.php');exit;
}
elseif($rydnik['over']<=time()){

mysql_query("UPDATE `dost` SET `proshah` = `proshah`+'1' WHERE `usr` = '$log'");

$aaa=mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `usr` = '$log' AND `lat_name` = 'zakal'"));
if($aaa==0){
$cena=$set['shahter']/5;
mysql_query("INSERT INTO `res` SET `usr`= '$log', `name` = 'Тиски закалки', `lat_name` = 'zakal', `tip` = 'artefact', `what` = 'res', `kol` = '$cena', `cena` = '100'");
}else{
$cena=$set['shahter']/5;
mysql_query("UPDATE `res` SET `kol` = `kol` + '$cena' WHERE `usr` = '$log' AND `lat_name` = 'zakal'");
}

$bbb=mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `usr` = '$log' AND `lat_name` = 'remont'"));
if($bbb==0){
$cena=$set['shahter']/5;
mysql_query("INSERT INTO `res` SET `usr` = '$log', `name` = 'Молоток ремонта', `lat_name` = 'remont', `tip` = 'artefact', `what` = 'res', `kol` = '$cena', `cena` = '100'");
}else{
$cena=$set['shahter']/5;
mysql_query("UPDATE `res` SET `kol` = `kol` + '$cena' WHERE `usr` = '$log' AND `lat_name` = 'remont'");
}

mysql_query("DELETE FROM `rydnik` WHERE `usr` = '$log'");
header('Location: rydnik.php?r='.$rand.'');
$_SESSION['message'] = 'Поиск Инструмента завершен успешно!';
exit();
include($path.'files/down.php');exit;
}
}
if($_GET['mod']=='rab'){
if(!empty($rydnik['usr'])){
mysql_query("UPDATE `rydnik` SET `last` = '".time()."' WHERE `usr` = '$log'");
header('Location: rydnik.php?r='.$rand.'');
$_SESSION['err'] = 'Вы уже ищите инструмент!';
exit();
}else{
$over=time()+3600; //время работы
$last=time();
mysql_query("INSERT INTO `rydnik` SET `usr` = '$log', `over` = '$over', `last` = '$last'");
mysql_query("UPDATE `users` SET `s5` = '1' WHERE `usr` = '$log'");
header('Location: rydnik.php?r='.$rand.'');
$_SESSION['message'] = 'Поиск инструмента начат!';
exit();
}
}elseif($_GET['mod']=='cancel'){
if(empty($rydnik['usr'])){
header('Location: rydnik.php?r='.$rand.'');
$_SESSION['err'] = 'Вы ничего не ищите!';
exit();
}else{
mysql_query("DELETE FROM `rydnik` WHERE `usr`='$log'");
header('Location: rydnik.php?r='.$rand.'');
$_SESSION['err'] = 'Поиск Артефакта отменён!';
exit();
}
}else{
if(empty($rydnik['usr'])){
echo"<a href=\"rydnik.php?mod=rab&amp;r=$rand\"><span class='btn'><span class='end'><input class='label' type=\"submit\" value=\"Поиск Инструмента\" /></a></span></span>";
}else{
mysql_query("UPDATE `rydnik` SET `last` = '".time()."' WHERE `usr` = '$log'");
$abc=$rydnik['over']-time();
echo'<span style="color: #999;">До завершения поиска: '.Sec2Time($abc).'</span></div><div class="dot-line"></div><div class="block_zero center">';
echo"<a href=\"rydnik.php?mod=cancel&amp;r=$rand\"><span class='btn'><span class='end'><input class='label' type=\"submit\" value=\"Отменить поиск\" /></a></span></span></div>";
}
}
echo'</div><div class="mini-line"></div><div class="main"><ul class="hint"><li>Количество найденных инструментов равно уровню профессии - Работяга!</a></li></ul></div></div></div>';
include($path.'files/down.php');
?>