From 36979d2da8489e2c2e589412942c29e8baed1ac8 Mon Sep 17 00:00:00 2001 From: Dusk-92 Date: Mon, 24 Aug 2026 08:20:32 +0200 Subject: [PATCH] Phase 2: prefer live ClassicAPI vendor prices --- mods/vendor-values-classicapi.lua | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 mods/vendor-values-classicapi.lua diff --git a/mods/vendor-values-classicapi.lua b/mods/vendor-values-classicapi.lua new file mode 100644 index 0000000..5491367 --- /dev/null +++ b/mods/vendor-values-classicapi.lua @@ -0,0 +1,32 @@ +local API = ShaguTweaks.API + +-- Keep the original static database as an immediate compatibility fallback. +-- ClassicAPI's live item cache is authoritative when it has the item record, +-- which also covers Turtle/custom items and server-side price changes. +if not API or not API.itemprice or not ShaguTweaks.SellValueDB then return end + +local legacy = ShaguTweaks.SellValueDB +local live = {} + +setmetatable(live, { + __index = function(tab, itemID) + if type(itemID) ~= "number" then + return legacy[itemID] + end + + local price = API.GetItemSellPriceByID(itemID) + if price ~= nil then + -- Vendor values don't change during a session. Cache successful reads so + -- the tooltip's repeated lookups stay pure Lua after the first hit. + rawset(tab, itemID, price) + return price + end + + -- An uncached item is warmed by ClassicAPI in the background. Use the old + -- database now; a later tooltip lookup will transparently pick up live data. + return legacy[itemID] + end +}) + +ShaguTweaks.SellValueLegacyDB = legacy +ShaguTweaks.SellValueDB = live