landsandboat/scripts/effects/leavegame.lua
2026-02-20 18:42:33 -07:00

55 lines
1.5 KiB
Lua

-----------------------------------
-- xi.effect.LEAVEGAME
-----------------------------------
---@type TEffect
local effectObject = {}
local kinds =
{
LOGOUT = 1,
SHUTDOWN = 3,
}
local messages =
{
[kinds.LOGOUT] = xi.msg.system.EXECUTING_LOGOUT,
[kinds.SHUTDOWN] = xi.msg.system.EXECUTING_SHUTDOWN,
}
effectObject.onEffectGain = function(target, effect)
-- If you're a GM or in a MH, you get disconnected immediately.
if
target:inMogHouse() or
target:getGMLevel() > 0
then
target:leaveGame()
return
end
-- addStatusEffect (non-Ex) forces the icon to the effect ID...
if not target:hasStatusEffect(xi.effect.HEALING) then
target:addStatusEffect(xi.effect.HEALING, { origin = target, tick = xi.settings.map.HEALING_TICK_DELAY, icon = 0, silent = true })
end
-- Note: Power stores the kind.
target:messageSystem(messages[effect:getPower()], 30)
end
effectObject.onEffectTick = function(target, effect)
-- Note: The type of leavegame may change while it's ticking.
-- Logout to Shutdown or vice versa.
-- This has no bearing on the way the player gets disconnected
-- but it does change the message displayed.
local elapsedTicks = effect:getTickCount()
if elapsedTicks > 5 then
target:leaveGame()
else
target:messageSystem(messages[effect:getPower()], 30 - elapsedTicks * 5)
end
end
effectObject.onEffectLose = function(target, effect)
target:delStatusEffect(xi.effect.HEALING)
end
return effectObject