Conditions and chance
Do one thing or another depending on the target (an execute, Holy Light on the undead), or only some of the time (Bash).
Quick start
import type { AbilityDef } from '@v12-engine/engine'
const execute: AbilityDef = {
id: 'execute',
name: 'Execute',
target: 'unit',
range: 4,
targets: { enemies: true },
effects: [
{
type: 'if',
target: { healthBelow: 0.2 },
effects: [{ type: 'damage', amount: 9999, damageType: 'true' }],
otherwise: [{ type: 'damage', amount: 120 }]
}
]
}Below 20% health, the target dies; otherwise it takes 120 damage.
Common tasks
A chance to stun on hit
chance on any effect makes it happen that share of the time. On a trigger it decides whether the trigger goes off at all. Bash:
import type { AbilityDef } from '@v12-engine/engine'
const bash: AbilityDef = {
id: 'bash',
name: 'Bash',
target: 'passive',
effects: [
{
type: 'onHit',
chance: [0.2, 0.3, 0.4],
effects: [
{ type: 'buff', buff: 'bashed' },
{ type: 'damage', amount: 25 }
]
}
]
}Chance draws from the world's random numbers (world.rng), so replays and saves come out the same.
Hurt the undead, heal the living
A unit type's tags are your game's words for what it is. An if asks about them:
import type { AbilityDef } from '@v12-engine/engine'
const holyLight: AbilityDef = {
id: 'holyLight',
name: 'Holy Light',
target: 'unit',
range: 8,
targets: { allies: true, enemies: true },
effects: [
{
type: 'if',
target: { tags: ['undead'], is: 'enemy' },
effects: [{ type: 'damage', amount: [100, 175, 250] }],
otherwise: [{ type: 'if', target: { notTags: ['undead'], is: 'ally' }, effects: [{ type: 'heal', amount: [200, 350, 500] }] }]
}
]
}Cast only on some units
targets.tags limits what the ability can be cast on; the screen greys out the rest. Dark Ritual on an undead ally:
import type { AbilityDef } from '@v12-engine/engine'
const darkRitual: AbilityDef = { id: 'darkRitual', name: 'Dark Ritual', target: 'unit', range: 6, targets: { allies: true, tags: ['undead'] }, effects: [{ type: 'mana', amount: 150, on: 'caster' }] }Hit only some units in an area
An effect's own tags hits only units with one of them.
import type { EffectDef } from '@v12-engine/engine'
const exorcism: EffectDef = { type: 'damage', amount: 200, radius: 5, tags: ['undead'] }Hit only those a condition holds for, or a few of them
where takes the same UnitCondition as an if, on any effect. sort and limit take a few of what the area reaches (Querying the world):
import type { EffectDef } from '@v12-engine/engine'
// the three most hurt living allies around the caster
const mend: EffectDef = { type: 'heal', amount: 120, radius: 8, affects: 'allies', where: { notTags: ['mechanical'] }, sort: 'lowestHealthShare', limit: 3 }Check each unit in an area
With a radius or shape, an if asks each unit inside, and does its effects to that one.
import type { EffectDef } from '@v12-engine/engine'
// heroes in the area take more
const crush: EffectDef = { type: 'if', radius: 3, target: { hero: true }, effects: [{ type: 'damage', amount: 200 }], otherwise: [{ type: 'damage', amount: 80 }] }Ask about the caster
import type { EffectDef } from '@v12-engine/engine'
// stronger while the caster is enraged
const blow: EffectDef = { type: 'if', caster: { buff: 'enraged' }, effects: [{ type: 'damage', amount: 180 }], otherwise: [{ type: 'damage', amount: 100 }] }A condition in code
target (or caster) can be a function. Pyke's execute threshold grows by level:
import type { EffectDef } from '@v12-engine/engine'
const threshold = [250, 400, 550]
const deathFromBelow: EffectDef = {
type: 'if',
shape: 'cross',
length: 8,
width: 0.6,
target: (context, unit) => unit.health <= threshold[Math.min(context.level, threshold.length) - 1],
effects: [{ type: 'damage', amount: 9999, damageType: 'true' }],
otherwise: [{ type: 'damage', amount: 150 }]
}Reference
The if effect
| Field | Type | What it does |
|---|---|---|
target | UnitCondition or function | What must hold of the target |
caster | UnitCondition or function | What must hold of the caster |
chance | EffectValue | One more condition, drawn per unit asked |
effects | EffectDef[] | When it holds |
otherwise | EffectDef[] | When it doesn't |
radius, shape | from EffectCommon | Ask each unit within (affects, enemies by default) |
Without radius or shape, it asks of the unit the ability was cast on. With no such unit, a target condition doesn't hold.
UnitCondition
Every part given must hold.
| Field | Holds when the unit |
|---|---|
buff | carries this buff |
noBuff | doesn't carry it |
healthBelow | is under this share of its max health |
healthAbove | is over it |
hero | is (true) or isn't (false) a hero |
tags | has one of these tags |
notTags | has none of them |
is | is an enemy or ally of the caster |
chance
- On any effect: once each time its list runs, for all it reaches.
- On a trigger: whether it goes off; its
cooldownstarts only when it does. - On an
if: a condition per unit; a failed draw goes tootherwise. - A number, one per level, or code. A tooltip's
{chance}is the first effect's, in percent.
In code
byChance, conditionHolds, hasTag, unitMatches (a UnitCondition with no effect around it, as world.query asks it). A beforeEffect hook can stop any effect reaching a target (Write your own effect).
Notes
checkRules warns of a tag no unit type has (and suggests the one meant), an if that asks nothing, a chance outside 0 to 1, caster or target on an effect that isn't an if, a buff that doesn't exist (in a where too), and a limit with no area or under 1.