$offer=mysql_fetch_assoc(mysql_query("SELECT `timeout`, `type`, `blood`, `kulak`, `stavka` FROM offers WHERE time='".$stat['battle']."' LIMIT 1"));
$max11=mysql_fetch_assoc(mysql_query("SELECT MAX(time) AS time FROM battles WHERE offer='".$stat['battle']."'"));
if ($stat['hp_now'] && $participant['hp']) {
if ($kick1!="" && $block1!="" && $opponent!="") {
$user_turn=mysql_fetch_array(
mysql_query(
"select * from battles
where offer=$stat[battle]
and attacker='$stat[user]'
and defender='".addslashes($opponent)."'
and type is NULL"));
if (!$user_turn) {
$opp_stats=mysql_query("SELECT id, user, level, strength, dex, agility, vitality, razum, hp_now, invisible, battle, rank, m_k, m_m, m_t, m_d, elik_time, elik_action, aura, aura_t, artbot FROM person WHERE user='".addslashes($opponent)."' LIMIT 1");
$opp_stat=mysql_fetch_array($opp_stats);
if ($opp_stat['hp_now'] == 0)
$opponent = "";
include("includes/battle/changed_opp.php");
$rating=calculate_fight_rating($stat,$opp_stat);
$str1='
[i]По мнению местных криминальных авторитетов шансы на победу [b]'.$stat['user'].'[/b] составляют '.$rating[0].'%, соответственно шансы на победу [b]'.$opp_stat['user'].'[/b] - '.$rating[1].'%[/i]';
if ($participant['wait'] == 1 AND $participant['priem'] != 0){
$id_p = $participant['priem'];
include("includes/battle/priem/$id_p.php");
}
if ($opp_stat['rank'] == 60 && $opponent!="") {
$max=mysql_fetch_assoc(mysql_query("select max(id) as id from battles where offer='".$stat['battle']."'"));
if (!$max)
$new_id=1;
else
$new_id=$max['id']+1;
$opponent_turn['kick1'] = rand(1,5);
$opponent_turn['block1'] = rand(1,5);
$opponent_turn['block2'] = rand(1,5);
$opponent_turn['id'] = $new_id;
mysql_query(
"insert into battles (offer, time, id, attacker, defender, kick1, block1, block2, side)
values ($stat[battle],$now,$new_id,'".$opp_stat['user']."','$stat[user]','".$opponent_turn['kick1']."','".$opponent_turn['block1']."','".$opponent_turn['block2']."', ".$opp_side.")");
mysql_query("UPDATE `person` SET `lpv` = '".time()."' WHERE `id`='".$opp_stat['id']."'");
}
elseif ($opponent!="")
$opponent_turn=mysql_fetch_array(
mysql_query(
"select * from battles
where offer='".$stat['battle']."'
AND attacker='".addslashes($opponent)."'
AND defender='".$stat[user]."'
AND type is NULL"));
if ($opponent_turn) {
$kick1=round($kick1);
$kick2=round($kick2);
$block1=round($block1);
$block2=round($block2);
$block3=round($block3);
$b1 = array();
$b2 = array();
$b1['1']=$stat['br1'];
$b1['2']=$stat['br2'];
$b1['3']=$stat['br3'];
$b1['4']=$stat['br4'];
$b1['5']=$stat['br5'];
$b2['1']=$opp_stat['br1'];
$b2['2']=$opp_stat['br2'];
$b2['3']=$opp_stat['br3'];
$b2['4']=$opp_stat['br4'];
$b2['5']=$opp_stat['br5'];
if ($priem_id == 3) $priem_krit =100000; else $priem_krit =0;
if ($priem_id == 4) $priem_uvorot =100000; else $priem_uvorot =0;
$i1+=$priem_krit;
$l1+=$priem_uvorot;
$priem_krit =0;
$priem_uvorot =0;
$x = $stat['agility'] + $stat['unuv']/STATS_VS_MOD;
$y = $opp_stat['agility'] + $opp_stat['uv']/STATS_VS_MOD;
if (4*$x <= $y) $pu1 = 1 - 2*$x/(5*$y);
elseif (2*$x <= $y && $y < 4*$x) $pu1 = 1.05 - 0.6*$x/$y;
elseif (4*$x/3 <= $y && $y < 2*$x) $pu1 = 1.75 - 2*$x/$y;
elseif ($x <= $y && $y < 4*$x/3) $pu1 = 0.7 - 0.6*$x/$y;
elseif (2*$x/3 <= $y && $y < $x) $pu1 = 0.28 - 0.18*$x/$y;
elseif ($x/2 <= $y && $y < 2*$x/3) $pu1 = 0.04 - 0.02*$x/$y;
elseif ($y < $x/2) $pu1 = 0;
$x = $opp_stat['dex'] + $opp_stat['unkrit']/STATS_VS_MOD;
$y = $stat['dex'] + $stat['krit']/STATS_VS_MOD;
if (4*$x <= $y) $pi1 = 1 - 2*$x/(5*$y);
elseif (2*$x <= $y && $y < 4*$x) $pi1 = 1.05 - 0.6*$x/$y;
elseif (4*$x/3 <= $y && $y < 2*$x) $pi1 = 1.75 - 2*$x/$y;
elseif ($x <= $y && $y < 4*$x/3) $pi1 = 0.7 - 0.6*$x/$y;
elseif (2*$x/3 <= $y && $y < $x) $pi1 = 0.28 - 0.18*$x/$y;
elseif ($x/2 <= $y && $y < 2*$x/3) $pi1 = 0.04 - 0.02*$x/$y;
elseif ($y < $x/2) $pi1 = 0;
$x = $opp_stat['agility'] + $opp_stat['unuv']/STATS_VS_MOD;
$y = $stat['agility'] + $stat['uv']/STATS_VS_MOD;
if (4*$x <= $y) $pu2 = 1 - 2*$x/(5*$y);
elseif (2*$x <= $y && $y < 4*$x) $pu2 = 1.05 - 0.6*$x/$y;
elseif (4*$x/3 <= $y && $y < 2*$x) $pu2 = 1.75 - 2*$x/$y;
elseif ($x <= $y && $y < 4*$x/3) $pu2 = 0.7 - 0.6*$x/$y;
elseif (2*$x/3 <= $y && $y < $x) $pu2 = 0.28 - 0.18*$x/$y;
elseif ($x/2 <= $y && $y < 2*$x/3) $pu2 = 0.04 - 0.02*$x/$y;
elseif ($y < $x/2) $pu2 = 0;
$x = $stat['dex'] + $stat['unkrit']/STATS_VS_MOD;
$y = $opp_stat['dex'] + $opp_stat['krit']/STATS_VS_MOD;
if (4*$x <= $y) $pi2 = 1 - 2*$x/(5*$y);
elseif (2*$x <= $y && $y < 4*$x) $pi2 = 1.05 - 0.6*$x/$y;
elseif (4*$x/3 <= $y && $y < 2*$x) $pi2 = 1.75 - 2*$x/$y;
elseif ($x <= $y && $y < 4*$x/3) $pi2 = 0.7 - 0.6*$x/$y;
elseif (2*$x/3 <= $y && $y < $x) $pi2 = 0.28 - 0.18*$x/$y;
elseif ($x/2 <= $y && $y < 2*$x/3) $pi2 = 0.04 - 0.02*$x/$y;
elseif ($y < $x/2) $pi2 = 0;
$uron_attacker_1=0;
$uron_attacker_2=0;
$uron_attacker=0;
$uron_defender_1=0;
$uron_defender_2=0;
$uron_defender=0;
$a1=mt_rand(0,PRECESSION)/PRECESSION;
$a2=mt_rand(0,PRECESSION)/PRECESSION;
# случайное число на (0,1), показывающее, сработал ли уворот в данном случае.
$rb1=mt_rand(0,PRECESSION)/PRECESSION;
$rb2=mt_rand(0,PRECESSION)/PRECESSION;
# случайное число на (0,1), показывающее, сработал ли крит в данном случае.
if($pu1>$a1) { // уворот 1
$uron_attacker_1=0;
$uron_attacker_2=0;
$uron_attacker=0;
$action_attacker=uvorot;
}elseif ($pi1>$rb1) { // крит 1
$uron_attacker=(int)rand(1.5*$stat['strength']+2*$stat['min'], 2*$stat['strength']+2*$stat['max']);
$action_attacker=krit;
}else{
if($kick1==$opponent_turn['block1'] or $kick1==$opponent_turn['block2'] or $kick1==$opponent_turn['block3']) {
$uron_attacker_1=0;
$action_attacker_1=block1;
}else{
$uron_attacker_1=(int)rand(0.75*$stat['strength']+$stat['min']-$b2[$kick1], $stat['strength']+$stat['max']-0.5*$b2[$kick1]);
if($uron_attacker_1<0) $uron_attacker_1=0;
$action_attacker_1=udar;
}
if ($stat_obj_t2['tip'] == 1){
if($kick2==$opponent_turn['block1'] or $kick2==$opponent_turn['block2'] or $kick2==$opponent_turn['block3']) {
$uron_attacker_2=0;
$action_attacker_2=block2;
}else{
$uron_attacker_2=(int)rand(0.5*$stat['strength']+$stat['min']-$b2[$kick2], 0.75*($stat['strength']+$stat['max']-0.5*$b2[$kick2]));
if($uron_attacker_2<0) $uron_attacker_2=0;
$action_attacker_2=udar;
}}
}
if($pu2>$a2) { // уворот 2
$uron_defender_1=0;
$uron_defender_2=0;
$uron_defender=0;
$action_defender=uvorot;
}elseif ($pi2>$rb2) { // крит 2
$uron_defender=(int)rand(1.5*$opp_stat['strength']+2*$opp_stat['min'], 2*$opp_stat['strength']+2*$opp_stat['max']);
$action_defender=krit;
}else{
if($opponent_turn['kick1']==$block1 or $opponent_turn['kick1']==$block2 or $opponent_turn['kick1']==$block3) {
$uron_defender_1=0;
$action_defender_1=block1;
}else{
$uron_defender_1=(int)rand(0.75*$opp_stat['strength']+$opp_stat['min']-$b1[$opponent_turn['kick1']], $opp_stat['strength']+$opp_stat['max']-0.5*$b1[$opponent_turn['kick1']]);
if($uron_defender_1<0) $uron_defender_1=0;
$action_defender_1=udar;
}
if ($ostat_obj_t2['tip'] == 1){
if($opponent_turn['kick2']==$block1 or $opponent_turn['kick2']==$block2 or $opponent_turn['kick2']==$block3) {
$uron_defender_2=0;
$action_defender_2=block2;
}else{
$uron_defender_2=(int)rand(0.5*$opp_stat['strength']+$opp_stat['min']-$b1[$opponent_turn['kick2']], 0.75*($opp_stat['strength']+$opp_stat['max']-0.5*$b1[$opponent_turn['kick2']]));
if($uron_defender_2<0) $uron_defender_2=0;
$action_defender_2=udar;
}}
}
$damage[0] = $uron_attacker + $uron_attacker_1 + $uron_attacker_2;
$damage[1] = $uron_defender + $uron_defender_1 + $uron_defender_2;
if($action_attacker == krit) mysql_query("UPDATE person, participants SET participants.krit=participants.krit+".$pi1." WHERE person.id='".$stat['id']."' AND participants.time='".$stat['battle']."' AND participants.id='".$stat['id']."'");
if($action_defender == krit) mysql_query("UPDATE person, participants SET participants.krit=participants.krit+".$pi2." WHERE person.id='".$opp_stat['id']."' AND participants.time='".$opp_stat['battle']."' AND participants.id='".$opp_stat['id']."'");
if($action_defender == uvorot) mysql_query("UPDATE person, participants SET participants.parry=participants.parry+".$pu1." WHERE person.id='".$stat['id']."' AND participants.time='".$stat['battle']."' AND participants.id='".$stat['id']."'");
if($action_attacker == uvorot) mysql_query("UPDATE person, participants SET participants.parry=participants.parry+".$pu2." WHERE person.id='".$opp_stat['id']."' AND participants.time='".$opp_stat['battle']."' AND participants.id='".$opp_stat['id']."'");
$damage[0]+=$priem_dam;