<?php
$menuhide=1;
$atkpage=1;
require_once("globals.php");
$_GET['ID'] = isset($_GET['ID']) && ctype_digit($_GET['ID']) ? abs((int) $_GET['ID']) : false;
if(!$_GET['ID']){ echo "You did not select a valid ID"; $h->endpage(); exit; }
$energy = $ir['maxenergy']/4;
$error = ($ir['hp'] <= 0) ? "You can't attack someone when you have no health!" : $error;
$error = ($ir['energy']<$energy) ? "You need to have at least 25% of your energy if you want to attack someone." : $error;
$error = ($ir['jail'] > 0) ? "You can't attack someone if you are in jail." : $error;
$error = ($ir['hospital'] > 0) ? "You can't attack someone if you are in the hospital." : $error;
$error = ($_GET['ID'] == "") ? "You didn't choose someone to attack." : $error;
$error = ($_GET['ID'] == $ir['userid']) ? "You can't attack yourself." : $error;
if($ir['equip_armor'] > 0) { $yourarmorstuff = $db->query("SELECT * FROM `items` WHERE (`itmid`=".$ir['equip_armor'].")");
$dat = $db->fetch_row($yourarmorstuff);
$defense = $dat['armor']; }
else { $defense = 0; }
$attacking_person = mysql_query("SELECT `u`.`userid`,`u`.`username`,`u`.`hp`,`u`.`maxhp`,`u`.`level`, " .
"`u`.`money`,`u`.`location`,`u`.`hospital`,`u`.`jail`,`u`.`fedjail`,`u`.`gang`,`u`.`user_level`, " .
"`u`.`equip_primary`,`u`.`equip_secondary`,`u`.`equip_armor`,`u`.`exp`,`us`.`strength`,`us`.`agility`, " .
"`us`.`guard` " .
"FROM `users` `u` " .
"LEFT JOIN `userstats` `us` " .
"ON `u`.`userid`=`us`.`userid` " .
"WHERE (`u`.`userid`=".$_GET['ID'].")", $c)
OR die(mysql_error());
$attack_person = mysql_fetch_array($attacking_person);
$primarydamage = $db->query("SELECT * FROM `items` WHERE `itmid`=".$attack_person['equip_primary']."");
$ouch = $db->fetch_row($primarydamage);
$prim = ($attack_person['strength']+$ouch['weapon'])-($ir['guard']+$defense); // PRIMARY "weapon" Damage.
$secondarydamage = $db->query("SELECT * FROM `items` WHERE `itmid`=".$attack_person['equip_secondary']."");
$ouchy = $db->fetch_row($secondarydamage);
$second = ($attack_person['strength']+$ouchy['weapon'])-($ir['guard']+$defense); // Secondary "weapon" Damage.
if($attack_person['equip_primary'] > 0) { $killer = $prim; }
elseif($attack_person['equip_primary'] = 0 && $attack_person['equip_secondary'] > 0) { $killer = $second; }
else { $killer = $attack_person['strength'] - $ir['guard']; }
if($attack_person['equip_armor'] > 0) { $ayourarmorstuff = $db->query("SELECT * FROM `items` WHERE (`itmid`=".$attack_person['equip_armor'].")");
$adat = $db->fetch_row($ayourarmorstuff);
$adefense = $dat['armor']; }
else { $defense = 0; }
$aprimarydamage = $db->query("SELECT * FROM `items` WHERE `itmid`=".$ir['equip_primary']."");
$winn = $db->fetch_row($aprimarydamage);
$aprim = ($ir['strength']+$winn['weapon'])-($attack_person['guard']+$defense); // PRIMARY "weapon" Damage.
$asecondarydamage = $db->query("SELECT * FROM `items` WHERE `itmid`=".$ir['equip_secondary']."");
$win = $db->fetch_row($asecondary);
$secondd = ($ir['strength']+$win['weapon'])-($attack_person['guard']+$defense); // Secondary "weapon" Damage.
if($ir['equip_primary'] > 0) { $killers = $aprim; }
elseif($ir['equip_primary'] = 0 && $ir['equip_secondary'] > 0) { $killers = $secondd; }
else { $killers = $ir['strength'] - $ir['guard']; }
if(!mysql_num_rows($attacking_person)) { echo "Invalid User Selected to attack."; $h->endpage(); exit; }
$error = ($attack_person['location'] != $ir['location']) ? "You must be in the same city as the person you are attacking. Duh." : $error;
$error = ($attack_person['username'] == "") ? "That person doesn't exist." : $error;
$error = ($attack_person['hospital'] > 0) ? "You can't attack someone that is in the hospital." : $error;
$error = ($attack_person['jail'] > 0) ? "You can't attack someone that is in jail." : $error;
$error = ($ir['level'] > 5 && $attack_person['level'] < 6) ? "You can't attack someone that is level 5 or below because you are higher than level 5." : $error;
$error = ($ir['gang'] == $attack_person['gang'] AND $ir['gang'] != 0) ? "You cant attack someone in the same clan as yourself!" : $error;
$error = ($attack_person['hp'] <= 0) ? "This person has no health at the moment." : $error;
$error = ($attack_person['fedjail'] > 1) ? "This person is in fed and cannot be attacked." : $error;
$error = ($attack_person['user_level'] == 2) ? "Admins Cannot be attacked." : $error;
if (isset($error)){
echo "".htmlentities(stripslashes($error))."";
$h->endpage();
exit;
}
$yourhp = $ir['hp'];
$theirhp = $attack_person['hp'];
echo "<center>Fight House</center>
<center><font color=white>You are in a fight with ".$attack_person['username'].".</center>
";
$wait = ($ir['agility'] > $attack_person['agility']) ? 1 : 0;
while($yourhp > 0 && $theirhp > 0)
{
$damage = $killer;
$damage = ($damage < 1) ? 1 : $damage;
if($wait == 0)
{
$yourhp = $yourhp - $damage;
echo "<font color=white><center> " . $attack_person['username'] . " hit you for " . $damage . " damage using their Fists.
</center>"; // WEAPON STUFF HERE LATER.
}
else { $wait = 0; }
if($yourhp > 0)
{
$damage = $killers;
$damage = ($damage < 1) ? 1 : $damage;
$theirhp = $theirhp - $damage;
echo "<font color=white><center> You hit " . $attack_person['username'] . " for " . $damage . " damage using your Fists. </center>
";
}
if($theirhp <= 0){ // ATTACKER WINS AND UPDATES
$winner = $ir['userid'];
$theirhp = 0;
$moneywon = floor($attack_person['money'] /10);
$expwon = 150 - (25 * ($ir['level'] - $attack_person['level']));
$expwon = ($expwon < 0) ? 0 : $expwon;
$newexp = $expwon + $ir['exp'];
$newmoney = $ir['money'] + $moneywon;
$result = mysql_query("UPDATE `users` SET `exp` = ".$newexp.", money = ".$newmoney." WHERE (`userid`=".$ir['userid'].")", $c) or die(mysql_error());
$newmoney = $attack_person['money'] - $moneywon;
$result = mysql_query("UPDATE `users` SET `money` = ".$newmoney.", `hospital` = 10 WHERE (`userid`=".$attack_person['userid'].")", $c) or die(mysql_error());
event_add($attack_person['userid'], "You were hospitalized by ".$ir['username']." for 10 minutes.");
echo "<font color=white><center>You hospitalized " . $attack_person['username'] . ". You gain $expwon exp and stole $".$moneywon." from " . $attack_person['username'] . ".</center>";
}
if($yourhp <= 0){ // DEFENDER WINS AND UPDATES
$winner = $attack_person['userid'];
$yourhp = 0;
$moneywon = floor($ir['money'] /10);
$expwon = 100 - (25 * ($attack_person['level'] - $ir['level']));
$expwon = ($expwon < 0) ? 0 : $expwon;
$newexp = $expwon + $attack_person['exp'];
$newmoney = $attack_person['money'] + $moneywon;
$result = mysql_query("UPDATE `users` SET `exp` = ".$newexp.", `money` = ".$newmoney." WHERE (`userid`=".$attack_person['userid'].")", $c) or die(mysql_error());
$newmoney = $ir['money'] - $moneywon;
$result = mysql_query("UPDATE `users` SET `money` = '".$newmoney."',`hospital` = '20' WHERE (`userid`=".$ir['userid'].")", $c) or die(mysql_error());
event_add($ir['userid'], "You were hospitalized by ".$attack_person['username']." for 20 minutes.");
echo "<center><font color=white>".$attack_person['username']." Hospitalized you and stole $".$moneywon." from you.</center>";
}
}
//UPDATE USERS
$newenergy = $ir['energy'] - floor($ir['energy'] * .20);
$result = mysql_query("UPDATE `users` SET `hp` = ".$theirhp." WHERE (`userid`=".$attack_person['userid'].")", $c) or die(mysql_error());
$result = mysql_query("UPDATE `users` SET `hp` = ".$yourhp.", `energy` = '".$newenergy."' WHERE (`userid`=".$ir['userid'].")", $c) or die(mysql_error());
echo "</td></tr>";
?>