From 0ec432d28877054f58cfd3f8bc37553bbd38d501 Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 22 Mar 2024 13:20:23 -0300 Subject: [PATCH] chore: remove unnecessary checking --- data-canary/npc/king_canary.lua | 11 ++++------- data-otservbr-global/npc/emperor_kruzak.lua | 9 +++------ data-otservbr-global/npc/king_tibianus.lua | 9 +++------ data-otservbr-global/npc/queen_eloise.lua | 11 ++++------- .../actions/objects/outfits_memorial.lua | 19 ++++++++++--------- 5 files changed, 24 insertions(+), 35 deletions(-) diff --git a/data-canary/npc/king_canary.lua b/data-canary/npc/king_canary.lua index edaafc482cb..e24c80aa18f 100644 --- a/data-canary/npc/king_canary.lua +++ b/data-canary/npc/king_canary.lua @@ -69,7 +69,7 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:setTopic(playerId, 0) elseif npcHandler:getTopic(playerId) == 3 then if player:kv():get("golden-outfit-quest") < 1 then - if player:getMoney() + player:getBankBalance() >= 500000000 then + if player:removeMoneyBank(500000000) then local inbox = player:getStoreInbox() local inboxItems = inbox:getItems() if inbox and #inboxItems <= inbox:getMaxCapacity() then @@ -78,10 +78,9 @@ local function creatureSayCallback(npc, creature, type, message) decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a " .. decoItemName .. ".") decoKit:setCustomAttribute("unWrapId", 31510) npcHandler:say("Take this armor as a token of great gratitude. Let us forever remember this day, my friend!", npc, creature) - player:removeMoneyBank(500000000) player:addOutfit(1211) player:addOutfit(1210) - player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDERs) + player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) player:kv():set("golden-outfit-quest", 1) else npcHandler:say("Please make sure you have free slots in your store inbox.", npc, creature) @@ -96,9 +95,8 @@ local function creatureSayCallback(npc, creature, type, message) elseif npcHandler:getTopic(playerId) == 4 then if player:kv():get("golden-outfit-quest") == 1 then if player:kv():get("golden-outfit-quest") < 2 then - if player:getMoney() + player:getBankBalance() >= 250000000 then + if player:removeMoneyBank(250000000) then npcHandler:say("Take this helmet as a token of great gratitude. Let us forever remember this day, my friend. ", npc, creature) - player:removeMoneyBank(250000000) player:addOutfitAddon(1210, 1) player:addOutfitAddon(1211, 1) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) @@ -120,9 +118,8 @@ local function creatureSayCallback(npc, creature, type, message) elseif npcHandler:getTopic(playerId) == 5 then if player:kv():get("golden-outfit-quest") == 2 then if player:kv():get("golden-outfit-quest") < 3 then - if player:getMoney() + player:getBankBalance() >= 250000000 then + if player:removeMoneyBank(250000000) then npcHandler:say("Take this boots as a token of great gratitude. Let us forever remember this day, my friend. ", npc, creature) - player:removeMoneyBank(250000000) player:addOutfitAddon(1210, 2) player:addOutfitAddon(1211, 2) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) diff --git a/data-otservbr-global/npc/emperor_kruzak.lua b/data-otservbr-global/npc/emperor_kruzak.lua index a080258fbf4..6568ba6f28f 100644 --- a/data-otservbr-global/npc/emperor_kruzak.lua +++ b/data-otservbr-global/npc/emperor_kruzak.lua @@ -74,7 +74,7 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:setTopic(playerId, 0) elseif npcHandler:getTopic(playerId) == 3 then if player:kv():get("golden-outfit-quest") < 1 then - if player:getMoney() + player:getBankBalance() >= 500000000 then + if player:removeMoneyBank(500000000) then local inbox = player:getStoreInbox() local inboxItems = inbox:getItems() if inbox and #inboxItems <= inbox:getMaxCapacity() then @@ -83,7 +83,6 @@ local function creatureSayCallback(npc, creature, type, message) decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a " .. decoItemName .. ".") decoKit:setCustomAttribute("unWrapId", 31510) npcHandler:say("Take this armor as a token of great gratitude. Let us forever remember this day, my friend!", npc, creature) - player:removeMoneyBank(500000000) player:addOutfit(1211) player:addOutfit(1210) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) @@ -101,9 +100,8 @@ local function creatureSayCallback(npc, creature, type, message) elseif npcHandler:getTopic(playerId) == 4 then if player:kv():get("golden-outfit-quest") == 1 then if player:kv():get("golden-outfit-quest") < 2 then - if player:getMoney() + player:getBankBalance() >= 250000000 then + if player:removeMoneyBank(250000000) then npcHandler:say("Take this helmet as a token of great gratitude. Let us forever remember this day, my friend. ", npc, creature) - player:removeMoneyBank(250000000) player:addOutfitAddon(1210, 1) player:addOutfitAddon(1211, 1) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) @@ -125,9 +123,8 @@ local function creatureSayCallback(npc, creature, type, message) elseif npcHandler:getTopic(playerId) == 5 then if player:kv():get("golden-outfit-quest") == 2 then if player:kv():get("golden-outfit-quest") < 3 then - if player:getMoney() + player:getBankBalance() >= 250000000 then + if player:removeMoneyBank(250000000) then npcHandler:say("Take this boots as a token of great gratitude. Let us forever remember this day, my friend. ", npc, creature) - player:removeMoneyBank(250000000) player:addOutfitAddon(1210, 2) player:addOutfitAddon(1211, 2) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) diff --git a/data-otservbr-global/npc/king_tibianus.lua b/data-otservbr-global/npc/king_tibianus.lua index acdd6c4b0ad..5f84d81b2c8 100644 --- a/data-otservbr-global/npc/king_tibianus.lua +++ b/data-otservbr-global/npc/king_tibianus.lua @@ -79,7 +79,7 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:setTopic(playerId, 0) elseif npcHandler:getTopic(playerId) == 3 then if player:kv():get("golden-outfit-quest") < 1 then - if player:getMoney() + player:getBankBalance() >= 500000000 then + if player:removeMoneyBank(500000000) then local inbox = player:getStoreInbox() local inboxItems = inbox:getItems() if inbox and #inboxItems <= inbox:getMaxCapacity() then @@ -88,7 +88,6 @@ local function creatureSayCallback(npc, creature, type, message) decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Unwrap it in your own house to create a " .. decoItemName .. ".") decoKit:setCustomAttribute("unWrapId", 31510) npcHandler:say("Take this armor as a token of great gratitude. Let us forever remember this day, my friend!", npc, creature) - player:removeMoneyBank(500000000) player:addOutfit(1211) player:addOutfit(1210) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) @@ -106,9 +105,8 @@ local function creatureSayCallback(npc, creature, type, message) elseif npcHandler:getTopic(playerId) == 4 then if player:kv():get("golden-outfit-quest") == 1 then if player:kv():get("golden-outfit-quest") < 2 then - if player:getMoney() + player:getBankBalance() >= 250000000 then + if player:removeMoneyBank(250000000) then npcHandler:say("Take this helmet as a token of great gratitude. Let us forever remember this day, my friend. ", npc, creature) - player:removeMoneyBank(250000000) player:addOutfitAddon(1210, 2) player:addOutfitAddon(1211, 2) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) @@ -130,9 +128,8 @@ local function creatureSayCallback(npc, creature, type, message) elseif npcHandler:getTopic(playerId) == 5 then if player:kv():get("golden-outfit-quest") == 2 then if player:kv():get("golden-outfit-quest") < 3 then - if player:getMoney() + player:getBankBalance() >= 250000000 then + if player:removeMoneyBank(250000000) then npcHandler:say("Take this boots as a token of great gratitude. Let us forever remember this day, my friend. ", npc, creature) - player:removeMoneyBank(250000000) player:addOutfitAddon(1210, 1) player:addOutfitAddon(1211, 1) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) diff --git a/data-otservbr-global/npc/queen_eloise.lua b/data-otservbr-global/npc/queen_eloise.lua index ab0b04132c7..f893361a7b9 100644 --- a/data-otservbr-global/npc/queen_eloise.lua +++ b/data-otservbr-global/npc/queen_eloise.lua @@ -69,7 +69,7 @@ local function creatureSayCallback(npc, creature, type, message) npcHandler:setTopic(playerId, 0) elseif npcHandler:getTopic(playerId) == 3 then if player:kv():get("golden-outfit-quest") < 1 then - if player:getMoney() + player:getBankBalance() >= 500000000 then + if player:removeMoneyBank(500000000) then local inbox = player:getStoreInbox() local inboxItems = inbox:getItems() if inbox and #inboxItems <= inbox:getMaxCapacity() then @@ -78,7 +78,6 @@ local function creatureSayCallback(npc, creature, type, message) decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a " .. decoItemName .. ".") decoKit:setCustomAttribute("unWrapId", 31510) npcHandler:say("Take this armor as a token of great gratitude. Let us forever remember this day, my friend!", npc, creature) - player:removeMoneyBank(500000000) player:addOutfit(1211) player:addOutfit(1210) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) @@ -96,9 +95,8 @@ local function creatureSayCallback(npc, creature, type, message) elseif npcHandler:getTopic(playerId) == 4 then if player:kv():get("golden-outfit-quest") == 1 then if player:kv():get("golden-outfit-quest") < 2 then - if player:getMoney() + player:getBankBalance() >= 250000000 then + if player:removeMoneyBank(250000000) then npcHandler:say("Take this helmet as a token of great gratitude. Let us forever remember this day, my friend. ", npc, creature) - player:removeMoneyBank(250000000) player:addOutfitAddon(1210, 1) player:addOutfitAddon(1211, 1) player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) @@ -120,12 +118,11 @@ local function creatureSayCallback(npc, creature, type, message) elseif npcHandler:getTopic(playerId) == 5 then if player:kv():get("golden-outfit-quest") == 2 then if player:kv():get("golden-outfit-quest") < 3 then - if player:getMoney() + player:getBankBalance() >= 250000000 then + if player:removeMoneyBank(250000000) then npcHandler:say("Take this boots as a token of great gratitude. Let us forever remember this day, my friend. ", npc, creature) - player:removeMoneyBank(250000000) player:addOutfitAddon(1210, 2) player:addOutfitAddon(1211, 2) - player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDERss) + player:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) player:kv():set("golden-outfit-quest", 3) npcHandler:setTopic(playerId, 2) else diff --git a/data/scripts/actions/objects/outfits_memorial.lua b/data/scripts/actions/objects/outfits_memorial.lua index ce4f536c5e4..8f61442e794 100644 --- a/data/scripts/actions/objects/outfits_memorial.lua +++ b/data/scripts/actions/objects/outfits_memorial.lua @@ -1,8 +1,8 @@ -local lastUpdated = 0 -local goldenOutfitCache +local lastCacheUpdateTime = 0 +local goldenOutfitCache = {} local function updateGoldenOutfitCache() - if os.time() < lastUpdated + 10 * 60 then + if os.time() < lastCacheUpdateTime + 10 * 60 then return end @@ -23,7 +23,7 @@ local function updateGoldenOutfitCache() result.free(resultId) end - lastUpdated = os.time() + lastCacheUpdateTime = os.time() end local memorial = Action() @@ -34,8 +34,8 @@ function memorial.onUse(player, item, fromPosition, target, toPosition, isHotkey local msg = NetworkMessage() msg:addByte(0xB0) - local prices = { 500000000, 750000000, 1000000000 } - for i, price in ipairs(prices) do + local goldenOutfitPrices = { 500000000, 750000000, 1000000000 } + for i, price in ipairs(goldenOutfitPrices) do msg:addU32(price) end @@ -47,10 +47,11 @@ function memorial.onUse(player, item, fromPosition, target, toPosition, isHotkey end end - -- royal costume + local royalOutfitPrices = { 30000, 25000 } for i = 1, 3 do - msg:addU16(0) -- price in silver tokens - msg:addU16(0) -- price in golden tokens + for i, price in ipairs(royalOutfitPrices) do + msg:addU16(price) + end end for i = 1, 3 do