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
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.
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:
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:
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:
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).
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).
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)
| Field | Type | Default | What it does |
|---|---|---|---|
max | number | Most it holds | |
start | number | max | What a new unit has |
regen | number | 0 | Back each second |
decay | number | 0 | Lost each second once idle |
idle | number | Seconds with nothing spent or gained before decay starts | |
moving | number | Gained per cell walked | |
reload | number | Full again this long after running out | |
thresholds | { at, buff, kept?, empties? }[] | Buffs as the pool reaches at | |
name, color | string | Its bar's label and colour (plate, selection, hero panel) |
Costs and gains
| Field | On | What it does |
|---|---|---|
manaCost | ability | Mana per cast |
healthCost | ability | Share of max health per cast |
cost: { pool: Scaled } | ability | Pool cost, paid as it goes off |
gain: { pool: Scaled } | ability | Pool given as it goes off |
costGrowth: { buff, per } | ability | Costs grow with the caster's stacks of a buff |
attackCost: { pool: n } | unit type | An attack with less doesn't go off |
drain: { pool: n } | buff | Taken each second; the buff ends without enough |
gain effect | any effect | pool, amount (negative empties); allies, or on: 'caster' |
mana effect | any effect | Gives mana |
manaBurn effect | any effect | Burns 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
checkRuleswarns of a pool no unit type has in a cost, gain or drain; an attack cost of a pool the unit lacks; a threshold abovemax; 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).