Support native Auto Loot in AoE Loot
This commit is contained in:
+46
-3
@@ -13,12 +13,24 @@ local module = ShaguTweaks:register({
|
|||||||
module.enable = function(self)
|
module.enable = function(self)
|
||||||
local frame = CreateFrame("Frame", "ShaguTweaksAoELoot")
|
local frame = CreateFrame("Frame", "ShaguTweaksAoELoot")
|
||||||
local pending = false
|
local pending = false
|
||||||
|
local releaseDeadline = 0
|
||||||
|
|
||||||
local function IsMasterLootActive()
|
local function IsMasterLootActive()
|
||||||
if not GetLootMethod then return false end
|
if not GetLootMethod then return false end
|
||||||
return GetLootMethod() == "master"
|
return GetLootMethod() == "master"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function IsAutoLootActive()
|
||||||
|
if not GetCVar then return false end
|
||||||
|
|
||||||
|
local enabled = tonumber(GetCVar("autoLootDefault")) == 1
|
||||||
|
if IsShiftKeyDown and IsShiftKeyDown() then
|
||||||
|
enabled = not enabled
|
||||||
|
end
|
||||||
|
|
||||||
|
return enabled
|
||||||
|
end
|
||||||
|
|
||||||
local function CanStartAoELoot()
|
local function CanStartAoELoot()
|
||||||
if IsMasterLootActive() then return false end
|
if IsMasterLootActive() then return false end
|
||||||
if not C_Loot or not C_Loot.LootAllCorpses then return false end
|
if not C_Loot or not C_Loot.LootAllCorpses then return false end
|
||||||
@@ -33,12 +45,35 @@ module.enable = function(self)
|
|||||||
local function StartAoELoot()
|
local function StartAoELoot()
|
||||||
-- Defer for one frame so the normal loot session can close cleanly.
|
-- Defer for one frame so the normal loot session can close cleanly.
|
||||||
frame:SetScript("OnUpdate", nil)
|
frame:SetScript("OnUpdate", nil)
|
||||||
|
pending = false
|
||||||
|
releaseDeadline = 0
|
||||||
|
|
||||||
if CanStartAoELoot() then
|
if CanStartAoELoot() then
|
||||||
C_Loot.LootAllCorpses()
|
C_Loot.LootAllCorpses()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function QueueAoELoot()
|
||||||
|
pending = false
|
||||||
|
releaseDeadline = 0
|
||||||
|
frame:SetScript("OnUpdate", StartAoELoot)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function WaitForLootRelease()
|
||||||
|
-- Native Auto Loot can finish before this module receives LOOT_OPENED.
|
||||||
|
-- In that case LOOT_CLOSED has already passed, so use the empty session
|
||||||
|
-- as a fallback and queue the ClassicAPI walk on the following frame.
|
||||||
|
if pending and (not GetNumLootItems or GetNumLootItems() == 0) then
|
||||||
|
QueueAoELoot()
|
||||||
|
elseif pending and GetTime() >= releaseDeadline then
|
||||||
|
-- Never leave a per-frame waiter behind if the native loot session
|
||||||
|
-- cannot finish, for example because every inventory bag is full.
|
||||||
|
pending = false
|
||||||
|
releaseDeadline = 0
|
||||||
|
frame:SetScript("OnUpdate", nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
frame:RegisterEvent("LOOT_OPENED")
|
frame:RegisterEvent("LOOT_OPENED")
|
||||||
frame:RegisterEvent("LOOT_CLOSED")
|
frame:RegisterEvent("LOOT_CLOSED")
|
||||||
|
|
||||||
@@ -47,6 +82,7 @@ module.enable = function(self)
|
|||||||
-- The master looter must keep the normal window to inspect and assign loot.
|
-- The master looter must keep the normal window to inspect and assign loot.
|
||||||
if IsMasterLootActive() then
|
if IsMasterLootActive() then
|
||||||
pending = false
|
pending = false
|
||||||
|
releaseDeadline = 0
|
||||||
frame:SetScript("OnUpdate", nil)
|
frame:SetScript("OnUpdate", nil)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -54,13 +90,20 @@ module.enable = function(self)
|
|||||||
if pending or not CanStartAoELoot() then return end
|
if pending or not CanStartAoELoot() then return end
|
||||||
|
|
||||||
pending = true
|
pending = true
|
||||||
CloseLoot()
|
releaseDeadline = GetTime() + 3
|
||||||
|
frame:SetScript("OnUpdate", WaitForLootRelease)
|
||||||
|
|
||||||
|
-- Let native Auto Loot drain the first corpse. Without Auto Loot,
|
||||||
|
-- close the normal session so ClassicAPI can take over all corpses.
|
||||||
|
if not IsAutoLootActive() then
|
||||||
|
CloseLoot()
|
||||||
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if event == "LOOT_CLOSED" and pending then
|
if event == "LOOT_CLOSED" and pending then
|
||||||
pending = false
|
QueueAoELoot()
|
||||||
frame:SetScript("OnUpdate", StartAoELoot)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user