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
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:
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:
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:
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.
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.
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:
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:
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:
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)
| Effect | Fields | What it does |
|---|---|---|
grantAbility | ability, atLevel, duration, uses | Adds an ability (allies, or on: 'caster'); for good when neither is given |
swapAbility | ability, from, atLevel, duration, uses | The caster's from gives way to ability in its place |
stealAbility | pick (ultimate, first, random), duration, uses | The target's ability in place of the one cast, at its level, for one cast by default |
convert | duration | What it reaches becomes the caster's owner's |
AbilityDef.upgrades | ability ids | What it can be made into for good, chosen once |
morph
| Field | Type | Default | What it does |
|---|---|---|---|
into | string | The form's unit type | |
duration | EffectValue | Seconds in the form | |
toggle | boolean | false | Cast again to turn back |
back | ('ability' | 'time' | 'death')[] | time, death | What turns it back. death: it dies as itself |
Without ability in back, casting again in the form restarts its time.
HeroForm (HeroDef.forms[type])
| Field | What it does |
|---|---|
learns | What it learns in the form, by id (the form type's own hero.learns when left out) |
levels | The level each starts at: a hero ability's id (shares its level and points) or a number (0: learned there) |
keeps | What of the hero's own stays in place (an ultimate, a passive) |
cooldowns | Put-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
| Function | What it does |
|---|---|
grantAbility(world, entity, id, { level, until, uses, slot }) | Give one |
removeAbility | Take 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, learnsOf | What 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
abilityGrantscomponent (saved, sent to the owner); a converted unit carriesconverted. - During a form the hero carries a
formcomponent;morphedBacksays when and why it turned back, andentityMorphedfires both ways. - The command card, hotkeys and hero panel follow the form, and the client draws the form's look.
checkRuleswarns of an upgrade orfromthat is no ability, apickthat doesn't exist, andupgradesin a game without the pack.