From 5ad41c9939a9e787baf8ed69cd68d04913141934 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 12 Dec 2024 13:07:49 -0300 Subject: [PATCH] refactor: simplify and optimize CultsOnItemMoved event logic --- .../cults_of_tibia/event_on_item_moved.lua | 58 +++++++++---------- .../event_on_item_moved.lua | 1 - data/events/scripts/player.lua | 12 +++- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/data-otservbr-global/scripts/quests/cults_of_tibia/event_on_item_moved.lua b/data-otservbr-global/scripts/quests/cults_of_tibia/event_on_item_moved.lua index 13ecaa37431..15fc805c37d 100644 --- a/data-otservbr-global/scripts/quests/cults_of_tibia/event_on_item_moved.lua +++ b/data-otservbr-global/scripts/quests/cults_of_tibia/event_on_item_moved.lua @@ -3,44 +3,42 @@ local callback = EventCallback("CultsOnItemMoved") function callback.onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder) local fromPos = Position(33023, 31904, 14) local toPos = Position(33052, 31932, 15) - local removeItem = false if player:getPosition():isInRange(fromPos, toPos) and item:getId() == 23729 then local tile = Tile(toPosition) - if tile then - local tileBoss = tile:getTopCreature() - if tileBoss and tileBoss:isMonster() then - local bossName = tileBoss:getName():lower() - if bossName == "the remorseless corruptor" then - tileBoss:addHealth(-17000) - tileBoss:remove() - - local monster = Game.createMonster("The Corruptor of Souls", toPosition) - if not monster then - return false - end - - removeItem = true - monster:registerEvent("CheckTile") - - local storedHealth = Game.getStorageValue("healthSoul") - if storedHealth > 0 then - monster:addHealth(-(monster:getHealth() - storedHealth)) - end - - Game.setStorageValue("CheckTile", os.time() + 30) - elseif bossName == "the corruptor of souls" then - Game.setStorageValue("CheckTile", os.time() + 30) - removeItem = true - end - end + if not tile then + return + end + + local tileBoss = tile:getTopCreature() + if not (tileBoss and tileBoss:isMonster()) then + return end - if removeItem then + local bossName = tileBoss:getName():lower() + if bossName == "the remorseless corruptor" then + tileBoss:addHealth(-17000) + tileBoss:remove() + + local monster = Game.createMonster("The Corruptor of Souls", toPosition) + if not monster then + return + end + + monster:registerEvent("CheckTile") + + local storedHealth = Game.getStorageValue("healthSoul") + if storedHealth > 0 then + monster:addHealth(-(monster:getHealth() - storedHealth)) + end + + Game.setStorageValue("CheckTile", os.time() + 30) + item:remove(1) + elseif bossName == "the corruptor of souls" then + Game.setStorageValue("CheckTile", os.time() + 30) item:remove(1) end end - return true end callback:register() diff --git a/data-otservbr-global/scripts/quests/the_secret_library_quest/event_on_item_moved.lua b/data-otservbr-global/scripts/quests/the_secret_library_quest/event_on_item_moved.lua index d165d2be73a..01bb4ef715e 100644 --- a/data-otservbr-global/scripts/quests/the_secret_library_quest/event_on_item_moved.lua +++ b/data-otservbr-global/scripts/quests/the_secret_library_quest/event_on_item_moved.lua @@ -7,7 +7,6 @@ function callback.onItemMoved(item, count, fromPosition, toPosition, fromCylinde Game.setStorageValue(Storage.Quest.U11_80.TheSecretLibrary.SmallIslands.Turtle, os.time() + 10 * 60) item:remove(1) end - return true end callback:register() diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index 8e96828ac74..a8fe0bfb679 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -370,7 +370,9 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, return true end -function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder) end +function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder) + return true +end function Player:onMoveCreature(creature, fromPosition, toPosition) local player = creature:getPlayer() @@ -381,8 +383,12 @@ function Player:onMoveCreature(creature, fromPosition, toPosition) return true end -function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation) end -function Player:onReportBug(message, position, category) end +function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation) + return +end +function Player:onReportBug(message, position, category) + return true +end function Player:onTurn(direction) if self:getGroup():getAccess() and self:getDirection() == direction then