More structure and implement some providers and filter

This commit is contained in:
2024-12-16 13:47:33 +01:00
parent 84e44dbb7d
commit 969ffe7d48
2 changed files with 124 additions and 33 deletions

View File

@@ -7,12 +7,12 @@ local addonname, shared = ...
---@class Value
---@field value any
---@field Gt fun(other: any): boolean
---@field Lt fun(other: any): boolean
---@field Eq fun(other: any): boolean
---@field Ne fun(other: any): boolean
---@field Ge fun(other: any): boolean
---@field Le fun(other: any): boolean
---@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
@@ -31,6 +31,30 @@ local NumberValue = {
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
@@ -38,18 +62,76 @@ function shared.Autoloot.Init()
return
end
-- ____ ____ _____ _____ ____ _____ ____ ____
-- | _ \| _ \ / _ \ \ / /_ _| _ \| ____| _ \/ ___|
-- | |_) | |_) | | | \ \ / / | || | | | _| | |_) \___ \
-- | __/| _ <| |_| |\ V / | || |_| | |___| _ < ___) |
-- |_| |_| \_\\___/ \_/ |___|____/|_____|_| \_\____/
---@param slot number
---@return NumberValue, string?
local function Ilvl(slot)
local ret =
if slot == nil then return
---@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
}
-- _ ___ ___ _____ _ ___ ____ ___ ____
-- | | / _ \ / _ \_ _| | | / _ \ / ___|_ _/ ___|
-- | | | | | | | | || | | | | | | | | _ | | |
-- | |__| |_| | |_| || | | |__| |_| | |_| || | |___
-- |_____\___/ \___/ |_| |_____\___/ \____|___\____|
local lootReadyFrame = CreateFrame("Frame")
lootReadyFrame:RegisterEvent("LOOT_READY")
lootReadyFrame:SetScript("OnEvent", function()
local lootInfo = GetLootInfo()
shared.DumpTable(lootInfo, 0)
for _, loot in ipairs(lootInfo) do
if loot.locked then
Name(loot.item)
end
end
--aura_env.FilterService.Run(lootInfo)
--CloseLoot()
end)

View File

@@ -20,6 +20,10 @@ local addonname, shared = ...
---@class CykaAutolootConfig
---@field enabled boolean
---@field filter CykaAutoLootFilterConfig
---@class CykaAutoLootFilterConfig
---@field gold { enabled: boolean }
local function init()
if not CykaPersistentData then CykaPersistentData = {} end
@@ -46,33 +50,38 @@ local function init()
return value
end
---@param table table
---@param depth number?
shared.DumpTable = function(table, depth)
if not table then
print(tostring(table))
return
end
if depth == nil then
depth = 0
end
if (depth > 200) then
print("Error: Depth > 200 in dumpTable()")
return
end
for k, v in pairs(table) do
if (type(v) == "table") then
print(string.rep(" ", depth) .. k .. ":")
shared.DumpTable(v, depth + 1)
else
print(string.rep(" ", depth) .. k .. ": ", v)
end
end
end
---@param table table
---@param depth number?
shared.DumpTable = function(table, depth)
if not table then
print(tostring(table))
return
end
if depth == nil then
depth = 0
end
if (depth > 200) then
print("Error: Depth > 200 in dumpTable()")
return
end
for k, v in pairs(table) do
if (type(v) == "table") then
print(string.rep(" ", depth) .. k .. ":")
shared.DumpTable(v, depth + 1)
else
print(string.rep(" ", depth) .. k .. ": ", v)
end
end
end
shared.config = {
autoloot = {
enabled = shared.GetOrDefault(CykaPersistentData.config, { "autoloot", "enabled" }, true),
filter = {
gold = {
enabled = shared.GetOrDefault(CykaPersistentData.config, { "autoloot", "filter", "gold", "enabled" }, true),
}
}
}
}