annotate Looting.lua @ 81:62805e6b46c5

Fleshing out the UI for those without the addon. Announcements in the raid, bidding via whisper.
author John@Yosemite-PC
date Fri, 13 Apr 2012 22:09:17 -0400
parents 7b8fcea357d2
children db7e4ee34dce
rev   line source
John@73 1 local bsk=bsk
John@73 2 local _G=_G
John@73 3 local table=table
John@73 4 local pairs=pairs
John@73 5 local setmetatable=setmetatable
John@73 6 local ipairs=ipairs
John@73 7 local string=string
John@73 8 local sformat=string.format
John@73 9 local tostring=tostring
John@73 10 local type=type
John@73 11 local getn=getn
John@73 12
John@73 13 local event = LibStub("AceEvent-3.0")
John@73 14
John@73 15 setfenv(1,bsk)
John@73 16
John@73 17 local isMasterLootEvent = false
John@73 18
John@73 19 local function OpenMasterLootList()
John@73 20 print("Open!")
John@73 21 isMasterLootEvent = true
John@73 22 end
John@73 23
John@73 24 local function UpdateMasterLootList()
John@73 25 print("Update MLL!")
John@73 26 end
John@73 27
John@73 28 local function LootClosed()
John@73 29 print("Close!")
John@73 30 if isMasterLootEvent then
John@73 31 isMasterLootEvent = false -- end the event
John@73 32 InitiateCloseLooting()
John@73 33 end
John@73 34 end
John@73 35
John@73 36 local function LootOpened()
John@73 37 print("Open loot!")
John@73 38 isMasterLootEvent = false
John@73 39 local n = _G.GetNumLootItems()
John@73 40 for i = 1,n do
John@73 41 _G.LootSlot(i)
John@73 42 end
John@73 43 local items = {}
John@73 44 for i = 1,n do
John@73 45 local link = _G.GetLootSlotLink(i)
John@73 46 if link then
John@78 47 table.insert(items,{link=link,mlid=i})
John@78 48 print("Item: ", link, i)
John@73 49 end
John@73 50 end
John@73 51 if not isMasterLootEvent then return end
John@73 52
John@73 53 print("Let's get started SKing")
John@73 54 -- todo: check that I am ML and that I'm an admin!
John@73 55
John@73 56 InitiateBeginLoot(items,stateactivelist)
John@81 57
John@81 58 local chan -- todo: idiom
John@81 59 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
John@81 60 _G.SendChatMessage("The following items are available -",chan)
John@81 61 for i,v in pairs(items) do
John@81 62 _G.SendChatMessage(v.link,chan)
John@81 63 end
John@73 64 end
John@73 65
John@76 66 function FreeLoot(item,person)
John@76 67 PrintTable(item)
John@76 68 PrintTable(person)
John@76 69 for ci = 1, 40 do
John@76 70 if _G.GetMasterLootCandidate(ci) == person.textPlain then
John@78 71 print("GML",item.mlid,ci)
John@78 72 _G.GiveMasterLoot(item.mlid, ci)
John@76 73 return true
John@76 74 end
John@76 75 end
John@76 76
John@76 77 print("Could not assign loot to ", person.textPlain)
John@76 78 end
John@76 79
John@76 80 function ExpensiveLoot(item,lref)
John@76 81 if getn(statebids) > 0 then
John@76 82 if FreeLoot(item,statebids[1]) then
John@81 83 local chan -- todo: idiom
John@81 84 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
John@81 85 _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),chan)
John@81 86 --_G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),"GUILD") -- todo: enable
John@76 87 lref:SuicidePerson(statebids[1].value)
John@81 88 InitiateCloseBidding()
John@76 89 else
John@76 90 printf("Could not suicide %s for item; they are ineligible or offline",statebids[1].textPlain)
John@76 91 end
John@76 92 return
John@76 93 end
John@76 94 if getn(staterolls) > 0 then
John@76 95 if FreeLoot(item,staterolls[1]) then
John@81 96 local chan -- todo: idiom
John@81 97 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
John@81 98 _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,staterolls[1].textPlain),chan)
John@81 99 InitiateCloseBidding()
John@76 100 else
John@76 101 printf("Could not suicide %s for item; they are ineligible or offline",staterolls[1].textPlain)
John@76 102 end
John@76 103 return
John@76 104 end
John@76 105 _G.error("Trying to suicide+loot without bids or rolls")
John@76 106 end
John@76 107
John@78 108 function DirectSuicideLoot(item,person,lref)
John@78 109 if FreeLoot(item,person) then
John@78 110 lref:SuicidePerson(person.value)
John@78 111 else
John@78 112 printf("Could not suicide %s for item; they are ineligible or offline", person.textPlain)
John@78 113 end
John@78 114 end
John@78 115
John@81 116 function WhisperReceived(...)
John@81 117 local _,message,sender = ...
John@81 118 local senderAction = function(func)
John@81 119 local le = PersonList:Select(sender)
John@81 120 if le then
John@81 121 local person = ConvertLe2Line(le)
John@81 122 if person then
John@81 123 func(person)
John@81 124 end
John@81 125 end
John@81 126 end
John@81 127
John@81 128 if state == "bidding" and admin then -- todo: should only be ML
John@81 129 message = _G.strtrim(message)
John@81 130 message = _G.strlower(message)
John@81 131 if message == "bid" then
John@81 132 senderAction(InitiateBid)
John@81 133 elseif message == "retract" then
John@81 134 senderAction(InitiateRetract)
John@81 135 elseif message == "roll" then
John@81 136 senderAction(InitiateRollRequest)
John@81 137 end
John@81 138 end
John@81 139 end
John@81 140
John@81 141 local statelistener =
John@81 142 {
John@81 143 ["StateEvent"] = function(self)
John@81 144 if state == "bidding" then
John@81 145 event:RegisterEvent("CHAT_MSG_WHISPER", WhisperReceived)
John@81 146 else
John@81 147 --event:UnregisterEvent("CHAT_MSG_WHISPER") -- todo
John@81 148 end
John@81 149 end,
John@81 150 }
John@81 151
John@73 152 function InitializeLooting()
John@73 153 event:RegisterEvent("OPEN_MASTER_LOOT_LIST",OpenMasterLootList)
John@73 154 event:RegisterEvent("UPDATE_MASTER_LOOT_LIST",UpdateMasterLootList)
John@73 155 event:RegisterEvent("LOOT_CLOSED",LootClosed)
John@73 156 event:RegisterEvent("LOOT_OPENED",LootOpened)
John@76 157
John@76 158 -- todo: what are these
John@76 159 event:RegisterEvent("LOOT_SLOT_CLEARED",function() print("LSCleared") end)
John@76 160 event:RegisterEvent("LOOT_SLOT_CHANGED",function() print("LSChanged") end)
John@81 161
John@81 162 RegisterListenerStateChange(statelistener)
John@81 163 statelistener:StateEvent()
John@73 164 end
John@73 165