151 lines
4.6 KiB
Lua
151 lines
4.6 KiB
Lua
local addonname, shared = ...
|
|
---@cast shared CykaShared
|
|
---@cast addonname string
|
|
|
|
---@class Autoloot
|
|
---@field Init fun()
|
|
|
|
---@class Value
|
|
---@field value any
|
|
---@field Gt fun(self:Value, other: any): boolean
|
|
---@field Lt fun(self:Value, other: any): boolean
|
|
---@field Eq fun(self:Value, other: any): boolean
|
|
---@field Ne fun(self:Value, other: any): boolean
|
|
---@field Ge fun(self:Value, other: any): boolean
|
|
---@field Le fun(self:Value, other: any): boolean
|
|
|
|
---@class NumberValue : Value
|
|
---@field value number
|
|
local NumberValue = {
|
|
---@param other number
|
|
Gt = function(self, other) return self.value > other end,
|
|
---@param other number
|
|
Lt = function(self, other) return self.value < other end,
|
|
---@param other number
|
|
Eq = function(self, other) return self.value == other end,
|
|
---@param other number
|
|
Ne = function(self, other) return self.value ~= other end,
|
|
---@param other number
|
|
Ge = function(self, other) return self.value >= other end,
|
|
---@param other number
|
|
Le = function(self, other) return self.value <= other end,
|
|
}
|
|
|
|
---@class StringValue : Value
|
|
---@field value string
|
|
local StringValue = {
|
|
---@param other string
|
|
Gt = function(self, other) return self.value > other end,
|
|
---@param other string
|
|
Lt = function(self, other) return self.value < other end,
|
|
---@param other string
|
|
Eq = function(self, other) return self.value == other end,
|
|
---@param other string
|
|
Ne = function(self, other) return self.value ~= other end,
|
|
---@param other string
|
|
Ge = function(self, other) return self.value >= other end,
|
|
---@param other string
|
|
Le = function(self, other) return self.value <= other end,
|
|
---@param other string
|
|
Matches = function(self, other) return string.match(self.value, other) end,
|
|
---@param other string
|
|
Contains = function(self, other) return string.find(self.value, other) end,
|
|
}
|
|
|
|
---@class Filter
|
|
---@field Matches fun(slot: number): boolean
|
|
|
|
shared.Autoloot = { Init = function() end }
|
|
function shared.Autoloot.Init()
|
|
if not shared.config.autoloot.enabled then
|
|
print("Cyka - Autoloot disabled")
|
|
return
|
|
end
|
|
|
|
-- ____ ____ _____ _____ ____ _____ ____ ____
|
|
-- | _ \| _ \ / _ \ \ / /_ _| _ \| ____| _ \/ ___|
|
|
-- | |_) | |_) | | | \ \ / / | || | | | _| | |_) \___ \
|
|
-- | __/| _ <| |_| |\ V / | || |_| | |___| _ < ___) |
|
|
-- |_| |_| \_\\___/ \_/ |___|____/|_____|_| \_\____/
|
|
|
|
---@param slot number
|
|
---@return StringValue, string?
|
|
local function Link(slot)
|
|
local ret = StringValue("")
|
|
if slot == nil then return ret, "slot is nil" end
|
|
local link = GetLootSlotLink(slot)
|
|
if link == nil then return ret, "link is nil" end
|
|
ret.value = link
|
|
return ret, nil
|
|
end
|
|
|
|
---@param slot number
|
|
---@return StringValue, string?
|
|
local function Name(slot)
|
|
local ret = StringValue("")
|
|
if slot == nil then return ret, "slot is nil" end
|
|
local name = select(2, GetLootSlotInfo(slot))
|
|
if name == nil then return ret, "name is nil" end
|
|
ret.value = name
|
|
return ret, nil
|
|
end
|
|
|
|
---@param slot number
|
|
---@return StringValue, string?
|
|
local function Type(slot)
|
|
local ret = StringValue("")
|
|
if slot == nil then return ret, "slot is nil" end
|
|
local type = select(6, GetItemInfo(Link(slot).value))
|
|
if type == nil then return ret, "type is nil" end
|
|
ret.value = type
|
|
return ret, nil
|
|
end
|
|
|
|
-- _____ ___ _ _____ _____ ____ ____
|
|
-- | ___|_ _| | |_ _| ____| _ \/ ___|
|
|
-- | |_ | || | | | | _| | |_) \___ \
|
|
-- | _| | || |___| | | |___| _ < ___) |
|
|
-- |_| |___|_____|_| |_____|_| \_\____/
|
|
|
|
---@class GoldFilter : Filter
|
|
local GoldFilter = {
|
|
Matches = function(slot)
|
|
if not shared.config.autoloot.filter.gold.enabled then return false end
|
|
local name = Name(slot)
|
|
return name:Contains("Gold") or name:Contains("Silver") or name:Contains("Copper")
|
|
end
|
|
}
|
|
|
|
---@type Filter[]
|
|
local Filters = {
|
|
GoldFilter,
|
|
}
|
|
|
|
-- _ ___ ___ _____ _ ___ ____ ___ ____
|
|
-- | | / _ \ / _ \_ _| | | / _ \ / ___|_ _/ ___|
|
|
-- | | | | | | | | || | | | | | | | | _ | | |
|
|
-- | |__| |_| | |_| || | | |__| |_| | |_| || | |___
|
|
-- |_____\___/ \___/ |_| |_____\___/ \____|___\____|
|
|
|
|
local lootReadyFrame = CreateFrame("Frame")
|
|
lootReadyFrame:RegisterEvent("LOOT_READY")
|
|
lootReadyFrame:SetScript("OnEvent", function()
|
|
local lootInfo = GetLootInfo()
|
|
shared.DumpTable(lootInfo, 0)
|
|
|
|
for slot = #lootInfo, 1, -1 do
|
|
for _, filter in ipairs(Filters) do
|
|
if filter.Matches(slot) then
|
|
print(string.format("Autolooting slot %s", tostring(slot)))
|
|
shared.DumpTable(filter, 0)
|
|
LootSlot(slot)
|
|
end
|
|
end
|
|
end
|
|
--aura_env.FilterService.Run(lootInfo)
|
|
--CloseLoot()
|
|
end)
|
|
|
|
print("Cyka - Autoloot loaded")
|
|
end
|