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