From da475c620d07dbf807d4dfd1cd5ccfa35ab20ec9 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 13 Nov 2024 13:34:06 -0300 Subject: [PATCH] fix: item usage mechanics to obtain Phantasmal Jade --- .../soul_war/action-reward_soul_war.lua | 32 ------------- .../items/usable_phantasmal_jade_items.lua | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+), 32 deletions(-) create mode 100644 data/scripts/actions/items/usable_phantasmal_jade_items.lua diff --git a/data-otservbr-global/scripts/quests/soul_war/action-reward_soul_war.lua b/data-otservbr-global/scripts/quests/soul_war/action-reward_soul_war.lua index fae3fc59794..652a74af84b 100644 --- a/data-otservbr-global/scripts/quests/soul_war/action-reward_soul_war.lua +++ b/data-otservbr-global/scripts/quests/soul_war/action-reward_soul_war.lua @@ -26,35 +26,3 @@ end rewardSoulWar:position({ x = 33620, y = 31400, z = 10 }) rewardSoulWar:register() - -local phantasmalJadeMount = Action() - -function phantasmalJadeMount.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local soulWarQuest = player:soulWarQuestKV() - if soulWarQuest:get("panthasmal-jade-mount") then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already have Phantasmal Jade mount!") - return true - end - - if table.contains({ 34072, 34073, 34074 }, item.itemid) then - if player:getItemCount(34072) >= 4 and player:getItemCount(34073) == 1 and player:getItemCount(34074) == 1 then - player:removeItem(34072, 4) - player:removeItem(34073, 1) - player:removeItem(34074, 1) - player:addMount(167) - player:addAchievement("You got Horse Power") - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You won Phantasmal Jade mount.") - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You won You got Horse Power achievement.") - player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE) - soulWarQuest:set("panthasmal-jade-mount", true) - else - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You don't have the necessary items!") - player:getPosition():sendMagicEffect(CONST_ME_POFF) - end - end - - return true -end - -phantasmalJadeMount:id(34072, 34073, 34074) -phantasmalJadeMount:register() diff --git a/data/scripts/actions/items/usable_phantasmal_jade_items.lua b/data/scripts/actions/items/usable_phantasmal_jade_items.lua new file mode 100644 index 00000000000..8075125df25 --- /dev/null +++ b/data/scripts/actions/items/usable_phantasmal_jade_items.lua @@ -0,0 +1,45 @@ +local config = { + requiredItems = { + [34072] = { key = "spectral-horseshoes", count = 4 }, + [34073] = { key = "spectral-saddle", count = 1 }, + [34074] = { key = "spectral-horse-tac", count = 1 }, + }, + + mountId = 167, +} + +local usablePhantasmalJadeItems = Action() + +function usablePhantasmalJadeItems.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local itemInfo = config.requiredItems[item:getId()] + if not itemInfo then + return true + end + + if player:hasMount(config.mountId) then + return true + end + + local currentCount = (player:kv():get(itemInfo.key) or 0) + 1 + player:kv():set(itemInfo.key, currentCount) + player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE) + item:remove(1) + + for _, info in pairs(config.requiredItems) do + if (player:kv():get(info.key) or 0) < info.count then + return true + end + end + + player:addMount(config.mountId) + player:addAchievement("Natural Born Cowboy") + player:addAchievement("You got Horse Power") + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Phantasmal jade is now yours!") + return true +end + +for itemId, _ in pairs(config.requiredItems) do + usablePhantasmalJadeItems:id(itemId) +end + +usablePhantasmalJadeItems:register()