Skip to content

Changing abilities at runtime ​

Give a unit an ability for a while, swap one for another, steal an enemy's ultimate, upgrade one for good, or turn a hero into another form with its own abilities.

Quick start ​

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

const hijack: AbilityDef = {
	id: 'hijack',
	name: 'Hijack',
	target: 'unit',
	targets: { enemies: true },
	range: 8,
	ultimate: true,
	effects: [{ type: 'stealAbility' }]
}

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

Sylas takes the target's ultimate in place of Hijack, at Hijack's level, for one cast.

Common tasks ​

Grant an ability for a while ​

The grantAbility effect adds an ability after the unit's others, for duration seconds or uses casts, or for good. A shrine's gift:

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

const gift: EffectDef = { type: 'grantAbility', ability: 'holyNova', atLevel: 1, duration: 60, on: 'caster' }

Swap one ability for another ​

swapAbility puts ability in the place of from (the effect's own ability when left out) on the card, then back. Udyr's stances, Aphelios's weapons:

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

const awaken: AbilityDef = { id: 'awaken', name: 'Awaken', target: 'none', effects: [{ type: 'swapAbility', from: 'wildfire', ability: 'wildfireAwakened', uses: 1 }] }

The swapped-out ability's cooldown keeps running.

Upgrade an ability for good ​

upgrades lists what it can become. The player picks once (the upgradeAbility command); it keeps its level and cooldown. Viktor's augments:

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

const siphonPower: AbilityDef = {
	id: 'siphonPower',
	name: 'Siphon Power',
	target: 'unit',
	targets: { enemies: true },
	range: 6,
	upgrades: ['siphonPowerAugmented'],
	effects: [{ type: 'damage', amount: 60 }]
}

Take control of an enemy ​

convert makes what it reaches the caster's owner's, for good or for duration. Heroes and buildings are left alone.

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

const charm: EffectDef = { type: 'convert', duration: 30 }

Change abilities from a hook ​

In code, any rule can change abilities. Viego's possession: who he kills lends him its abilities for ten seconds.

ts
import { abilityChangesPack, defineHook, swapAbility } from '@v12-engine/engine'

const possession = defineHook({
	hook: 'death',
	id: 'viego.possession',
	run(world, { entity, killer }) {
		if (killer?.def.id !== 'viego') return
		entity.abilities.forEach((state, index) => {
			const own = killer.abilities[index]
			if (own) swapAbility(world, killer, own.id, state.id, { until: 10 })
		})
	}
})
const rules = { /* … */ packs: [abilityChangesPack()], hooks: [possession] }

Give a hero a second form ​

The morph effect turns a hero into another unit type where it stands. Level, items, buffs and health share are kept. toggle turns it back when cast again. Metamorphosis for a minute:

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

const metamorphosis: AbilityDef = { id: 'metamorphosis', name: 'Metamorphosis', target: 'none', ultimate: true, cooldown: 180, effects: [{ type: 'morph', into: 'demonForm', duration: 60 }] }

No pack needed for forms.

Give the form its own abilities ​

HeroDef.forms says what each form learns, at what level, and what it keeps. Nidalee's cougar:

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

const aspect: AbilityDef = { id: 'aspect', name: 'Aspect', target: 'none', cooldown: 3, effects: [{ type: 'morph', into: 'cougar', toggle: true }] }
const huntress: Partial<UnitTypeDef> = {
	hero: {
		growth: { stats: { health: 45 } },
		learns: ['spear', 'trap', 'aspect', 'heartbreaker'],
		// Takedown at Spear's level, Pounce at Trap's, Swipe learned as a cougar; the ultimate kept, and the aspect (it made the form)
		forms: { cougar: { learns: ['takedown', 'pounce', 'swipe'], levels: { takedown: 'spear', pounce: 'trap' }, keeps: ['heartbreaker'] } }
	}
}

cooldowns: 'shared' makes Takedown ready when Spear is, in either form.

Take a fallen enemy's form ​

The heroes pack remembers each hero that fell for 8 seconds (fallenHeroes(world)). Your own effect hands one to takeForm:

ts
const fallen = fallenHeroes(world).filter((each) => each.id === soul.hero).pop()
const ultimate = (id: string) => world.registry.ability(id).ultimate
const learns = world.registry.unit(fallen.type).hero!.learns.filter((id) => !ultimate(id))
const keeps = learnsOf(caster).filter(ultimate)
takeForm(world, caster, fallen.type, { learns, levels: fallen.levels, keeps, duration: 10, by: 'possess' })
// on a kill: leaveForm(world, killer, 'kill')

Reference ​

Effects (ability changes pack) ​

EffectFieldsWhat it does
grantAbilityability, atLevel, duration, usesAdds an ability (allies, or on: 'caster'); for good when neither is given
swapAbilityability, from, atLevel, duration, usesThe caster's from gives way to ability in its place
stealAbilitypick (ultimate, first, random), duration, usesThe target's ability in place of the one cast, at its level, for one cast by default
convertdurationWhat it reaches becomes the caster's owner's
AbilityDef.upgradesability idsWhat it can be made into for good, chosen once

morph ​

FieldTypeDefaultWhat it does
intostringThe form's unit type
durationEffectValueSeconds in the form
togglebooleanfalseCast again to turn back
back('ability' | 'time' | 'death')[]time, deathWhat turns it back. death: it dies as itself

Without ability in back, casting again in the form restarts its time.

HeroForm (HeroDef.forms[type]) ​

FieldWhat it does
learnsWhat it learns in the form, by id (the form type's own hero.learns when left out)
levelsThe level each starts at: a hero ability's id (shares its level and points) or a number (0: learned there)
keepsWhat of the hero's own stays in place (an ultimate, a passive)
cooldownsPut-away abilities on return: left out, they ran down while away. keep: as left. reset: ready. shared: a form ability shares its cooldown with the hero ability whose level it takes

The shorter shape, learns alone, goes by slot: the form's first at the level of the hero's first, and so on.

In code ​

FunctionWhat it does
grantAbility(world, entity, id, { level, until, uses, slot })Give one
removeAbilityTake one away
swapAbility(world, entity, from, to, { level, until, uses })Swap
upgradeAbility(world, entity, from, to)Upgrade for good
takeForm(world, hero, into, { learns, levels, keeps, cooldowns, duration, back, by })Take a form with explicit abilities
leaveForm(world, hero, why)Turn back (why: one of back's words, or yours)
formOf, learnsOfWhat form it's in; what it learns there
fallenHeroes(world)Heroes fallen in the last 8 seconds: type, levels, player, place, killer

Given for good, these need no pack. For a while, the pack's system ends them.

Notes ​

  • What lasts a while is the abilityGrants component (saved, sent to the owner); a converted unit carries converted.
  • During a form the hero carries a form component; morphedBack says when and why it turned back, and entityMorphed fires both ways.
  • The command card, hotkeys and hero panel follow the form, and the client draws the form's look.
  • checkRules warns of an upgrade or from that is no ability, a pick that doesn't exist, and upgrades in a game without the pack.