annotate Looting.lua @ 97:19fd02bff870

Cleanup
author John@Doomsday
date Fri, 27 Apr 2012 08:26:17 -0400
parents b89558d3e833
children 0cd1d46e7b66
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@83 40 --for i = 1,n do
John@83 41 -- _G.LootSlot(i)
John@83 42 --end
John@73 43 local items = {}
John@82 44 local threshold = _G.GetLootThreshold()
John@82 45 print("threshold: ", threshold)
John@73 46 for i = 1,n do
John@82 47 local _,_,_,rarity,_ = _G.GetLootSlotInfo(i)
John@82 48 print("item: rarity: ",rarity)
John@73 49 local link = _G.GetLootSlotLink(i)
John@82 50 if link and rarity >= threshold then
John@78 51 table.insert(items,{link=link,mlid=i})
John@78 52 print("Item: ", link, i)
John@89 53 isMasterLootEvent = true
John@73 54 end
John@73 55 end
John@73 56 if not isMasterLootEvent then return end
John@73 57
John@73 58 print("Let's get started SKing")
John@73 59 -- todo: check that I am ML and that I'm an admin!
John@73 60
John@89 61 if masterLooterIsMe and admin then
John@89 62 InitiateBeginLoot(items,stateactivelist)
John@81 63
John@89 64 local chan -- todo: idiom
John@89 65 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
John@89 66 _G.SendChatMessage("The following items are available -",chan)
John@89 67 for i,v in pairs(items) do
John@89 68 _G.SendChatMessage(v.link,chan)
John@89 69 end
John@81 70 end
John@73 71 end
John@73 72
John@76 73 function FreeLoot(item,person)
John@76 74 PrintTable(item)
John@76 75 PrintTable(person)
John@76 76 for ci = 1, 40 do
John@76 77 if _G.GetMasterLootCandidate(ci) == person.textPlain then
John@78 78 print("GML",item.mlid,ci)
John@78 79 _G.GiveMasterLoot(item.mlid, ci)
John@76 80 return true
John@76 81 end
John@76 82 end
John@76 83
John@76 84 print("Could not assign loot to ", person.textPlain)
John@76 85 end
John@76 86
John@76 87 function ExpensiveLoot(item,lref)
John@76 88 if getn(statebids) > 0 then
John@76 89 if FreeLoot(item,statebids[1]) then
John@81 90 local chan -- todo: idiom
John@81 91 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
John@81 92 _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),chan)
John@81 93 --_G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),"GUILD") -- todo: enable
John@76 94 lref:SuicidePerson(statebids[1].value)
John@81 95 InitiateCloseBidding()
John@76 96 else
John@76 97 printf("Could not suicide %s for item; they are ineligible or offline",statebids[1].textPlain)
John@76 98 end
John@76 99 return
John@76 100 end
John@76 101 if getn(staterolls) > 0 then
John@76 102 if FreeLoot(item,staterolls[1]) then
John@81 103 local chan -- todo: idiom
John@81 104 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
John@81 105 _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,staterolls[1].textPlain),chan)
John@81 106 InitiateCloseBidding()
John@76 107 else
John@76 108 printf("Could not suicide %s for item; they are ineligible or offline",staterolls[1].textPlain)
John@76 109 end
John@76 110 return
John@76 111 end
John@76 112 _G.error("Trying to suicide+loot without bids or rolls")
John@76 113 end
John@76 114
John@78 115 function DirectSuicideLoot(item,person,lref)
John@78 116 if FreeLoot(item,person) then
John@78 117 lref:SuicidePerson(person.value)
John@78 118 else
John@78 119 printf("Could not suicide %s for item; they are ineligible or offline", person.textPlain)
John@78 120 end
John@78 121 end
John@78 122
John@81 123 function WhisperReceived(...)
John@81 124 local _,message,sender = ...
John@81 125 local senderAction = function(func)
John@81 126 local le = PersonList:Select(sender)
John@81 127 if le then
John@81 128 local person = ConvertLe2Line(le)
John@81 129 if person then
John@81 130 func(person)
John@81 131 end
John@81 132 end
John@81 133 end
John@81 134
John@89 135 if state == "bidding" and admin and masterLooterIsMe then
John@81 136 message = _G.strtrim(message)
John@81 137 message = _G.strlower(message)
John@81 138 if message == "bid" then
John@81 139 senderAction(InitiateBid)
John@81 140 elseif message == "retract" then
John@81 141 senderAction(InitiateRetract)
John@81 142 elseif message == "roll" then
John@81 143 senderAction(InitiateRollRequest)
John@81 144 end
John@81 145 end
John@81 146 end
John@81 147
John@81 148 local statelistener =
John@81 149 {
John@81 150 ["StateEvent"] = function(self)
John@81 151 if state == "bidding" then
John@81 152 event:RegisterEvent("CHAT_MSG_WHISPER", WhisperReceived)
John@81 153 else
John@81 154 --event:UnregisterEvent("CHAT_MSG_WHISPER") -- todo
John@81 155 end
John@81 156 end,
John@81 157 }
John@81 158
John@87 159
John@87 160 masterLooter = nil
John@87 161 masterLooterIsMe = false
John@87 162
John@87 163 function UpdateML()
John@87 164 local lootmethod, masterlooterPartyID, masterlooterRaidID = _G.GetLootMethod()
John@87 165 if lootmethod == "master" then
John@87 166 local oldMasterLooter
John@87 167 oldMasterLooter = masterLooter
John@87 168 masterLooterIsMe = false
John@87 169 if masterlooterPartyID and masterlooterPartyID > 0 then
John@87 170 masterLooter = _G.UnitName("party"..masterlooterPartyID)
John@87 171 elseif masterlooterRaidID and masterlooterRaidID > 0 then
John@87 172 masterLooter = _G.UnitName("raid"..masterlooterRaidID)
John@87 173 else
John@87 174 masterLooter = _G.UnitName("player")
John@87 175 masterLooterIsMe = true
John@87 176 end
John@87 177
John@87 178 if masterLooter ~= oldMasterLooter then
John@87 179 statelistener:StateEvent() -- todo: this isn't how to fire an event!
John@89 180
John@89 181 if not masterLooterIsMe then
John@89 182 Comm:RequestCatchup()
John@89 183 end
John@87 184 end
John@87 185 else
John@87 186 masterLooter = nil
John@87 187 masterLooterIsMe = false
John@87 188 end
John@87 189 end
John@87 190
John@73 191 function InitializeLooting()
John@73 192 event:RegisterEvent("OPEN_MASTER_LOOT_LIST",OpenMasterLootList)
John@73 193 event:RegisterEvent("UPDATE_MASTER_LOOT_LIST",UpdateMasterLootList)
John@73 194 event:RegisterEvent("LOOT_CLOSED",LootClosed)
John@73 195 event:RegisterEvent("LOOT_OPENED",LootOpened)
John@76 196
John@82 197 event:RegisterEvent("LOOT_SLOT_CLEARED",function(_,index) InitiateLSClear(index) end)
John@87 198 --event:RegisterEvent("LOOT_SLOT_CHANGED",function() print("LSChanged") end)
John@81 199
John@81 200 RegisterListenerStateChange(statelistener)
John@81 201 statelistener:StateEvent()
John@87 202
John@87 203 UpdateML()
John@87 204 event:RegisterEvent("PARTY_LOOT_METHOD_CHANGED",UpdateML)
John@73 205 end
John@87 206