Upgrading a couple of raidbots from 2.x to 4.1. I didn't do the original installs so I don't know where our original "Loot.php" came from, but I've left the original credits intact. I don't claim authorship, just fixed/cleaned up a bit.
This version doesn't have a re-roll function, just the basic commands from the original module. Our org likes this better than !raffle (though that's still there too) and we don't use a points system atm.
<?
/*
* Loot Module for BE Bot <http://bebot.fieses.net>
* Module coded by Craized <http://www.craized.net>
... Modifications 2007-08-18 by Doctorhyde@RK2 for BeBot 4.1
* Updated to use the 'Colors.inc' file (note: symlink or copy 'Colors.inc'
from your "modules" to "custom/modules" if you're putting this script
in "custom/modules").
* Updated to use the "security -> check_access()" function instead of the
"admin -> in_group()" function.
*/
/*
Add a "_" at the beginning of the file (_Loot.php) if you do not want it to be loaded.
*/
include_once("Colors.inc");
$loot = new Rolls($bot);
$commands["tell"]["rem"] = &$loot;
$commands["tell"]["add"] = &$loot;
$commands["pgmsg"]["loot"] = &$loot;
$commands["pgmsg"]["add"] = &$loot;
$commands["pgmsg"]["rem"] = &$loot;
$commands["pgmsg"]["roll"] = &$loot;
$commands["pgmsg"]["mode"] = &$loot;
$commands["pgmsg"]["list"] = &$loot;
$commands["pgmsg"]["clear"] = &$loot;
/*
The Class itself...
*/
class Rolls {
var $bot;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function Rolls (&$bot) {
$this -> bot = &$bot;
$this -> mode = "single";
}
/*
This gets called on a tell with the command
*/
function tell($name, $msg) {
if(preg_match("/^" . $this -> bot -> commpre . "rem ([0-9]+)/i", $msg, $info)) {
unset($this -> loot[$info[1]][$name]);
$this -> bot -> send_pgroup(Higlight($name)." removed from rolls in slot ".Highlight("#" . $info[1]));
$this -> bot -> send_tell($name, Highlight($name)." removed from rolls in slot ".Highlight("#".$info[1]));
}
if(preg_match("/^" . $this -> bot -> commpre . "add ([0-9]+)/i", $msg, $info)) {
$this -> add($name, $info[1]);
$this -> bot -> send_tell($name, $this -> addmsg);
}
}
/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg) {
if(preg_match("/^" . $this -> bot -> commpre . "loot (.*)/i", $msg, $info)) {
$this -> loot($info[1], $name);
}
if(preg_match("/^" . $this -> bot -> commpre . "add ([0-9]+)/i", $msg, $info)) {
$this -> add($name, $info[1]);
}
if(preg_match("/^" . $this -> bot -> commpre . "list/i", $msg)) {
$this -> rlist();
}
if(preg_match("/^" . $this -> bot -> commpre . "mode ?(.*)/i", $msg, $info)) {
if(!$info[1]) {
$this -> bot -> send_pgroup("Loot mode currently set to ".Highlight($this -> mode).".");
}
if(!$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> security -> check_access($name, "leader") || $this -> bot -> security -> check_access($name, "admin")) {
if(!$this -> lead) {
if($info[1] == single) {
$this -> mode = "single";
$this -> bot -> send_pgroup("Roll mode changed to ".Highlight("single loot").".");
} else if($info[1] == multi) {
$this -> mode = "multi";
$this -> bot -> send_pgroup("Roll mode changed to ".Highlight("multiple loot").".");
}
} else {
$this -> bot -> send_pgroup("You cannot change the loot mode while rolling is in progress.");
}
}
}
if(preg_match("/^" . $this -> bot -> commpre . "rem ([0-9]+)/i", $msg, $info)) {
unset($this -> loot[$info[1]][$name]);
$this -> bot -> send_pgroup(Highlight($name)." removed from rolls in slot ".Highlight("#".$info[1]));
}
if(preg_match("/^" . $this -> bot -> commpre . "roll/i", $msg)) {
if($this -> lead == $name || !$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> security -> check_access($name, "leader") || $this -> bot -> security -> check_access($name, "admin")) {
$this -> roll($name);
}
}
if(preg_match("/^" . $this -> bot -> commpre . "clear/i", $msg)) {
if($this -> lead == $name || !$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> security -> check_access($name, "leader") || $this -> bot -> security -> check_access($name, "admin")) {
unset($this -> loot);
unset($this -> lead);
$this -> bot -> send_pgroup(Highlight($name)."<font color=#FF0000> cancelled the loot rolls in progress");
}
}
}
function add($name, $slot) {
unset($present);
if($this -> loot[$slot]) {
if($this -> mode == 'single') {
$slots = array_keys($this -> loot);
foreach($slots as $key=>$sslot) {
$list = array_keys($this -> loot[$sslot]);
foreach($list as $playerslot=>$player) {
if($player == $name) {
unset($this -> loot[$sslot][$player]);
$present = true;
}
}
}
if($present == true) {
$this -> addmsg = Highlight($name)." changed to slot ".Highlight("#$slot");
} else {
$this -> addmsg = Highlight($name)." assigned to slot ".Highlight("#$slot");
}
$this -> loot[$slot][$name] = true;
} else {
$this -> loot[$slot][$name] = true;
$this -> addmsg = Highlight($name)." assiged to slot ".Highlight("#$slot");
}
} else {
$this -> addmsg = "There is currently no roll in slot $slot";
}
$this -> bot -> send_pgroup($this -> addmsg);
}
function loot($msg, $name) {
if($this -> lead == $name || !$this -> lead) {
$this -> lead = $name;
$count = count($this -> loot)+1;
$this -> loot[$count][item] = $msg;
$this -> bot -> send_pgroup(Highlight($msg)." being rolled in slot ".Highlight("#".$count));
}
}
function roll($name){
$num = 1;
if($this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> security -> check_access($name, "leader") || $this -> bot -> security -> check_access($name, "admin") || $this -> lead == $name || !$this -> lead) {
foreach($this -> loot as $slot) {
unset($winner);
$users = array();
$item = $slot[item];
unset($slot[item]);
$list = $slot;
$users = array_keys($slot);
$rolling = $users;
$count = count($slot)-1;
for($i = 1; $i <= 10000; $i++) {
$list[$users[rand(0, $count)]] += 1;
}
natsort($list);
foreach($list as $name => $points) {
$winner = $name;
}
if(!$winner) {
$winner = "[ none ]";
}
$this -> bot -> send_pgroup("<font color=#FF0000>$winner</font> won the roll for ".Highlight($item)." in slot ".Highlight("#".$num)."!");
unset($this -> loot[$num]);
unset($this -> lead);
$num++;
}
}
}
function rlist() {
$num = 0;
foreach($this -> loot as $slot) {
unset($msg);
$num++;
$msg .= "Rolling on item ".Highlight($slot[item])." in slot ".Highlight("#$num").": ";
if(count($slot) == 1) {
$msg .= "[ none ]";
} else {
$list = array_keys($slot);
foreach($list as $key=>$player) {
if($player != "item") {
$msg .= "(".Highlight($player).") ";
}
}
}
$this -> bot -> send_pgroup($msg);
}
}
}
?>