Code format

This commit is contained in:
2025-05-01 17:06:20 +02:00
parent c365178b99
commit 3d8fa46711
7 changed files with 642 additions and 490 deletions

View File

@@ -19,17 +19,29 @@ local skills = {}
---@field value number
local NumberValue = {
---@param other number
Gt = function(self, other) return self.value > other end,
Gt = function(self, other)
return self.value > other
end,
---@param other number
Lt = function(self, other) return self.value < other end,
Lt = function(self, other)
return self.value < other
end,
---@param other number
Eq = function(self, other) return self.value == other end,
Eq = function(self, other)
return self.value == other
end,
---@param other number
Ne = function(self, other) return self.value ~= other end,
Ne = function(self, other)
return self.value ~= other
end,
---@param other number
Ge = function(self, other) return self.value >= other end,
Ge = function(self, other)
return self.value >= other
end,
---@param other number
Le = function(self, other) return self.value <= other end,
Le = function(self, other)
return self.value <= other
end,
}
local function NewNumberValue(value)
local ret = { value = value }
@@ -47,21 +59,37 @@ end
---@field value string
local StringValue = {
---@param other string
Gt = function(self, other) return self.value > other end,
Gt = function(self, other)
return self.value > other
end,
---@param other string
Lt = function(self, other) return self.value < other end,
Lt = function(self, other)
return self.value < other
end,
---@param other string
Eq = function(self, other) return self.value == other end,
Eq = function(self, other)
return self.value == other
end,
---@param other string
Ne = function(self, other) return self.value ~= other end,
Ne = function(self, other)
return self.value ~= other
end,
---@param other string
Ge = function(self, other) return self.value >= other end,
Ge = function(self, other)
return self.value >= other
end,
---@param other string
Le = function(self, other) return self.value <= other end,
Le = function(self, other)
return self.value <= other
end,
---@param other string
Matches = function(self, other) return string.match(self.value, other) end,
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,
Contains = function(self, other)
return string.find(self.value, other)
end,
}
local function NewStringValue(value)
local ret = { value = value }
@@ -98,9 +126,13 @@ function shared.Autoloot.Init()
---@return StringValue, string?
local function Link(slot)
local ret = NewStringValue("")
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local link = GetLootSlotLink(slot)
if link == nil then return ret, "link is nil" end
if link == nil then
return ret, "link is nil"
end
ret.value = link
return ret, nil
end
@@ -109,9 +141,13 @@ function shared.Autoloot.Init()
---@return StringValue, string?
local function Name(slot)
local ret = NewStringValue("")
if slot == nil then return ret, "slot is nil" end
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
if name == nil then
return ret, "name is nil"
end
ret.value = name
return ret, nil
end
@@ -120,9 +156,13 @@ function shared.Autoloot.Init()
---@return StringValue, string?
local function Type(slot)
local ret = NewStringValue("")
if slot == nil then return ret, "slot is nil" end
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
if type == nil then
return ret, "type is nil"
end
ret.value = type
return ret, nil
end
@@ -131,9 +171,13 @@ function shared.Autoloot.Init()
---@return StringValue, string?
local function SubType(slot)
local ret = NewStringValue("")
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local subType = select(7, GetItemInfo(Link(slot).value))
if subType == nil then return ret, "subType is nil" end
if subType == nil then
return ret, "subType is nil"
end
ret.value = subType
return ret, nil
end
@@ -142,9 +186,13 @@ function shared.Autoloot.Init()
---@return NumberValue, string?
local function ItemLevel(slot)
local ret = NewNumberValue(0)
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local itemLevel = select(4, GetItemInfo(Link(slot).value))
if itemLevel == nil then return ret, "itemLevel is nil" end
if itemLevel == nil then
return ret, "itemLevel is nil"
end
ret.value = itemLevel
return ret, nil
end
@@ -153,9 +201,13 @@ function shared.Autoloot.Init()
---@return NumberValue, string?
local function Value(slot)
local ret = NewNumberValue(0)
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local itemValue = select(11, GetItemInfo(Link(slot).value))
if itemValue == nil then return ret, "itemValue is nil" end
if itemValue == nil then
return ret, "itemValue is nil"
end
ret.value = itemValue
return ret, nil
end
@@ -164,9 +216,13 @@ function shared.Autoloot.Init()
---@return NumberValue, string?
local function SubclassId(slot)
local ret = NewNumberValue(0)
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local subclassId = select(13, GetItemInfo(Link(slot).value))
if subclassId == nil then return ret, "subclassId is nil" end
if subclassId == nil then
return ret, "subclassId is nil"
end
ret.value = subclassId
return ret, nil
end
@@ -175,9 +231,13 @@ function shared.Autoloot.Init()
---@return NumberValue, string?
local function Quantity(slot)
local ret = NewNumberValue(1)
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local quantity = select(3, GetLootSlotInfo(slot))
if quantity == nil then return ret, "quantity is nil" end
if quantity == nil then
return ret, "quantity is nil"
end
ret.value = quantity
return ret, nil
end
@@ -186,9 +246,13 @@ function shared.Autoloot.Init()
---@return StringValue, string?
local function EquipLocation(slot)
local ret = NewNumberValue(0)
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local equipLocation = select(9, GetItemInfo(Link(slot).value))
if equipLocation == nil then return ret, "equipLocation is nil" end
if equipLocation == nil then
return ret, "equipLocation is nil"
end
ret.value = equipLocation
return ret, nil
end
@@ -197,9 +261,13 @@ function shared.Autoloot.Init()
---@return StringValue, string?
local function Icon(slot)
local ret = NewStringValue("")
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local icon = select(10, GetItemInfo(Link(slot).value))
if icon == nil then return ret, "icon is nil" end
if icon == nil then
return ret, "icon is nil"
end
ret.value = icon
return ret, nil
end
@@ -208,9 +276,13 @@ function shared.Autoloot.Init()
---@return NumberValue, string?
local function BindType(slot)
local ret = NewStringValue("")
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local bindType = select(14, GetItemInfo(Link(slot).value))
if bindType == nil then return ret, "bindType is nil" end
if bindType == nil then
return ret, "bindType is nil"
end
ret.value = bindType
return ret, nil
end
@@ -219,9 +291,13 @@ function shared.Autoloot.Init()
---@return NumberValue, string?
local function Quality(slot)
local ret = NewNumberValue(-1)
if slot == nil then return ret, "slot is nil" end
if slot == nil then
return ret, "slot is nil"
end
local quality = select(4, GetLootSlotInfo(slot))
if quality == nil then return ret, "quality is nil" end
if quality == nil then
return ret, "quality is nil"
end
ret.value = quality
return ret, nil
end
@@ -235,93 +311,121 @@ function shared.Autoloot.Init()
---@class GoldFilter : Filter
local GoldFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.gold.enabled then return false end
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
end,
}
---@class OrderResourceFilter : Filter
local OrderResourceFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.orderResource.enabled then return false end
if not shared.config.autoloot.filter.orderResource.enabled then
return false
end
return Name(slot):Contains("Order Resources")
end
end,
}
---@class MountFilter : Filter
local MountFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.mount.enabled then return false end
if not shared.config.autoloot.filter.mount.enabled then
return false
end
return Type(slot):Eq("Mount")
end
end,
}
---@class IlvlFilter : Filter
local IlvlFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.ilvl.enabled then return false end
if not shared.config.autoloot.filter.ilvl.enabled then
return false
end
return ItemLevel(slot):Ge(shared.config.autoloot.filter.ilvl.value)
end
end,
}
---@class ProfessionFilter : Filter
local ProfessionFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.profession.enabled then return false end
if not shared.config.autoloot.filter.profession.enabled then
return false
end
local type = Type(slot)
if not type:Eq("Tradeskill") then return false end
if not type:Eq("Tradeskill") then
return false
end
local subtype = SubType(slot)
local professions = { strsplit(",", shared.config.autoloot.filter.profession.professions) }
return shared.TableContains(professions, subtype) or false
end
end,
}
---@class ValueFilter : Filter
local ValueFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.value.enabled then return false end
if not shared.config.autoloot.filter.value.enabled then
return false
end
local value = Value(slot)
if shared.config.autoloot.filter.value.byStack then
value = value * Quantity(slot).value
end
return value:Ge(shared.config.autoloot.filter.value.value)
end
end,
}
---@class GreyValueFilter : Filter
local GreyValueFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.greyvalue.enabled then return false end
if not shared.config.autoloot.filter.greyvalue.enabled then
return false
end
local quality = Quality(slot)
if not quality:Eq(0) then return false end
if not quality:Eq(0) then
return false
end
local value = Value(slot)
if shared.config.autoloot.filter.greyvalue.byStack then
value = value * Quantity(slot).value
end
return value:Ge(shared.config.autoloot.filter.greyvalue.value)
end
end,
}
---@class QuestItemFilter : Filter
local QuestItemFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.questItem.enabled then return false end
if not shared.config.autoloot.filter.questItem.enabled then
return false
end
return Type(slot):Eq("Quest") and SubType(slot):Eq("Quest")
end
end,
}
---@class ClassGearFilter : Filter
local ClassGearFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.classGear.enabled then return false end
if not shared.config.autoloot.filter.classGear.enabled then
return false
end
local ilvlThreshold = shared.config.autoloot.filter.classGear.ilvlThreshold
local qualityThreshold = shared.config.autoloot.filter.classGear.qualityThreshold
local isEquippable = skills[select(3, UnitClass("player"))][SubType(slot).value] or false
if not isEquippable then return false end
if not isEquippable then
return false
end
return ItemLevel(slot):Ge(ilvlThreshold) and Quality(slot):Ge(qualityThreshold)
end
end,
}
---@class NameFilter : Filter
local NameFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.name.enabled then return false end
if not shared.config.autoloot.filter.name.enabled then
return false
end
local whitelist = { strsplit(",", shared.config.autoloot.filter.name.whitelist) }
for _, name in ipairs(whitelist) do
if not shared.config.autoloot.filter.name.caseSensitive then name = name:lower() end
if not shared.config.autoloot.filter.name.caseSensitive then
name = name:lower()
end
if shared.config.autoloot.filter.name.exact then
return Name(slot):Eq(name)
else
@@ -329,37 +433,47 @@ function shared.Autoloot.Init()
end
end
return false
end
end,
}
---@class BoeFilter : Filter
local BoeFilter = {
types = { "Armor", "Weapon" },
equipLocs = { "INVTYPE_FINGER", "INVTYPE_TRINKET", "INVTYPE_CLOAK", "INVTYPE_NECK" },
Matches = function(self, slot)
if not shared.config.autoloot.filter.boe.enabled then return false end
if not shared.config.autoloot.filter.boe.enabled then
return false
end
local ilvlThreshold = shared.config.autoloot.filter.boe.ilvlThreshold
local qualityThreshold = shared.config.autoloot.filter.boe.qualityThreshold
local type = Type(slot)
local equipLoc = EquipLocation(slot)
if not shared.TableContains(self.types, type) or not shared.TableContains(self.equipLocs, equipLoc) then return false end
if not shared.TableContains(self.types, type) or not shared.TableContains(self.equipLocs, equipLoc) then
return false
end
return BindType(slot):Eq(1) and ItemLevel(slot):Ge(ilvlThreshold) and Quality(slot):Ge(qualityThreshold)
end
end,
}
---@class APFilter : Filter
local APFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.ap.enabled then return false end
return Value(slot):Eq(0) and Type(slot):Eq("Consumable") and SubType(slot):Eq("Other") and
SubclassId(slot):Eq(8)
end
if not shared.config.autoloot.filter.ap.enabled then
return false
end
return Value(slot):Eq(0)
and Type(slot):Eq("Consumable")
and SubType(slot):Eq("Other")
and SubclassId(slot):Eq(8)
end,
}
---@class EverythingFilter : Filter
local EverythingFilter = {
Matches = function(self, slot)
if not shared.config.autoloot.filter.everything.enabled then return false end
if not shared.config.autoloot.filter.everything.enabled then
return false
end
return true
end
end,
}
---@type Filter[]
@@ -401,11 +515,7 @@ function shared.Autoloot.Init()
local quality = Quality(slot).value
local icon = Icon(slot).value
local addonPayload = string.format("%s|%s|%s|%s",
name,
quantity,
quality,
icon)
local addonPayload = string.format("%s|%s|%s|%s", name, quantity, quality, icon)
SendAddonMessage("CYKA_AUTOLOOT", addonPayload, "WHISPER", UnitName("player"))
LootSlot(slot)