Skip to content

Abilities ​

An ability is data: how it is aimed, what it costs, and a list of effects. You write code only for a new kind of effect or a new look.

Quick start ​

ts
import type { AbilityDef, BuffDef, Rules, UnitTypeDef } from '@v12-engine/engine'

export const burning: BuffDef = { id: 'burning', name: 'Burning', harmful: true, duration: 3, stats: { healthRegen: -20 } }

export const fireball: AbilityDef = {
	id: 'fireball',
	name: 'Fireball',
	hotkey: 'Q',
	target: 'unit',
	targets: { enemies: true },
	range: 8,
	manaCost: 60,
	cooldown: 8,
	effects: [
		{
			type: 'missile',
			homing: true,
			speed: 16,
			effects: [
				{ type: 'damage', amount: [80, 120, 160] },
				{ type: 'buff', buff: 'burning' }
			]
		}
	]
}

export const mage: UnitTypeDef = {
	id: 'mage',
	name: 'Mage',
	kind: 'unit',
	radius: 0.5,
	stats: { health: 400, mana: 300, attackDamage: 12, attackSpeed: 1, attackRange: 5, moveSpeed: 3 },
	sight: 10,
	abilities: ['fireball']
}

export const rules: Rules = { id: 'my-game', name: 'My game', units: [mage], abilities: [fireball], buffs: [burning] }

The mage gets a Fireball button on its command card. Cast on an enemy, it walks into range, throws a homing missile, deals 80 damage at level 1 and sets the target on fire for 3 seconds. The cooldown, the aiming line, the tooltip and the computer player's use of it all come from the data.

To give it a look, add a line to the view (see Ability visuals):

ts
import type { GameView } from '@v12-engine/client'

export const view: GameView = {
	units: { looks: {} },
	fx: { abilities: { looks: { fireball: { color: [1, 0.45, 0.1], style: 'missile' } } } }
}

Common tasks ​

Cast it on a unit, a point, or nothing ​

target sets how the player aims. These three cover most abilities:

ts
import type { AbilityDef } from '@v12-engine/engine'

// on a unit: Holy Light on an ally
const holyLight: AbilityDef = {
	id: 'holyLight',
	name: 'Holy Light',
	target: 'unit',
	targets: { allies: true },
	range: 8,
	effects: [{ type: 'heal', amount: [200, 400, 600] }]
}
// on a point: Flame Strike burns the ground there
const flameStrike: AbilityDef = {
	id: 'flameStrike',
	name: 'Flame Strike',
	target: 'point',
	range: 8,
	effects: [{ type: 'damage', amount: 120, radius: 2 }]
}
// on nothing: Thunder Clap around the caster
const thunderClap: AbilityDef = {
	id: 'thunderClap',
	name: 'Thunder Clap',
	target: 'none',
	effects: [{ type: 'damage', amount: 70, radius: 3 }]
}

The others are direction (fires from the caster toward a spot, without walking there), vector (two clicks: a start and a direction) and passive (always on). See Areas and shapes.

Set the cost and cooldown ​

Any number can be one value or one per level.

ts
import type { AbilityDef } from '@v12-engine/engine'

const charge: AbilityDef = {
	id: 'charge',
	name: 'Charge',
	target: 'point',
	range: 6,
	manaCost: [50, 60, 70],
	cooldown: [12, 10, 8],
	castTime: 0.3, // the caster stands still this long before it goes off
	effects: [{ type: 'dash', distance: 6, speed: 20 }]
}

healthCost costs a share of the caster's max health. Energy, fury, heat and ammo are pools: see Resources. Several uses before a cooldown are charges: see Recasts, charges and holds.

Make a hero's ultimate ​

ts
import type { AbilityDef } from '@v12-engine/engine'

const starfall: AbilityDef = {
	id: 'starfall',
	name: 'Starfall',
	target: 'none',
	ultimate: true, // first learned at hero level 6
	cooldown: 180,
	effects: [],
	channel: { duration: 30, every: 1.5, effects: [{ type: 'damage', amount: [50, 75, 100], radius: 10 }] }
}

A hero learns abilities from its hero.learns. maxLevel (3), requiresLevel and levelStep (2) set how it levels.

Write the tooltip ​

Values in braces are worked out for the caster as it is now, the same way the simulation deals them.

ts
import type { AbilityDef } from '@v12-engine/engine'

const stoneShard: AbilityDef = {
	id: 'stoneShard',
	name: 'Stone Shard',
	target: 'unit',
	targets: { enemies: true },
	range: 7,
	description: 'Hurls a shard for {damage}. For {duration}, {steal} of its speed is yours.',
	values: { steal: { amount: [0.2, 0.25, 0.3], percent: true } },
	effects: [
		{ type: 'damage', amount: [70, 120, 170], scaling: { abilityPower: 0.6 } },
		{ type: 'buff', buff: 'shardSlow' }
	]
}
// level 1, 50 ability power: "Hurls a shard for 100 (70 + 60% ability power). For 3s, 20% of its speed is yours."

Without values, these names are found in the effects: damage, heal, shield, amount, duration, radius, chance, count, distance, plus the ability's own range, cooldown, charges, refill, mana and a recast's window.

Let units cast it on their own ​

autocast: true makes a unit use it when it has nothing to do (the player can switch it off). autoAim picks where in code. A computer player works out where to use most abilities from their effects; one built on a game's own effect says where with ai.

Keep a unit out of its way ​

Give the ability tags and a buff avoids those tags: nothing of that ability touches the carrier. A leap that dodges ground slams:

ts
import type { AbilityDef, BuffDef } from '@v12-engine/engine'

const slam: AbilityDef = { id: 'slam', name: 'Slam', target: 'none', tags: ['ground'], effects: [{ type: 'damage', amount: 90, radius: 3 }] }
const inTheAir: BuffDef = { id: 'inTheAir', name: 'In the air', duration: 0.6, avoids: ['ground'] }

Find what you need ​

You wantPage
Hurt, heal, give mana, scale with statsDamage and heal
Stat buffs, shields, stacks, aurasBuffs and auras
Projectiles, bounces, hooks, boomerangsMissiles
Cones, lines, rings, zones, delayed blastsAreas and shapes
Dash, blink, knockback, pull, swapMoves
Stun, root, silence, fear, charm, cleanseCrowd control
On hit, on kill, on damaged, cheat deathTriggers and passives
Cast again, charges, hold to chargeRecasts, charges and holds
Mana, energy, fury, heat, ammoResources
Summons, wards, traps, walls, proxiesSummons and ground objects
Reveal, stealth, true sightVision and stealth
Only if, a chance, by tag, executesConditions and chance
Steal, swap, grant abilities; hero formsChanging abilities at runtime
An effect the engine doesn't haveWrite your own effect
Twenty-five famous abilities, ready-madeCookbook
How it looksAbility visuals

Editor ​

  1. Open the Data panel and pick Abilities.
  2. Click Add… and give it an id and a name.
  3. Set target, range, manaCost and cooldown.
  4. Under effects, click Add…, pick a type (damage, missile…) and fill in its fields.
  5. Add the ability's id to a unit type's abilities or a hero's learns, then press Play.

The panel offers every field that applies, including those of the packs your game turns on. See The Data panel.

Reference ​

AbilityDef ​

Full type: AbilityDef. Scaled means a number, or one per level.

FieldTypeDefaultWhat it does
id, namestringIts id (prefix it with your game's) and shown name
targetAbilityTargetnone, unit, point, direction, vector, passive, or your own
targetsobjectFor unit: allies, enemies, self, kinds, layers, heroes, tags
rangeScaledHow far the target may be
attackRangebooleanReaches as far as the caster's attacks, plus range
effectsEffectDef[]What it does when cast, in order
passiveEffectDef[]Always on once learned, beside the cast (buffs, auras, triggers)
manaCostScaled0Mana per cast
healthCostScaled0Share of max health per cast; can't cast with less
cost, gain{ pool: Scaled }Pool costs and gains (Resources)
cooldownScaled0Seconds before it can be used again; ability haste shortens it
charges{ count, refill }Uses held, one back every refill seconds
recastAbilityRecastCast again within a window (Recasts)
castTimenumber0Wind-up: the caster stands still, can't be called away; a stun holds it
channelobjectKept up: duration, every, effects, finished, leash, breaksOnDamage
holdHoldDefHold to charge, release to fire (holds pack)
chargestringA stacking buff that "charges" it at max stacks
aimshapeThe ground it covers, when its effects don't say
hotkeystringKey on the command card
ultimatebooleanfalseFirst learned at hero level 6; the AI saves it for crowds
maxLevelnumber3Levels a hero can put into it
requiresLevelnumber1 (6)Hero level for its first level
levelStepnumber2Hero levels between its levels
tagsstring[]What kind of thing it is, for buffs that avoids it
autocastbooleanUsed on its own when idle
autoAimfunctionWhere to autocast, in code
aifunctionWhere a computer player casts it
piercesImmunityboolean or functionGets through spell immunity
upgradesstring[]What it can be made into for good (ability changes pack)
descriptionstringTooltip template with {values}
valuesrecordYour own tooltip values: { amount, scaling, unit, percent } or code
describefunctionThe whole tooltip in code
howstring or functionHow what it kills dies, for the screen (Destruction)
rangeOf, castTimeOffunctionRange and wind-up in code

Things worth knowing ​

  • What has no castTime and is aimed at none or a direction goes off without stopping the caster: it keeps walking. Items work the same, so a hero drinks on the run.
  • A unit in the air (a leap, a knock-up) does nothing until it lands, then picks up what it was doing.
  • castTime called off (the caster killed, feared, charmed) fires the castCancelled event and its ground shape goes at once.
  • Ability power, crits, penetration, life steal, tenacity and haste come with mobaStatsPack() in Rules.packs. Without it, scaling: { abilityPower } is refused.
  • Tooltips in code: abilityValues(ability, level, casterFacts(world, caster)), describeAbility, abilityText(segments). GameView.hud.abilityTip(tip, caster, client) changes what the HUD shows; client.abilityTip(caster, ability, level) gives it for your own panel.
  • checkRules(rules) reports ids that don't exist, effects with no handler and fields that do nothing. The editor's Data panel names where each problem is.

Packs ​

Some ability features come with a pack you add to Rules.packs. A game without the pack pays nothing for it.

PackAddsPage
movesPack()dash to a unit, collisions, wall stuns, swap, attachMoves
groundObjectsPack()traps, things to click, missile walls, barrelsSummons and ground objects
resourcesPack()unit pools: energy, fury, heat, ammoResources
holdsPack()hold to charge, aimed and walking channelsRecasts, charges and holds
abilityChangesPack()grant, swap, steal, upgrade abilities; convert unitsChanging abilities
visionPack()reveal a unit, camouflage, true sightVision and stealth
mobaStatsPack()ability power, crits, tenacity, hasteDamage and heal