bot -> db -> query("CREATE TABLE IF NOT EXISTS " . $this -> bot -> db -> define_tablename("raid_points", "true") . " (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, points INT, raiding TINYINT DEFAULT '0', raidbot VARCHAR(20))"); $this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " . $this -> bot -> db -> define_tablename("raid_bidding", "true") . " (name VARCHAR(20), current INT, max INT)"); $this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " . $this -> bot -> db -> define_tablename("raid_loot_history", "true") . " (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20), loot VARCHAR(100), time INT(20), points INT)"); $this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " . $this -> bot -> db -> define_tablename("raid_history", "true") . " (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, raidleader VARCHAR(20), topic VARCHAR(100), points INT, raidtime INT(20))"); $this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " . $this -> bot -> db -> define_tablename("raider_history", "true") . " (id INT NOT NULL, name VARCHAR(20))"); $this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " . $this -> bot -> db -> define_tablename("raids", "true") . " (short VARCHAR(15), name VARCHAR(100), points INT)"); $this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " . $this -> bot -> db -> define_tablename("raid_list", "true") . " (name VARCHAR(20), id INT NOT NULL PRIMARY KEY)"); $this -> bot -> core("settings") -> create("Raid", "Points_To_Main", TRUE, "Do all alts share one point account?"); $this -> bot -> core("settings") -> create("Raid", "Running", FALSE, "Is a raid currently running?", "On:Off", TRUE); $this -> bot -> core("settings") -> create("Raid", "Locked", FALSE, "Is the currently running raid locked for new raidjoins?", "On:Off", TRUE); $this -> bot -> core("settings") -> create("Raid", "Done", FALSE, "Has points be given in this raid already?", "On:Off", TRUE); $this -> bot -> core("settings") -> create("Raid", "Start_Points", 5, "How many points do new members get on their first raid once?", "0;1;2;3;4;5;10"); $this -> bot -> core("settings") -> create("Raid", "Topic", "", "The topic of the currently running raid.", "", TRUE); $this -> bot -> core("settings") -> create("Raid", "Leader", "", "Who started the currently running raid?", "", TRUE); $this -> bot -> core("settings") -> create("Raid", "Time", 0, "The time the current raid got started.", "", TRUE); $this -> bot -> core("settings") -> create("Raid", "Name", "", "The short name for the currently running raid.", "", TRUE); $this -> bot -> core("settings") -> create("Raid", "Points", 0, "The amount of points awarded for a success of the current raid.", "", TRUE); $this -> bot -> core("settings") -> create("Raid", "Loot", "", "The currently rolled loot on this raid.", "", TRUE); $this -> bot -> core("settings") -> create("Raid", "Hidden_Rolling", TRUE, "Is the amount of points people bid on loot hidden or open during rolling?"); $this -> bot -> core("settings") -> create("Raid", "Bid_Cost", 1, "The amount of points bidding on an item costs.", "0;1;2;3;4;5"); $this -> bot -> core("settings") -> create("Raid", "Only_Increasing", FALSE, "Can bids only be revoked or increased, but never reduced below last own bid?"); $this -> bot -> core("settings") -> create("Raid", "Roll_Text", "To bid use /tell
bid #. To unbid use /tell  
unbid", "The informative text printed when bidding for an item is started.", "", TRUE);

		if ($this -> bot -> game == "ao")
		{
			$chan = "pgmsg";
		}
		else
		{
			$chan = "gc";
		}
		$this -> bot -> core("settings") -> create("Raid", "OutputChannel", $chan, "Which channel should be used as raid channel?", "gc;pgmsg;both");

		$this -> register_command('all', 'raidstart', 'LEADER');
		$this -> register_command('all', 'raidupdate', 'LEADER');
		$this -> register_command('all', 'raidadd', 'LEADER');
		$this -> register_command('all', 'raidjoin', 'MEMBER');
		$this -> register_command('all', 'raidleave', 'MEMBER');
		$this -> register_command('all', 'raidkick', 'LEADER');
		$this -> register_command('all', 'raidlist', 'MEMBER');
		$this -> register_command('all', 'raidloot', 'LEADER');
		$this -> register_command('all', 'raidpoints', 'LEADER');
		$this -> register_command('all', 'raidend', 'LEADER');
		$this -> register_command('all', 'raidloot', 'LEADER');
		$this -> register_command('all', 'raidlock', 'LEADER');
		$this -> register_command('all', 'raidroll', 'LEADER');
		$this -> register_command('all', 'raidabort', 'LEADER');

		$this -> register_command('tell', 'mypoint', 'MEMBER');
		$this -> register_command('tell', 'raidql', 'LEADER');
		$this -> register_command('tell', 'raidhistory', 'MEMBER');
		$this -> register_command('tell', 'raiderhistory', 'MEMBER');
		$this -> register_command('tell', 'bid', 'MEMBER');
		$this -> register_command('tell', 'unbid', 'MEMBER');
		$this -> register_command('tell', 'history', 'MEMBER');
		$this -> register_command('tell', 'raidadmin', 'ADMIN');

		$this -> register_alias('raidpoints', 'raiddone');
		$this -> register_alias('raidlock', 'raidclose');
		$this -> register_alias('mypoint', 'mypoints');

		$this -> help['description'] = 'Point per run based raid system.';
		$this -> help['command']['mypoint'] = "Shows you your current points";
		$this -> help['command']['raidstart'] = "Starts a new raid out of all existing raid types, with an empty raidlist.";
		$this -> help['command']['raidupdate'] = "Starts a new raid out of all existing raid types, keeping the current raidlist.";
		$this -> help['command']['raidadd '] = "Adds  to the raidlist, even if the raid is locked.";
		$this -> help['command']['raidjoin'] = "Adds yourself to the raidlist if the raid is not yet locked.";
		$this -> help['command']['raidleave'] = "Removes yourself from the raidlist.";
		$this -> help['command']['raidkick '] = "Removes  from the raidlist.";
		$this -> help['command']['raidlist'] = "Shows the current raidlist. If a roll is running it shows the current roll too.";
		$this -> help['command']['raidloot '] = "Starts the roll for .";
		$this -> help['command']['raidhistory'] = "Shows the last finished raids.";
		$this -> help['command']['history'] = "Shows the last won items.";
		$this -> help['command']['history '] = "Shows the last items  won.";
		$this -> help['command']['bid #'] = "Bids # of points for the currently rolled item.";
		$this -> help['command']['bid 0'] = "Remove your bid.";
		$this -> help['command']['unbid'] = "Remove your bid.";
		$this -> help['command']['raidpoints'] = "Gives points at the end of a successful raid.";
		$this -> help['command']['raidend'] = "Ends the current raid, deleting the raid list. Should be used after 
raidpoints.";
		$this -> help['command']['raidlock'] = "Locks the running raid, stopping people from adding themself to the raidlist.";
		$this -> help['command']['raidroll'] = "Ends the bidding for the currently rolled item and determines the winner.";
		$this -> help['command']['raidabort'] = "Aborts rolling the currently rolled item.";
		$this -> help['command']['raidadmin addraid   '] = "Adds a new raid to the list of available raids.  must be unique and can only contain letters.";
		$this -> help['command']['raidadmin delraid '] = "Deletes the raid  of the list of available raids.";
		$this -> help['command']['raidadmin raidstart  '] = "Starts a raid for  points and with  as description, without adding it to the list of available raids.";
		$this -> help['command']['raidadmin bidding (open|hidden)'] = "Sets bidding to open points or hidden points.";
		$this -> help['command']['raidadmin increase (true|false)'] = "Sets bidding to increase only with  or unconstrained bidding with .";
		$this -> help['notes'] = 'The This module is not compatible with the default BeBot raid system. To use you have to disable all the default BeBot raid modules.';

		$this -> bot -> core("colors") -> define_scheme("raid", "info", "lime");
		$this -> bot -> core("colors") -> define_scheme("raid", "title", "lightbeige");
		$this -> bot -> core("colors") -> define_scheme("raid", "text", "bluegray");
		$this -> bot -> core("colors") -> define_scheme("raid", "item", "darkaqua");
	}

	/*
	This gets called on a tell with the command
	*/
	function tell($name, $msg)
	{
		if (preg_match("/^mypoint$/i", $msg, $info))
			$this -> show_points($name);
		elseif (preg_match("/^raidadd (.+)$/i", $msg, $info))
			$this -> raid_add($info[1]);
		elseif (preg_match("/^raidjoin$/i", $msg, $info))
		{
			if (!($this -> bot -> core("settings") -> get("Raid", "Locked")))
				$this -> raid_add($name);
			else
				$this -> bot -> send_tell($name, "Raid is locked!");
		}
		elseif (preg_match("/^raidlist$/i", $msg, $info))
			$this -> bot -> send_tell($name, $this -> raid_list());
		elseif (preg_match("/^raidlock$/i", $msg, $info))
			$this -> raid_lock($name);
		elseif (preg_match("/^raidclose$/i", $msg, $info))
			$this -> raid_lock($name);
		elseif (preg_match("/^raidstart$/i", $msg, $info))
			$this -> raid_start($name, '');
		elseif (preg_match("/^raidstart (.+)$/i", $msg, $info))
			$this -> raid_start($name, $info[1]);
		elseif (preg_match("/^raidupdate (.+)$/i", $msg, $info))
			$this -> raid_update($name, $info[1]);
		elseif (preg_match("/^raidkick (.+)$/i", $msg, $info))
			$this -> raid_kick($info[1]);
		elseif (preg_match("/^raidleave$/i", $msg, $info))
			$this -> raid_kick($name);
		elseif (preg_match("/^bid ([0-9]+)$/i", $msg, $info))
			$this -> raid_bid($name, $info[1]);
		elseif (preg_match("/^unbid$/i", $msg, $info))
			$this -> raid_unbid($name);
		elseif (preg_match("/^raidhistory$/i", $msg, $info))
			$this -> bot -> send_tell($name, $this -> raid_history());
		elseif (preg_match("/^raiderhistory ([0-9]+)$/i", $msg, $info))
			$this -> bot -> send_tell($name, $this -> raider_history($info[1]));
		elseif (preg_match("/^history$/i", $msg, $info))
			$this -> bot -> send_tell($name, $this -> raid_loot_history(""));
		elseif (preg_match("/^history (.*)$/i", $msg, $info))
			$this -> bot -> send_tell($name, $this -> raid_loot_history($info[1]));
		elseif (preg_match("/^raidadmin addraid ([a-zA-Z]+) ([0123456789]+) (.*)$/i", $msg, $info))
			$this -> admin_add_raid($name, $info[1], $info[2], $info[3]);
		elseif (preg_match("/^raidadmin delraid ([a-zA-Z]+)$/i", $msg, $info))
			$this -> admin_del_raid($name, $info[1]);
		elseif (preg_match("/^raidadmin raidstart ([0123456789]+) (.*)$/i", $msg, $info))
			$this -> admin_raid_start($name, $info[1], $info[2]);
		elseif (preg_match("/^raidadmin bidding (open|hidden)$/i", $msg, $info))
			$this -> admin_set_bidding($name, $info[1]);
		elseif (preg_match("/^raidadmin increase (true|false)$/i", $msg, $info))
			$this -> admin_set_only_increase($name, $info[1]);

		return false;
	}
    
	/*
	This gets called on a group message with the command
	*/
	function command_handler($name, $msg, $origin)
	{
		if (preg_match("/^raidend$/i", $msg, $info))
			$this -> raid_end();
		elseif (preg_match("/^raidstart$/i", $msg, $info))
			$this -> raid_start($name, '');
		elseif (preg_match("/^raidstart (.+)$/i", $msg, $info))
			$this -> raid_start($name, $info[1]);
		elseif (preg_match("/^raidupdate (.+)$/i", $msg, $info))
			$this -> raid_update($name, $info[1]);
		elseif (preg_match("/^raidlock$/i", $msg, $info))
			$this -> raid_lock($name);
		elseif (preg_match("/^raidpoints$/i", $msg, $info))
			$this -> raid_points($name);
		elseif (preg_match("/^raidlist$/i", $msg, $info))
			$this -> bot -> send_output("", $this -> raid_list(), $this -> bot -> core("settings") -> get("Raid", "OutputChannel"));
		elseif (preg_match("/^raidadd (.+)$/i", $msg, $info))
			$this -> raid_add($info[1]);
		elseif (preg_match("/^raidjoin$/i", $msg, $info))
		{
			if (!($this -> bot -> core("settings") -> get("Raid", "Locked")))
				$this -> raid_add($name);
			else
				$this -> bot -> send_tell($name, "Raid is locked!");
		}
		elseif (preg_match("/^raidkick (.+)$/i", $msg, $info))
			$this -> raid_kick($info[1]);
		elseif (preg_match("/^raidleave$/i", $msg, $info))
			$this -> raid_kick($name);
		elseif (preg_match("/^raidloot (.+)$/i", $msg, $info))
			$this -> raid_loot($info[1]);
		elseif (preg_match("/^raidabort$/i", $msg, $info))
			$this -> raid_abort($name);
		elseif (preg_match("/^raidroll$/i", $msg, $info))
			$this -> raid_roll($name);

		return false;
	}

	function raid_add($who)
	{
		$who = ucfirst($who);
		// only if a raid is running can people be added, otherwise just ignore it silently
		// no need to check for lock, it's checked with raidjoin, and raidadd should be RL only
		if ($this -> bot -> core("settings") -> get("Raid", "Running"))
		{
			if ($this -> bot -> core("chat") -> get_uid($who))
			{
				$uid = $this -> points_to($who);

				$result = $this -> bot -> db -> select("SELECT * FROM #___raid_list WHERE id = " . $uid);
				if (!empty($result))
				{
					// player already in raidlist, perhaps with different char, just update name in list
					$this -> bot -> db -> query("UPDATE #___raid_list"
						. " SET name = '" . $who . "' WHERE id = " . $uid);
					$addtext = " is already in the raidlist!";
				}
				else
				{
					// player not in raidlist
					$this -> bot -> db -> query("INSERT IGNORE INTO #___raid_list"
						. " (name, id) VALUES ('" . $who . "', " . $uid . ")");
					$addtext = " has been added to the raidlist!";
				}

				$result = $this -> bot -> db -> select("SELECT * FROM #___raid_points WHERE id = " . $uid);

				$first_points = $this -> bot -> core("settings") -> get("Raid", "Start_points");

				if (empty($result))
					$this -> bot -> db -> query("INSERT INTO #___raid_points"
						. " (id, points, raiding, raidbot) VALUES (" . $uid . ", " . $first_points . ", 1, '"
						. $this -> bot -> botname . "')");
				else
					$this -> bot -> db -> query("UPDATE #___raid_points"
						. " SET raiding = 1, raidbot = '" . $this -> bot -> botname . "' WHERE id = " . $uid);

				$this -> bot -> send_output("", "##raid_info##" . $who . $addtext, $this -> bot -> core("settings") -> get("Raid", "OutputChannel"));
			}
		}
	}

	function raid_kick($who)
	{
		$who = ucfirst($who);
		if ($this -> bot -> core("settings") -> get("Raid", "Running"))
		{
			$this -> bot -> db -> query("DELETE FROM #___raid_list WHERE name = '" . $who . "'");
			$this -> bot -> db -> query("UPDATE #___raid_points SET raiding = 0 WHERE id = "
				. $this -> points_to($who));
			$this -> bot -> send_output("", "##raid_info##" . $who . " removed from raidlist!", $this -> bot -> core("settings") -> get("Raid", "OutputChannel"));
		}
	}

	function rolling()
	{
		$loot = $this -> bot -> core("settings") -> get("Raid", "Loot");
		if ($loot == '')
			return '';

		$retstr = "##raid_info##" . "The following people are rolling for "
			. stripslashes($loot) . ":
##raid_title##"; $rollers = $this -> bot -> db -> select("SELECT * FROM #___raid_bidding" . " WHERE current > 0 ORDER BY name ASC"); foreach ($rollers as $rolling) $retstr .= $rolling[0] . "
"; if (empty($rollers)) $count = 0; else $count = count($rollers); return " " . $this -> bot -> core("tools") -> make_blob("Roll in progress (" . $count . " bidding)!", $retstr); } function raid_list() { if ($this -> bot -> core("settings") -> get("Raid", "Running")) { $result = $this -> bot -> db -> select("SELECT * FROM #___raid_list" . " ORDER BY name ASC"); if (empty($result)) return "Raidlist emtpy!"; $count = $this -> bot -> db -> select("SELECT count(*) as cnt FROM #___raid_list"); $ret = "##raid_info##" . $count[0][0] . " people in the raidlist:
"; foreach ($result as $res) $ret .= $res[0] . "
"; return $this -> bot -> core("tools") -> make_blob("Raidlist (" . count($result) . ")", $ret) . $this -> rolling(); } else return "No raid in progress!"; } function raid_lock($name) { if ($this -> bot -> core("settings") -> get("Raid", "Running")) { $this -> bot -> core("settings") -> save("raid", "locked", TRUE); $this -> bot -> send_output("", "##raid_info##Raidlist locked! [by " . $name . "]", $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } } function raid_points($name) { if ($this -> bot -> core("settings") -> get("Raid", "Running") && !($this -> bot -> core("settings") -> get("Raid", "Done"))) { $result = $this -> bot -> db -> select("SELECT * FROM #___raid_list ORDER BY name ASC"); $this -> bot -> core("settings") -> save("raid", "done", TRUE); if (empty($result)) { $this -> bot -> send_output("", "Nobody raiding!",$this -> bot -> core("settings") -> get("Raid", "OutputChannel")); return; } $this -> bot -> db -> query("UPDATE #___raid_points set points = points + " . $this -> bot -> core("settings") -> get("Raid", "Points") . " WHERE raiding = 1 AND raidbot = '" . $this -> bot -> botname . "'"); // save raid in raidhistory $currenttime = time(); $this -> bot -> db -> query("INSERT INTO #___raid_history" . " (raidleader, topic, points, raidtime) VALUES ('" . $name . "', '" . $this -> bot -> core("settings") -> get("Raid", "Topic") . "', " . $this -> bot -> core("settings") -> get("Raid", "Points") . ", " . $currenttime . ")"); $rhistory = $this -> bot -> db -> select("SELECT * FROM #___raid_history" . " WHERE raidtime = " . $currenttime . " AND raidleader = '" . $name . "' AND topic = '" . $this -> bot -> core("settings") -> get("Raid", "Topic") . "'"); $raidid = $rhistory[0][0]; // give list out, and add all raider to the history: $blob = "##raid_title##" . $this -> bot -> core("settings") -> get("Raid", "Points") . " points give to:
" . "##raid_text##"; foreach ($result as $raider) { $blob .= $raider[0] . "
"; $this -> bot -> db -> query("INSERT INTO #___raider_history" . " (id, name) VALUES (" . $raidid . ", '" . $raider[0] . "')"); } $this -> bot -> send_output("", $this -> bot -> core("tools") -> make_blob($this -> bot -> core("settings") -> get("Raid", "Points") . " points awarded!", $blob), $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } } function raid_end() { $this -> bot -> core("settings") -> save("raid", "running", FALSE); $this -> bot -> core("settings") -> save("raid", "locked", FALSE); $this -> bot -> core("settings") -> save("raid", "done", FALSE); $this -> bot -> core("settings") -> save("raid", "points", 0); $this -> bot -> core("settings") -> save("raid", "topic", ""); $this -> bot -> core("settings") -> save("raid", "leader", ""); $this -> bot -> core("settings") -> save("raid", "name", ""); $this -> bot -> core("settings") -> save("raid", "loot", ""); $this -> bot -> db -> query("TRUNCATE TABLE #___raid_list"); $this -> bot -> db -> query("TRUNCATE TABLE #___raid_bidding"); $this -> bot -> db -> query("UPDATE #___raid_points SET raiding = 0 WHERE raidbot = '" . $this -> bot -> botname . "'"); $this -> bot -> send_output("", "##raid_info##Raid ended!", $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } function do_new_raid($name, $title, $raidtitle, $points) { $this -> bot -> core("settings") -> save("raid", "topic", $raidtitle); $this -> bot -> core("settings") -> save("raid", "running", TRUE); $this -> bot -> core("settings") -> save("raid", "locked", FALSE); $this -> bot -> core("settings") -> save("raid", "points", $points); $this -> bot -> core("settings") -> save("raid", "done", FALSE); $this -> bot -> core("settings") -> save("raid", "leader", $name); $this -> bot -> core("settings") -> save("raid", "time", time()); $this -> bot -> core("settings") -> save("raid", "name", $title); $this -> bot -> core("settings") -> save("raid", "points", $points); $this -> bot -> core("settings") -> save("raid", "loot", ""); $this -> bot -> db -> query("TRUNCATE TABLE #___raid_bidding"); } function raid_start($name, $title) { $raid = $this -> bot -> db -> select("SELECT * FROM #___raids WHERE short = '" . $title . "'"); // if no raid chosen, show a list with all raids: if (empty($raid)) { $blob = ''; $raids = $this -> bot -> db -> select("SELECT * FROM #___raids ORDER BY name ASC"); foreach ($raids as $raid) $blob .= $this -> bot -> core("tools") -> chatcmd("raidstart " . $raid[0], $raid[1] . " [" . $raid[2] . " points]") . "
"; $this -> bot -> send_tell($name, $this -> bot -> core("tools") -> make_blob("Please choose a valid raid!", $blob)); } else { $this -> do_new_raid($name, $title, $raid[0][1] . " [" . $raid[0][2] . " points]", $raid[0][2]); $this -> bot -> db -> query("TRUNCATE TABLE #___raid_list"); $this -> bot -> db -> query("UPDATE #___raid_points" . " SET raiding = 0 WHERE raidbot = '" . $this -> bot -> botname . "'"); $this -> bot -> send_output("", "##raid_info##Raid started: " . $raid[0][1] . " [" . $raid[0][2] . " points] [by " . $name . "]", $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } } function raid_update($name, $title) { $raid = $this -> bot -> db -> select("SELECT * FROM #___raids WHERE short = '" . $title . "'"); if (!empty($raid)) { $this -> do_new_raid($name, $title, $raid[0][1] . " [" . $raid[0][2] . " points]", $raid[0][2]); $this -> bot -> send_output("", "##raid_info##Raid updated: " . $raid[0][1] . " [" . $raid[0][2] . " points] [by " . $name . "]", $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } } function id_bio($realword) { if (ereg("Solid Clump of Kyr'Ozch Bio-Material",$realword)) { $idql = str_replace("Solid Clump of Kyr'Ozch Bio-Material","",$idql); $splitidql = split('/',$idql); $lid = $splitidql[0]; $hid = $splitidql[1]; $ql = $splitidql[2]; switch ($hid) { case 247103: $type = "Pristine Kyr'Ozch Bio-Material (DNA soup)"; break; case 247105: $type = "Mutated Kyr'Ozch Bio-Material (DNA soup)"; break; case 247698: $type = "Kyr'Ozch Bio-Material - Type 76 (Weapon Upgrade) / Brawl and Fast Attack"; break; case 247700: $type = "Kyr'Ozch Bio-Material - Type 112 (Weapon Upgrade) / Brawl, Dimach and Fast Attack"; break; case 247702: $type = "Kyr'Ozch Bio-Material - Type 240 (Weapon Upgrade) / Brawl, Dimach, Fast Attack and Sneak Attack"; break; case 247704: $type = "Kyr'Ozch Bio-Material - Type 880 (Weapon Upgrade) / Dimach, Fast Attack, Parry and Riposte"; break; case 247706: $type = "Kyr'Ozch Bio-Material - Type 992 (Weapon Upgrade) / Dimach, Fast Attack, Sneak Attack, Parry and Riposte"; break; case 247708: $type = "Kyr'Ozch Bio-Material - Type 1 (Weapon Upgrade) / Fling shot"; break; case 247710: $type = "Kyr'Ozch Bio-Material - Type 2 (Weapon Upgrade) / Aimed Shot"; break; case 247712: $type = "Kyr'Ozch Bio-Material - Type 4 (Weapon Upgrade) / Burst"; break; case 247714: $type = "Kyr'Ozch Bio-Material - Type 5 (Weapon Upgrade) / Fling Shot and Burst"; break; case 247716: $type = "Kyr'Ozch Bio-Material - Type 12 (Weapon Upgrade) / Burst and Full Auto"; break; case 247718: $type = "Kyr'Ozch Bio-Material - Type 3 (Weapon Upgrade) / Fling Shot and Aimed Shot"; break; case 247720: $type = "Kyr'Ozch Bio-Material - Type 13 (Weapon Upgrade) / Burst, Fling Shot and Full Auto"; break; case 254804: $type = "Kyr'Ozch Viral Serum (Making high QL buildings)"; break; default: $type = "Unidentified"; } return "QL ".$ql." of ".$type; } return ""; } function raid_loot($loot) { if (!($this -> bot -> core("settings") -> get("Raid", "Running"))) return; $this -> bot -> db -> query("TRUNCATE TABLE #___raid_bidding"); if ($this -> id_bio($loot) != '') $loot = $this -> id_bio($loot); $loot = mysql_real_escape_string(str_replace('"', "'", $loot)); $this -> bot -> core("settings") -> save("raid", "loot", $loot); $this -> bot -> send_output("", "##raid_info##Roll on " . stripslashes($loot) . " started!
" . $this -> bot -> core("settings") -> get("Raid", "Roll_text") . "
Point cost for bidding: " . $this -> bot -> core("settings") -> get("Raid", "Bid_cost"), $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } function raid_abort($name) { $loot = $this -> bot -> core("settings") -> get("Raid", "Loot"); if ($loot != '') { $this -> bot -> core("settings") -> save("raid", "loot", ""); $this -> bot -> db -> query("TRUNCATE TABLE #___raid_bidding"); $this -> bot -> send_output("", "##raid_info##Roll for " . stripslashes($loot) . " aborted by " . $name . "!", $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } } function raid_bid($name, $points) { $loot = $this -> bot -> core("settings") -> get("Raid", "Loot"); $bidcost = $this -> bot -> core("settings") -> get("Raid", "Bid_cost"); $hidden = $this -> bot -> core("settings") -> get("Raid", "Hidden_rolling"); if ($loot != '') { $res = $this -> bot -> db -> select("SELECT * FROM #___raid_list" . " WHERE name = '" . $name . "'"); if (empty($res)) { $this -> bot -> send_tell($name, "You are not in the raidlist!"); return; } if ($points == 0) { $this -> raid_unbid($name); return; } $id = $this -> points_to($name); $idpts = $this -> bot -> db -> select("SELECT points FROM #___raid_points WHERE id = " . $id); if ($points < 0 || $points > $idpts[0][0] - $bidcost) { $maxpoints = $idpts[0][0] - $bidcost; $this -> bot -> send_tell($name, "You can only bid between 0 and " . $maxpoints . " points!"); return; } $currentbid = $this -> bot -> db -> select("SELECT * FROM #___raid_bidding WHERE name = '" . $name . "'"); if (empty($currentbid)) { $this -> bot -> db -> query("INSERT INTO #___raid_bidding" . " (name, current, max) VALUES ('" . $name . "', " . $points . ", " . $points . ")"); $retstr = $name . " is bidding"; if ($hidden) $retstr .= "!"; else $retstr .= " " . $points . " points!"; } else { if ($this -> bot -> core("settings") -> get("Raid", "Only_increasing") == 'true') { if ($points < $currentbid[0][2]) { $this -> bot -> send_tell($name, "You need to bid at least the same as your last bid of " . $currentbid[0][2] . " points!"); return; } } $this -> bot -> db -> query("UPDATE #___raid_bidding" . " SET current = " . $points . ", max = " . $points . " WHERE name = '" . $name . "'"); $retstr = $name . " has updated the bid"; if ($hidden) $retstr .= "!"; else $retstr .= " to " . $points . " points!"; } if ($hidden) $this -> bot -> send_tell($name, "Your bid over " . $points . " points is accepted!"); $this -> bot -> send_output("", "##raid_info##" . $retstr, $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } } function raid_unbid($name) { $loot = $this -> bot -> core("settings") -> get("Raid", "Loot"); if ($loot != '') { $this -> bot -> db -> query("UPDATE #___raid_bidding SET current = 0 WHERE name = '" . $name . "'"); $this -> bot -> send_tell($name, "You have left the bidding!"); $this -> bot -> send_output("", $name . " has unbid!", $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } } function do_rolls($number) { for ($i = 1; $i <= $number; $i++) { $rolls[$i] = 0; } for ($i = 0; $i < 10000; $i++) { $rolls[mt_rand(1, $number)]++; } $maxpoints = 0; $winner = 0; $onlyone = true; do { for ($i = 1; $i <= $number; $i++) { if ($rolls[$i] == $maxpoints) { $onlyone = false; } elseif ($rolls[$i] > $maxpoints) { $maxpoints = $rolls[$i]; $winner = $i; $onlyone = true; } } if (!($onlyone)) { $rolls[mt_rand(1, $number)]++; } } while (!($onlyone)); return $winner; } function raid_roll($name) { $blue = "##raid_item##"; $green = "##raid_info##"; $loot = $this -> bot -> core("settings") -> get("Raid", "Loot"); if ($loot == '') return; // Make sure someone is bidding at all (at least one current bid off 1 or more): $ret = $this -> bot -> db -> select("SELECT * FROM #___raid_bidding WHERE current > 0"); if (empty($ret)) { // clear roll. $this -> bot -> core("settings") -> save("raid", "loot", ""); $this -> bot -> db -> query("TRUNCATE TABLE #___raid_bidding"); $this -> bot -> send_output("", $green . "Nobody rolling! Item cleared!", $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); return; } // get the maximum bid (it definitly exists, as otherwise we wouldn't be here): $maxbid = $this -> bot -> db -> select("SELECT MAX(current) FROM #___raid_bidding WHERE current > 0"); // get all bidders that did that maximum bid: $rolls = $this -> bot -> db -> select("SELECT * FROM #___raid_bidding" . " WHERE current = " . $maxbid[0][0] . " ORDER BY name ASC"); if (count($rolls) > 1) { // do roll between highest! $winner = $this -> do_rolls(count($rolls)) - 1; $winname = $rolls[$winner][0]; $winnerstr = $green . "Winner is " . $blue . $rolls[$winner][0] . $green . "
Flatrolled between the following, as they had the same bid:
##raid_title##"; foreach ($rolls as $roll) $winnerstr .= $roll[0] . "
"; } else { $winner = 0; $winname = $rolls[0][0]; $winnerstr = $green . "Winner is " . $blue . $rolls[0][0] . "
"; } $bidcost = $this -> bot -> core("settings") -> get("Raid", "Bid_cost"); // get all bidders to list and take cost for bidding of: $bidders = $this -> bot -> db -> select("SELECT * FROM #___raid_bidding" . " WHERE current > 0 ORDER BY name ASC"); $winnerstr .= $green . "
The following people were deducted the bidding cost of " . $bidcost . ":
##raid_title##"; foreach ($bidders as $bidded) { $uid = $this -> points_to($bidded[0]); $this -> bot -> db -> query("UPDATE #___raid_points SET points = points - " . $bidcost . " WHERE id = " . $uid); $winnerstr .= $bidded[0] . "
"; } // add winner to history: $this -> bot -> db -> query("INSERT INTO #___raid_loot_history" . " (name, loot, time, points) VALUES ('" . $winname . "', '" . mysql_real_escape_string($loot) . "', " . time() . ", " . $maxbid[0][0] . ")"); // deduct the bid of the winner: $this -> bot -> db -> query("UPDATE #___raid_points SET points = points - " . $maxbid[0][0] . " WHERE id = " . $this -> points_to($winname)); $this -> bot -> send_tell($winname, "Congratulation! You won " . stripslashes($loot) . " with your bid of " . $maxbid[0][0] . " points! The bid has been deducted of your points."); // and finally clear the bidding tables. $this -> bot -> core("settings") -> save("raid", "loot", ""); $this -> bot -> db -> query("TRUNCATE TABLE #___raid_bidding"); $this -> bot -> send_output("", $green . "Winner of " . $loot . " is " . $blue . $winname . $green . " with a bid of " . $blue . $maxbid[0][0] . $green . "! " . $this -> bot -> core("tools") -> make_blob("More information", $winnerstr), $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } /* Lists the last 20 raids that happened */ function raid_history() { $white = "##raid_title##"; $grey = "##raid_text##"; $raids = $this -> bot -> db -> select("SELECT * FROM #___raid_history ORDER BY raidtime DESC LIMIT 20"); if (empty($raids)) return "There never was a raid!"; $raidstr = ''; foreach ($raids as $raid) { $raidstr .= $this -> bot -> core("tools") -> chatcmd("raiderhistory " . $raid[0], $raid[2]); $raidstr .= $grey . " led by " . $white . $raid[1] . "\n"; $raidstr .= $grey . gmdate($this -> bot -> core("settings") -> get("Time", "FormatString"), $raid[4]) . "\n\n"; } return $this -> bot -> core("tools") -> make_blob("Last 20 raids in " . $this -> bot -> botname, $raidstr); } /* Lists all people in the raidlist of a specific raid: */ function raider_history($id) { $raiders = $this -> bot -> db -> select("SELECT name FROM #___raider_history" . " WHERE id = " . $id . " ORDER BY name ASC"); if (empty($raiders)) return "Nobody participated!"; $raiderstr = "##raid_text##"; foreach ($raiders as $raider) { $raiderstr .= $raider[0] . "\n"; } return $this -> bot -> core("tools") -> make_blob("Participants", $raiderstr); } /* Shows the last 20 items won by $name - or last 20 total if no name is given */ function raid_loot_history($name) { $white = "##raid_title##"; $grey = "##raid_text##"; $lightblue = "##raid_item##"; if ($name == '') $wherestr = "1"; else $wherestr = "name = '" . $name . "'"; $items = $this -> bot -> db -> select("SELECT * FROM #___raid_loot_history" . " WHERE " . $wherestr . " ORDER BY time DESC LIMIT 20"); if (empty($items)) return "No items won!"; $lootstr = ''; foreach ($items as $item) { $lootstr .= $white . $item[1] . $grey . " won " . $lightblue . stripslashes($item[2]) . $grey . " for "; $lootstr .= $white . $item[4] . $grey . " points\n"; $lootstr .= $grey . gmdate($this -> bot -> core("settings") -> get("Time", "FormatString"), $item[3]) . "\n\n"; } return $this -> bot -> core("tools") -> make_blob("Last 20 items won", $lootstr); } /* Shows your points */ function show_points($name) { $result = $this -> bot -> db -> select("SELECT points FROM #___raid_points WHERE id = " . $this -> points_to($name)); if (empty($result)) $text = "You have never joined a raid!"; else $text = "You have " . $result[0][0] . " points."; $this -> bot -> send_tell($name, $text); } /* Get correct char for points */ function points_to($name) { if (!($this -> bot -> core("settings") -> get("Raid", "Points_to_main"))) return $this -> bot -> core("chat") -> get_uid($name); return $this -> bot -> core("chat") -> get_uid($this -> bot -> core("alts") -> main($name)); } /* Adds a new raid to the list */ function admin_add_raid($name, $short, $points, $title) { $retstr = ''; $res = $this -> bot -> db -> select("SELECT short FROM #___raids where short = '" . $short . "'"); if (!(empty($res))) { $this -> bot -> send_tell($name, $short . " already exists as short name for a raid, it has to be unique!"); return; } if ($points <= 0) { $this -> bot -> send_tell($name, $points . " is an illegal point reward for the raid, the reward has to be greater then zero!"); return; } $this -> bot -> db -> query("INSERT INTO #___raids (short, name, points) VALUES " . " ('" . $short . "', '" . mysql_escape_string($title) . "', " . $points . ")"); $this -> bot -> send_tell($name, "##raid_item##". $title . "##end##" . " added as new raid with the shortcut##raid_item## " . $short . "##end## and point reward of ##raid_item##" . $points . "##end##"); } /* Deletes a raid out of the list */ function admin_del_raid($name, $short) { $res = $this -> bot -> db -> select("SELECT short FROM #___raids where short = '" . $short . "'"); if (empty($res)) { $this -> bot -> send_tell($name, $short . " does not exists as short name for a raid!"); return; } $this -> bot -> db -> query("DELETE FROM #___raids WHERE short = '" . $short . "'"); $this -> bot -> send_tell($name, "##raid_item##" . $short . "##end## deleted as raid!"); } /* Allows an admin to start a raid without entering it into the raid table, e.g. to refund points lost */ function admin_raid_start($name, $points, $title) { $title = mysql_escape_string($title); $this -> do_new_raid($name, "adminraid", $title . " [" . $points . " points]", $points); $this -> bot -> db -> query("TRUNCATE TABLE #___raid_list"); $this -> bot -> db -> query("UPDATE #___raid_points" . " SET raiding = 0 WHERE raidbot = '" . $this -> bot -> botname . "'"); $this -> bot -> send_output("", "##raid_info##Raid started: " . $title . " [" . $points . " points] [by " . $name . "]", $this -> bot -> core("settings") -> get("Raid", "OutputChannel")); } /* Sets bidding to open or hidden */ function admin_set_bidding($name, $hidden) { if (strtolower($hidden) == 'hidden') $hid_roll = TRUE; else $hid_roll = FALSE; $this -> bot -> core("settings") -> save("raid", "hidden_rolling", $hid_roll); $this -> bot -> send_tell($name, "Hidden rolling set to " . $hid_roll); } /* Toggles whether bids can only be increased or bidder are free to lower too */ function admin_set_only_increase($name, $inc) { if (strtolower($inc) == 'true') $h = TRUE; else $h = FALSE; $this -> bot -> core("settings") -> save("raid", "only_increasing", $h); $this -> bot -> send_tell($name, "Only increasing bids set to " . strtolower($inc)); } } ?>