Skip to content

Commit

Permalink
Merge pull request #64 from veechs/outfitter-test
Browse files Browse the repository at this point in the history
  • Loading branch information
veechs authored Jan 25, 2025
2 parents 6ed393d + 4e42b73 commit 5ad2848
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions Config/RuleFunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,8 @@ Bagshui.config.RuleFunctions = {

-- Borrowing some code from ItemRack because it doesn't provide an
-- isolated function to parse an itemLink into their format.
local _ ,_, id = string.find(rules.item.itemLink or "", "(item:%d+:%d+:%d+:%d+)")
local _ ,_, itemRackItemId = string.find(id or "", "item:(%d+:%d+:%d+):%d+")
if not itemRackItemId or (type(itemRackItemId) == "string" and string.len(itemRackItemId) == 0) then
local found ,_, itemRackItemId = string.find(rules.item.itemLink or "", "item:(%d+:%d+:%d+):%d+")
if not found or (type(itemRackItemId) == "string" and string.len(itemRackItemId) == 0) then
return false
end

Expand Down Expand Up @@ -572,24 +571,30 @@ Bagshui.config.RuleFunctions = {
return false
end

if not _G.Outfitter_GetItemInfoFromLink then
return false
end
local outfitterItemInfo = _G.Outfitter_GetItemInfoFromLink(rules.item.itemLink)
if not outfitterItemInfo then
-- Not using `Outfitter_GetItemInfoFromLink` because it generates throwaway
-- tables and will make the garbage collector upset.
local found , _, code, enchantCode, subCode = string.find(rules.item.itemLink or "", "item:(%d+):(%d+):(%d+)")
if not found then
return false
end

local matchAny = (table.getn(ruleArguments) == 0)

for _, outfits in pairs(outfitterOutfits) do
for _, outfit in pairs(outfits) do
for outfitType, outfits in pairs(outfitterOutfits) do
for outfitId, outfit in pairs(outfits) do
local outfitName = string.lower(BsUtil.Trim(outfit.Name))
for _, item in pairs(outfit.Items) do
for slot, item in pairs(outfit.Items) do
if
item.Code == outfitterItemInfo.Code
and item.SubCode == outfitterItemInfo.SubCode
and item.EnchantCode == outfitterItemInfo.EnchantCode
item.Code == tonumber(code)
and item.SubCode == tonumber(subCode)
-- False positives seem preferable to false negatives?
-- Replicating exactly what Outfitter does in terms of
-- when it decides to do fuzzy matching and ignore
-- enchants would require more work than I'm currently
-- willing to put in. Always ignoring enchants will at
-- least ensure that items are matched more permissively.
--
-- and item.EnchantCode == tonumber(enchantCode)
then
if matchAny then
return true
Expand Down

0 comments on commit 5ad2848

Please sign in to comment.