From 1c4bea7cf7f518af04c4ffd64f87ad64307073f2 Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 18 Feb 2024 16:26:48 -0300 Subject: [PATCH] chore: move addon items to core (#2254) --- data-otservbr-global/lib/core/storages.lua | 6 -- .../actions/addons/afflicted_outfit.lua | 65 ----------------- .../items/usable_afflicted_outfit_items.lua | 57 +++++++++++++++ .../actions/items/usable_outfit_items.lua | 71 ++++++++++--------- 4 files changed, 95 insertions(+), 104 deletions(-) delete mode 100644 data-otservbr-global/scripts/actions/addons/afflicted_outfit.lua create mode 100644 data/scripts/actions/items/usable_afflicted_outfit_items.lua rename data-otservbr-global/scripts/actions/addons/addons.lua => data/scripts/actions/items/usable_outfit_items.lua (58%) diff --git a/data-otservbr-global/lib/core/storages.lua b/data-otservbr-global/lib/core/storages.lua index 78d2535646f..4cfc904c716 100644 --- a/data-otservbr-global/lib/core/storages.lua +++ b/data-otservbr-global/lib/core/storages.lua @@ -817,11 +817,6 @@ Storage = { -- Until all outfit quests are completed DefaultStart = 50960, Ref = 50961, - Afflicted = { - Outfit = 50962, - AddonPlagueMask = 50963, - AddonPlagueBell = 50964, - }, Citizen = { -- Mission storages for temporary questlog entries MissionHat = 50966, @@ -2414,7 +2409,6 @@ Storage = { TheColoursOfMagic = {}, }, U9_1 = { --update 9.1 - Reserved Storages 43351 - 43550 - AfflictedOutfits = {}, AwashWorldChange = {}, DemonWarsWorldChange = {}, ElementalistOutfits = {}, diff --git a/data-otservbr-global/scripts/actions/addons/afflicted_outfit.lua b/data-otservbr-global/scripts/actions/addons/afflicted_outfit.lua deleted file mode 100644 index 179e981451e..00000000000 --- a/data-otservbr-global/scripts/actions/addons/afflicted_outfit.lua +++ /dev/null @@ -1,65 +0,0 @@ -local afflictedOutfit = Action() - -function afflictedOutfit.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local hasOutfit = player:getStorageValue(Storage.OutfitQuest.Afflicted.Outfit) == 1 - -- Plgue Mask - if item.itemid == 12786 then - if not hasOutfit then - return false - end - - if player:getStorageValue(Storage.OutfitQuest.Afflicted.AddonPlagueMask) == 1 then - return false - end - - player:addOutfitAddon(430, 2) - player:addOutfitAddon(431, 2) - player:getPosition():sendMagicEffect(CONST_ME_POFF) - player:setStorageValue(Storage.OutfitQuest.Afflicted.AddonPlagueMask, 1) - player:say("You gained a plague mask for your outfit.", TALKTYPE_MONSTER_SAY, false, player) - item:remove() - - -- Plague Bell - elseif item.itemid == 12787 then - if not hasOutfit then - return false - end - - if player:getStorageValue(Storage.OutfitQuest.Afflicted.AddonPlagueBell) == 1 then - return false - end - - player:addOutfitAddon(430, 1) - player:addOutfitAddon(431, 1) - player:getPosition():sendMagicEffect(CONST_ME_POFF) - player:setStorageValue(Storage.OutfitQuest.Afflicted.AddonPlagueBell, 1) - player:say("You gained a plague bell for your outfit.", TALKTYPE_MONSTER_SAY, false, player) - item:remove() - - -- Outfit - else - if hasOutfit then - return false - end - - for id = 12551, 12556 do - if player:getItemCount(id) < 1 then - return false - end - end - - for id = 12551, 12556 do - player:removeItem(id, 1) - end - - player:addOutfit(430) - player:addOutfit(431) - player:getPosition():sendMagicEffect(CONST_ME_POFF) - player:setStorageValue(Storage.OutfitQuest.Afflicted.Outfit, 1) - player:say("You have restored an outfit.", TALKTYPE_MONSTER_SAY, false, player) - end - return true -end - -afflictedOutfit:id(12551, 12552, 12553, 12554, 12555, 12556, 12786, 12787) -afflictedOutfit:register() diff --git a/data/scripts/actions/items/usable_afflicted_outfit_items.lua b/data/scripts/actions/items/usable_afflicted_outfit_items.lua new file mode 100644 index 00000000000..30c92194655 --- /dev/null +++ b/data/scripts/actions/items/usable_afflicted_outfit_items.lua @@ -0,0 +1,57 @@ +local usableAfflictedOutfitItems = Action() + +function usableAfflictedOutfitItems.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if not player:isPremium() then + player:sendCancelMessage(RETURNVALUE_YOUNEEDPREMIUMACCOUNT) + return true + end + + local outfitId = player:getSex() == PLAYERSEX_FEMALE and 431 or 430 + if item.itemid == 12786 then + if not player:hasOutfit(outfitId) or player:hasOutfit(outfitId, 2) then + return true + end + + player:addOutfitAddon(430, 2) + player:addOutfitAddon(431, 2) + player:say("You gained a plague mask for your outfit.", TALKTYPE_MONSTER_SAY, false, player) + player:getPosition():sendMagicEffect(CONST_ME_POFF) + player:addAchievementProgress("Beak Doctor", 2) + item:remove() + elseif item.itemid == 12787 then + if not player:hasOutfit(outfitId) or player:hasOutfit(outfitId, 1) then + return true + end + + player:addOutfitAddon(430, 1) + player:addOutfitAddon(431, 1) + player:getPosition():sendMagicEffect(CONST_ME_POFF) + player:say("You gained a plague bell for your outfit.", TALKTYPE_MONSTER_SAY, false, player) + player:addAchievementProgress("Beak Doctor", 2) + item:remove() + else + if player:hasOutfit(outfitId) then + return true + end + + local requiredItemIds = { 12551, 12552, 12553, 12554, 12555, 12556 } + for _, itemId in ipairs(requiredItemIds) do + if player:getItemCount(itemId) < 1 then + return true + end + end + + for _, itemId in ipairs(requiredItemIds) do + player:removeItem(itemId, 1) + end + + player:addOutfit(430) + player:addOutfit(431) + player:say("You have restored an outfit.", TALKTYPE_MONSTER_SAY, false, player) + player:getPosition():sendMagicEffect(CONST_ME_POFF) + end + return true +end + +usableAfflictedOutfitItems:id(12551, 12552, 12553, 12554, 12555, 12556, 12786, 12787) +usableAfflictedOutfitItems:register() diff --git a/data-otservbr-global/scripts/actions/addons/addons.lua b/data/scripts/actions/items/usable_outfit_items.lua similarity index 58% rename from data-otservbr-global/scripts/actions/addons/addons.lua rename to data/scripts/actions/items/usable_outfit_items.lua index 0658ab69312..f9e3b5b61dd 100644 --- a/data-otservbr-global/scripts/actions/addons/addons.lua +++ b/data/scripts/actions/items/usable_outfit_items.lua @@ -1,73 +1,78 @@ -local config = { +local outfitConfig = { -- soil guardian [16252] = { female = 514, male = 516, effect = CONST_ME_GREEN_RINGS }, [16253] = { female = 514, male = 516, addon = 1, effect = CONST_ME_GREEN_RINGS, achievement = "Funghitastic" }, [16254] = { female = 514, male = 516, addon = 2, effect = CONST_ME_GREEN_RINGS, achievement = "Funghitastic" }, + -- crystal warlord [16255] = { female = 513, male = 512, effect = CONST_ME_GIANTICE }, [16256] = { female = 513, male = 512, addon = 1, effect = CONST_ME_GIANTICE, achievement = "Crystal Clear" }, [16257] = { female = 513, male = 512, addon = 2, effect = CONST_ME_GIANTICE, achievement = "Crystal Clear" }, + -- makeshift warrior [27655] = { female = 1043, male = 1042 }, [27657] = { female = 1043, male = 1042, addon = 1, achievement = "Cobbled and Patched" }, [27656] = { female = 1043, male = 1042, addon = 2, achievement = "Cobbled and Patched" }, + -- hand of the inquisition [31738] = { female = 1244, male = 1243, addon = 1, effect = CONST_ME_HOLYAREA, achievement = "Inquisition's Arm" }, [31737] = { female = 1244, male = 1243, addon = 2, effect = CONST_ME_HOLYAREA, achievement = "Inquisition's Arm" }, + -- poltergeist [32630] = { female = 1271, male = 1270, addon = 1, effect = CONST_ME_BLUE_GHOST, achievement = "Mainstreet Nightmare" }, [32631] = { female = 1271, male = 1270, addon = 2, effect = CONST_ME_BLUE_GHOST, achievement = "Mainstreet Nightmare" }, + -- rascoohan [35595] = { female = 1372, male = 1371, addon = 1, achievement = "Honorary Rascoohan" }, [35695] = { female = 1372, male = 1371, addon = 2, achievement = "Honorary Rascoohan" }, + -- fire-fighter [39544] = { female = 1569, male = 1568, addon = 1, achievement = "Friendly Fire" }, [39545] = { female = 1569, male = 1568, addon = 2, achievement = "Friendly Fire" }, } -local addons = Action() +local usableOutfitItems = Action() -function addons.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local useItem = config[item.itemid] - if not useItem then +function usableOutfitItems.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if not player:isPremium() then + player:sendCancelMessage(RETURNVALUE_YOUNEEDPREMIUMACCOUNT) return true end - local looktype = player:getSex() == PLAYERSEX_FEMALE and useItem.female or useItem.male - - if useItem.addon then - if not player:isPremium() or not player:hasOutfit(looktype) or player:hasOutfit(looktype, useItem.addon) then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You own no premium account, lack the base outfit or already own this outfit part.") + local outfitInfo = outfitConfig[item.itemid] + local looktype = player:getSex() == PLAYERSEX_FEMALE and outfitInfo.female or outfitInfo.male + if not player:hasOutfit(looktype) then + if outfitInfo.addon then + player:sendCancelMessage("You need the outfit for this part.") return true end - player:addOutfitAddon(useItem.female, useItem.addon) - player:addOutfitAddon(useItem.male, useItem.addon) - player:getPosition():sendMagicEffect(useItem.effect or CONST_ME_GIFT_WRAPS) - if player:hasOutfit(looktype, 3) then - if useItem.achievement then - player:addAchievement(useItem.achievement) - end - end - item:remove() - else - if not player:isPremium() or player:hasOutfit(looktype) then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You own no premium account or already own this outfit part.") - return true - end + player:addOutfit(outfitInfo.female) + player:addOutfit(outfitInfo.male) + player:getPosition():sendMagicEffect(outfitInfo.effect) + item:remove(1) + return true + end + + if player:hasOutfit(looktype, outfitInfo.addon) then + player:sendCancelMessage("You already own this outfit part.") + return true + end - player:addOutfit(useItem.female) - player:addOutfit(useItem.male) - player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS) - item:remove() + player:addOutfitAddon(outfitInfo.female, outfitInfo.addon) + player:addOutfitAddon(outfitInfo.male, outfitInfo.addon) + player:getPosition():sendMagicEffect(outfitInfo.effect) + + if player:hasOutfit(looktype, 3) then + player:addAchievement(outfitInfo.achievement) end + + item:remove(1) return true end -local ids = {} -for value in pairs(config) do - table.insert(ids, value) +for itemId, _ in pairs(outfitConfig) do + usableOutfitItems:id(itemId) end -addons:id(unpack(ids)) -addons:register() +usableOutfitItems:register()