From 932dcfdf255198e83bc9ca365c8647d5926e709b Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 22 Mar 2024 14:37:32 -0300 Subject: [PATCH] fix: outfit memorial --- .../actions/objects/outfit_memorial.lua | 70 +++++++++++++++++++ .../actions/objects/outfits_memorial.lua | 67 ------------------ 2 files changed, 70 insertions(+), 67 deletions(-) create mode 100644 data/scripts/actions/objects/outfit_memorial.lua delete mode 100644 data/scripts/actions/objects/outfits_memorial.lua diff --git a/data/scripts/actions/objects/outfit_memorial.lua b/data/scripts/actions/objects/outfit_memorial.lua new file mode 100644 index 00000000000..6a55fee2531 --- /dev/null +++ b/data/scripts/actions/objects/outfit_memorial.lua @@ -0,0 +1,70 @@ +local goldenOutfitCache = { [1] = {}, [2] = {}, [3] = {} } +local royalOutfitCache = { [1] = {}, [2] = {}, [3] = {} } +local lastUpdatedGolden = os.time() +local lastUpdatedRoyal = os.time() + +local function updateOutfitCache(storageKey, cache, lastUpdated) + local currentTime = os.time() + if currentTime < lastUpdated + 60 * 10 then + return cache, lastUpdated + end + + local newCache = { [1] = {}, [2] = {}, [3] = {} } + + local resultId = db.storeQuery("SELECT `key_name`, `timestamp`, `value` FROM `kv_store` WHERE `key_name` = '" .. storageKey .. "'") + + if resultId then + repeat + table.insert(newCache[Result.getNumber(resultId, "value")], Result.getString(resultId, "name")) + until not Result.next(resultId) + + Result.free(resultId) + end + + return newCache, currentTime +end + +local outfitMemorial = Action() + +function outfitMemorial.onUse(player, item, fromPosition, target, toPosition, isHotkey) + goldenOutfitCache, lastUpdatedGolden = updateOutfitCache("golden-outfit-quest", goldenOutfitCache, lastUpdatedGolden) + royalOutfitCache, lastUpdatedRoyal = updateOutfitCache("royal-costume-outfit-quest", royalOutfitCache, lastUpdatedRoyal) + + local msg = NetworkMessage() + msg:addByte(0xB0) + + local goldenOutfitPrices = { 500000000, 750000000, 1000000000 } + for _, price in ipairs(goldenOutfitPrices) do + msg:addU32(price) + end + + for i = 1, 3 do + msg:addU16(#goldenOutfitCache[i]) + + for j = 1, #goldenOutfitCache[i] do + msg:addString(goldenOutfitCache[i][j], "outfitMemorial.onUse - goldenOutfitCache[i][j]") + end + end + + local royalOutfitPrices = { 30000, 25000 } + for _ = 1, 3 do + for _, price in ipairs(royalOutfitPrices) do + msg:addU16(price) + end + end + + for i = 1, 3 do + msg:addU16(#royalOutfitCache[i]) + + for j = 1, #royalOutfitCache[i] do + msg:addString(royalOutfitCache[i][j], "outfitMemorial.onUse - royalOutfitCache[i][j]") + end + end + + msg:sendToPlayer(player) + msg:delete() + return true +end + +outfitMemorial:id(31518, 31519, 31520, 31521, 31522, 31523) +outfitMemorial:register() diff --git a/data/scripts/actions/objects/outfits_memorial.lua b/data/scripts/actions/objects/outfits_memorial.lua deleted file mode 100644 index ce200c5ab90..00000000000 --- a/data/scripts/actions/objects/outfits_memorial.lua +++ /dev/null @@ -1,67 +0,0 @@ -local lastCacheUpdateTime = 0 -local goldenOutfitCache = {} - -local function updateGoldenOutfitCache() - if os.time() < lastCacheUpdateTime + 10 * 60 then - return - end - - goldenOutfitCache = { [1] = {}, [2] = {}, [3] = {} } - - local resultId = db.storeQuery("SELECT `key_name`, `timestamp`, `value` FROM `kv_store` WHERE `key_name` = '" .. "golden-outfit-quest" .. "'") - - if resultId ~= 0 then - repeat - local addons = result.getNumber(resultId, "value") - local name = result.getString(resultId, "name") - if not goldenOutfitCache[addons] then - goldenOutfitCache[addons] = {} - end - - table.insert(goldenOutfitCache[addons], name) - until not result.next(resultId) - result.free(resultId) - end - - lastCacheUpdateTime = os.time() -end - -local memorial = Action() - -function memorial.onUse(player, item, fromPosition, target, toPosition, isHotkey) - updateGoldenOutfitCache() - - local msg = NetworkMessage() - msg:addByte(0xB0) - - local goldenOutfitPrices = { 500000000, 750000000, 1000000000 } - for i, price in ipairs(goldenOutfitPrices) do - msg:addU32(price) - end - - for i = 1, 3 do - msg:addU16(#goldenOutfitCache[i]) - - for j = 1, #goldenOutfitCache[i] do - msg:addString(goldenOutfitCache[i][j]) - end - end - - local royalOutfitPrices = { 30000, 25000 } - for i = 1, 3 do - for j, price in ipairs(royalOutfitPrices) do - msg:addU16(price) - end - end - - for i = 1, 3 do - msg:addU16(0) -- list of spenders - end - - msg:sendToPlayer(player) - msg:delete() - return true -end - -memorial:id(31518, 31519, 31520, 31521, 31522, 31523) -memorial:register()