Skip to content

Commit

Permalink
fix: outfit memorial
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Mar 22, 2024
1 parent 85e6518 commit 4075e2c
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions data/scripts/actions/objects/outfits_memorial.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 4075e2c

Please sign in to comment.