Mercurial > wow > breuesk
view Looting.lua @ 82:db7e4ee34dce
Lots of support for mobs with multiple loots
author | John@Yosemite-PC |
---|---|
date | Fri, 13 Apr 2012 23:14:03 -0400 |
parents | 62805e6b46c5 |
children | ef4f6dc262ea |
line wrap: on
line source
local bsk=bsk local _G=_G local table=table local pairs=pairs local setmetatable=setmetatable local ipairs=ipairs local string=string local sformat=string.format local tostring=tostring local type=type local getn=getn local event = LibStub("AceEvent-3.0") setfenv(1,bsk) local isMasterLootEvent = false local function OpenMasterLootList() print("Open!") isMasterLootEvent = true end local function UpdateMasterLootList() print("Update MLL!") end local function LootClosed() print("Close!") if isMasterLootEvent then isMasterLootEvent = false -- end the event InitiateCloseLooting() end end local function LootOpened() print("Open loot!") isMasterLootEvent = false local n = _G.GetNumLootItems() for i = 1,n do _G.LootSlot(i) end local items = {} local threshold = _G.GetLootThreshold() print("threshold: ", threshold) for i = 1,n do local _,_,_,rarity,_ = _G.GetLootSlotInfo(i) print("item: rarity: ",rarity) local link = _G.GetLootSlotLink(i) if link and rarity >= threshold then table.insert(items,{link=link,mlid=i}) print("Item: ", link, i) end end if not isMasterLootEvent then return end print("Let's get started SKing") -- todo: check that I am ML and that I'm an admin! InitiateBeginLoot(items,stateactivelist) local chan -- todo: idiom if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end _G.SendChatMessage("The following items are available -",chan) for i,v in pairs(items) do _G.SendChatMessage(v.link,chan) end end function FreeLoot(item,person) PrintTable(item) PrintTable(person) for ci = 1, 40 do if _G.GetMasterLootCandidate(ci) == person.textPlain then print("GML",item.mlid,ci) _G.GiveMasterLoot(item.mlid, ci) return true end end print("Could not assign loot to ", person.textPlain) end function ExpensiveLoot(item,lref) if getn(statebids) > 0 then if FreeLoot(item,statebids[1]) then local chan -- todo: idiom if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),chan) --_G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),"GUILD") -- todo: enable lref:SuicidePerson(statebids[1].value) InitiateCloseBidding() else printf("Could not suicide %s for item; they are ineligible or offline",statebids[1].textPlain) end return end if getn(staterolls) > 0 then if FreeLoot(item,staterolls[1]) then local chan -- todo: idiom if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,staterolls[1].textPlain),chan) InitiateCloseBidding() else printf("Could not suicide %s for item; they are ineligible or offline",staterolls[1].textPlain) end return end _G.error("Trying to suicide+loot without bids or rolls") end function DirectSuicideLoot(item,person,lref) if FreeLoot(item,person) then lref:SuicidePerson(person.value) else printf("Could not suicide %s for item; they are ineligible or offline", person.textPlain) end end function WhisperReceived(...) local _,message,sender = ... local senderAction = function(func) local le = PersonList:Select(sender) if le then local person = ConvertLe2Line(le) if person then func(person) end end end if state == "bidding" and admin then -- todo: should only be ML message = _G.strtrim(message) message = _G.strlower(message) if message == "bid" then senderAction(InitiateBid) elseif message == "retract" then senderAction(InitiateRetract) elseif message == "roll" then senderAction(InitiateRollRequest) end end end local statelistener = { ["StateEvent"] = function(self) if state == "bidding" then event:RegisterEvent("CHAT_MSG_WHISPER", WhisperReceived) else --event:UnregisterEvent("CHAT_MSG_WHISPER") -- todo end end, } function InitializeLooting() event:RegisterEvent("OPEN_MASTER_LOOT_LIST",OpenMasterLootList) event:RegisterEvent("UPDATE_MASTER_LOOT_LIST",UpdateMasterLootList) event:RegisterEvent("LOOT_CLOSED",LootClosed) event:RegisterEvent("LOOT_OPENED",LootOpened) -- todo: what are these event:RegisterEvent("LOOT_SLOT_CLEARED",function(_,index) InitiateLSClear(index) end) event:RegisterEvent("LOOT_SLOT_CHANGED",function() print("LSChanged") end) RegisterListenerStateChange(statelistener) statelistener:StateEvent() end