Spell script structure
Each spell has a Lua file inscripts/actions/spells/ organized by spell school. Spells expose standard handler functions.
Spell handler reference
| Handler | Signature | When called |
|---|---|---|
onMagicCastingCheck | (caster, target, spell) | Validates whether the spell can be cast; return 0 to allow, non-zero to deny |
onSpellCast | (caster, target, spell) | Main spell execution; return the damage dealt |
Damage spell calculations
scripts/globals/spells/damage_spell.lua contains xi.spells.damage, used for all direct-damage magic (Black, White, Dark, Ninjutsu).
Damage parameters are stored in a table indexed by spell ID:
xi.spells.damage.useDamageSpell(caster, target, spell) to run the full pipeline including:
- Base power lookup from the parameter table
- Stat modifier (INT/MND) application
- Magic accuracy vs. magic evasion (resist rate from
magic_hit_rate.lua) - Day/weather bonus (
damage_multipliers.lua) - Magic burst multiplier (
magicburst.lua) - Stoneskin, Phalanx, One For All absorption
- Final HP adjustment
Cure spells
Cure calculations live inscripts/globals/magic.lua:
Enfeebling and enhancing spells
Helper modules inscripts/globals/spells/ cover other spell families:
| File | Covers |
|---|---|
enfeebling_spell.lua | Slow, Paralyze, Blind, etc. |
enhancing_spell.lua | Protect, Shell, Haste, etc. |
enfeebling_song.lua | Bard enfeebling songs |
enhancing_song.lua | Bard enhancing songs |
enhancing_ninjutsu.lua | Ninjutsu enhancing buffs |
enhancing_teleport.lua | Teleport/Warp spells |
absorb_spell.lua | Absorb-TP, Absorb-STR, etc. |
Blue magic
scripts/globals/bluemagic.lua provides xi.spells.blue with calculation routines for Blue Mage spells. Blue magic spells can be physical or magical and reuse the mob skill calculation pipeline.
scripts/actions/spells/blue/ and call into xi.spells.blue helpers.
Job abilities
scripts/globals/ability.lua provides xi.ability.adjustDamage(), which applies universal modifiers to job ability damage:
scripts/actions/abilities/ and return a table with:
Ninjutsu
Ninjutsu tools are checked and consumed automatically by the C++ core. Ninjutsu spell scripts follow the same structure as regular spells but may referencescripts/globals/spells/enhancing_ninjutsu.lua for buff ninjutsu.
Spell object API
Thespell object passed to all spell handlers is a CLuaSpell (bound in src/map/lua/lua_spell.cpp).