Skip to content

Resources: mana, energy, ammo ​

Mana is built in (manaCost). Energy, fury, heat, ammo and any other pool a unit has come with resourcesPack().

Quick start ​

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

const akali: Partial<UnitTypeDef> = {
	pools: { energy: { name: 'Energy', color: '#ffe14d', max: 200, regen: 10 } }
}

const fivePointStrike: AbilityDef = {
	id: 'fivePointStrike',
	name: 'Five Point Strike',
	target: 'direction',
	range: 5,
	cost: { energy: [120, 110, 100] },
	effects: [{ type: 'damage', amount: 90, shape: 'cone', length: 5, angle: 1 }]
}

const rules = { /* … */ packs: [resourcesPack()] }

The unit gets an energy bar that fills 10 a second up to 200. With less than the cost, the ability isn't ready ("Not enough Energy").

Common tasks ​

Cost mana or health ​

No pack needed.

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

const bloodRite: AbilityDef = { id: 'bloodRite', name: 'Blood Rite', target: 'none', manaCost: 40, healthCost: 0.1, effects: [{ type: 'heal', amount: 100, radius: 4 }] }

healthCost: 0.1 costs a tenth of max health; it can't be cast with less left.

Build up a resource as you fight ​

gain on an ability fills a pool as it goes off. The gain effect fills one from anywhere: from an onHit, say. Tryndamere's fury:

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

const battleFury: AbilityDef = {
	id: 'battleFury',
	name: 'Battle Fury',
	target: 'passive',
	effects: [{ type: 'onHit', effects: [{ type: 'gain', pool: 'fury', amount: 5, on: 'caster' }] }]
}
// heals more the more fury he has, then spends it all
const bloodlust: AbilityDef = {
	id: 'bloodlust',
	name: 'Bloodlust',
	target: 'none',
	effects: [
		{ type: 'heal', on: 'caster', amount: (context) => 30 + 2 * (context.effect ? poolOf(context.effect.caster, 'fury') : 0) },
		{ type: 'gain', pool: 'fury', on: 'caster', amount: -100 }
	]
}

Heat that cools down and overheats ​

decay drains a pool once nothing has touched it for idle seconds. thresholds put buffs on at a level. Rumble:

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

const rumble: Partial<UnitTypeDef> = {
	pools: {
		heat: {
			name: 'Heat',
			color: '#ff6a00',
			max: 100,
			start: 0,
			decay: 10,
			idle: 2,
			thresholds: [
				{ at: 50, buff: 'dangerZone', kept: true },
				{ at: 100, buff: 'overheat', empties: true } // a buff with `silence` and a duration
			]
		}
	}
}

kept holds the buff while the pool stays that high. empties freezes the pool while the buff lasts and empties it as the buff ends.

Ammo that reloads ​

attackCost makes attacks spend a pool. reload refills it some seconds after it runs out. Jhin's four shots:

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

const jhin: Partial<UnitTypeDef> = { pools: { ammo: { name: 'Ammo', max: 4, reload: 2.5 } }, attackCost: { ammo: 1 } }

Gain a resource by walking ​

moving adds so much per cell walked (Yasuo's flow).

Make each cast cost more ​

costGrowth multiplies mana and cost by 1 + per for each stack of a buff on the caster (Kassadin's Riftwalk).

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

const riftwalk: AbilityDef = {
	id: 'riftwalk',
	name: 'Riftwalk',
	target: 'point',
	range: 5,
	manaCost: 50,
	costGrowth: { buff: 'riftwalkStacks', per: 1 },
	effects: [{ type: 'blink', distance: 5 }, { type: 'buff', buff: 'riftwalkStacks', stack: true, on: 'caster' }]
}

Drain mana while a buff is on ​

drain takes mana or a pool every second; the buff comes off when there isn't enough. See Buffs.

Trade player resources ​

The exchange effect trades the owner's resources at a rate, like a marketplace (presetMarket).

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

const sellLumber: EffectDef = { type: 'exchange', sell: 'lumber', buy: 'gold', amount: 100, rate: 0.5 }

Reference ​

PoolDef (UnitTypeDef.pools) ​

FieldTypeDefaultWhat it does
maxnumberMost it holds
startnumbermaxWhat a new unit has
regennumber0Back each second
decaynumber0Lost each second once idle
idlenumberSeconds with nothing spent or gained before decay starts
movingnumberGained per cell walked
reloadnumberFull again this long after running out
thresholds{ at, buff, kept?, empties? }[]Buffs as the pool reaches at
name, colorstringIts bar's label and colour (plate, selection, hero panel)

Costs and gains ​

FieldOnWhat it does
manaCostabilityMana per cast
healthCostabilityShare of max health per cast
cost: { pool: Scaled }abilityPool cost, paid as it goes off
gain: { pool: Scaled }abilityPool given as it goes off
costGrowth: { buff, per }abilityCosts grow with the caster's stacks of a buff
attackCost: { pool: n }unit typeAn attack with less doesn't go off
drain: { pool: n }buffTaken each second; the buff ends without enough
gain effectany effectpool, amount (negative empties); allies, or on: 'caster'
mana effectany effectGives mana
manaBurn effectany effectBurns mana and deals as much damage, times ratio (manaBurnPack)

In code ​

poolOf(entity, pool), changePool(world, entity, pool, amount) (keeps within bounds, applies thresholds), poolCosts(caster, ability, level). A unit's pools are the pools component, saved and sent to everyone who sees it in whole numbers.

Notes ​

  • checkRules warns of a pool no unit type has in a cost, gain or drain; an attack cost of a pool the unit lacks; a threshold above max; and pool fields in a game without the pack.
  • For state of your own on an ability (ammo per ability, a zone it left), use AbilityState.data (Write your own effect).