Location: PHPKode > projects > Dominant Creature RPG > class/redundant_hunt.txt
		if (empty($huntID) OR preg_match("/[^0-9]+/", $huntID)) {

			echo "<table align='center'><tr><td>Invalid action or no hunt exists</td></tr></table>";}



			else {

					

				// here goes big, clumsy data preparation :)

					

				//echo $huntID;



				$q = mysql_query("

		SELECT

			*

		FROM

			creature_hunts

		WHERE

			id = $huntID

		");



				$battle = mysql_fetch_assoc($q);



				$a = mysql_query("SELECT * FROM player_creatures WHERE user_id = '".$battle[uid]."'");

				$d = mysql_query("SELECT * FROM player_creatures WHERE user_id = '".$battle[tid]."'");

				$att = mysql_fetch_assoc($a);

				$def = mysql_fetch_assoc($d);



				if ($battle[active] != 1 ) {

					echo "<table align='center'><tr><td>Invalid action or no hunt exists</td></tr></table>"; exit;

				}





				echo "<table width='500' align='left' border='0'>";

				echo "<tr><td colspan='2' style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'><center>Battle details</center></td></tr>";





				// Izvadi sve potrebne podatke iz attack_types, i skills itd.

				$i = 1;

				while ($i <= 6) {

					$a = "a$i";

					$d = "d$i";

					$aty = mysql_query("

		SELECT id, name, opposite FROM attack_types WHERE id = '".$battle[$a]."'

		");		

					$dty = mysql_query("

		SELECT id, name, opposite FROM attack_types WHERE id = '".$battle[$d]."'

		");		

					$att_a[$i] = mysql_fetch_assoc($aty);

					$def_a[$i] = mysql_fetch_assoc($dty);



					$i++;

				}



				// begin output



				$max = 6;

				$t = 1;

				$a_max_dmg = 0;

				$d_max_dmg = 0;

				while ($t <= $max) {



					if ($att[speed] > $def[speed]) {

						$firstC = $att; $secondC = $def;

						$firstA = $att_a; $secondA = $def_a;

					} else {

						$firstC = $def; $secondC = $att;

						$firstA = $def_a; $secondA = $att_a;

					}



					// basically what we have here is sorted mess: $firstC (first creature to strike and stats) and

					// $firstA as attacks for first creature. Also, same is for second.



					if ($firstA[$t] == "") {

						$firstA[$t][name] = "no action";

					}

					if ($secondA[$t] == "") {

						$secondA[$t][name] = "no action";

					}



					echo "<tr><td>".$firstC[name]." attacked with ". $firstA[$t][name] . "<br />

			 ".$secondC[name]." responded with " . $secondA[$t][name] . "</td>";



					if ($secondA[$t][id] == $firstA[$t][opposite]) {$ddmg[$t] = " blocked attack";}



					else



					if ($firstA[$t][id] == $secondA[$t][opposite]) {$admg[$t] = 0 . ", was blocked";}



					else {

						// add opponent defence into equasion

						$adm[$t] = rand((($firstC[att] - $secondC[def]) / 3), (int)(($firstC[att] - ($secondC[def] - 1)) * 1.25));

						$ddm[$t] = rand((($secondC[att] - $firstC[def]) / 3), (int)(abs(($secondC[att] - 1) - $firstC[def]) * 1.25));

							

						$admg[$t] = " dealt ".$adm[$t]. " damage";

						$ddmg[$t] = " dealt ".$ddm[$t]. " damage";

					}

					if (empty($admg[$t])) {$admg[$t] = 0;}

					echo"<td>".$firstC[name]." dealt ".$admg[$t]."<br />".$secondC[name].$ddmg[$t] ."</td></tr>";





					$a_max_dmg = $a_max_dmg + $adm[$t];

					$d_max_dmg = $d_max_dmg + $ddm[$t];



					$t++;

				}





				echo $firstC[name] . " vs. " . $secondC[name];



				/*       Battle queries       */





				if ($a_max_dmg >= $def[hp]) {

						

					echo $a_max_dmg >= $def[hp];

						

					//gold plunder calc

					$gold_won = (int)($def[gold] * (rand(450, 500)/1000));

					$gold_total = $att[gold] + $gold_won;

					$gold_left = $def[gold] - $gold_won;

					if ($def[gold] <= 0) {$def[gold] = 0;}



					//exp plunder calc

					$exp_gained = 12 * $def[level];

					$exp_total = $att[exp] + $exp_gained;

						

					$ahp_left = $def[hp] - $a_max_dmg; if ($ahp_left <= 0) {$ahp_left = 0;}

					$dhp_left = $att[hp] - $d_max_dmg; if ($dhp_left <= 0) {$dhp_left = 0;}

						

						

					//echo $att[name] . " killed " . $def[name];

					//target first

					$update1 = mysql_query("UPDATE player_creatures SET hp = '$dhp_left', gold = '$gold_left' WHERE id = '".$def[id]."'");

					//attacker then



					$update2 = mysql_query("UPDATE player_creatures SET hp = '". $ahp_left ."', exp = '$exp_total', gold = '$gold_total' WHERE id = '".$att[id]."'");



					$this->win = $att[id];





				}

				else



				if ($d_max_dmg >= $att[hp]) {



					echo $d_max_dmg >= $att[hp];

						

					//gold plunder calc  - something goes wrong and attacker gets killed

					$gold_won = (int)($att[gold] * (rand(450, 500)/1000));

					$gold_total = $def[gold] + $gold_won;

					$gold_left = $att[gold] - $gold_won;

					if ($att[gold] <= 0) {$att[gold] = 0;}



					//exp plunder calc

					$exp_gained = 12 * $att[level];

					$exp_total = $def[exp] + $exp_gained;

						

					$ahp_left = $def[hp] - $a_max_dmg; if ($ahp_left <= 0) {$ahp_left = 0;}

					$dhp_left = $att[hp] - $d_max_dmg; if ($dhp_left <= 0) {$dhp_left = 0;}

						

						

					//echo $def[name] . " killed " . $att[name];

					//looser first

					$update1 = mysql_query("UPDATE player_creatures SET hp = '$ahp_left', gold = '$gold_left' WHERE id = '".$att[id]."'");

						

					//winner then



					$update2 = mysql_query("UPDATE player_creatures SET hp = '". $dhp_left ."', exp = '$exp_total', gold = '$gold_total' WHERE id = '".$def[id]."'");



					$this->win = $def[id];











				}



				else {



					echo "nothing";

						

					//gold plunder calc

					$gold_won = (int)($def[gold] * (rand(50, 100)/1000)); // only a 5-10% of gold can be snitched instead of plundered

					$gold_total = $att[gold] + $gold_won;

					$gold_left = $def[gold] - $gold_won;

					if ($def[gold] <= 0) {$def[gold] = 0;}



					//exp plunder calc

					$exp_gained = 3 * $def[level]; // and a small amount of exp only.

					$exp_total = $att[exp] + $exp_gained;

						

					echo $gold_won;

					echo $exp_gained;

						

					$ahp_left = $def[hp] - $a_max_dmg;

					$dhp_left = $att[hp] - $d_max_dmg;

						

						

					//target first

					$update1 = mysql_query("UPDATE player_creatures SET hp = '". $dhp_left ."', gold = '$gold_left' WHERE id = '".$secondC[id]."'");

					//attacker then



					$update2 = mysql_query("UPDATE player_creatures SET hp = '". $ahp_left ."', exp = '$exp_total', gold = '$gold_total' WHERE id = '".$firstC[id]."'");



					$this->win = 0;

						





				}



				// set attack to inactive, so it can't be repeated



				$ia2 = mysql_query("UPDATE creature_hunts SET active = '0', gold = '$gold_won', exp = '$exp_gained', winner = '".$this->win."' WHERE id = '$huntID'");





				/*    Then we output all, depending on outcome     */



				echo "<tr><td colspan='2' style='padding-top: 4px; border-top: 1px solid #ccc;'>

		In total, ".$att[name]." dealt $a_max_dmg damage and suffered $d_max_dmg HP of damage<br />

		$gold_won gold plundered and $exp_gained exp gained.</td></tr>";





			} // else end



			echo "</table>";
Return current item: Dominant Creature RPG