From 414ddc1133d9e339a576d1feff9a4e294c79fb6c Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 29 Feb 2024 12:51:48 -0300 Subject: [PATCH] refactor: scroll of ascencion and swimming to core (#2334) --- .../actions/other/scroll_of_ascension.lua | 17 ---------- data-canary/scripts/movements/swimming.lua | 33 ------------------- .../scroll_of_ascension.lua | 18 ---------- data/global.lua | 1 + .../actions/items/scroll_of_ascension.lua | 27 +++++++++++++++ .../scripts/movements}/swimming.lua | 18 ++++++---- 6 files changed, 39 insertions(+), 75 deletions(-) delete mode 100644 data-canary/scripts/actions/other/scroll_of_ascension.lua delete mode 100644 data-canary/scripts/movements/swimming.lua delete mode 100644 data-otservbr-global/scripts/actions/quests/ferumbras_ascendant/scroll_of_ascension.lua create mode 100644 data/scripts/actions/items/scroll_of_ascension.lua rename {data-otservbr-global/scripts/movements/others => data/scripts/movements}/swimming.lua (70%) diff --git a/data-canary/scripts/actions/other/scroll_of_ascension.lua b/data-canary/scripts/actions/other/scroll_of_ascension.lua deleted file mode 100644 index 6a598484591..00000000000 --- a/data-canary/scripts/actions/other/scroll_of_ascension.lua +++ /dev/null @@ -1,17 +0,0 @@ -local scrollOfAscencion = Action() - -function scrollOfAscencion.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if math.random(10) > 1 then - player:setMonsterOutfit("Demon", 30 * 10 * 1000) - else - player:setMonsterOutfit("Ferumbras", 30 * 10 * 1000) - end - item:transform(22772) - item:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) - item:decay() - player:say("Magical sparks whirl around the scroll as you read it and then your appearance is changing.", TALKTYPE_MONSTER_SAY) - return true -end - -scrollOfAscencion:id(22771) -scrollOfAscencion:register() diff --git a/data-canary/scripts/movements/swimming.lua b/data-canary/scripts/movements/swimming.lua deleted file mode 100644 index 494a4433a21..00000000000 --- a/data-canary/scripts/movements/swimming.lua +++ /dev/null @@ -1,33 +0,0 @@ -local condition = Condition(CONDITION_OUTFIT) -condition:setOutfit({ lookType = 267 }) -condition:setTicks(-1) - -local swimming = MoveEvent() -swimming:type("stepin") - -function swimming.onStepIn(creature, item, position, fromPosition) - if not creature:isPlayer() then - return false - end - - creature:addCondition(condition) - return true -end - -swimming:id(629, 630, 631, 632, 633, 634, 4809, 4810, 4811, 4812, 4813, 4814) -swimming:register() - -local swimming = MoveEvent() -swimming:type("stepout") - -function swimming.onStepOut(creature, item, position, fromPosition) - if not creature:isPlayer() then - return false - end - - creature:removeCondition(CONDITION_OUTFIT) - return true -end - -swimming:id(629, 630, 631, 632, 633, 634, 4809, 4810, 4811, 4812, 4813, 4814) -swimming:register() diff --git a/data-otservbr-global/scripts/actions/quests/ferumbras_ascendant/scroll_of_ascension.lua b/data-otservbr-global/scripts/actions/quests/ferumbras_ascendant/scroll_of_ascension.lua deleted file mode 100644 index 7eccfa18edb..00000000000 --- a/data-otservbr-global/scripts/actions/quests/ferumbras_ascendant/scroll_of_ascension.lua +++ /dev/null @@ -1,18 +0,0 @@ -local ferumbrasAscendantScroll = Action() -function ferumbrasAscendantScroll.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local outfit = { lookType = 35 } - if item.itemid == 22771 then - doSetCreatureOutfit(player, outfit, 30 * 1000) - item:transform(22772) - item:decay() - player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Magical sparks whirl around the scroll as you read and then your appearance is changing.") - return true - elseif item.itemid == 22772 then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are tired of the last scroll reading, rest your eyes for a moment.") - end - return true -end - -ferumbrasAscendantScroll:id(22771, 22772) -ferumbrasAscendantScroll:register() diff --git a/data/global.lua b/data/global.lua index d545ced7dd7..9ea4fd128a9 100644 --- a/data/global.lua +++ b/data/global.lua @@ -77,6 +77,7 @@ SCARLETT_MAY_DIE = 0 ropeSpots = { 386, 421, 386, 7762, 12202, 12936, 14238, 17238, 23363, 21965, 21966, 21967, 21968 } specialRopeSpots = { 12935 } +swimmingTiles = { 629, 630, 631, 632, 633, 634, 4809, 4810, 4811, 4812, 4813, 4814 } -- Global tables for systems if not _G.GlobalBosses then diff --git a/data/scripts/actions/items/scroll_of_ascension.lua b/data/scripts/actions/items/scroll_of_ascension.lua new file mode 100644 index 00000000000..b763460c09b --- /dev/null +++ b/data/scripts/actions/items/scroll_of_ascension.lua @@ -0,0 +1,27 @@ +local scrollOfAscension = Action() + +function scrollOfAscension.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if player:hasExhaustion("scroll-of-ascension") then + return true + end + + local playerTile = Tile(player:getPosition()) + if playerTile and playerTile:getGround() and table.contains(swimmingTiles, playerTile:getGround():getId()) then + player:say("The scroll could get wet, step out of the water first.", TALKTYPE_MONSTER_SAY) + return true + end + + if math.random(10) > 1 then + player:setMonsterOutfit("Demon", 30 * 10 * 1000) + else + player:setMonsterOutfit("Ferumbras", 30 * 10 * 1000) + end + + player:setExhaustion("scroll-of-ascension", 60 * 60) + player:say("Magical sparks whirl around the scroll as you read it and then your appearance is changing.", TALKTYPE_MONSTER_SAY) + player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) + return true +end + +scrollOfAscension:id(22771) +scrollOfAscension:register() diff --git a/data-otservbr-global/scripts/movements/others/swimming.lua b/data/scripts/movements/swimming.lua similarity index 70% rename from data-otservbr-global/scripts/movements/others/swimming.lua rename to data/scripts/movements/swimming.lua index eee6858a1ce..d34d5036510 100644 --- a/data-otservbr-global/scripts/movements/others/swimming.lua +++ b/data/scripts/movements/swimming.lua @@ -18,31 +18,35 @@ local conditions = { local swimming = MoveEvent() function swimming.onStepIn(creature, item, position, fromPosition) - if not creature:isPlayer() then + local player = creature:getPlayer() + if not player then return false end + for i = 1, #conditions do - creature:removeCondition(conditions[i]) + player:removeCondition(conditions[i]) end - creature:addCondition(condition) + + player:addCondition(condition) return true end swimming:type("stepin") -swimming:id(629, 630, 631, 632, 633, 634) +swimming:id(unpack(swimmingTiles)) swimming:register() swimming = MoveEvent() function swimming.onStepOut(creature, item, position, fromPosition) - if not creature:isPlayer() then + local player = creature:getPlayer() + if not player then return false end - creature:removeCondition(CONDITION_OUTFIT) + player:removeCondition(CONDITION_OUTFIT) return true end swimming:type("stepout") -swimming:id(629, 630, 631, 632, 633, 634) +swimming:id(unpack(swimmingTiles)) swimming:register()