refactor checkStashItem()

This'll probably break it, (it works for me) but refactored the stash item check, it was calling `stashHasItem()` for every ingredient check, now it sends the whole table of ingredients per item to craft and checks them together instead of separately

Also removes a `Wait()`, as it shouldn't need it with this change..maybe
This commit is contained in:
Jim Shield
2025-05-05 12:28:30 +01:00
parent e9c54cbdd4
commit 1f4a2ee3d9

View File

@@ -47,12 +47,12 @@ function GetStashTimeout(stashName, stop)
stashCache[stashName] = { items = {}, timeout = 0 } stashCache[stashName] = { items = {}, timeout = 0 }
stash = stashCache[stashName] stash = stashCache[stashName]
else else
debugPrint("^6Bridge^7: ^2Local Stash ^7'^3"..stashName.."^7'^2 cache found^7") debugPrint("^6Bridge^7: ^2Local Stash for ^7'^3"..stashName.."^7'^2 cache found^7")
end end
-- If there are already items in cache, skip recheck. -- If there are already items in cache, skip recheck.
if countTable(stashCache[stashName].items) > 0 then if countTable(stashCache[stashName].items) > 0 then
debugPrint("^6Bridge^7: '^3"..stashName.." ^2Items found in cache, skipping recheck") debugPrint("^6Bridge^7: '^3"..stashName.."^7' ^2Items found in local cache, skipping server recheck")
return true return true
end end
@@ -90,22 +90,14 @@ function checkStashItem(stashes, itemTable)
end end
if type(stashes) == "table" then if type(stashes) == "table" then
local successes = 0 debugPrint("^6Bridge^7: ^2Checking multiple stashes for ingredients^7")
local itemCount = countTable(itemTable)
-- Iterate over each provided stash name. -- Iterate over each provided stash name.
for _, name in pairs(stashes) do for _, name in pairs(stashes) do
Wait(10) -- Delay to avoid multiple callbacks issues.
GetStashTimeout(name) GetStashTimeout(name)
for item, amount in pairs(itemTable) do if stashhasItem(stashCache[name].items, itemTable, nil) then
debugPrint("^6Bridge^7: ^2Checking "..(name and " '^3"..name.."^7'" or "").." ingredients - ^6"..item.."^7")
if stashhasItem(stashCache[name].items, item, amount) then
successes += 1
if successes == itemCount then
return true, name return true, name
end end
end end
end
end
else else
debugPrint("^6Bridge^7: ^2Checking "..(stashes and " '^3"..stashes.."^7'" or "").." ingredients") debugPrint("^6Bridge^7: ^2Checking "..(stashes and " '^3"..stashes.."^7'" or "").." ingredients")
GetStashTimeout(stashes) GetStashTimeout(stashes)