Skip to content

Make a MOBA (lanes) ​

Two sides, a core each, lanes between them that waves of minions walk, towers along them, heroes that last-hit, deny, recall and respawn, and computer heroes.

Quick start ​

ts
import { type Rules, heroesPack, lanesPack, lastHitsPack, respawnPack } from '@v12-engine/engine'
import { lanesBrain } from '@v12-engine/engine/ai'

const minions = { melee: 'grunt', ranged: 'archer', siege: 'ram' }

export const rules: Rules = {
	id: 'my-moba',
	name: 'My MOBA',
	units: [], // your heroes, minions, towers and cores
	brains: [lanesBrain],
	packs: [heroesPack(), lanesPack({ minions, cores: 'ancient' }), lastHitsPack(), respawnPack()]
}

On a map with lanes, waves of grunts, archers and rams come out of each side's spawners 20 seconds in and every 30 after, walk their lane fighting, and attack the far side's ancient. Destroy every enemy core to win. Heroes come back by themselves, and last hits and denies are counted. Seat computer heroes with world.computers.seat(2, { brain: lanesBrain }).

Build it yourself ​

1. Lanes on a map ​

A lane is a map path with a spawner at each end, one for each side. Give the editor the spawner kind:

ts
import { LANE_SPAWNER_KIND } from '@v12-engine/engine'

const editor = editorScene({ id: 'lanes-editor', name: 'Lanes map editor', game, kinds: [{ ...LANE_SPAWNER_KIND, key: 'KeyJ' }] })

Place spawners at path ends and set each one's player and path. Put checkLanes(map) in Rules.editor.check to flag spawners off a lane and lanes missing an end. The rules read lanes with lanesOf(world).

2. Waves, towers and cores ​

ts
lanesPack({
	cores: 'core', // a unit type id or a test; false keeps your own Rules.victory
	firstWave: 15,
	every: 25,
	minions: { melee: 'grunt', ranged: 'archer', siege: 'ram' },
	wave: (world, wave) => (wave.number % 5 === 0 ? ['ogre', 'grunt', 'grunt'] : ['grunt', 'grunt', 'archer']), // or your own wave
	goal: (world, minion, lane, from) => world.named('core.red')?.pos, // where they go at the far end
	towers: (world, entity) => entity.def.id === 'laneTower',
	towerAggro: 5,
	minionAggro: { radius: 9, chase: 4, leash: 14 } // or false
})

Towers hit minions first, but turn on a hero who hits one of their side's heroes in reach (for three seconds, heroStrike). Minions near a hero who hits one of theirs chase it briefly, then return to their lane.

3. Denying and last hits ​

ts
lastHitsPack({ deny: { below: 0.5 }, experience: 0.5, counts: (world, dead) => dead.has(laneMinion) })
// on the HUD, from the game's report
report: (world, player) => lastHitsOf(world, player)
status: (report) => [{ text: `Last hits ${report.lastHits} · Denies ${report.denies}` }]

A player denies by ordering an attack on an own-side unit below half health. Without lastHitsPack, add the rule alone:

ts
import { denying } from '@v12-engine/engine'

export const hooks = [...denying({ below: 0.5 })]
// towers too, below a tenth
export const towerHooks = [...denying({ below: 0.1, denies: (world, attacker, target) => target.def.id === 'laneTower' })]

4. Respawn and recall ​

ts
import { heroOf, respawnPack } from '@v12-engine/engine'

export const respawn = respawnPack({
	time: (world, hero) => 5 + heroOf(hero)!.level * 3,
	at: (world, hero) => world.map.point('fountain'),
	heroes: (world, hero) => hero.def.id !== 'boss'
})
ts
import { recallAbility } from '@v12-engine/engine'

abilities: [recallAbility({ duration: 8, cooldown: 30, hotkey: 'B' })]
// a gate to an ally, anywhere
{ id: 'gate', name: 'Gate', target: 'unit', targets: { allies: true }, range: 999, effects: [{ type: 'teleport', to: 'target' }] }

Computer heroes ​

ts
world.computers.seat(2, { brain: lanesBrain, settings: { lanes: { backAt: 0.4, camps: false } } })

The lanes brain walks a lane behind its wave, takes last hits, stays out of tower range without minions, falls back when outmatched, recalls home to heal, helps allied heroes and takes camps between waves. It commands heroes only, and waits for respawnPack. Its goals and numbers: AI reference.

Reference ​

lanesPack options ​

OptionDefaultWhat it does
minions{ melee, ranged, siege }: waves grow from these over time
wave(world, wave)Your own wave by number, lane, end and side
coresWhat the far end is; a side with no cores left loses (coreVictory)
firstWave, every20, 30Seconds to the first wave, and between waves
goalthe far coreWhere minions go at the end
towersattacking structures, not coresWhich structures are lane towers
towerAggro3Seconds towers stay on a hero who struck
minionAggro{ radius: 7, chase: 2.5, leash: 10 }Minions turning on a hero; false for never

Waves are saved timers. Each minion has laneMinion (its lane and end) and takes no supply. sendWave(world, spawner, options) sends one now; wavesSent(world, spawner) counts them. Path orders take towards: 'first' | 'last' (followPath, attackPath).

Other packs ​

Pack / callWhat it does
denying({ below, denies })A canAttack rule letting ordered attacks (CanAttack.ordered) hit own-side units below a share of health; mayDeny(world, attacker, target)
lastHitsPack({ deny, experience, counts })Counts last hits and denies (lastHitsOf(world, player)); a denied unit gives no bounty, half xp, and dies how: 'denied'
respawnPack({ time, at, heroes })Brings heroes back after 4 s + 2 s a level at home.<team> or the nearest own structure (homeOf); respawnIn(world, hero), HeroSummary.respawnIn
recallAbility({ duration, cooldown, hotkey })Channel 6 s (breaksOnDamage), then teleport home (to: 'home' | 'point' | 'target')

In the example ​

  • apps/example/src/games/lanes: lanes on melee's units (lanesOn), two against two, three lanes, two towers a side, a shop, two camps, a map made in code (lanesMap).
  • apps/example/src/scenes/lanesGame.ts and scenes/lanes.ts: the Lanes scene and its editor on the example's menu.
  • Tests: apps/example/tests/lanes.test.ts, aiLanes.test.ts.