From 220138cc705664983d4d34c393b927a2e02cff38 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 16 Dec 2024 15:29:34 +0100 Subject: [PATCH] Migrate from weakaura --- Autoloot.lua | 545 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 544 insertions(+), 1 deletion(-) diff --git a/Autoloot.lua b/Autoloot.lua index a347f6b..773db4b 100644 --- a/Autoloot.lua +++ b/Autoloot.lua @@ -1,6 +1,7 @@ local addonname, shared = ... ---@cast shared CykaShared ---@cast addonname string +local skills = {} ---@class Autoloot ---@field Init fun() @@ -101,6 +102,105 @@ function shared.Autoloot.Init() return ret, nil end + ---@param slot number + ---@return StringValue, string? + local function SubType(slot) + local ret = StringValue("") + 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 + ret.value = subType + return ret, nil + end + + ---@param slot number + ---@return NumberValue, string? + local function ItemLevel(slot) + local ret = NumberValue(0) + 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 + ret.value = itemLevel + return ret, nil + end + + ---@param slot number + ---@return NumberValue, string? + local function Value(slot) + local ret = NumberValue(0) + 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 + ret.value = itemValue + return ret, nil + end + + ---@param slot number + ---@return NumberValue, string? + local function SubclassId(slot) + local ret = NumberValue(0) + 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 + ret.value = subclassId + return ret, nil + end + + ---@param slot number + ---@return NumberValue, string? + local function Quantity(slot) + local ret = NumberValue(1) + if slot == nil then return ret, "slot is nil" end + local quantity = select(3, GetItemInfo(Link(slot).value)) + if quantity == nil then return ret, "quantity is nil" end + ret.value = quantity + return ret, nil + end + + ---@param slot number + ---@return StringValue, string? + local function EquipLocation(slot) + local ret = NumberValue(0) + 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 + ret.value = equipLocation + return ret, nil + end + + ---@param slot number + ---@return StringValue, string? + local function Icon(slot) + local ret = StringValue("") + 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 + ret.value = icon + return ret, nil + end + + ---@param slot number + ---@return NumberValue, string? + local function BindType(slot) + local ret = StringValue("") + 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 + ret.value = bindType + return ret, nil + end + + ---@param slot number + ---@return NumberValue, string? + local function Quality(slot) + local ret = NumberValue(-1) + if slot == nil then return ret, "slot is nil" end + local quality = select(3, GetItemInfo(Link(slot).value)) + if quality == nil then return ret, "quality is nil" end + ret.value = quality + return ret, nil + end + -- _____ ___ _ _____ _____ ____ ____ -- | ___|_ _| | |_ _| ____| _ \/ ___| -- | |_ | || | | | | _| | |_) \___ \ @@ -109,16 +209,146 @@ function shared.Autoloot.Init() ---@class GoldFilter : Filter local GoldFilter = { - Matches = function(slot) + Matches = function(self, 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 } + ---@class OrderResourceFilter : Filter + local OrderResourceFilter = { + Matches = function(self, slot) + if not shared.config.autoloot.filter.orderResource.enabled then return false end + return Name(slot):Contains("Order Resources") + end + } + ---@class MountFilter : Filter + local MountFilter = { + Matches = function(self, slot) + if not shared.config.autoloot.filter.mount.enabled then return false end + return Type(slot):Eq("Mount") + end + } + ---@class IlvlFilter : Filter + local IlvlFilter = { + Matches = function(self, slot) + if not shared.config.autoloot.filter.ilvl.enabled then return false end + return ItemLevel(slot):Ge(shared.config.autoloot.filter.ilvl.value) + end + } + ---@class ProfessionFilter : Filter + local ProfessionFilter = { + Matches = function(self, slot) + 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 + local subtype = SubType(slot) + return shared.config.autoloot.filter.profession.professions[subtype] or false + end + } + ---@class ValueFilter : Filter + local ValueFilter = { + Matches = function(self, slot) + if not shared.config.autoloot.filter.value.enabled then return false end + local value = ItemValue(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 + } + ---@class GreyValueFilter : Filter + local GreyValueFilter = { + Matches = function(self, slot) + 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 + local value = ItemValue(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 + } + ---@class QuestItemFilter : Filter + local QuestItemFilter = { + Matches = function(self, slot) + if not shared.config.autoloot.filter.questItem.enabled then return false end + return Type(slot):Eq("Quest") and SubType(slot):Eq("Quest") + end + } + ---@class ClassGearFilter : Filter + local ClassGearFilter = { + Matches = function(self, slot) + 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 + return ItemLevel(slot):Ge(ilvlThreshold) and Quality(slot):Ge(qualityThreshold) + end + } + ---@class NameFilter : Filter + local NameFilter = { + Matches = function(self, slot) + 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 shared.config.autoloot.filter.name.exact then + return Name(slot):Eq(name) + else + return Name(slot):Contains(name) + end + end + return false + 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 + 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 + return BindType(slot):Eq(1) and ItemLevel(slot):Ge(ilvlThreshold) and Quality(slot):Ge(qualityThreshold) + 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 + } + ---@class EverythingFilter : Filter + local EverythingFilter = { + Matches = function(self, slot) + return true + end + } ---@type Filter[] local Filters = { + APFilter, + BoeFilter, + ClassGearFilter, + EverythingFilter, GoldFilter, + GreyValueFilter, + IlvlFilter, + MountFilter, + NameFilter, + OrderResourceFilter, + ProfessionFilter, + QuestItemFilter, + ValueFilter, } -- _ ___ ___ _____ _ ___ ____ ___ ____ @@ -148,3 +378,316 @@ function shared.Autoloot.Init() print("Cyka - Autoloot loaded") end + +skills = { + --Warrior + [1] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 0, + ["Mail"] = 0, + ["Plate"] = 1, + ["Shields"] = 1, + --Weapon Skills + ["One-Handed Axes"] = 1, + ["Two-Handed Axes"] = 1, + ["Bows"] = 1, + ["Guns"] = 1, + ["One-Handed Maces"] = 1, + ["Two-Handed Maces"] = 1, + ["Polearms"] = 1, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 1, + ["Warglaives"] = 1, + ["Staves"] = 1, + ["Fist Weapons"] = 1, + ["Daggers"] = 1, + ["Crossbows"] = 1, + ["Wands"] = 0, + }, + --Paladin + [2] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 0, + ["Mail"] = 0, + ["Plate"] = 1, + ["Shields"] = 1, + --Weapon Skills + ["One-Handed Axes"] = 1, + ["Two-Handed Axes"] = 1, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 1, + ["Two-Handed Maces"] = 1, + ["Polearms"] = 1, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 1, + ["Warglaives"] = 0, + ["Staves"] = 0, + ["Fist Weapons"] = 0, + ["Daggers"] = 0, + ["Crossbows"] = 0, + ["Wands"] = 0, + }, + --Hunter + [3] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 0, + ["Mail"] = 1, + ["Plate"] = 0, + ["Shields"] = 0, + --Weapon Skills + ["One-Handed Axes"] = 1, + ["Two-Handed Axes"] = 1, + ["Bows"] = 1, + ["Guns"] = 1, + ["One-Handed Maces"] = 0, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 1, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 1, + ["Warglaives"] = 0, + ["Staves"] = 1, + ["Fist Weapons"] = 1, + ["Daggers"] = 1, + ["Crossbows"] = 1, + ["Wands"] = 0, + }, + --Rogue + [4] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 1, + ["Mail"] = 0, + ["Plate"] = 0, + ["Shields"] = 0, + --Weapon Skills + ["One-Handed Axes"] = 1, + ["Two-Handed Axes"] = 0, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 1, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 0, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 0, + ["Warglaives"] = 0, + ["Staves"] = 0, + ["Fist Weapons"] = 1, + ["Daggers"] = 1, + ["Crossbows"] = 0, + ["Wands"] = 0, + }, + --Priest + [5] = { + --Armor Skills + ["Cloth"] = 1, + ["Leather"] = 0, + ["Mail"] = 0, + ["Plate"] = 0, + ["Shields"] = 0, + --Weapon Skills + ["One-Handed Axes"] = 0, + ["Two-Handed Axes"] = 0, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 1, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 0, + ["One-Handed Swords"] = 0, + ["Two-Handed Swords"] = 0, + ["Warglaives"] = 0, + ["Staves"] = 1, + ["Fist Weapons"] = 0, + ["Daggers"] = 1, + ["Crossbows"] = 0, + ["Wands"] = 1, + }, + --Death Knight + [6] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 0, + ["Mail"] = 0, + ["Plate"] = 1, + ["Shields"] = 0, + --Weapon Skills + ["One-Handed Axes"] = 1, + ["Two-Handed Axes"] = 1, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 1, + ["Two-Handed Maces"] = 1, + ["Polearms"] = 1, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 1, + ["Warglaives"] = 0, + ["Staves"] = 0, + ["Fist Weapons"] = 0, + ["Daggers"] = 0, + ["Crossbows"] = 0, + ["Wands"] = 0, + }, + --Shaman + [7] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 0, + ["Mail"] = 1, + ["Plate"] = 0, + ["Shields"] = 1, + --Weapon Skills + ["One-Handed Axes"] = 1, + ["Two-Handed Axes"] = 0, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 1, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 0, + ["One-Handed Swords"] = 0, + ["Two-Handed Swords"] = 0, + ["Warglaives"] = 0, + ["Staves"] = 1, + ["Fist Weapons"] = 1, + ["Daggers"] = 1, + ["Crossbows"] = 0, + ["Wands"] = 0, + }, + --Mage + [8] = { + --Armor Skills + ["Cloth"] = 1, + ["Leather"] = 0, + ["Mail"] = 0, + ["Plate"] = 0, + ["Shields"] = 0, + --Weapon Skills + ["One-Handed Axes"] = 0, + ["Two-Handed Axes"] = 0, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 0, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 0, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 0, + ["Warglaives"] = 0, + ["Staves"] = 1, + ["Fist Weapons"] = 0, + ["Daggers"] = 1, + ["Crossbows"] = 0, + ["Wands"] = 1, + }, + --Warlock + [9] = { + --Armor Skills + ["Cloth"] = 1, + ["Leather"] = 0, + ["Mail"] = 0, + ["Plate"] = 0, + ["Shields"] = 0, + --Weapon Skills + ["One-Handed Axes"] = 0, + ["Two-Handed Axes"] = 0, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 0, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 0, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 0, + ["Warglaives"] = 0, + ["Staves"] = 1, + ["Fist Weapons"] = 0, + ["Daggers"] = 1, + ["Crossbows"] = 0, + ["Wands"] = 1, + }, + --Monk + [10] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 1, + ["Mail"] = 0, + ["Plate"] = 1, + ["Shields"] = 1, + --Weapon Skills + ["One-Handed Axes"] = 1, + ["Two-Handed Axes"] = 0, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 1, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 1, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 0, + ["Warglaives"] = 0, + ["Staves"] = 1, + ["Fist Weapons"] = 1, + ["Daggers"] = 0, + ["Crossbows"] = 0, + ["Wands"] = 0, + }, + --Druid + [11] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 1, + ["Mail"] = 0, + ["Plate"] = 0, + ["Shields"] = 0, + --Weapon Skills + ["One-Handed Axes"] = 0, + ["Two-Handed Axes"] = 0, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 1, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 1, + ["One-Handed Swords"] = 0, + ["Two-Handed Swords"] = 0, + ["Warglaives"] = 0, + ["Staves"] = 1, + ["Fist Weapons"] = 1, + ["Daggers"] = 1, + ["Crossbows"] = 0, + ["Wands"] = 0, + }, + --Demon Hunter + [12] = { + --Armor Skills + ["Cloth"] = 0, + ["Leather"] = 1, + ["Mail"] = 0, + ["Plate"] = 0, + ["Shields"] = 0, + --Weapon Skills + ["One-Handed Axes"] = 1, + ["Two-Handed Axes"] = 0, + ["Bows"] = 0, + ["Guns"] = 0, + ["One-Handed Maces"] = 0, + ["Two-Handed Maces"] = 0, + ["Polearms"] = 0, + ["One-Handed Swords"] = 1, + ["Two-Handed Swords"] = 0, + ["Warglaives"] = 1, + ["Staves"] = 0, + ["Fist Weapons"] = 1, + ["Daggers"] = 0, + ["Crossbows"] = 0, + ["Wands"] = 0, + }, +} +--aura_env.qualityColors = { +-- "\124cff9d9d9d", -- Poor +-- "\124cffffffff", -- Common +-- "\124cff1eff00", -- Uncommon +-- "\124cff0070dd", -- Rare +-- "\124cffa335ee", -- Epic +-- "\124cffff8000", -- Legendary +-- "\124cffe6cc80", -- Artifact +-- "\124cff00ccff", -- Heirloom +--}