Skip to content

Give my game heroes ​

Heroes come from the heroes pack: add heroesPack() to packs. It brings experience, levels, ability points, revival at an altar, creep camps, shops and taverns.

ts
// in src/rules.ts
import { defineIds, type Rules, heroesPack } from '@v12-engine/engine'

export const UNIT = defineIds('knight', 'altar')
export const ABILITY = defineIds('holyLight')

export const rules: Rules = {
	id: 'my-game',
	name: 'My game',
	units: [
		{
			id: UNIT.knight,
			name: 'Knight',
			kind: 'unit',
			radius: 0.5,
			sight: 10,
			stats: { health: 600, moveSpeed: 4 },
			// a hero: what it grows by a level, and the abilities it puts points into
			hero: { growth: { stats: { health: 50 } }, learns: [ABILITY.holyLight] }
		},
		{ id: UNIT.altar, name: 'Altar', kind: 'building', radius: 1.5, sight: 8, stats: { health: 900 }, trains: [UNIT.knight], revives: true }
	],
	abilities: [{ id: ABILITY.holyLight, name: 'Holy Light', target: 'unit', range: 6, cooldown: 5, effects: [{ type: 'heal', amount: 200 }] }],
	// heroes, with one at a time, ten levels and a quicker climb than the classic one
	packs: [heroesPack({ maxHeroes: 1, maxHeroLevel: 10, xpForLevel: (level) => (level - 1) * 100 })]
}

Done: train a knight at the altar. It levels up from kills, puts points into Holy Light, and can be revived at the altar.

Show heroes in the HUD ​

Add the view's half of the pack: packs: [heroesViewPack()] in your GameView. It fills the hero panel, the hero portraits and the shop window.

Respawn heroes on a timer, MOBA-style ​

packs: [heroesPack(), respawnPack()].

Make heroes die for good ​

A fallen hero stays in the world's entities (the pack's fallenHero hook). Add a hook of your own with a higher priority that sets stays = false.

Give a hero a second form ​

List its forms in hero.forms, by the form's unit type, and switch with a morph effect:

ts
hero: { forms: { cougar: { learns: ['takedown'], levels: { takedown: 'grab' }, keeps: ['heartbreaker'] } } }

cooldowns says what happens to cooldowns on the way in and out: 'keep', 'reset' or 'shared'. See Abilities.

Make an ultimate ​

ultimate: true on the ability: first learned at level 6.

Reference ​

HeroSettingsWhat it does
maxHeroesHeroes a player may have at once.
maxHeroLevelHighest level.
xpForLevelExperience needed for a level.
xpRangeHow close to a kill a hero must be to share it.
killXpExperience a kill gives.
pointsForLevelAbility points a level gives.
reviveWhat reviving costs, and how long it takes.
fallenForSeconds a fallen hero is remembered (default 8).

Read them in the rules as world.settings.heroes, on the screen as registry.settings.heroes. The pack's commands are buy, hire, sell, learn and revive; withoutCommands: ['sell'] drops one. fallenHeroes(world) lists recent fallen heroes as FallenRecords (id, type, owner, level, levels, at, pos, killer), saved with the world. Camps' rules are settings.camps (Creeps).