Lasting spells
Magic · Casting a spell · SpellEffectFlags
In brief
A lasting spell sets effect bits on its target, on the party or on every member, and starts a character timer whose length grows with the caster's level. Until the timer ends, the places of the game that test those bits change: hit rolls, defense, attacks, hands, poison, what the party sees. When the timer expires, the spell's end routine runs and the bits are cleared; some events end an effect earlier.
The timer
A spell with SPELL_FLAG_TIMED starts a
character timer on its
target, whose event is the definition number made negative. It lasts:
duration = unit × (base + per_level × caster_level) # in ticks
with the four timer parameters of the definition; the level is the caster's cleric level (a paladin's level minus 8) for a spell from the cleric book, and its mage level for a spell from the mage book; a spell cast from an item always counts level 9. The values of every timed spell are listed in the spell catalogue: a unit is 546 ticks, for instance Haste lasts 546 × (3 + level) ticks.
When the timer expires, the game prints "name's spell spell expires.", runs the spell's end routine and clears the effect bits from where the start put them.1
How long each spell lasts
The definitions with TIMED last unit × (base + per level × level)
ticks, where the level is the caster's; see
lasting spells. A unit is 546 ticks except for Slow Poison.
| Definition | Spell | Base | Per level | Unit |
|---|---|---|---|---|
| 3 | Detect Magic (mage) | 0 | 2 | 546 |
| 5 | Shield | 0 | 5 | 546 |
| 6 | Shocking Grasp | 0 | 1 | 546 |
| 7 | Blur | 3 | 1 | 546 |
| 8 | Detect Invisible | 0 | 5 | 546 |
| 14 | Haste | 3 | 1 | 546 |
| 18 | Vampiric Touch | 0 | 1 | 546 |
| 21 | Improved Invisibility | 5 | 1 | 546 |
| 29 | True Seeing (mage) | 0 | 1 | 546 |
| 34 | Bless | 6 | 0 | 546 |
| 37 | Detect Magic (cleric) | 0 | 2 | 546 |
| 38 | Protection from Evil | 0 | 3 | 546 |
| 39 | Aid | 1 | 1 | 546 |
| 40 | Flame Blade | 4 | 1 | 546 |
| 42 | Slow Poison | 0 | 1 | 32760 |
| 45 | Magical Vestment | 0 | 5 | 546 |
| 46 | Prayer | 0 | 1 | 546 |
| 51 | Protection from Evil 10' | 0 | 3 | 546 |
| 57 | True Seeing (cleric) | 0 | 1 | 546 |
What lasting effects do
Every test of the effect bits in the executable is accounted for; the
complete list is on the SpellEffectFlags
page.
A lasting spell acts in two ways: through its own routines, described in the attack spells, and through the places of the game that test its effect bit. The second kind is summed up here.2
| What changes | Effects |
|---|---|
| A character's hit roll | +1 under Bless or Prayer, on the party, or Aid, on the character; see a character's hit roll. |
| A monster's hit roll on a character | −2 for Protection from Evil and −2 for Blur on the character, −1 for Prayer on the party; see a monster's hit roll. |
| Defense | Shield caps it at 4 and Magical Vestment at 5 + (L − 5) / 3. Armor gives 6, adjusted by dexterity, while its reserve lasts; when the defense is recomputed and the character's own is already better, the reserve is dropped and Armor protects no more, although its effect lasts. |
| Being attacked | Under Invisibility or Improved Invisibility, a monster's close attack passes over the character unless a 1d20 roll is below 5; under Shield, Magic Missiles do nothing. |
| Hands | Under Haste, a hand is ready 27 ticks after an attack instead of 54. |
| Damage | Under Slow Poison, poison deals nothing. |
| What the party sees | Detect Invisible and True Seeing show hidden monsters; True Seeing also lifts illusion walls; Detect Magic tints magical items in the inventory, in the hands and under the cursor. |
| Scripts | A character under Invisibility is skipped by the script test for an eligible character. |
| Monster spells | Mystic defense weakens one kind of monster spell, and that spell's hit ends it. |
Some events end an effect before its timer: Dispel Magic ends them all; attacking with a hand item, or casting a spell that ends invisibility, ends Invisibility but not Improved Invisibility; being poisoned, by a monster or by a potion, ends Slow Poison, as does Neutralize Poison; damage that uses up the Armor reserve ends Armor.
The portraits show the effects too. Around each portrait the frame takes one colour when a protection is active — Shield, Blur, Protection from Evil, Magical Vestment, an Armor reserve or mystic defense on the party, which changes that colour — and another colour for Aid, Slow Poison, Haste or the party's Bless, Prayer or Detect Invisible; with both kinds, the two colours alternate along the frame. An invisible character's face is drawn with other colours, as are a poisoned and a petrified one, and the inventory page writes "POISON (SLOW)" instead of "POISONED" under Slow Poison.3
Magic reaches the rest of the game through the spells' own routines: monsters take damage, saving throws and conditions; the party is healed and cured; walls of force appear and disappear; items are identified, uncursed or conjured; food is created. Level scripts can react to any spell, through the spell-cast event and the last spell cast; see events that start scripts. Monsters cast their own spells at the party; see monster spells.
Sources
Locations refer to the game executable reference.