John@73: local bsk=bsk John@73: local _G=_G John@73: local table=table John@73: local pairs=pairs John@73: local setmetatable=setmetatable John@73: local ipairs=ipairs John@73: local string=string John@73: local sformat=string.format John@73: local tostring=tostring John@73: local type=type John@73: local getn=getn John@73: John@73: local event = LibStub("AceEvent-3.0") John@73: John@73: setfenv(1,bsk) John@73: John@73: local isMasterLootEvent = false John@73: John@73: local function OpenMasterLootList() John@73: print("Open!") John@73: isMasterLootEvent = true John@73: end John@73: John@73: local function UpdateMasterLootList() John@73: print("Update MLL!") John@73: end John@73: John@73: local function LootClosed() John@73: print("Close!") John@73: if isMasterLootEvent then John@73: isMasterLootEvent = false -- end the event John@73: InitiateCloseLooting() John@73: end John@73: end John@73: John@73: local function LootOpened() John@73: print("Open loot!") John@73: isMasterLootEvent = false John@73: local n = _G.GetNumLootItems() John@83: --for i = 1,n do John@83: -- _G.LootSlot(i) John@83: --end John@73: local items = {} John@82: local threshold = _G.GetLootThreshold() John@82: print("threshold: ", threshold) John@73: for i = 1,n do John@82: local _,_,_,rarity,_ = _G.GetLootSlotInfo(i) John@82: print("item: rarity: ",rarity) John@73: local link = _G.GetLootSlotLink(i) John@82: if link and rarity >= threshold then John@78: table.insert(items,{link=link,mlid=i}) John@78: print("Item: ", link, i) John@89: isMasterLootEvent = true John@73: end John@73: end John@73: if not isMasterLootEvent then return end John@73: John@73: print("Let's get started SKing") John@73: -- todo: check that I am ML and that I'm an admin! John@73: John@89: if masterLooterIsMe and admin then John@89: InitiateBeginLoot(items,stateactivelist) John@81: John@89: local chan -- todo: idiom John@89: if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end John@89: _G.SendChatMessage("The following items are available -",chan) John@89: for i,v in pairs(items) do John@89: _G.SendChatMessage(v.link,chan) John@89: end John@81: end John@73: end John@73: John@76: function FreeLoot(item,person) John@76: PrintTable(item) John@76: PrintTable(person) John@76: for ci = 1, 40 do John@76: if _G.GetMasterLootCandidate(ci) == person.textPlain then John@78: print("GML",item.mlid,ci) John@78: _G.GiveMasterLoot(item.mlid, ci) John@76: return true John@76: end John@76: end John@76: John@76: print("Could not assign loot to ", person.textPlain) John@76: end John@76: John@76: function ExpensiveLoot(item,lref) John@76: if getn(statebids) > 0 then John@76: if FreeLoot(item,statebids[1]) then John@81: local chan -- todo: idiom John@81: if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end John@81: _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),chan) John@81: --_G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),"GUILD") -- todo: enable John@76: lref:SuicidePerson(statebids[1].value) John@81: InitiateCloseBidding() John@76: else John@76: printf("Could not suicide %s for item; they are ineligible or offline",statebids[1].textPlain) John@76: end John@76: return John@76: end John@76: if getn(staterolls) > 0 then John@76: if FreeLoot(item,staterolls[1]) then John@81: local chan -- todo: idiom John@81: if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end John@81: _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,staterolls[1].textPlain),chan) John@81: InitiateCloseBidding() John@76: else John@76: printf("Could not suicide %s for item; they are ineligible or offline",staterolls[1].textPlain) John@76: end John@76: return John@76: end John@76: _G.error("Trying to suicide+loot without bids or rolls") John@76: end John@76: John@78: function DirectSuicideLoot(item,person,lref) John@78: if FreeLoot(item,person) then John@78: lref:SuicidePerson(person.value) John@78: else John@78: printf("Could not suicide %s for item; they are ineligible or offline", person.textPlain) John@78: end John@78: end John@78: John@81: function WhisperReceived(...) John@81: local _,message,sender = ... John@81: local senderAction = function(func) John@81: local le = PersonList:Select(sender) John@81: if le then John@81: local person = ConvertLe2Line(le) John@81: if person then John@81: func(person) John@81: end John@81: end John@81: end John@81: John@89: if state == "bidding" and admin and masterLooterIsMe then John@81: message = _G.strtrim(message) John@81: message = _G.strlower(message) John@81: if message == "bid" then John@81: senderAction(InitiateBid) John@81: elseif message == "retract" then John@81: senderAction(InitiateRetract) John@81: elseif message == "roll" then John@81: senderAction(InitiateRollRequest) John@81: end John@81: end John@81: end John@81: John@81: local statelistener = John@81: { John@81: ["StateEvent"] = function(self) John@81: if state == "bidding" then John@81: event:RegisterEvent("CHAT_MSG_WHISPER", WhisperReceived) John@81: else John@81: --event:UnregisterEvent("CHAT_MSG_WHISPER") -- todo John@81: end John@81: end, John@81: } John@81: John@87: John@87: masterLooter = nil John@87: masterLooterIsMe = false John@87: John@87: function UpdateML() John@87: local lootmethod, masterlooterPartyID, masterlooterRaidID = _G.GetLootMethod() John@87: if lootmethod == "master" then John@87: local oldMasterLooter John@87: oldMasterLooter = masterLooter John@87: masterLooterIsMe = false John@87: if masterlooterPartyID and masterlooterPartyID > 0 then John@87: masterLooter = _G.UnitName("party"..masterlooterPartyID) John@87: elseif masterlooterRaidID and masterlooterRaidID > 0 then John@87: masterLooter = _G.UnitName("raid"..masterlooterRaidID) John@87: else John@87: masterLooter = _G.UnitName("player") John@87: masterLooterIsMe = true John@87: end John@87: John@87: if masterLooter ~= oldMasterLooter then John@87: statelistener:StateEvent() -- todo: this isn't how to fire an event! John@89: John@89: if not masterLooterIsMe then John@89: Comm:RequestCatchup() John@89: end John@87: end John@87: else John@87: masterLooter = nil John@87: masterLooterIsMe = false John@87: end John@87: end John@87: John@73: function InitializeLooting() John@73: event:RegisterEvent("OPEN_MASTER_LOOT_LIST",OpenMasterLootList) John@73: event:RegisterEvent("UPDATE_MASTER_LOOT_LIST",UpdateMasterLootList) John@73: event:RegisterEvent("LOOT_CLOSED",LootClosed) John@73: event:RegisterEvent("LOOT_OPENED",LootOpened) John@76: John@82: event:RegisterEvent("LOOT_SLOT_CLEARED",function(_,index) InitiateLSClear(index) end) John@87: --event:RegisterEvent("LOOT_SLOT_CHANGED",function() print("LSChanged") end) John@81: John@81: RegisterListenerStateChange(statelistener) John@81: statelistener:StateEvent() John@87: John@87: UpdateML() John@87: event:RegisterEvent("PARTY_LOOT_METHOD_CHANGED",UpdateML) John@73: end John@87: