// ----- # Выигрыш # ----- //
if (!$endbattle) {
$echo="<center>Поздравляем! Победа за Вами!
<input type=button value=' Вернуться ' onclick='window.location.href=\"main.php?tmp=\"+Math.random();\"\"' class=standbut></center>
";
mysql_query("UPDATE players SET last_battle=".$_RESERVER['battle']." WHERE battle='".$stat['battle']."' AND side='".$opp_side."'");
echo mysql_error();
//if ($offer['blood'] == 1) mysql_query("UPDATE players SET travma=$now+10800 WHERE battle='".$stat['battle']."' AND side='".$opp_side."'");
if ($offer[stavka]>=0) $stv=mysql_query("Update players set credits=credits+'".$offer[stavka]."' where id='".$stat[id]."'");
mysql_query("UPDATE participants SET hp=0 WHERE time='".$stat['battle'].$opp_stat['id']."' AND side='".$opp_side."'");
get_exp();
require_once("inc/chat/functions.php");
insert_msg("Поздравляем, Вы одержали победу! Всего Вами нанесено урона: ".$participant['damage']." HP. Получено опыта: ".$addexp.".","","","1",$stat['user'],"",$stat['room']);
if ($stat['exp']+$addexp >= $stat['next_exp'] && $stat['next_exp']!=0) {
$new_exp=$stat['exp']+$addexp;
$up_level=mysql_fetch_array(mysql_query("SELECT level, credits, updates FROM levels WHERE exp=".$stat['next_exp'].""));
$new_exp=mysql_fetch_array(mysql_query("SELECT exp FROM levels WHERE exp>".$stat['next_exp']." ORDER BY level LIMIT 1"));
if (!$new_exp['exp']) $new_exp['exp']=0;
if ($stat['level']==$up_level['level'])
insert_msg("Поздравляем, Вы получили новое повышение","","","1",$stat['user'],"",$stat['room']);
elseif ($stat['level']<$up_level['level'])
insert_msg("Поздравляем, Вы получили новый уровень","","","1",$stat['user'],"",$stat['room']);
mysql_query("update players set wins=wins+1, battle=NULL, exp=exp+".$addexp.", next_exp=".$new_exp['exp'].", s_updates=s_updates+".$up_level['updates'].", credits=credits+".$up_level['credits'].", level=".$up_level['level']." WHERE id='".$stat['id']."'");
mysql_query("UPDATE participants SET live=1 WHERE time='".$stat['battle']."' AND id='".$stat['id']."'");
}
else {
mysql_query("UPDATE players SET wins=wins+1, battle=NULL, exp=exp+'".$addexp."' where id='".$stat['id']."'");
mysql_query("UPDATE participants SET live=1 WHERE time='".$stat['battle']."' AND id='".$stat['id']."'");
$D_S = mysql_query("SELECT * FROM participants WHERE time='".$stat['battle']."' AND id NOT LIKE '".$stat['id']."' ");
while ($D_SA = mysql_fetch_array($D_S)) {
$d_ss ++;
$d_id = $D_SA[id];
$D_SP = mysql_query("SELECT * FROM players WHERE id=$d_id ");
$D_SPA = mysql_fetch_array($D_SP);
$drop = $D_SPA[drop];
$user_d = $D_SPA["user"];
$D_P1 = mysql_query("SELECT * FROM `drop`");
$D_PS1 = mysql_fetch_array($D_P1);
$D_P = mysql_query("SELECT * FROM `drop` WHERE `p_drop` = $drop ");
$D_PS = mysql_fetch_array($D_P);
$p_drop = $D_PS1[p_drop];
$name = $D_PS["name"];
$chance = $D_PS[chance];
$ch = rand(1,$chance);
//if ($p_drop == $drop) {$nms = "Вы обнаружили $name";}
$buyitem_res = mysql_query("SELECT * FROM `items` WHERE `title` = '$name' ");
if (mysql_num_rows($buyitem_res)) {
$buyitem = mysql_fetch_array($buyitem_res);
$inf = "".$buyitem['name']."|".$buyitem['title']."|".$buyitem['price']."|0|".$secondary."|".$buyitem['art']."|0|".$buyitem['iznos']."";
$min = "".$buyitem['min_level']."|".$buyitem['min_str']."|".$buyitem['min_dex']."|".$buyitem['min_ag']."|".$buyitem['min_vit']."|".$buyitem['min_razum']."|".$buyitem['min_rase']."|".$buyitem['min_proff']."";
$result2 = mysql_query("INSERT INTO `objects` (`user`,`inf`,`min`,`tip`,`br1`,`br2`,`br3`,`br4`,`br5`,`min_d`,`max_d`,`hp`,`energy`,`strength`,`dex`,`agility`,`vitality`,`razum`,`krit`,`unkrit`,`uv`,`unuv`,`time`) VALUES ('".$stat['user']."','".$inf."','".$min."','".$buyitem['tip']."','".$buyitem['br1']."','".$buyitem['br2']."','".$buyitem['br3']."','".$buyitem['br4']."','".$buyitem['br5']."','".$buyitem['min']."','".$buyitem['max']."','".$buyitem['hp']."','".$buyitem['energy']."','".$buyitem['strength']."','".$buyitem['dex']."','".$buyitem['agility']."','".$buyitem['vitality']."','".$buyitem['razum']."','".$buyitem['krit']."','".$buyitem['unkrit']."','".$buyitem['uv']."','".$buyitem['unuv']."','".time()."')");
}
}
}
if ($stat['vitality']*5 != $stat[ustal_now]) {
mysql_query("UPDATE players SET ustal_now=ustal_now+15 WHERE id='".$stat['id']."'");
}
if ($stat['vitality']*5 < $stat[ustal_now]) {
mysql_query("UPDATE players SET ustal_now='".$stat['vitality']."'*5 WHERE id='".$stat['id']."'");
}
//echo mysql_error();
// -------- # ЕСЛИ БОТ ТО ВЫКИДЫВАМ ИЗ БОЯ И ВОСТАНАВЛИВАЕМ HP # -------- //
if ($opp_stat['rank'] == 60 && $opponent)
mysql_query("UPDATE players SET losses=losses+1, battle=0, hp_now=hp_now+15 WHERE id='".$opp_stat['id']."'");
$endbattle = 1;
$stat['battle'] = 1;
}
// ----- # Конец # ----- //