Skip to content

Add an ability or a spell ​

An ability is an entry of abilities in your rules: its target, cost, cooldown and a list of effects. A unit type lists the abilities it has.

ts
// in src/rules.ts
import { defineIds, type Rules } from '@v12-engine/engine'

export const UNIT = defineIds('mage')
export const ABILITY = defineIds('fireball', 'blink')

export const rules: Rules = {
	id: 'my-game',
	name: 'My game',
	units: [
		{
			id: UNIT.mage,
			name: 'Mage',
			kind: 'unit',
			radius: 0.4,
			sight: 9,
			stats: { health: 70, moveSpeed: 4, mana: 120 },
			abilities: [ABILITY.fireball, ABILITY.blink]
		}
	],
	abilities: [
		{
			id: ABILITY.fireball,
			name: 'Fireball',
			description: 'A ball of fire hurled at a point: 60 damage to every enemy within 2 cells',
			hotkey: 'F',
			// aimed at a point of the ground, within 8 cells, after half a second of casting
			target: 'point',
			range: 8,
			castTime: 0.5,
			manaCost: 40,
			cooldown: 6,
			// what happens: a missile flies there, and where it lands every enemy in the circle is hurt
			effects: [{ type: 'missile', speed: 18, effects: [{ type: 'damage', amount: 60, radius: 2, affects: 'enemies', damageType: 'magic' }] }]
		},
		{
			id: ABILITY.blink,
			name: 'Blink',
			hotkey: 'B',
			target: 'point',
			range: 10,
			manaCost: 30,
			cooldown: 12,
			effects: [{ type: 'blink' }]
		}
	],
	victory: null
}

Done: select the mage, press F, click the ground. A fireball flies there and hurts every enemy within 2 cells.

Scale it by level ​

Give a number per level and a maxLevel: amount: [40, 60, 80], maxLevel: 3.

Make it look like something ​

The view draws each ability by its id: an effect at the caster, along the missile and at the impact, plus a sound (GameView.abilityLooks). Tune effects in the editor's Effects panel; see Show an effect.

In the editor ​

  1. Open the Code panel and click New with code. It writes an ability stub and opens it.
  2. Edit its numbers in the Data panel (the fields Rules.editable allows) and click Keep.
  3. Select a unit on the map: the Inspector lists its abilities and a hero's learned levels.

Reference ​

FieldWhat it does
targetnone (on the caster), unit, point, direction or passive (always on).
rangeHow far it reaches, in cells.
castTimeSeconds before it goes off.
manaCostMana it takes.
cooldownSeconds before it can be cast again.
effectsWhat happens: damage, heal, buff, missile, spawn, blink, knockback…
channelKeeps the caster at it for a while.
autocastLets the player leave it on.
aiWhen a computer player casts it.

Abilities covers every effect, targeting, channels and charges. For a new kind of effect, see Make an effect of my own.