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 ff48f7e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 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()
12 changes: 9 additions & 3 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion data/scripts/eventcallbacks/player/on_report_bug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function callback.playerOnReportBug(player, message, position, category)
file:close()

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Your report has been sent to %s.", SERVER_NAME))
return true
end

callback:register()

0 comments on commit ff48f7e

Please sign in to comment.