Skip to content

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 ​

ts
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:

ts
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:

ts
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:

ts
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.

ts
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):

ts
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.

ts
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 ​

ts
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:

ts
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 ​

FieldTypeWhat it does
targetUnitCondition or functionWhat must hold of the target
casterUnitCondition or functionWhat must hold of the caster
chanceEffectValueOne more condition, drawn per unit asked
effectsEffectDef[]When it holds
otherwiseEffectDef[]When it doesn't
radius, shapefrom EffectCommonAsk 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.

FieldHolds when the unit
buffcarries this buff
noBuffdoesn't carry it
healthBelowis under this share of its max health
healthAboveis over it
herois (true) or isn't (false) a hero
tagshas one of these tags
notTagshas none of them
isis 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 cooldown starts only when it does.
  • On an if: a condition per unit; a failed draw goes to otherwise.
  • 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.