Four abilities of League of Legends
How much it takes to write a MOBA hero's abilities in V12. Four League abilities, each built on one trial hero, the Steam Golem in apps/my-game (src/game/units/trial.ts, played by apps/my-game/tests/trial.test.ts). Three of the four are data alone.
| Ability | Data lines | Code lines | Built on |
|---|---|---|---|
| Blitzcrank's Rocket Grab | 27 | 0 | a missile, a pull, a stun, a when chain |
| Nidalee's Aspect of the Cougar | 68 | 0 | morph with toggle, HeroDef.forms |
| Malzahar's Void Swarm | 23 | 0 | summon and its defaults |
| Viego's passive and R | 40 | 51 | a leap; fallenHeroes, takeForm in an effect |
Rocket Grab
A fist fired along a line; the first enemy it meets is dragged back, held, and hurt as it arrives.
import type { AbilityDef, BuffDef } from '@v12-engine/engine'
export const rocketGrab: AbilityDef = {
id: 'rocketGrab',
name: 'Rocket Grab',
hotkey: 'Q',
target: 'direction',
range: 9,
manaCost: 100,
cooldown: [20, 18, 16],
castTime: 0.25,
effects: [
{ type: 'missile', speed: 28, distance: 9, radius: 0.7, pierce: false, returns: true, layers: ['ground'] },
{ type: 'pull', seconds: 0.6, when: 'hit' },
{ type: 'damage', amount: [70, 120, 170], damageType: 'magic', when: 'arrived' },
{ type: 'buff', buff: 'grabbed', when: 'hit' }
]
}
export const grabbed: BuffDef = { id: 'grabbed', name: 'Grabbed', harmful: true, duration: 0.6, stun: true }Aspect of the Cougar
A toggle into a cougar form with abilities of its own, keeping level and items. The form's abilities share the levels of the golem's own.
import type { AbilityDef, UnitTypeDef } from '@v12-engine/engine'
export const aspectOfTheCougar: AbilityDef = {
id: 'aspectOfTheCougar',
name: 'Aspect of the Cougar',
hotkey: 'R',
target: 'none',
cooldown: 3,
effects: [{ type: 'morph', into: 'trialCougar', toggle: true }]
}
// on the golem: what the cougar learns, at whose level, and what stays in place
export const golemHero: UnitTypeDef['hero'] = {
growth: { stats: { health: 45 } },
learns: ['rocketGrab', 'voidSwarm', 'aspectOfTheCougar', 'heartbreaker'],
forms: { trialCougar: { learns: ['takedown', 'pounce', 'swipe'], levels: { takedown: 'rocketGrab', pounce: 'voidSwarm' }, keeps: ['heartbreaker', 'possess'] } }
}
// the cougar's W
export const pounce: AbilityDef = {
id: 'pounce',
name: 'Pounce',
target: 'direction',
range: 4,
effects: [{ type: 'dash', distance: 4, speed: 16, leap: 0.8, effects: [{ type: 'damage', amount: [60, 100, 140], radius: 1.5 }] }]
}The cougar itself is a unit type with its own stats. See Changing abilities at runtime.
Void Swarm
Four voidlings for eight seconds. Following the caster and turning on whoever hits it are what a summon does by default.
import type { AbilityDef, UnitTypeDef } from '@v12-engine/engine'
export const voidSwarm: AbilityDef = {
id: 'voidSwarm',
name: 'Void Swarm',
hotkey: 'W',
target: 'none',
manaCost: 90,
cooldown: 16,
castTime: 0.2,
effects: [{ type: 'summon', unit: 'trialVoidling', count: 4, lifetime: 8, spread: 1.5 }]
}
export const trialVoidling: UnitTypeDef = {
id: 'trialVoidling',
name: 'Voidling',
kind: 'unit',
radius: 0.3,
stats: { health: 60, attackDamage: 9, attackSpeed: 1.4, attackRange: 0.6, moveSpeed: 5 },
sight: 7,
attacks: [{ damagePoint: 0.25, acquisitionRange: 7 }]
}Viego's passive and Heartbreaker
Heartbreaker is data: a leap, then a blow by missing health where it lands. The passive (an enemy hero that falls nearby leaves a soul only Viego can take, and taking it he becomes that hero for ten seconds) is a small pack of the game's: an effect, a listener of deaths and a component.
import type { AbilityDef, UnitTypeDef } from '@v12-engine/engine'
export const heartbreaker: AbilityDef = {
id: 'heartbreaker',
name: 'Heartbreaker',
hotkey: 'R',
target: 'point',
range: 7,
ultimate: true,
manaCost: 100,
cooldown: [100, 85, 70],
effects: [
{ type: 'dash', distance: 7, speed: 18, leap: 1.6 },
{ type: 'damage', amount: [120, 190, 260], radius: 2.5, byMissingHealth: 0.2, when: 'landed' }
]
}
// what a fallen enemy hero leaves: only `possess` may target it
export const trialSoul: UnitTypeDef = { id: 'trialSoul', name: 'Soul', kind: 'unit', radius: 0.4, stats: { health: 1 }, sight: 0, targetableBy: ['possess'], lifetime: 8 }The pack's effect takes the fallen hero's form at the levels it had, from the heroes pack's record of the fallen:
defineEffect({
type: 'warden.possess',
run: ({ world, caster, target }) => {
const soul = target?.get(soulOf)
const fallen = soul && fallenHeroes(world).find((each) => each.id === soul.hero && each.at === soul.at)
if (!target || !fallen) return
// ... the fallen's abilities but its ultimate; the golem's own ultimate kept
takeForm(world, caster, fallen.type, { learns, levels, duration: 10, by: possess.id })
world.kill(target, undefined, false, 'removed')
}
})An entityDied listener leaves a soul where an enemy hero falls near the golem, and turns a possessing golem back on a kill (leaveForm).
Where next
- Abilities: every effect and field.
- Abilities cookbook: twenty-five more, each cast in a test.
- Heroes, items and abilities: levels, inventories, the hero panel.
- Testing and balancing rules: playing a hero in a test with no page.