Skip to content

Draft: Dehardcoding spellcasting

Spurred by a discussion on Discord, i've concluded that the optimal path for dehardcoding some of my VR changes is to first dehardcode some or all combat functions of OpenMW.

The target for this MR is spellcasting.

The MR adds 5 .lua scripts

CREATURE, NPC, PLAYER: scripts/omw/mechanics/actorcontroller.lua
CREATURE, NPC, PLAYER: scripts/omw/mechanics/spellcasting.lua
GLOBAL: scripts/omw/mechanics/globalcontroller.lua
CREATURE: scripts/omw/mechanics/creaturecontroller.lua
NPC: scripts/omw/mechanics/npccontroller.lua

and two common files used to keep some functions as libraries


The scripts create 2 handlers

  • actorcontroller.lua:onSpellStartHandlers -- Called when actor initiates a spellcast and allows modifying all attributes of the spell before it is cast, such as magicka/charge cost, spell success chance, animation keys, or even which spell is being cast.
  • spellcasting.lua:onSpellCastHandlers -- Called when a spell is cast. Once again allows modifying all attributes of the spell before applying it to other actors / launching the projectile.

And 4 events

  • Actor/Global:ApplyMagicEffects -- Sent to the target of magic effects, including on self. If the target is not an actor, the event is sent to Global instead to apply lock/open effects. Also sent by the engine when a magic bolt makes impact.
  • Global:SpellCast -- Sent to global for all spells. Carries all available information about the spell, but the built in scripts use it only to apply enchantment charge costs.
  • Global:ExplodeSpell -- Used to apply AOE effects from a local script. Also sent by the engine when a magic bolt makes impact.
  • Global:LaunchMagicBolt -- Used to launch a magic bolt from a local script

The Global:ExplodeSpell and Global:LaunchMagicBolt events are also created engine side

Two new interfaces are added

  • ActorMechanics -- Adds a few actor functions related to mechanics, and for adding onSpellStart handlers.
  • SpellCasting -- Adds a few methods related to spells, for adding onSpellCast handlers, and notably the castSpell method.

Documentation is sorely incomplete as of now.

Prerequisite MRs:

It might still be necessary to simplify this MR by moving parts of it to separate MRs.

Edited by Mads Buvik Sandvei

Merge request reports