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@73
|
53 end
|
John@73
|
54 end
|
John@73
|
55 if not isMasterLootEvent then return end
|
John@73
|
56
|
John@73
|
57 print("Let's get started SKing")
|
John@73
|
58 -- todo: check that I am ML and that I'm an admin!
|
John@73
|
59
|
John@73
|
60 InitiateBeginLoot(items,stateactivelist)
|
John@81
|
61
|
John@81
|
62 local chan -- todo: idiom
|
John@81
|
63 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
|
John@81
|
64 _G.SendChatMessage("The following items are available -",chan)
|
John@81
|
65 for i,v in pairs(items) do
|
John@81
|
66 _G.SendChatMessage(v.link,chan)
|
John@81
|
67 end
|
John@73
|
68 end
|
John@73
|
69
|
John@76
|
70 function FreeLoot(item,person)
|
John@76
|
71 PrintTable(item)
|
John@76
|
72 PrintTable(person)
|
John@76
|
73 for ci = 1, 40 do
|
John@76
|
74 if _G.GetMasterLootCandidate(ci) == person.textPlain then
|
John@78
|
75 print("GML",item.mlid,ci)
|
John@78
|
76 _G.GiveMasterLoot(item.mlid, ci)
|
John@76
|
77 return true
|
John@76
|
78 end
|
John@76
|
79 end
|
John@76
|
80
|
John@76
|
81 print("Could not assign loot to ", person.textPlain)
|
John@76
|
82 end
|
John@76
|
83
|
John@76
|
84 function ExpensiveLoot(item,lref)
|
John@76
|
85 if getn(statebids) > 0 then
|
John@76
|
86 if FreeLoot(item,statebids[1]) then
|
John@81
|
87 local chan -- todo: idiom
|
John@81
|
88 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
|
John@81
|
89 _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),chan)
|
John@81
|
90 --_G.SendChatMessage(sformat("Awarding %s to %s!",item.link,statebids[1].textPlain),"GUILD") -- todo: enable
|
John@76
|
91 lref:SuicidePerson(statebids[1].value)
|
John@81
|
92 InitiateCloseBidding()
|
John@76
|
93 else
|
John@76
|
94 printf("Could not suicide %s for item; they are ineligible or offline",statebids[1].textPlain)
|
John@76
|
95 end
|
John@76
|
96 return
|
John@76
|
97 end
|
John@76
|
98 if getn(staterolls) > 0 then
|
John@76
|
99 if FreeLoot(item,staterolls[1]) then
|
John@81
|
100 local chan -- todo: idiom
|
John@81
|
101 if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
|
John@81
|
102 _G.SendChatMessage(sformat("Awarding %s to %s!",item.link,staterolls[1].textPlain),chan)
|
John@81
|
103 InitiateCloseBidding()
|
John@76
|
104 else
|
John@76
|
105 printf("Could not suicide %s for item; they are ineligible or offline",staterolls[1].textPlain)
|
John@76
|
106 end
|
John@76
|
107 return
|
John@76
|
108 end
|
John@76
|
109 _G.error("Trying to suicide+loot without bids or rolls")
|
John@76
|
110 end
|
John@76
|
111
|
John@78
|
112 function DirectSuicideLoot(item,person,lref)
|
John@78
|
113 if FreeLoot(item,person) then
|
John@78
|
114 lref:SuicidePerson(person.value)
|
John@78
|
115 else
|
John@78
|
116 printf("Could not suicide %s for item; they are ineligible or offline", person.textPlain)
|
John@78
|
117 end
|
John@78
|
118 end
|
John@78
|
119
|
John@81
|
120 function WhisperReceived(...)
|
John@81
|
121 local _,message,sender = ...
|
John@81
|
122 local senderAction = function(func)
|
John@81
|
123 local le = PersonList:Select(sender)
|
John@81
|
124 if le then
|
John@81
|
125 local person = ConvertLe2Line(le)
|
John@81
|
126 if person then
|
John@81
|
127 func(person)
|
John@81
|
128 end
|
John@81
|
129 end
|
John@81
|
130 end
|
John@81
|
131
|
John@81
|
132 if state == "bidding" and admin then -- todo: should only be ML
|
John@81
|
133 message = _G.strtrim(message)
|
John@81
|
134 message = _G.strlower(message)
|
John@81
|
135 if message == "bid" then
|
John@81
|
136 senderAction(InitiateBid)
|
John@81
|
137 elseif message == "retract" then
|
John@81
|
138 senderAction(InitiateRetract)
|
John@81
|
139 elseif message == "roll" then
|
John@81
|
140 senderAction(InitiateRollRequest)
|
John@81
|
141 end
|
John@81
|
142 end
|
John@81
|
143 end
|
John@81
|
144
|
John@81
|
145 local statelistener =
|
John@81
|
146 {
|
John@81
|
147 ["StateEvent"] = function(self)
|
John@81
|
148 if state == "bidding" then
|
John@81
|
149 event:RegisterEvent("CHAT_MSG_WHISPER", WhisperReceived)
|
John@81
|
150 else
|
John@81
|
151 --event:UnregisterEvent("CHAT_MSG_WHISPER") -- todo
|
John@81
|
152 end
|
John@81
|
153 end,
|
John@81
|
154 }
|
John@81
|
155
|
John@73
|
156 function InitializeLooting()
|
John@73
|
157 event:RegisterEvent("OPEN_MASTER_LOOT_LIST",OpenMasterLootList)
|
John@73
|
158 event:RegisterEvent("UPDATE_MASTER_LOOT_LIST",UpdateMasterLootList)
|
John@73
|
159 event:RegisterEvent("LOOT_CLOSED",LootClosed)
|
John@73
|
160 event:RegisterEvent("LOOT_OPENED",LootOpened)
|
John@76
|
161
|
John@76
|
162 -- todo: what are these
|
John@82
|
163 event:RegisterEvent("LOOT_SLOT_CLEARED",function(_,index) InitiateLSClear(index) end)
|
John@76
|
164 event:RegisterEvent("LOOT_SLOT_CHANGED",function() print("LSChanged") end)
|
John@81
|
165
|
John@81
|
166 RegisterListenerStateChange(statelistener)
|
John@81
|
167 statelistener:StateEvent()
|
John@73
|
168 end
|
John@73
|
169
|