From 9169b013788fbf7b13460a13392d46bf4185d3ca Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 8 Feb 2024 18:04:50 -0300 Subject: [PATCH] refactor: simplify code and use table for transformations (#2196) Refactored the code to make it more modular and understandable, using a table to store transformation IDs in a more compact manner. --------- Co-authored-by: GitHub Actions --- .../actions/object/golden_outfit_display.lua | 42 +++++++++++++ .../actions/other/golden_outfit_display.lua | 62 ------------------- 2 files changed, 42 insertions(+), 62 deletions(-) create mode 100644 data-otservbr-global/scripts/actions/object/golden_outfit_display.lua delete mode 100644 data-otservbr-global/scripts/actions/other/golden_outfit_display.lua diff --git a/data-otservbr-global/scripts/actions/object/golden_outfit_display.lua b/data-otservbr-global/scripts/actions/object/golden_outfit_display.lua new file mode 100644 index 00000000000..a675f6dfee5 --- /dev/null +++ b/data-otservbr-global/scripts/actions/object/golden_outfit_display.lua @@ -0,0 +1,42 @@ +local transformations = { + [31509] = 31500, + [31500] = 31505, + [31505] = 31513, + [31513] = 31509, + [31510] = 31502, + [31502] = 31506, + [31506] = 31514, + [31514] = 31510, + [31511] = 31503, + [31503] = 31507, + [31507] = 31515, + [31515] = 31511, + [31512] = 31504, + [31504] = 31508, + [31508] = 31516, + [31516] = 31512, +} + +local goldenOutfitDisplay = Action() + +function goldenOutfitDisplay.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local newItemID = transformations[item:getId()] + if not newItemID then + return true + end + + if player:getStorageValue(Storage.OutfitQuest.GoldenOutfit) == 3 then + item:transform(newItemID) + item:getPosition():sendMagicEffect(CONST_ME_EARLY_THUNDER) + else + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need Full Golden Outfit to use it.") + item:getPosition():sendMagicEffect(CONST_ME_POFF) + end + return true +end + +for index, value in pairs(transformDisplay) do + goldenOutfitDisplay:id(index) +end + +goldenOutfitDisplay:register() diff --git a/data-otservbr-global/scripts/actions/other/golden_outfit_display.lua b/data-otservbr-global/scripts/actions/other/golden_outfit_display.lua deleted file mode 100644 index d8bd03a7816..00000000000 --- a/data-otservbr-global/scripts/actions/other/golden_outfit_display.lua +++ /dev/null @@ -1,62 +0,0 @@ -local goldenOutfitDisplay = Action() - -function goldenOutfitDisplay.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if player:getStorageValue(Storage.OutfitQuest.GoldenOutfit) == 3 then - if item:getId() == 31509 then --direita - item:transform(31500) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31500 then - item:transform(31505) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31505 then - item:transform(31513) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31513 then - item:transform(31509) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31510 then --baixo - item:transform(31502) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31502 then - item:transform(31506) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31506 then - item:transform(31514) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31514 then - item:transform(31510) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31511 then --esquerda - item:transform(31503) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31503 then - item:transform(31507) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31507 then - item:transform(31515) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31515 then - item:transform(31511) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31512 then --cima - item:transform(31504) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31504 then - item:transform(31508) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31508 then - item:transform(31516) - item:getPosition():sendMagicEffect(171) - elseif item:getId() == 31516 then - item:transform(31512) - item:getPosition():sendMagicEffect(171) - end - else - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need Full Golden Outfit to use it.") - item:getPosition():sendMagicEffect(CONST_ME_POFF) - end - return true -end - -goldenOutfitDisplay:id(31500, 31502, 31503, 31504, 31505, 31506, 31507, 31508, 31509, 31510, 31511, 31512, 31513, 31514, 31515, 31516) -goldenOutfitDisplay:register()