Fix autoloot
This commit is contained in:
55
Autoloot.lua
55
Autoloot.lua
@@ -31,6 +31,17 @@ local NumberValue = {
|
|||||||
---@param other number
|
---@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 }
|
||||||
|
setmetatable(ret, NumberValue)
|
||||||
|
ret.Gt = NumberValue.Gt
|
||||||
|
ret.Lt = NumberValue.Lt
|
||||||
|
ret.Eq = NumberValue.Eq
|
||||||
|
ret.Ne = NumberValue.Ne
|
||||||
|
ret.Ge = NumberValue.Ge
|
||||||
|
ret.Le = NumberValue.Le
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
---@class StringValue : Value
|
---@class StringValue : Value
|
||||||
---@field value string
|
---@field value string
|
||||||
@@ -52,9 +63,23 @@ local StringValue = {
|
|||||||
---@param other string
|
---@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 }
|
||||||
|
-- Idk why setmetatable is not working... I thought it would...
|
||||||
|
setmetatable(ret, StringValue)
|
||||||
|
ret.Gt = StringValue.Gt
|
||||||
|
ret.Lt = StringValue.Lt
|
||||||
|
ret.Eq = StringValue.Eq
|
||||||
|
ret.Ne = StringValue.Ne
|
||||||
|
ret.Ge = StringValue.Ge
|
||||||
|
ret.Le = StringValue.Le
|
||||||
|
ret.Matches = StringValue.Matches
|
||||||
|
ret.Contains = StringValue.Contains
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
---@class Filter
|
---@class Filter
|
||||||
---@field Matches fun(slot: number): boolean
|
---@field Matches fun(self: Filter, slot: number): boolean
|
||||||
|
|
||||||
shared.Autoloot = { Init = function() end }
|
shared.Autoloot = { Init = function() end }
|
||||||
function shared.Autoloot.Init()
|
function shared.Autoloot.Init()
|
||||||
@@ -72,7 +97,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return StringValue, string?
|
---@return StringValue, string?
|
||||||
local function Link(slot)
|
local function Link(slot)
|
||||||
local ret = StringValue("")
|
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)
|
local link = GetLootSlotLink(slot)
|
||||||
if link == nil then return ret, "link is nil" end
|
if link == nil then return ret, "link is nil" end
|
||||||
@@ -83,7 +108,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return StringValue, string?
|
---@return StringValue, string?
|
||||||
local function Name(slot)
|
local function Name(slot)
|
||||||
local ret = StringValue("")
|
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))
|
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
|
||||||
@@ -94,7 +119,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return StringValue, string?
|
---@return StringValue, string?
|
||||||
local function Type(slot)
|
local function Type(slot)
|
||||||
local ret = StringValue("")
|
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))
|
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
|
||||||
@@ -105,7 +130,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return StringValue, string?
|
---@return StringValue, string?
|
||||||
local function SubType(slot)
|
local function SubType(slot)
|
||||||
local ret = StringValue("")
|
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))
|
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
|
||||||
@@ -116,7 +141,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return NumberValue, string?
|
---@return NumberValue, string?
|
||||||
local function ItemLevel(slot)
|
local function ItemLevel(slot)
|
||||||
local ret = NumberValue(0)
|
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))
|
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
|
||||||
@@ -127,7 +152,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return NumberValue, string?
|
---@return NumberValue, string?
|
||||||
local function Value(slot)
|
local function Value(slot)
|
||||||
local ret = NumberValue(0)
|
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))
|
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
|
||||||
@@ -138,7 +163,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return NumberValue, string?
|
---@return NumberValue, string?
|
||||||
local function SubclassId(slot)
|
local function SubclassId(slot)
|
||||||
local ret = NumberValue(0)
|
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))
|
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
|
||||||
@@ -149,7 +174,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return NumberValue, string?
|
---@return NumberValue, string?
|
||||||
local function Quantity(slot)
|
local function Quantity(slot)
|
||||||
local ret = NumberValue(1)
|
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, GetItemInfo(Link(slot).value))
|
local quantity = select(3, GetItemInfo(Link(slot).value))
|
||||||
if quantity == nil then return ret, "quantity is nil" end
|
if quantity == nil then return ret, "quantity is nil" end
|
||||||
@@ -160,7 +185,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return StringValue, string?
|
---@return StringValue, string?
|
||||||
local function EquipLocation(slot)
|
local function EquipLocation(slot)
|
||||||
local ret = NumberValue(0)
|
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))
|
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
|
||||||
@@ -171,7 +196,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return StringValue, string?
|
---@return StringValue, string?
|
||||||
local function Icon(slot)
|
local function Icon(slot)
|
||||||
local ret = StringValue("")
|
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))
|
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
|
||||||
@@ -182,7 +207,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return NumberValue, string?
|
---@return NumberValue, string?
|
||||||
local function BindType(slot)
|
local function BindType(slot)
|
||||||
local ret = StringValue("")
|
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))
|
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
|
||||||
@@ -193,7 +218,7 @@ function shared.Autoloot.Init()
|
|||||||
---@param slot number
|
---@param slot number
|
||||||
---@return NumberValue, string?
|
---@return NumberValue, string?
|
||||||
local function Quality(slot)
|
local function Quality(slot)
|
||||||
local ret = NumberValue(-1)
|
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(3, GetItemInfo(Link(slot).value))
|
local quality = select(3, GetItemInfo(Link(slot).value))
|
||||||
if quality == nil then return ret, "quality is nil" end
|
if quality == nil then return ret, "quality is nil" end
|
||||||
@@ -332,6 +357,7 @@ function shared.Autoloot.Init()
|
|||||||
---@class EverythingFilter : Filter
|
---@class EverythingFilter : Filter
|
||||||
local EverythingFilter = {
|
local EverythingFilter = {
|
||||||
Matches = function(self, slot)
|
Matches = function(self, slot)
|
||||||
|
if not shared.config.autoloot.filter.everything.enabled then return false end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -367,9 +393,8 @@ function shared.Autoloot.Init()
|
|||||||
|
|
||||||
for slot = #lootInfo, 1, -1 do
|
for slot = #lootInfo, 1, -1 do
|
||||||
for _, filter in ipairs(Filters) do
|
for _, filter in ipairs(Filters) do
|
||||||
if filter.Matches(slot) then
|
if filter:Matches(slot) then
|
||||||
print(string.format("Autolooting slot %s", tostring(slot)))
|
print(string.format("Autolooting slot %s", tostring(slot)))
|
||||||
shared.DumpTable(filter, 0)
|
|
||||||
LootSlot(slot)
|
LootSlot(slot)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
4
Cyka.lua
4
Cyka.lua
@@ -41,6 +41,7 @@ local addonname, shared = ...
|
|||||||
---@field name { enabled: boolean, exact: boolean, caseSensitive: boolean, whitelist: string }
|
---@field name { enabled: boolean, exact: boolean, caseSensitive: boolean, whitelist: string }
|
||||||
---@field boe { enabled: boolean, ilvlThreshold: number, qualityThreshold: number }
|
---@field boe { enabled: boolean, ilvlThreshold: number, qualityThreshold: number }
|
||||||
---@field ap { enabled: boolean }
|
---@field ap { enabled: boolean }
|
||||||
|
---@field everything { enabled: boolean }
|
||||||
|
|
||||||
local function init()
|
local function init()
|
||||||
if not CykaPersistentData then CykaPersistentData = {} end
|
if not CykaPersistentData then CykaPersistentData = {} end
|
||||||
@@ -161,6 +162,9 @@ local function init()
|
|||||||
caseSensitive = shared.GetOrDefault(CykaPersistentData.config, { "autoloot", "filter", "name", "caseSensitive" }, false),
|
caseSensitive = shared.GetOrDefault(CykaPersistentData.config, { "autoloot", "filter", "name", "caseSensitive" }, false),
|
||||||
whitelist = shared.GetOrDefault(CykaPersistentData.config, { "autoloot", "filter", "name", "whitelist" }, ""),
|
whitelist = shared.GetOrDefault(CykaPersistentData.config, { "autoloot", "filter", "name", "whitelist" }, ""),
|
||||||
},
|
},
|
||||||
|
everything = {
|
||||||
|
enabled = shared.GetOrDefault(CykaPersistentData.config, { "autoloot", "filter", "everything", "enabled" }, true),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user