Ok, working in all my bots now. I will post the changes I've made. I have added the orbital strike info (stolen from
here), changed a little with colors to match what I like, and for my use I always relay to both gc, pgroup, and irc so added that in (easy to remove that part if you don't want it).
<?php
/*
* TowerAttack.php - Handle Tower attack events.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stensås, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
*
* See Credits file for all aknowledgements.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* File last changed at $LastChangedDate$
* Revision: $Id$
*/
/*
Needed for TowerAttack
*/
$db -> query("CREATE TABLE IF NOT EXISTS " . $db -> define_tablename("tower_attack", "true") . "
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
time int,
off_guild VARCHAR(50),
off_side VARCHAR(10),
off_player VARCHAR(20),
off_level int,
off_profession VARCHAR(15),
def_guild VARCHAR(50),
def_side VARCHAR(10),
zone VARCHAR(50),
x_coord INT,
y_coord INT)");
$db -> query("CREATE TABLE IF NOT EXISTS " . $db -> define_tablename("tower_result", "true") . "
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
time int,
win_guild VARCHAR(50),
win_side VARCHAR(10),
lose_guild VARCHAR(50),
lose_side VARCHAR(10))");
$towerAttack = new TowerAttack($bot);
$commands["tell"]["battle"] = &$towerAttack;
$commands["tell"]["victory"] = &$towerAttack;
$commands["tell"]["orbs"] = &$towerAttack;
$commands["pgmsg"]["battle"] = &$towerAttack;
$commands["pgmsg"]["victory"] = &$towerAttack;
$commands["pgmsg"]["orbs"] = &$towerAttack;
$commands["gc"]["battle"] = &$towerAttack;
$commands["gc"]["victory"] = &$towerAttack;
$commands["gc"]["orbs"] = &$towerAttack;
$commands["gmsg"]["All Towers"][] = &$towerAttack;
$commands["gmsg"]["Tower Battle Outcome"][] = &$towerAttack;
$commands["gmsg"]["Tower Battle Outcome"][] = &$towerAttack;
$commands['gmsg']['Org Msg'][] = &$towerAttack;
$cron["5sec"][] = &$towerAttack;
/*
The Class itself...
*/
class TowerAttack
{
var $bot;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function TowerAttack (&$bot)
{
$this -> bot = &$bot;
$this -> bot -> accesscontrol -> create("all", "battle", "GUEST");
$this -> bot -> accesscontrol -> create("all", "victory", "GUEST");
$this -> bot -> accesscontrol -> create("orbs", "victory", "MEMBER");
$this -> bot -> settings -> create("TowerAttack", "Spam", TRUE, "Is spamming of tower attacks into org chat on or off?");
$this -> help['description'] = 'Handle tower attack events.';
$this -> help['command']['battle']="Shows recent tower attacks.";
$this -> help['command']['victory'] = "Shows recent tower victories.";
$this -> help['command']['orbs']= "Show Orb Lock Times.";
$this -> help['notes'] = "The bot MUST be in the top-three rank of the guild for this module to work.";
$this -> index = 1;
}
/*
This gets called on a tell
*/
function tell($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "battle/i", $msg))
$this -> bot -> send_tell($name, $this -> battle_blob());
if (preg_match("/^" . $this -> bot -> commpre . "victory$/i", $msg))
$this -> bot -> send_tell($name, $this -> victory_blob());
else if (preg_match("/^" . $this -> bot -> commpre . "orbs$/i", $msg))
$this -> bot -> send_tell($name, $this -> orbtimes());
}
/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "battle/i", $msg))
$this -> bot -> send_pgroup($this -> battle_blob());
if (preg_match("/^" . $this -> bot -> commpre . "victory$/i", $msg))
$this -> bot -> send_pgroup($this -> victory_blob());
else if (preg_match("/^" . $this -> bot -> commpre . "orbs$/i", $msg))
$this -> bot -> send_pgroup($this -> orbtimes());
}
/*
This gets called on a msg in the guildchat with the command
*/
function gc($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "battle/i", $msg))
$this -> bot -> send_gc($this -> battle_blob());
if (preg_match("/^" . $this -> bot -> commpre . "victory$/i", $msg))
$this -> bot -> send_gc($this -> victory_blob());
else if (preg_match("/^" . $this -> bot -> commpre . "orbs$/i", $msg))
$this -> bot -> send_gc($this -> orbtimes());
}
/* Called to colorize faction string */
function factioncolor($side) {
$side = "##" . strtolower($side) . "##" . $side . "##end##";
return($side);
}
/*
Makes the victory results
*/
function victory_blob()
{
$battle = "<font color=CCInfoHeadline>:::: Recent Battle Results ::::</font>\n\n<font color=CCInfoText>";
$result = $this -> bot -> db -> select("SELECT time, win_guild, win_side, lose_guild, lose_side FROM #___tower_result ORDER BY time DESC LIMIT 0, 15");
foreach ($result as $res)
{
$battle .= "<font color=CCInfoHeader>" . gmdate($this -> bot -> settings -> get("Time", "FormatString"), $res[0]) . " GMT</font>\n";
$battle .= "Winner: <font color=CCCCTextColor>" . stripslashes($res[1]) . "</font> <font color=CCCCHeaderColor>(" . $this -> factioncolor($res[2]) . ")</font>\n";
$battle .= "Loser: <font color=CCCCTextColor>" . stripslashes($res[3]) . "</font> <font color=CCCCHeaderColor>(" . $this -> factioncolor($res[4]) . ")</font>\n";
$battle .= "\n";
}
return "Tower Battles Won: " . $this -> bot -> make_blob("click to view", $battle);
}
/*
Makes the battle results
*/
function battle_blob()
{
$battle = "##blob_title##:::: Recent Tower Battles ::::##end##\n\n";
$result = $this -> bot -> db -> select("SELECT time, off_guild, off_side, off_player, off_level, off_profession,
def_guild, def_side, zone, x_coord, y_coord FROM #___tower_attack ORDER BY time DESC LIMIT 0, 13");
foreach ($result as $res)
{
$lca = $this -> get_lcainfo($res['8'], $res['9'], $res['10']);
$lcanum = "##red##x".$lca['pid']."##end##";
$prtlca = "LCA: ".$lcanum."##normal## - ".$lca['name']."##end## ##highlight##(L".$lca['lrng']."-".$lca['hrng'].")##end##\n";
$battle .= "##lightgreen##" . $res[8] . " (" . $res[9] . "x" . $res[10] . ")##end##\n";
$battle .= $prtlca;
$battle .= "Time: ##highlight##" . gmdate($this -> bot -> settings -> get("Time", "FormatString"), $res[0]) . " GMT##end##\n";
if (empty($res[2])) { $res[2] = "error"; }
$battle .= "Attacker: ##" . $res[2] . "##" . $res[3] . " ##end##(" . $res[4] . " " . $res[5] . ")\n";
if (!empty($res[1]))
$battle .= "Attacking Guild: ##" . $res[2] . "##" . stripslashes($res[1]) . "##end##\n";
$battle .= "Defending Guild: ##" . $res[7] . "##" . stripslashes($res[6]) . "##end##\n";
$battle .= "\n";
}
return "Tower Battles: " . $this -> bot -> make_blob("click to view", $battle);
}
/*
This gets called on a msg in the group
*/
function gmsg($name, $group, $msg)
{
$attack = false;
$victory = false;
if (preg_match("/The (clan|neutral|omni) organization (.+) just entered a state of war! (.+) attacked the (clan|neutral|omni) organization (.+)'s tower in (.+) at location \(([0-9]+), ([0-9]+)\)/i", $msg, $info))
{
$off_guild = $info[2];
$off_side = ucfirst(strtolower($info[1]));
$off_player = $info[3];
$def_guild = $info[5];
$def_side = ucfirst(strtolower($info[4]));
$zone = $info[6];
$x_coords = $info[7];
$y_coords = $info[8];
$attack = true;
}
else if (preg_match("/(.+) just attacked the (clan|neutral|omni) organization (.+)'s tower in (.+) at location \(([0-9]+), ([0-9]+)\)/i", $msg, $info))
{
$off_guild = "";
$off_side = "";
$off_player = $info[1];
$def_guild = $info[3];
$def_side = ucfirst(strtolower($info[2]));
$zone = $info[4];
$x_coords = $info[5];
$y_coords = $info[6];
$attack = true;
}
else if (preg_match("/(.+) (Clan|Omni|Neutral) organization (.+) attacked the (Clan|Omni|Neutral) (.+) at their base in (.+). The attackers won!!/i", $msg, $info))
{
$this -> bot -> db -> query("INSERT INTO #___tower_result (time, win_guild, win_side, lose_guild, lose_side) VALUES
('" . time() . "', '" . mysql_escape_string($info[3]) . "', '" . $info[2] . "', '" . mysql_escape_string($info[5]) . "', '" . $info[4] . "')");
}
else if (preg_match("/Blammo! (.+) has launched an orbital attack!/i", $msg, $info))
{
$info[1] = "Somebody";// FIX ME
$this -> orb($info[1]);
}
if ($attack)
{
$player = $this -> bot -> whois -> lookup($off_player);
if (empty($player["level"]))
{
$player["level"] = '?';
}
if (empty($player["profession"]))
{
$player["profession"] = 'Unknown';
}
$lca = $this -> get_lcainfo($zone, $x_coords, $y_coords);
$lcanum = "<font color=#FF0000>x".$lca['pid']."</font>";
$prtlca = "LCA: ".$lcanum."<font color=CCCCTextColor> - ".$lca['name']."</font> <font color=CCCCHeaderColor>(L".$lca['lrng']."-".$lca['hrng'].")</font>\n";
if (!empty($off_guild)) {
if (empty($off_side)) { $off_side = "error"; }
$msg = "##" . $off_side . "##" . $off_guild . "##end## has attacked ##" . $def_side . "##" .
$def_guild . "##end## in " . $zone . " at " . $x_coords . "x" . $y_coords. " (" . $lcanum . "). Attacker: ##" . $off_side . "##" .
$off_player . "##end## (" . $player["level"] . " " . $player["profession"] . ")";
$ircmsg = "[Tower Attack] " . $off_player . " (" . $player["level"] . " " . $player["profession"] . ") of " . $off_guild . " (" . $off_side . ") has attacked " .$def_guild . " (" . $def_side . ") in " . $zone;
}
else {
if (empty($off_side)) { $off_side = "error"; }
$msg = "##" . $off_side . "##" . $off_player . "##end## (" . $player["level"] . " " . $player["profession"] . ") just attacked ##" . $def_side . "##" .
$def_guild . "##end## in " . $zone . " at " . $x_coords . "x" . $y_coords