Skip to content

Commit

Permalink
refactor: simplify and optimize CultsOnItemMoved event logic
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Dec 12, 2024
1 parent 0634c45 commit 016b6c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ 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()
Expand All @@ -381,8 +381,8 @@ 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
Expand Down

0 comments on commit 016b6c5

Please sign in to comment.