devilutionX
devilutionX copied to clipboard
Add Lua API for mana shield persistence across level changes
Summary
- Add Lua
manaShieldproperty (read/write) to Player usertype with proper network sync - Add new
levelmodule withtype()function and dungeon type constants - Add
LeavingLevelandEnterLevelevents for level transition hooks - Include sample
persist_mana_shieldmod demonstrating the API
API
Player module
local player = require("devilutionx.player")
local p = player.self()
p.manaShield = true -- Enable mana shield
local active = p.manaShield -- Check if mana shield is active
Level module
local level = require("devilutionx.level")
local currentType = level.type() -- Get current dungeon type
-- Available constants:
level.TOWN
level.CATHEDRAL
level.CATACOMBS
level.CAVES
level.HELL
level.NEST
level.CRYPT
Events
local events = require("devilutionx.events")
events.LeavingLevel.add(function()
-- Called before leaving current level (before mana shield is cleared)
end)
events.EnterLevel.add(function()
-- Called after entering a new level
end)
Test plan
- [x] Unit tests for manaShield property (LuaPlayerModuleTest)
- [x] Unit tests for Lua script access to manaShield (LuaPlayerModuleTest)
- [x] Unit tests for level.type() function (LuaLevelModuleTest)
- [x] Unit tests for level type constants (LuaLevelModuleTest)
- [x] Regression test for mana shield persistence logic (ManaShieldPersistenceTest)
- [x] Regression test for level module Lua access pattern (ManaShieldPersistenceTest)
- [x] Integration test with real player and Lua events (ManaShieldIntegration)
- [x] Integration test for town level type check (ManaShieldIntegration)
- [x] Manual test - mod on, mana shield stays / mod off, default behavior of clearing mana shield on level exit.