Repository navigation
Expand file tree
/
Copy pathAutoML.lua
More file actions
377 lines (336 loc) · 14.3 KB
/
Copy pathAutoML.lua
File metadata and controls
377 lines (336 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
--[[--------------------------------------------------------------------
WhoDidIt - auto master looting
While you're the master looter and it's switched on, every grey, white
and green item (bind on pickup too) in a loot window is handed out
straight away - to you, or to a raid member you pick - plus raid mats
that are blue or purple (scraps, AQ idols, cores, Elementium). Epics
are never given out: you get a warning and a sound instead.
"If my bags are full": loot meant for you goes to a backup player
once your bags run out of space. So someone else can collect all the
trash loot, or you can collect it for them.
The button in the title bar shows whether it's on; click it to pick
who gets the loot. Same job as the AutoMasterLooter addon (by balake).
----------------------------------------------------------------------]]
local W = WhoDidIt
local A = {}
W.AutoML = A
local getn, tinsert = table.getn, table.insert
-- blue / purple items that are handed out anyway (raid mats)
A.ALWAYS = {
"Wartorn Plate Scrap", "Wartorn Chain Scrap", "Wartorn Leather Scrap", "Wartorn Cloth Scrap",
"Frozen Rune", "Elementium Ore", "Fiery Core", "Lava Core",
"Idol of Death", "Idol of Life", "Idol of Night", "Idol of Rebirth",
"Idol of Strife", "Idol of War", "Idol of the Sage", "Idol of the Sun",
}
-- greys / whites / greens that are left for you to hand out by hand
A.NEVER = {
"Tome of Tranquilizing Shot", "Onyxia Hide Backpack", "Mr. Bigglesworth",
"Hazza'rah's Dream Thread", "Gri'lek's Blood", "Wushoolay's Mane", "Renataki's Tooth",
"Dream Frog", "Infinite Frog",
"Blue Sack of Gems", "Gray Sack of Gems", "Green Sack of Gems", "Red Sack of Gems", "Yellow Sack of Gems",
}
local QUALITY = { [0] = "|cff9d9d9dgrey|r", "|cffffffffwhite|r", "|cff1eff00green|r", "|cff0070ddblue|r", "|cffa335eepurple|r" }
local function db()
local d = WhoDidItDB.aml
if type(d) ~= "table" then
d = {}
WhoDidItDB.aml = d
end
if d.maxQuality == nil then d.maxQuality = 2 end -- up to green
if type(d.always) ~= "table" then
d.always = {}
for i = 1, getn(A.ALWAYS) do d.always[A.ALWAYS[i]] = true end
end
if type(d.never) ~= "table" then
d.never = {}
for i = 1, getn(A.NEVER) do d.never[A.NEVER[i]] = true end
end
return d
end
A.DB = db
function A:On() return WhoDidItDB and db().on and true or false end
function A:Target() return WhoDidItDB and db().to end -- nil = you
function A:Backup() return WhoDidItDB and db().backup end -- nil = nobody
function A.Who(name)
return name or W.L("you")
end
local function changed()
if W.UI and W.UI.UpdateAML then W.UI:UpdateAML() end
if A.panel and A.panel:IsVisible() then A:RefreshPanel() end
end
function A:SetOn(on)
db().on = on and true or false
W.Print("Auto master looting " .. (db().on and ("|cff33ff33on|r - greys, whites and greens go to |cffffffff" .. A.Who(db().to) .. "|r") or "|cffff5555off|r") .. ".")
changed()
end
function A:SetTarget(name)
if name == UnitName("player") then name = nil end
db().to = name
if name and db().backup == name then db().backup = nil end
changed()
end
function A:SetBackup(name)
if name == UnitName("player") then name = nil end
db().backup = name
changed()
end
------------------------------------------------------------------ handing out
local function freeBagSlots()
local free = 0
for bag = 0, 4 do
local n = GetContainerNumSlots(bag) or 0
for slot = 1, n do
if not GetContainerItemLink(bag, slot) then free = free + 1 end
end
end
return free
end
A.FreeBagSlots = freeBagSlots
local warned = {}
local function onLoot()
if not A:On() or IsAddOnLoaded("AutoMasterLooter") then return end
local method, partyML = GetLootMethod()
if method ~= "master" or partyML ~= 0 then return end -- only when you're the master looter
local d = db()
local me = UnitName("player")
-- who can receive loot from this corpse: name -> candidate index
local cand = {}
for i = 1, 40 do
local n = GetMasterLootCandidate(i)
if n then cand[n] = i end
end
local to = d.to or me
if not cand[to] then
if d.to and not warned[d.to] then
warned[d.to] = true
W.Print("|cffff9933" .. d.to .. " can't receive this loot (not here or too far away) - it goes to you instead.|r")
end
to = me
end
local backup = d.backup and cand[d.backup] and d.backup
local free = (to == me) and freeBagSlots() or 99
local epics = {}
for slot = 1, GetNumLootItems() do
if LootSlotIsItem(slot) then
local _, name, _, quality = GetLootSlotInfo(slot)
if name and quality then
local give = (quality <= d.maxQuality and not d.never[name]) or d.always[name]
if give then
local who = to
if who == me and free <= 0 and backup then who = backup end
if cand[who] then
GiveMasterLoot(slot, cand[who])
if who == me then free = free - 1 end
end
elseif quality >= 4 then
tinsert(epics, name)
end
end
end
end
if getn(epics) > 0 then
W.Print("|cffa335eeEpic inside!|r " .. table.concat(epics, ", "))
PlaySound("AuctionWindowClose")
end
if to == me and free <= 0 and not backup and d.backup == nil and not warned.bags then
warned.bags = true
W.Print("|cffff9933Your bags are full.|r Pick someone under \"If my bags are full\" (title bar button) to send the loot to them instead.")
end
end
W:On("LOOT_OPENED", onLoot)
------------------------------------------------------------------ picker panel
local function roster()
local list = {}
local n = GetNumRaidMembers()
if n > 0 then
for i = 1, n do
local name, _, _, _, _, class = GetRaidRosterInfo(i)
if name then tinsert(list, { name, class }) end
end
else
for i = 1, GetNumPartyMembers() do
local name = UnitName("party" .. i)
local _, class = UnitClass("party" .. i)
if name then tinsert(list, { name, class }) end
end
end
table.sort(list, function(a, b) return a[1] < b[1] end)
return list
end
local COLS, ROWS, CW, CH = 4, 11, 92, 18
local function makeButton(parent, text, w, h)
local b = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
if W.UI and W.UI.Skin then W.UI.Skin(b) end
b:SetWidth(w)
b:SetHeight(h)
b:SetText(text)
if b.SetTextFontObject then b:SetTextFontObject(W.FontO("GameFontNormalSmall")) end
if b.SetHighlightFontObject then b:SetHighlightFontObject(W.FontO("GameFontHighlightSmall")) end
return b
end
local function tip(b, title, lines)
b:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:SetText(title, 1, 0.82, 0)
local l = (type(lines) == "function") and lines() or lines
for i = 1, getn(l) do GameTooltip:AddLine(l[i], 0.9, 0.9, 0.9, 1) end
GameTooltip:Show()
end)
b:SetScript("OnLeave", function() GameTooltip:Hide() end)
end
function A:BuildPanel()
local p = CreateFrame("Frame", "WhoDidItAutoLootPanel", UIParent)
p:SetWidth(COLS * (CW + 4) + 20)
p:SetHeight(ROWS * (CH + 2) + 132)
p:SetFrameStrata("DIALOG")
p:SetToplevel(true)
p:EnableMouse(true)
p:SetMovable(true)
p:RegisterForDrag("LeftButton")
p:SetScript("OnDragStart", function() this:StartMoving() end)
p:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
p:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
p:SetBackdropColor(0.04, 0.04, 0.06, 0.97)
p:SetBackdropBorderColor(0.55, 0.55, 0.6, 1)
p:Hide()
-- a solid fill, so nothing behind shows through
local fill = p:CreateTexture(nil, "BACKGROUND")
fill:SetTexture(0.04, 0.04, 0.06, 1)
fill:SetPoint("TOPLEFT", p, "TOPLEFT", 4, -4)
fill:SetPoint("BOTTOMRIGHT", p, "BOTTOMRIGHT", -4, 4)
tinsert(UISpecialFrames, "WhoDidItAutoLootPanel")
local title = p:CreateFontString(nil, "OVERLAY", W.FontT("GameFontNormal"))
title:SetPoint("TOPLEFT", p, "TOPLEFT", 12, -12)
title:SetText("Auto master looting")
local close = CreateFrame("Button", nil, p, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", p, "TOPRIGHT", -2, -2)
p.status = p:CreateFontString(nil, "OVERLAY", W.FontT("GameFontHighlightSmall"))
p.status:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -6)
p.status:SetWidth(COLS * (CW + 4) - 4)
p.status:SetJustifyH("LEFT")
-- on / off, then which list the names below set
p.onBtn = makeButton(p, "Turn on", 110, 20)
p.onBtn:SetPoint("TOPLEFT", p.status, "BOTTOMLEFT", 0, -8)
p.onBtn:SetScript("OnClick", function() A:SetOn(not A:On()) end)
tip(p.onBtn, "On / off", { "On: while you're the master looter, greys, whites and greens", "(and the raid mats below) are handed out as soon as you open a corpse.", "Off: nothing happens - loot as normal." })
p.toBtn = makeButton(p, "Loot goes to", 120, 20)
p.toBtn:SetPoint("LEFT", p.onBtn, "RIGHT", 6, 0)
p.toBtn:SetScript("OnClick", function() A.mode = "to"; A:RefreshPanel() end)
tip(p.toBtn, "Loot goes to", { "Pick who receives the auto-looted items: you, or anyone in the raid.", "They need to be close enough to the corpse to receive loot." })
p.bkBtn = makeButton(p, "If my bags are full", 140, 20)
p.bkBtn:SetPoint("LEFT", p.toBtn, "RIGHT", 6, 0)
p.bkBtn:SetScript("OnClick", function() A.mode = "backup"; A:RefreshPanel() end)
tip(p.bkBtn, "If my bags are full", { "When the loot goes to you and your bags run out of space,", "it goes to this player instead. Nobody = it stays on the corpse." })
p.hint = p:CreateFontString(nil, "OVERLAY", W.FontT("GameFontDisableSmall"))
p.hint:SetPoint("TOPLEFT", p.onBtn, "BOTTOMLEFT", 0, -8)
p.hint:SetJustifyH("LEFT")
p.cells = {}
for i = 1, COLS * ROWS do
local c = makeButton(p, "", CW, CH)
local col, row = math.mod(i - 1, COLS), math.floor((i - 1) / COLS)
c:SetPoint("TOPLEFT", p.hint, "BOTTOMLEFT", col * (CW + 4), -6 - row * (CH + 2))
c:SetScript("OnClick", function()
if A.mode == "backup" then A:SetBackup(this.who) else A:SetTarget(this.who) end
end)
c:Hide()
p.cells[i] = c
end
p.foot = p:CreateFontString(nil, "OVERLAY", W.FontT("GameFontDisableSmall"))
p.foot:SetPoint("BOTTOMLEFT", p, "BOTTOMLEFT", 12, 10)
p.foot:SetWidth(COLS * (CW + 4) - 4)
p.foot:SetJustifyH("LEFT")
p.foot:SetText("Only works while you're the master looter. Epics are never handed out - you get a warning.\n"
.. "Always / never lists: /wdi aml always <item>, /wdi aml never <item>, /wdi aml list")
A.panel = p
A.mode = "to"
return p
end
function A:RefreshPanel()
local p = A.panel
if not p then return end
local d = db()
p.status:SetText(d.on
and ("|cff33ff33On.|r Greys, whites and greens go to |cffffffff" .. A.Who(d.to) .. "|r"
.. (d.backup and ("; when your bags are full, to |cffffffff" .. d.backup .. "|r") or "") .. ".")
or "|cffff5555Off.|r Turn it on to hand out trash loot automatically while you're the master looter.")
p.onBtn:SetText(d.on and "|cffff5555Turn off|r" or "|cff33ff33Turn on|r")
if A.mode == "backup" then p.bkBtn:LockHighlight(); p.toBtn:UnlockHighlight() else p.toBtn:LockHighlight(); p.bkBtn:UnlockHighlight() end
p.hint:SetText(A.mode == "backup" and "Click who gets the loot when your bags are full:" or "Click who gets the auto-looted items:")
local list = roster()
local me = UnitName("player")
local cur = (A.mode == "backup") and d.backup or d.to
local entries = { { nil, nil, (A.mode == "backup") and "Nobody" or "Me" } }
for i = 1, getn(list) do
if list[i][1] ~= me then tinsert(entries, { list[i][1], list[i][2] }) end
end
for i = 1, getn(p.cells) do
local c, e = p.cells[i], entries[i]
if e then
c.who = e[1]
c:SetText(e[3] or W.CName(e[1], e[2]))
if (cur == e[1]) then c:LockHighlight() else c:UnlockHighlight() end
c:Show()
else
c:Hide()
end
end
if getn(list) == 0 then p.hint:SetText(p.hint:GetText() .. " |cff888888(join a group to see raid members)|r") end
end
-- open / close the picker under the title bar button
function A:TogglePanel(anchor)
local p = A.panel or A:BuildPanel()
if p:IsVisible() then p:Hide() return end
p:ClearAllPoints()
if anchor then p:SetPoint("TOPRIGHT", anchor, "BOTTOMRIGHT", 0, -4) else p:SetPoint("CENTER", UIParent, "CENTER", 0, 0) end
A:RefreshPanel()
p:Show()
end
W:On("RAID_ROSTER_UPDATE", function() if A.panel and A.panel:IsVisible() then A:RefreshPanel() end end)
W:On("PARTY_MEMBERS_CHANGED", function() if A.panel and A.panel:IsVisible() then A:RefreshPanel() end end)
------------------------------------------------------------------ commands + hand-over
function A:Slash(rest)
local _, _, cmd, arg = string.find(rest or "", "^(%S*)%s*(.-)%s*$")
cmd = string.lower(cmd or "")
local d = db()
if cmd == "" then
A:SetOn(not d.on)
elseif cmd == "on" or cmd == "off" then
A:SetOn(cmd == "on")
elseif cmd == "to" then
A:SetTarget(arg ~= "" and string.lower(arg) ~= "me" and arg or nil)
W.Print("Auto-looted items go to |cffffffff" .. A.Who(d.to) .. "|r.")
elseif cmd == "backup" then
A:SetBackup(arg ~= "" and string.lower(arg) ~= "none" and arg or nil)
W.Print("When your bags are full, loot goes to |cffffffff" .. (d.backup or "nobody") .. "|r.")
elseif cmd == "always" or cmd == "never" then
if arg == "" then W.Print("Usage: /wdi aml " .. cmd .. " <exact item name>") return end
local other = (cmd == "always") and "never" or "always"
if d[cmd][arg] then d[cmd][arg] = nil else d[cmd][arg] = true; d[other][arg] = nil end
W.Print(arg .. (d[cmd][arg] and (" will " .. ((cmd == "always") and "always be handed out" or "never be handed out")) or (" removed from the " .. cmd .. " list")) .. ".")
elseif cmd == "list" then
local function keys(t) local l = {}; for k in pairs(t) do tinsert(l, k) end; table.sort(l); return table.concat(l, ", ") end
W.Print("Handed out: everything up to " .. QUALITY[d.maxQuality] .. ", except the never list.")
DEFAULT_CHAT_FRAME:AddMessage("|cff33ff33Always:|r " .. keys(d.always))
DEFAULT_CHAT_FRAME:AddMessage("|cffff7777Never:|r " .. keys(d.never))
else
W.Print("/wdi aml - on/off, /wdi aml to <name|me>, /wdi aml backup <name|none>, /wdi aml always|never <item>, /wdi aml list")
end
changed()
end
-- /automl for anyone used to AutoMasterLooter (not while it's still loaded)
if not IsAddOnLoaded("AutoMasterLooter") then
SLASH_WHODIDITAML1 = "/automl"
SLASH_WHODIDITAML2 = "/automasterlooter"
SlashCmdList["WHODIDITAML"] = function(msg) A:Slash(msg) end
end
local handedOver
W:On("PLAYER_ENTERING_WORLD", function()
if handedOver or not IsAddOnLoaded("AutoMasterLooter") then return end
handedOver = true
W:AskHandover("AutoMasterLooter", "auto master looting (the Auto-loot button in its title bar)")
end)