diff --git a/data/scripts/actions/objects/outfits_memorial.lua b/data/scripts/actions/objects/outfits_memorial.lua index ce200c5ab90..b10f0e1cd4d 100644 --- a/data/scripts/actions/objects/outfits_memorial.lua +++ b/data/scripts/actions/objects/outfits_memorial.lua @@ -1,35 +1,32 @@ -local lastCacheUpdateTime = 0 -local goldenOutfitCache = {} - -local function updateGoldenOutfitCache() - if os.time() < lastCacheUpdateTime + 10 * 60 then - return +local goldenOutfitCache = { [1] = {}, [2] = {}, [3] = {} } +local royalOutfitCache = { [1] = {}, [2] = {}, [3] = {} } +local lastUpdatedGolden = 0 +local lastUpdatedRoyal = 0 + +local function updateOutfitCache(storageKey, cache, lastUpdated) + if os.time() < lastUpdated + 60 * 10 then + return cache, lastUpdated end - goldenOutfitCache = { [1] = {}, [2] = {}, [3] = {} } - - local resultId = db.storeQuery("SELECT `key_name`, `timestamp`, `value` FROM `kv_store` WHERE `key_name` = '" .. "golden-outfit-quest" .. "'") + local newCache = { [1] = {}, [2] = {}, [3] = {} } - if resultId ~= 0 then + local resultId = db.storeQuery("SELECT `name`, `value` FROM `player_storage` INNER JOIN `players` as `p` ON `p`.`id` = `player_id` WHERE `key` = " .. storageKey .. " AND `value` >= 1;") + if resultId 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) + table.insert(newCache[Result.getNumber(resultId, "value")], Result.getString(resultId, "name")) + until not Result.next(resultId) + + Result.free(resultId) end - lastCacheUpdateTime = os.time() + return newCache, os.time() end local memorial = Action() function memorial.onUse(player, item, fromPosition, target, toPosition, isHotkey) - updateGoldenOutfitCache() + goldenOutfitCache, lastUpdatedGolden = updateOutfitCache(Storage.OutfitQuest.GoldenOutfit, goldenOutfitCache, lastUpdatedGolden) + royalOutfitCache, lastUpdatedRoyal = updateOutfitCache(Storage.OutfitQuest.RoyalCostumeOutfit, royalOutfitCache, lastUpdatedRoyal) local msg = NetworkMessage() msg:addByte(0xB0) @@ -43,7 +40,7 @@ function memorial.onUse(player, item, fromPosition, target, toPosition, isHotkey msg:addU16(#goldenOutfitCache[i]) for j = 1, #goldenOutfitCache[i] do - msg:addString(goldenOutfitCache[i][j]) + msg:addString(goldenOutfitCache[i][j], "memorial.onUse - goldenOutfitCache[i][j]") end end @@ -55,7 +52,11 @@ function memorial.onUse(player, item, fromPosition, target, toPosition, isHotkey end for i = 1, 3 do - msg:addU16(0) -- list of spenders + msg:addU16(#royalOutfitCache[i]) + + for j = 1, #royalOutfitCache[i] do + msg:addString(royalOutfitCache[i][j], "memorial.onUse - royalOutfitCache[i][j]") + end end msg:sendToPlayer(player)