Archive > 0.5.x Custom/Unofficial Modules

New apf

(1/3) > >>

Nogoal:
Did someone bothered to make a !apf 13/28/35 roll lists?

What I mean is, instead of adding loot 1 by one using !loot blahblah, you only have to type !apf 13 and all items are added to loot list.

Karsta:
Bump

I would like to get this if anyone will do it

!raidloot 13/35/28 maybe

Zacix:
I wrote a this for my own bot, new loot module + raidloot. It's not compatible with Bebot though, so someone would have to port it. Shouldn't be too much work as it's based on a really old bebot version I've modified a bit.

Nogoal:
Can you post a link to it or send by mail? Thank you.

Zacix:

--- Code: ---<?php
require_once("./includes/Item.php");
require_once("./includes/ItemInfo.php");
class Loot extends ModuleBase {
private static $instance;
protected $values;

protected function __construct(Bot $bot) {
$this->values = array(
"bot"   => $bot,
"lootlist"  => array(),
"rolllist"  => array(),
"singleloot" => true,
"preservewinners"  => false,
"reroll" => array(),
"winners"  => array(),
"pgroup"  => array(),
);
}

public static function Create(Bot $bot) {

if(!isset(self::$instance)) {
$o = __CLASS__;
self::$instance = new $o($bot);
}
return self::$instance;
}

public function AddLoot($name, $list) {
$num = 1;
$string = implode(" ", $list);
$info = array();

while(count($list)>0 && $list[0]!=="") {
if(is_numeric($list[0])) {
$num = $list[0];
$string = preg_replace("/".$num." /","",$string,1);
}
if(preg_match("/^<a href=\"itemref:\/\/([0-9]+)\/([0-9]+)\/([0-9]+)\">([^<]+)<\/a>/i", $string, $info)) {
$regex = "/^<a href=\"itemref:\/\/([0-9]+)\/([0-9]+)\/([0-9]+)\">([^<]+)<\/a>/i";
}
else if(preg_match("/^([^0-9]+)/i", $string, $info)) {
$regex = "/^([^0-9]+)/i";
}
else {
preg_match("/(.+)/i", $string, $info);
$regex = "/(.+)/i";
}
$item = Item::Create($info[0]);
$item->setQuantity($num);
$item->setLooter($name);
ItemInfo::Lookup($this->bot, $item);
$this->AddToLootList($item);
$string = preg_replace($regex,"",$string,1);
$string = ltrim($string);
$list = explode(" ", $string);
print_r($item);
$num = 1;
}
}

private function AddToLootList($item) {
for($i=0;$i<count($this->lootlist);$i++) {
if($this->lootlist[$i]->getName()===$item->getName() &&
$this->lootlist[$i]->getLowid()===$item->getLowid() &&
$this->lootlist[$i]->getHighid()===$item->getHighid() &&
$this->lootlist[$i]->getQl()===$item->getQl()) {
$this->lootlist[$i]->setQuantity($this->lootlist[$i]->getQuantity()+$item->getQuantity());
print_r($this->lootlist);
$this->bot->send_pgroup(Highlight($this->lootlist[$i]->getQuantity())."x".$this->lootlist[$i]->getItemReference()." in slot ".bcadd($i,1));
return;
}
}
$this->lootlist[] = $item;
$this->rolllist[] = array();
var_dump($item);
$this->bot->send_pgroup(Highlight($item->getQuantity())."x".$item->getItemReference()." in slot ".count($this->lootlist));
}

public function RemoveLoot($name, $index) {
$index = $this->IsValidIndex($index, $this->lootlist);
if($index===false)
return;
if($this->lootlist[$index]->getLooter() == $name || $this->bot->admin->InGroup($name, "raidleader")) {
$this->bot->send_pgroup(Highlight($name)." deleted " . $this->lootlist[$index]->getItemReference()." from slot ".Highlight(bcadd($index,1)));
unset($this->lootlist[$index]);
$this->lootlist = array_values($this->lootlist);
unset($this->rolllist[$index]);
$this->rolllist = array_values($this->rolllist);
}
}

public function Add($name, $index) {
$index = $this->IsValidIndex($index, $this->lootlist);
if($index===false)
return;

if($this->preservewinners) {
if(array_search($name,$this->winners) !== false) {
$this->bot->send_tell($name, "You have already won an item");
return;
}
}

if(class_exists("Wishlist",false) && $this->bot->commands["tell"]["mywish"]->active) {
if($this->bot->commands["tell"]["mywish"]->IsWishlistItem($this->lootlist[$index]->getName())) {
if(!$this->bot->commands["tell"]["mywish"]->IsOnWishlist($this->lootlist[$index]->getName(),$name)) {
$this->bot->send_tell($name,"[" . Highlight($this->lootlist[$index]->getItemReference()) . "] is a wishlist item not on your wishlist");
return;
}
if(!$this->bot->commands["tell"]["mywish"]->CanRoll($name,$this->lootlist[$index]->getName())) {
$this->bot->send_tell($name,"You are still in your graceperiod.");
return;
}
}
}

$indexes = false;
if($this->singleloot) {
$indexes = $this->IsRollingForItem($name);
if($indexes) {
foreach($indexes as $key=>$array) {
unset($this->rolllist[$array[0]][$array[1]]);
$this->rolllist[$array[0]] = array_values($this->rolllist[$array[0]]);
}
}
}
$this->rolllist[$index][] = $name;
$this->bot->send_pgroup(Highlight($name)." joined roll for ".$this->lootlist[$index]->getItemReference()." in slot ".Highlight(bcadd($index,1)));
}

private function IsRollingForItem($name) {
$indexes = array();
foreach($this->rolllist as $index=>$array) {
$exist = array_search($name,$array);
if($exist !== false)
$indexes[] = array($index,$exist);
}
if(count($indexes) > 0)
return $indexes;
return false;
}

private function IsValidIndex($index,$array,$decrement=true) {
if(!is_numeric($index))
return false;
if($decrement)
$index--;
if($index < 0 || $index >= count($this->lootlist))
return false;
return $index;
}

public function Remove($name, $index) {
$index = $this->IsValidIndex($index, $this->lootlist);
if($index===false)
return;

$nameindex = array_search($name, $this->rolllist[$index]);
if($nameindex !== false) {
unset($this->rolllist[$index][$nameindex]);
$this->rolllist[$index] = array_values($this->rolllist[$index]);
$this->bot->send_pgroup(Highlight($name)." left roll for ".$this->lootlist[$index]->getItemReference()." in slot ".Highlight(bcadd($index,1)));
}
}

public function LootList() {
$msg = Headertext("Loot");

foreach($this->lootlist as $index=>$item) {
$msg .= "<br><br>".$item->getIconReference();
$msg .= "<br>".bcadd($index,1).". Added by: ".$item->getLooter();
$msg .= "<br>"."QL ".$item->getQl()." ".$item->getItemReference()." (".Headertext($item->getQuantity()).")";
$msg .= "<br><a href='chatcmd:///tell " . $this->bot->botname . " " . $this->bot->commpre . "add " . bcadd($index,1) . "'>Join</a>" . "/";
$msg .= "<a href='chatcmd:///tell " . $this->bot->botname . " " . $this->bot->commpre . "rem " . bcadd($index,1) . "'>Leave</a>";

if(count($this->rolllist[$index])>0) {
$msg .= "<br>Added (".Headertext(count($this->rolllist[$index])).")<br>";
foreach($this->rolllist[$index] as $name) {
$msg .= "|".Highlight($name)."|";
}
}
else {
$msg .= "<br>Nobody included";
}
}
return $msg;
}

public function Roll() {
if(count($this->lootlist) == 0) {
$this->bot->send_pgroup("No items to roll");
return;
}

$winners = array();
$this->reroll = array();
$msg = Headertext("Winners");
foreach($this->lootlist as $index=>$item) {
$msg .= "<br><br>".$item->getIconReference();
$msg .= "<br>".bcadd($index,1).". Added by: ".$item->getLooter();
$msg .= "<br>"."QL ".$item->getQl()." ".$item->getItemReference();
$msg .= "<br>Winners: ";

if(count($this->rolllist[$index]) < $item->getQuantity()) {
$tmp = clone $item;
$tmp->setQuantity(bcsub($item->getQuantity(), count($this->rolllist[$index])));
$this->reroll[] = $tmp;
}
if(count($this->rolllist[$index]) == 0) {
$msg .= "Nobody rolled";
continue;
}

$winners[] = array();
for($i=count($this->rolllist[$index]);$i>0 && $item->getQuantity() > 0;$i--,$item->setQuantity($item->getQuantity()-1)) {
if(class_exists("Wishlist",false) && $this->bot->commands["tell"]["mywish"]->IsWishlistItem($item->getName())) {
$wishlistarray = $this->bot->commands["tell"]["mywish"]->GetRollArray($this->rolllist[$index]);
$winnerindex = mt_rand(0,count($wishlistarray)-1);
$winner = $wishlistarray[$winnerindex];
$winnerindex = array_search($winner,$this->rolllist[$index]);
$this->bot->commands["tell"]["mywish"]->wishlistwinners[] = $winner;
}
else {
$winnerindex = mt_rand(0,bcsub($i,1));
$winner = $this->rolllist[$index][$winnerindex];
}
$msg .= "|".Highlight($winner)."|";
unset($this->rolllist[$index][$winnerindex]);
$this->rolllist[$index] = array_values($this->rolllist[$index]);
$this->LogLootHistory($item,$winner,$this->rolllist[$index]);
if($this->preservewinners) {
$this->winners[] = $winner;
}
}
}
$this->lootlist = array();
$this->rolllist = array();
$this->bot->send_pgroup($this->make_blob("Winners", $msg));
}

public function LogLootHistory($item, $winner, $loosers) {
$sql = "INSERT INTO loothistory (itemql,itemname,itemlowid,itemhighid,itemiconid,winner,loosers,won) VALUES(";
$sql .= $item->getQl().",";
$sql .= "'".str_replace("'","''",$item->getName())."',";
$sql .= $item->getLowid().",";
$sql .= $item->getHighid().",";
$sql .= $item->getIconid().",";
$sql .= "'".$winner."','";
foreach($loosers as $index=>$name) {
$sql .= $name." ";
}
$sql = trim($sql);
$sql .= "',".time().")";
$this->bot->db->query($sql);
}

public function Reroll() {
if(count($this->reroll) == 0) {
$this->bot->send_pgroup("No items to reroll");
return;
}
$this->lootlist = $this->reroll;
$this->rolllist = array();
$this->reroll = array();
$this->bot->send_pgroup($this->make_blob("Loot List",$this->LootList()));
}

public function Clear($name) {
$this->lootlist = array();
$this->rolllist = array();
$this->bot->send_pgroup("Lootlist cleared by ".Highlight($name));
}

public function Preserve($name, $flag) {
switch(strtolower($flag)) {
case "on":
$this->preservewinners = true;
$this->bot->send_pgroup("Preserve winners has been turned ".Highlight("on")." by ".Highlight($name));
break;
case "off":
$this->preservewinners = false;
$this->bot->send_pgroup("Preserve winners has been turned ".Highlight("off")." by ".Highlight($name));
break;
}
}

public function History($index) {
if(is_numeric($index) !== true)
$index = 0;
$msg = Headertext("History");
$prev = bcsub($index,10);
$prev = $prev <= 0 ? 0 : $prev;
$msg .= "<br><br><a href='chatcmd:///tell <botname> <pre>history ".$prev."'>Previous</a>/";
$next = bcadd($index,10);
$next = $next <= 0 ? 0 : $next;
$msg .= "<a href='chatcmd:///tell <botname> <pre>history ".$next."'>Next</a>";

$sql = "SELECT * FROM loothistory ORDER BY id DESC LIMIT ".$index.",10";
$result = $this->bot->db->select($sql);

foreach($result as $index=>$row) {
$msg .= "<br><br><a href='itemref://".$row[3]."/".$row[4]."/".$row[1]."'>".$row[2]."</a>";
$msg .= "<br>Winner: ".Highlight($row[6]);
$msg .= "<br>When: ".Highlight(date("Y-F-d H:i", $row[8]) . " GMT");
}

return $msg;
}

function pgmsg($name, $msg) {
$pre = $this->bot->commpre;
$msg = explode(" ",$msg);

switch(ltrim(strtolower($msg[0]),$pre)) {
case "add":
$this->Add($name, $msg[1]);
break;
case "rem":
$this->Remove($name, $msg[1]);
break;
case "loot":
array_shift($msg);
print_r($msg);
$this->AddLoot($name, $msg);
break;
case "list":
$this->bot->send_pgroup($this->make_blob("Loot List",$this->LootList()));
break;
case "del":
$this->RemoveLoot($name,$msg[1]);
break;
case "roll":
case "result":
if($this->bot->admin->in_group($name,"raidleader")) {
$this->Roll();
}
break;
case "reroll":
if($this->bot->admin->in_group($name,"raidleader")) {
$this->Reroll();
}
break;
case "clear":
if($this->bot->admin->in_group($name,"raidleader")) {
$this->Clear($name);
}
break;
case "preserve":
if($this->bot->admin->in_group($name,"raidleader")) {
$this->Preserve($name, $msg[1]);
}
break;
case "clearwinners":
if($this->bot->admin->in_group($name,"raidleader")) {
$this->winners = array();
$this->bot->send_pgroup("Prior winners have been cleared by ".Highlight($name));
}
break;
case "history":
$this->bot->send_pgroup($this->make_blob("History",$this->History($msg[1])));
break;
}
}

function tell($name, $msg) {
$this->pgmsg($name, $msg);
}
}

$loot = Loot::Create($bot);

$bot->commands["tell"]["rem"] = $loot;
$bot->commands["tell"]["add"] = $loot;
$bot->commands["tell"]["loot"] = $loot;
$bot->commands["tell"]["history"] = $loot;
$bot->commands["tell"]["list"] = $loot;
$bot->commands["pgmsg"]["loot"] = $loot;
$bot->commands["pgmsg"]["add"] = $loot;
$bot->commands["pgmsg"]["rem"] = $loot;
$bot->commands["pgmsg"]["list"] = $loot;
$bot->commands["pgmsg"]["del"] = $loot;
$bot->commands["pgmsg"]["roll"] = $loot;
$bot->commands["pgmsg"]["result"] = $loot;
$bot->commands["pgmsg"]["reroll"] = $loot;
$bot->commands["pgmsg"]["clear"] = $loot;
$bot->commands["pgmsg"]["preserve"] = $loot;
$bot->commands["pgmsg"]["clearwinners"] = $loot;
$bot->commands["pgmsg"]["history"] = $loot;
?>

--- End code ---

--- Code: ---<?php

class Item {
private $ql = 1;
private $name = "";
private $lowid = 1;
private $highid = 1;
private $iconid = 1;
  private $req = "";
private $breedreq = "";
private $prefix = "";
private $postfix = "";
private $looter = "";
private $quantity = 1;

public static function Create($string) {
$item = new Item();
if(preg_match("/^<a href=\"itemref:\/\/([0-9]+)\/([0-9]+)\/([0-9]+)\">(.*)<\/a>$/i", $string, $info)) {
$item->setLowid($info[1]);
$item->setHighid($info[2]);
$item->setQl($info[3]);
$item->setName($info[4]);

}
else {
$item->setName($string);
}
return $item;
}

public function getItemReference() {
return "<a href='itemref://" . $this->lowid . "/" . $this->highid . "/" . $this->ql . "'>" . $this->name . "</a>";
}

public function getIconReference() {
     return "<img src='rdb://" . $this->iconid . "'>";
}

public function getName() {
return $this->name;
}

public function getLowid() {
return $this->lowid;
}

public function getHighid() {
return $this->highid;
}

public function getIconid() {
return $this->iconid;
}

public function getQl() {
return $this->ql;
}

public function getLooter() {
return $this->looter;
}

public function getQuantity() {
return $this->quantity;
}

public function setName($name) {
$this->name = $name;
}

public function setLowid($id) {
$this->lowid = $id;
}

public function setHighid($id) {
$this->highid = $id;
}

public function setIconid($id) {
$this->iconid = $id;
}

public function setQl($ql) {
$this->ql = $ql;
}

public function setLooter($looter) {
$this->looter = $looter;
}

public function setQuantity($quantity) {
$this->quantity = $quantity;
}
}
?>
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version