Location: PHPKode > projects > Dominant Creature RPG > class/raid_class.php
<?php

require_once ("data_class.php");



class Raid extends Data {

	

	

	function Init() {

		

		$this->GetUserData();

		

	}

	

	function CheckTime($timeLeft, $raidData, $creature) {

		

		if ($timeLeft <= 0) {

			

			$this->gold = rand (1, 1000);

			$this->exp = rand(1,30);

			

			$this->item = 1;

			

			$w = mysql_query("

			UPDATE village_raids SET 

			rfrom = 0, 

			rto = 0, 

			active = 0, 

			gold = '$this->gold', 

			exp = '$this->exp',

			item = '$this->item'

			WHERE uid = '".$_SESSION["id"]."' AND id = '".$this->raid[id]."'");

			

			$p = mysql_query("UPDATE player_creatures SET exp = exp + $this->exp, gold = gold + $this->gold, current_action = 'Doing nothing special...' WHERE user_id = '".$_SESSION["id"]."'");

			

			

			

			echo "Raid done. <br />

			You have collected $this->gold gold,<br />

			and earned $this->exp experience.";

			

		} else {

			

			echo "Raid in progress...($timeLeft seconds left...)";

			echo "<br /><a href='#'>Cancel</a>";

		}

		

	}

	

	function CheckRaid() {

		

		$this->Init();

		

		$c = mysql_query("SELECT * FROM village_raids WHERE uid = '".$_SESSION["id"]."' AND active = 1");

		if (mysql_num_rows($c) == 1) {

			

		$this->raid = mysql_fetch_assoc($c);

		

		$this->TimeLeft = $this->raid[rto] - time();

		

		$this->CheckTime($this->TimeLeft, $this->raid, $this->creature);

			

		} else {

		echo " <input type='submit' name='go_raid' value='Go berserk'/>";

		echo '

		<select name="raidtime">

					<option value="30">1 Turn</option>

					<option value="60">2 Turns</option>

					<option value="90">3 Turns</option>

					<option value="150">5 Turns</option>

					<option value="300">10 Turns</option>

		</select>';

		}

		

	}

	

	function RaidVillage() {

		

		$this->time = $_POST["raidtime"];

		$this->turns = $this->time/30;

		$this->from = time();

		$this->to = $this->from + $this->time;

		

		$c = mysql_query("SELECT * FROM village_raids WHERE uid = '".$_SESSION["id"]."' AND active = 1");

		if (mysql_num_rows($c) > 1) {

		echo "Cannot do multiple raids in same time";	

		}

		else {

		$do = mysql_query("

		INSERT INTO village_raids 

		VALUES ('' , '".$_SESSION["id"]."', '1', '$this->from', '$this->to', '', '', '');

		");

		$p = mysql_query("UPDATE player_creatures SET current_action = 'Raiding a nearby Village...'");

		

		$t = mysql_query("UPDATE users SET turns = turns - ".$this->turns."");

		

		echo "Raid stated.";

		}

	}

	

	function RaidSome() {

		

		$this->Init();



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

		echo "<form action='?p=raid' method='post'>";

		echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Village raiding: </td></tr><tr>";

		echo "<td>";

		if (isset($_POST["go_raid"])) {

		$this->RaidVillage();

		}

		else {

		$this->CheckRaid();

		}

		echo "</td></tr>";

		echo "</form>";

		echo "</table>";

		}



	

	function Intro() {

		

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

		echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Village raiding overview: </td></tr><tr>";

		echo "<td>Here you can raid villages near you</td></tr><tr>";

		echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Latest raids:</td></tr><tr>";

		

		$r = mysql_query("

		SELECT player_creatures.name, 

		       player_creatures.user_id, 

			   village_raids.uid, 

			   village_raids.gold, 

			   village_raids.exp, 

			   village_raids.item, 

			   shop_items.iname

		FROM player_creatures, village_raids, shop_items

		WHERE 

			village_raids.item = shop_items.id

			AND village_raids.uid = '".$_SESSION["id"]."'

			AND village_raids.uid = player_creatures.user_id

		ORDER BY village_raids.id DESC

		LIMIT 5 ");

		

		$max = mysql_num_rows($r);

		$i = 1;

		while ($i <= $max) {

		$this->raids[$i] = mysql_fetch_assoc($r);

		echo "<td>".$this->raids[$i][name].", Gold: ".$this->raids[$i][gold].", Exp: ".$this->raids[$i][exp].", Item: ".$this->raids[$i][iname]."</td></tr><tr>";

		$i++;	

		}

		echo "</tr></table>";		

		

		$this->RaidSome();

		

	}

	

	

}

?>
Return current item: Dominant Creature RPG