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
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):
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:
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.
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
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.
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:
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 want | Page |
|---|---|
| Hurt, heal, give mana, scale with stats | Damage and heal |
| Stat buffs, shields, stacks, auras | Buffs and auras |
| Projectiles, bounces, hooks, boomerangs | Missiles |
| Cones, lines, rings, zones, delayed blasts | Areas and shapes |
| Dash, blink, knockback, pull, swap | Moves |
| Stun, root, silence, fear, charm, cleanse | Crowd control |
| On hit, on kill, on damaged, cheat death | Triggers and passives |
| Cast again, charges, hold to charge | Recasts, charges and holds |
| Mana, energy, fury, heat, ammo | Resources |
| Summons, wards, traps, walls, proxies | Summons and ground objects |
| Reveal, stealth, true sight | Vision and stealth |
| Only if, a chance, by tag, executes | Conditions and chance |
| Steal, swap, grant abilities; hero forms | Changing abilities at runtime |
| An effect the engine doesn't have | Write your own effect |
| Twenty-five famous abilities, ready-made | Cookbook |
| How it looks | Ability visuals |
Editor
- Open the Data panel and pick Abilities.
- Click Add… and give it an id and a name.
- Set target, range, manaCost and cooldown.
- Under effects, click Add…, pick a type (
damage,missile…) and fill in its fields. - 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.
| Field | Type | Default | What it does |
|---|---|---|---|
id, name | string | Its id (prefix it with your game's) and shown name | |
target | AbilityTarget | none, unit, point, direction, vector, passive, or your own | |
targets | object | For unit: allies, enemies, self, kinds, layers, heroes, tags | |
range | Scaled | How far the target may be | |
attackRange | boolean | Reaches as far as the caster's attacks, plus range | |
effects | EffectDef[] | What it does when cast, in order | |
passive | EffectDef[] | Always on once learned, beside the cast (buffs, auras, triggers) | |
manaCost | Scaled | 0 | Mana per cast |
healthCost | Scaled | 0 | Share of max health per cast; can't cast with less |
cost, gain | { pool: Scaled } | Pool costs and gains (Resources) | |
cooldown | Scaled | 0 | Seconds before it can be used again; ability haste shortens it |
charges | { count, refill } | Uses held, one back every refill seconds | |
recast | AbilityRecast | Cast again within a window (Recasts) | |
castTime | number | 0 | Wind-up: the caster stands still, can't be called away; a stun holds it |
channel | object | Kept up: duration, every, effects, finished, leash, breaksOnDamage | |
hold | HoldDef | Hold to charge, release to fire (holds pack) | |
charge | string | A stacking buff that "charges" it at max stacks | |
aim | shape | The ground it covers, when its effects don't say | |
hotkey | string | Key on the command card | |
ultimate | boolean | false | First learned at hero level 6; the AI saves it for crowds |
maxLevel | number | 3 | Levels a hero can put into it |
requiresLevel | number | 1 (6) | Hero level for its first level |
levelStep | number | 2 | Hero levels between its levels |
tags | string[] | What kind of thing it is, for buffs that avoids it | |
autocast | boolean | Used on its own when idle | |
autoAim | function | Where to autocast, in code | |
ai | function | Where a computer player casts it | |
piercesImmunity | boolean or function | Gets through spell immunity | |
upgrades | string[] | What it can be made into for good (ability changes pack) | |
description | string | Tooltip template with {values} | |
values | record | Your own tooltip values: { amount, scaling, unit, percent } or code | |
describe | function | The whole tooltip in code | |
how | string or function | How what it kills dies, for the screen (Destruction) | |
rangeOf, castTimeOf | function | Range and wind-up in code |
Things worth knowing
- What has no
castTimeand is aimed atnoneor adirectiongoes 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.
castTimecalled off (the caster killed, feared, charmed) fires thecastCancelledevent and its ground shape goes at once.- Ability power, crits, penetration, life steal, tenacity and haste come with
mobaStatsPack()inRules.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.
| Pack | Adds | Page |
|---|---|---|
movesPack() | dash to a unit, collisions, wall stuns, swap, attach | Moves |
groundObjectsPack() | traps, things to click, missile walls, barrels | Summons and ground objects |
resourcesPack() | unit pools: energy, fury, heat, ammo | Resources |
holdsPack() | hold to charge, aimed and walking channels | Recasts, charges and holds |
abilityChangesPack() | grant, swap, steal, upgrade abilities; convert units | Changing abilities |
visionPack() | reveal a unit, camouflage, true sight | Vision and stealth |
mobaStatsPack() | ability power, crits, tenacity, haste | Damage and heal |