<?php
define('PROTECTOR', 1);
include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
if($_GET['mod']=='udar'){
$header=TRUE;
}else{
$textl='Стрелка';
}
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');
//
$time=time();
$timer=time()+300;
///Глобальные переменные///
$req = mysql_query("SELECT * FROM `userduel` WHERE `usr` = '$log' LIMIT 1");
$duel = mysql_fetch_array($req);
$redu = mysql_query("SELECT * FROM `duel` WHERE `id` = '$duel[duid]' LIMIT 1");
$dued = mysql_fetch_array($redu);
switch($_GET['mod']){

default:

if($dueli==0){
header('Location: duel.php?');exit();
break;
}

if($duel['storona']=="white"){
$pr="black";
$pica='0';
}else{
$pr="white";
$pica='1';
}

$rand=rand(1000000,10000000);

echo'<div class="main"><div class="mini-line"><div class="block_zero center"><img src="image/logo/coliseum.png" alt="logo"></div><div class="block_zero center"><span style="color: #9bc;">Стрелка - это увлекательное сражение двух команд: Красных и Синих. Раcставь все точки над "И" и покажи на что ты способен</div>';

echo'</div><div class="dot-line"></div><div class="block_zero center">';

$win = mysql_num_rows(mysql_query("SELECT `duid` FROM `userduel` WHERE `storona` = '$pr' AND `duid`='$duel[duid]'"));

if($win<=0){
mysql_query("DELETE FROM `duel` WHERE `id` = '$duel[duid]'");
header('Location: fiting.php?mod=novrag');exit();
break;
}

if($win>=1){
if(empty($duel['usr'])){
echo"<img src='pic/game/ext.png' alt='*'/><a href=\"start.php?\"> Продолжить »</a> ";
break;
}
$wins = mysql_num_rows(mysql_query("SELECT `duid` FROM `userduel` WHERE `storona` = '$pr' AND `status`='die' AND `duid`='$duel[duid]'"));
if($win=$wins){
if($udata['lvl']>=1 and $udata['lvl']<=10){$bon=30;}
if($udata['lvl']>10 and $udata['lvl']<=20){$bon=50;}
if($udata['lvl']>20 and $udata['lvl']<=30){$bon=100;}
if($udata['lvl']>30 and $udata['lvl']<=40){$bon=200;}
if($udata['lvl']>40 and $udata['lvl']<=50){$bon=300;}
if($udata['lvl']>50 and $udata['lvl']<=60){$bon=400;}
if($udata['lvl']>60 and $udata['lvl']<=71){$bon=500;}

if($duel['status']="active"){
$viz=round($udata['lvl']*1.5+$bon);
}else{
$viz=0;
}
$wins=$udata['lvl']+$bon;
$die=$duel['dies']*$bon;
$itogo=$wins+$die;

echo'</div></div></div><div class="block_zero center"><span style="color: #9c9;"><img src="image/icon/2hit.png" alt="*"> Победа! <img src="image/icon/2hit.png" alt="*"></span><br/>';

echo'<div class="separ"></div><img src="image/icon/money.png" alt="*"> '.$viz.' сигарет <img src="image/icon/exp.png" alt="*"> '.$itogo.' авторитета</div><div class="dot-line"></div>';

mysql_query("UPDATE `users` SET `money` = `money`+'$viz', `exp`=`exp`+'$itogo' WHERE `usr`='$log'");
$usr="$log x";
mysql_query("UPDATE `userduel` SET `usr` = '$usr' WHERE `usr`='$log' LIMIT 1");
$du = mysql_num_rows(mysql_query("SELECT `duid` FROM `userduel` WHERE `storona` = '$duel[storona]' AND `status`='active' AND `duid`='$duel[duid]'"));

if($du<=0){
mysql_query("DELETE FROM `duel` WHERE `id` = '$duel[duid]'");
}

echo'<div class="block_zero center"><a href="duel.php?"><span class="btn"><span class="end"><input class="label" type="submit" value="Назад"></span></span></a>';
break;
}
}
if($duel['status']=="die"){
echo'</div></div></div><div class="block_zero center"><span style="color: #c66;"><img src="image/icon/2hit.png" alt="*"> Поражение! <img src="image/icon/2hit.png" alt="*"></span><br/><div class="separ"></div>';
echo'Ты был убит на стрелке!<br>';

echo'<a href="fiting.php?mod=exit"><span class="btn"><span class="end"><input class="label" type="submit" value="Выйти"></span></span></a>';
break;
}else{

if(empty($_GET['oponent'])){
$boy=mysql_query("SELECT * FROM `userduel` WHERE `storona`='$pr' AND `duid`='$dued[id]' AND `status`='active' ORDER BY RAND() LIMIT 1");
$oponent = mysql_fetch_array($boy);
$_GET['oponent']="$oponent[usr]";
}

$hp=mysql_fetch_array(mysql_query("SELECT hp FROM `users` WHERE `usr`='$_GET[oponent]' LIMIT 1"));


echo'<img src="image/icon/'.$pica.'.png" alt="*"/> '.$_GET['oponent'].' '.$hp['hp'].'<br></div><div class="dot-line"></div><div class="block_zero center">';

echo'<a href="fiting.php?mod=udar&oponent='.$_GET['oponent'].'"><span class="btn"><span class="end"><input class="label" type="submit" value="Атаковать"></span></span></a><div class="separ"></div>';


$users=mysql_num_rows(mysql_query("SELECT `duid` FROM `userduel` WHERE `storona`='$pr' AND `duid`='$dued[id]' AND `status`='active'"));
if($users>=1){
$users=mysql_fetch_array(mysql_query("SELECT `usr` FROM `userduel` WHERE `usr`!='$_GET[oponent]' AND `storona`='$pr' AND `duid`='$dued[id]' ORDER BY RAND() LIMIT 1"));
echo'<a href="fiting.php?mod=udar&oponent='.$users['usr'].'"><span class="btn"><span class="end"><input class="label" type="submit" value="Сменить противника"></span></span></a><div class="separ"></div>';
}

$req=mysql_query("SELECT umen, timer FROM duellog WHERE usr = '$log' AND timer>='".time()."' AND umen='1' ORDER BY id DESC LIMIT 1");
$su = mysql_fetch_array($req);
if($su['timer']+9>$timer){
$vr=9-($timer-$su['timer']);
$vre="0:0$vr";
$cvet="<font color='#AAAAAA'>";
}else{
$vr=FALSE;
$vre=FALSE;
$cvet=FALSE;
}

echo'<a class="btn" href="fiting.php?mod=udar&oponent='.$_GET['oponent'].'&umen=sudar"><span class="end"><span class="label">'.$cvet.' Сильный удар '.$vre.'</span></span></a></font> ';

echo' <a class="btn" href="fiting.php?mod=udar&oponent='.$_GET['oponent'].'&umen=sfera"><span class="end"><span class="label">Сфера защиты</span></span></a></font>';


// Смена противника

}//die


$kom=mysql_num_rows(mysql_query("SELECT `duid` FROM `userduel` WHERE `storona`='$duel[storona]' and `duid`='$dued[id]' "));
/*
echo"<li><a href=\"fiting.php?mod=kom\"> <img src='pic/game/kom.png' alt='*'/> Моя команда ($kom) </a></li>";
*/

/*
echo"$div <font color='chocolate'>Твои противники:</font> $div";
*/
///Враги///
$boy=mysql_query("SELECT * FROM `userduel` WHERE `storona`='$pr' and `duid`='$dued[id]' ");
While($vrag=mysql_fetch_array($boy)){
if($vrag['status']=="active"){
/*
echo"<img src='pic/main/$vrag[storona].png' alt='*'/> <a href='fiting.php?mod=udar&oponent=$vrag[usr]'>$vrag[usr]</a>
<img src='pic/up.png' alt='*'/> $vrag[lvl] [<img src='pic/game/mob/hp.gif' alt='*'/>"; 
*/
$hp=mysql_fetch_array(mysql_query("SELECT hp FROM `users` WHERE `usr`='$vrag[usr]' LIMIT 1"));
/*
echo"$hp[hp]],";
*/
}
if($vrag['status']=="die"){
/*
echo"<img src='pic/main/$vrag[storona].png' alt='*'/> <font color='gray'>$vrag[usr]</font>
<img src='pic/game/die.png' alt='*'/> $vrag[lvl], "; 
*/
}
}

echo"$div <font color='chocolate'>Боевой журнал</font> $div";
$protiv = mysql_query("SELECT * FROM `userduel` WHERE `duid` = '$duel[duid]' and `storona`='$pr' ");
$souz = mysql_query("SELECT * FROM `userduel` WHERE `duid` = '$duel[duid]' and `storona`='$udata[storona]' ");
log_duel($tlog='duel');
break;

case 'udar':
$req=mysql_query("SELECT umen,timer FROM duellog WHERE usr = '$log' and timer>='".time()."' and umen='1' ORDER BY id DESC LIMIT 1");
$su = mysql_fetch_array($req);
if($su['timer']+9>$timer and $_GET['umen']=="sudar"){header ("Location: fiting.php?");exit;}
if(empty($_GET['oponent'])){header ("Location: fiting.php?");exit;}
if($udata['hp']<=0){header ("Location: fiting.php?");exit;}
$oponent = $_GET['oponent'];
$user = mysql_query("SELECT * FROM `users` WHERE `usr`='$oponent' ");
$rest = substr("$oponent", 0, -2);
if($rest==" x"){header ("Location: fiting.php?");exit;}

$vrag = mysql_fetch_array($user);
$udar = $udata['sila']-$vrag['prot'];
if($udar>=0 and $udar<=10){$bon=2;}
if($udar>10 and $udar<=30){$bon=4;}
if($udar>30 and $udar<=50){$bon=8;}
if($udar>50 and $udar<=70){$bon=12;}
if($udar>70 and $udar<=100){$bon=16;}
if($udar>100){$bon=20;}
if($udar<=0){
$shans=rand(0,100);
if($shans>=0 and $shans<=10){$udar=rand(3,5);}
if($shans>=10 and $shans<=30){$udar=rand(2,4);}
if($shans>=30 and $shans<=60){$udar=rand(1,3);}
if($shans>=60 and $shans<=100){$udar=rand(1,2);}
}else{
$shans=rand(0,100);
if($shans>=0 and $shans<=10){$udar=rand(7,10);}
if($shans>=10 and $shans<=30){$udar=rand(6,8);}
if($shans>=30 and $shans<=60){$udar=rand(5,6);}
if($shans>=60 and $shans<=100){$udar=rand(4,4);}
}
if($udata['lovk']-$vrag['lovk']<0){$uvorot=50;}else{$uvorot=25;}
$umen=mysql_query("SELECT `sfera` FROM `userduel` WHERE `usr`='$oponent' ");
$sfera = mysql_fetch_array($umen);
if($_GET['umen']=="sudar" and $sfera['sfera']==0){$udar=$udar*1.5;}
$req=mysql_query("SELECT * FROM duellog WHERE usr = '$log' and timer>='".time()."' ORDER BY id DESC LIMIT 1");
$ilog=mysql_fetch_array($req);
$razn=$timer-$ilog['timer'];
if($razn<=2){$uvorot=$uvorot+25;}
if($razn>=2 and $razn<=5){$uvorot=$uvorot;}
if($razn>=5 and $razn<=10){$uvorot=$uvorot-15;}
$sravn=rand(0,100);
if($sravn<$uvorot){$udar=0;}
if($udar==0){$sms="Промах";$pr=1;}
if($pr!==1){
$uron=round($vrag['hp']-(($vrag['hp']/100)*$udar)-$bon);
$udar=round(($vrag['hp']/100)*$udar+$bon);
$msg=rand(0,2);
if($msg=="0"){$sms="ударил";}
if($msg=="1"){$sms="поразил";}
if($msg=="2"){$sms="сразил";}
if($_GET['umen']=="sfera"){$sms=html_entity_decode("использовал</font>  защиту");
$um=1;
//$uron=0;
}
if($_GET['umen']=="sudar"){$sms=html_entity_decode("использовал</font> сильный удар");$um=1;}
if($uron<=0){$sms="убил";
$die=$duel['dies']+1;
mysql_query("UPDATE `userduel` SET `status` = 'die' WHERE `usr`='$oponent'") or die (mysql_error());
mysql_query("UPDATE `userduel` SET `dies` = '$die' WHERE `usr`='$log'") or die (mysql_error());
}

mysql_query("UPDATE `users` SET `hp` = '$uron' WHERE `usr`='$oponent'") or die (mysql_error());
mysql_query("UPDATE `userduel` SET `hp` = '$uron' WHERE `usr`='$oponent'") or die (mysql_error());
mysql_query("INSERT INTO duellog SET usr='$log',text='$sms',opon='$oponent',uron='$udar',timer='$timer', umen='$um'");}
else{
mysql_query("INSERT INTO duellog SET usr='$log',text='$sms',timer='$timer', umen='$um'");
}
$b = html_entity_decode($_POST[name]);
if($uron<=0){$oponent="";}
header ("Location: fiting.php?oponent=$oponent");exit;
break;

case 'novrag':
$usr="$log x";
mysql_query("UPDATE `userduel` SET `usr` = '$usr' WHERE `usr`='$log' LIMIT 1");
$_SESSION['err'] = 'Бой не начался, так как нет противников!';
header ("Location: duel.php?");exit();
break;

case 'exit':
$usr="$log x";
mysql_query("UPDATE `userduel` SET `usr` = '$usr' WHERE `usr`='$log' LIMIT 1");
header ("Location: duel.php?");exit();
break;

case 'kom':
echo"<div class='a'><b>Стрелка</b></div>$div";
echo"<img src='pic/game/kom.png' alt='*'/> Моя команда:$div";
if($duel['storona']=="white"){$pr="black";}else{$pr="white";}

$boy=mysql_query("SELECT * FROM `userduel` WHERE `storona`='$duel[storona]' and `duid`='$dued[id]' ");
While($vrag=mysql_fetch_array($boy)){
if($vrag['status']=="active"){
echo"<img src='pic/main/$vrag[storona].png' alt='*'/> <a href='fiting.php?mod=udar&oponent=$vrag[usr]'>$vrag[usr]</a>
<img src='pic/up.png' alt='*'/> $vrag[lvl] [<img src='pic/game/mob/hp.gif' alt='*'/>"; 
$hp=mysql_fetch_array(mysql_query("SELECT hp FROM `users` WHERE `usr`='$vrag[usr]' LIMIT 1"));
echo"$hp[hp]],"; }
if($vrag['status']=="die"){
echo"<img src='pic/main/$vrag[storona].png' alt='*'/> <font color='gray'>$vrag[usr]</font>
<img src='pic/game/die.png' alt='*'/> $vrag[lvl], "; 
}
}
echo"$div <img src='pic/game/vrag.png' alt='*'/> Противники:$div";
$boy=mysql_query("SELECT * FROM `userduel` WHERE `storona`='$pr' and `duid`='$dued[id]' ");
While($vrag=mysql_fetch_array($boy)){
if($vrag['status']=="active"){
echo"<img src='pic/main/$vrag[storona].png' alt='*'/> <a href='fiting.php?mod=udar&oponent=$vrag[usr]'>$vrag[usr]</a>
<img src='pic/up.png' alt='*'/> $vrag[lvl] [<img src='pic/game/mob/hp.gif' alt='*'/>"; 
$hp=mysql_fetch_array(mysql_query("SELECT hp FROM `users` WHERE `usr`='$vrag[usr]' LIMIT 1"));
echo"$hp[hp]],"; }
if($vrag['status']=="die"){
echo"<img src='pic/main/$vrag[storona].png' alt='*'/> <font color='gray'>$vrag[usr]</font>
<img src='pic/game/die.png' alt='*'/> $vrag[lvl], "; 
}
}
break;
}
echo'</div><div class="line"></div>';
include($path.'files/down.php');
?>