Skip to content

Hero spells ​

A hero spell is an ability every hero has from the start, besides what it learns: two a hero (HeroDef.spells), on D and F, for no point and no mana, on a long cooldown nothing shortens. The engine brings nine: Flash, Second Wind, Barrier, Brand, Wither, Phantom Stride, Purify, Waystone, Reap (every hero spell). A game takes them all, some, changes some, or gives its own: they are plain definitions.

Quick start ​

ts
import { defaultHeroSpellBuffs, defaultHeroSpells, heroesPack, type Rules } from '@v12-engine/engine'

export const rules: Rules = {
	id: 'my-game',
	name: 'My game',
	units: [
		{
			id: 'knight',
			name: 'Knight',
			kind: 'unit',
			radius: 0.5,
			sight: 10,
			stats: { health: 600, moveSpeed: 4 },
			hero: { growth: { stats: { health: 50 } }, learns: [], spells: ['flash', 'barrier'] }
		}
	],
	abilities: defaultHeroSpells(),
	buffs: defaultHeroSpellBuffs(),
	packs: [heroesPack()]
}

The knight has Flash on D and Barrier on F from level 1. Or take them with the set chooser, so data.json and the editor can choose again: useDefaults(rules, [defaultHeroSpellSet()]) (The default set).

Common tasks ​

Give a hero two spells ​

spells: ['flash', 'waystone']. The view's input.keys.spells (['D', 'F']) are their keys.

Take some, change some ​

ts
abilities: [...defaultHeroSpells().filter((spell) => spell.id !== 'reap'), ...own]
useDefaults(rules, [defaultHeroSpellSet()], { heroSpells: { except: ['reap'], change: { flash: { cooldown: 240 } } } })

defaultHeroSpells() and defaultHeroSpellBuffs() give new lists each time, to change as you like. Their ids are short and plain (flash): a game with an ability of the same id leaves theirs out or renames it.

Write your own ​

A hero spell is an ability like any other, tagged 'heroSpell' so a search finds it with the rest:

ts
{
	id: 'smokeBomb',
	name: 'Smoke Bomb',
	description: 'The hero and allies near are unseen for 3 seconds',
	tags: ['heroSpell', 'vision'],
	target: 'none',
	cooldown: 200,
	effects: [{ type: 'buff', buff: 'smoked', radius: 5, affects: 'allies' }]
}

Give it cooldown and no manaCost; a channel for one that takes a while (Waystone's four seconds). Say what it does in general words (heroes, creeps, allies, buildings), as the nine do, so it holds in every kind of game.

Build from the engine's ​

SpellBuilt from
Flashblink
Second Windheal with only: 'heroes', a buff of move speed
Barriera buff with shield and shieldScaling by level
Branda harmful buff: onTick true damage, incomingHealing: -0.4, revealed, stacking: 'refresh'
Withera harmful buff: percent.moveSpeed: -0.3, outgoingDamage: -0.35
Phantom Stridea buff with phasing and move speed that decays (change)
Purifycleanse on the caster, then a buff whose change gives tenacity where the game has the stat
Waystonea channel of 4 s whose finished is a teleport with to: 'target'; a stun breaks it
Reaptrue damage to what is no hero (where), heal on the caster

Show them ​

The hero panel puts the spells after the learned abilities, under their keys. hud.heroStats and the rest of the panel: Heroes.

Reference ​

WhereWhat
HeroDef.spellsThe two, by id
defaultHeroSpells()The nine, a new list each time
defaultHeroSpellBuffs()Their buffs
defaultHeroSpellSet()Both as a set for useDefaults (id heroSpells)
input.keys.spellsTheir keys on the view, ['D', 'F']

A spell's cooldown is not shortened by ability haste; Wildheart's quicken effect is the one thing that cools one faster (Reap).

Tests: packages/engine/tests/heroSpells.test.ts (each spell, Waystone broken by a stun, Reap refused on a hero, Purify against each kind of hold).