Skip to content

Heroes, items and shops ​

Heroes are units that gain experience, level up, learn abilities and carry items bought at shops. Turn them on with the heroes pack: packs: [heroesPack()]. Add mobaStatsPack() for ability power, crits, penetration, life steal, tenacity and haste (the default items bring it). See also Give my game heroes.

Quick start ​

ts
export const duskblade: UnitTypeDef = {
	id: 'duskblade',
	name: 'Duskblade',
	kind: 'unit',
	radius: 0.5,
	stats: { health: 560, mana: 300, manaRegen: 1.5, attackDamage: 50, attackSpeed: 0.8, attackRange: 0.6, armor: 30, moveSpeed: 4.5 },
	sight: 12,
	attacks: [{ damagePoint: 0.3, acquisitionRange: 8 }],
	hero: {
		growth: { stats: { health: 99, mana: 55, attackDamage: 3.5, armor: 4.3 }, percent: { attackSpeed: 0.03 } },
		callings: { stalker: 3, roamer: 2 },
		innate: 'shadowStep',
		innateLevels: [1, 5, 9],
		learns: ['duskMark', 'fade', 'twinFangs', 'eclipse'],
		spells: ['flash', 'brand']
	},
	inventory: 6,
	cost: { gold: 425, lumber: 100 },
	supply: 5,
	buildTime: 45
}
// an altar: trains: ['duskblade'], revives: true; a tavern: hires: ['duskblade']

Duskblade grows every level, puts points into four abilities, has Shadow Step from level 1 (stronger at 5 and 9), always has Flash and Brand, is a Stalker above all and a Roamer besides, and carries six items. An altar trains and revives it; a tavern hires it.

Common tasks ​

Give a hero an ability ​

ts
{
	id: 'holyLight',
	name: 'Holy Light',
	hotkey: 'Q',
	target: 'unit',
	targets: { allies: true, self: false },
	manaCost: 65,
	cooldown: 5,
	range: 8,
	castTime: 0.4,
	effects: [{ type: 'heal', amount: [200, 350, 500], scaling: { abilityPower: 0.8 } }]
}

One value per level. maxLevel is 3 by default; ultimate: true first unlocks at level 6 (requiresLevel for another). Every effect and buff is in Abilities.

Give a hero an aura ​

ts
{ id: 'devotionAura', name: 'Devotion Aura', target: 'passive', effects: [{ type: 'aura', buff: 'devotion', radius: 9 }] } // the ability
{ id: 'devotion', name: 'Devotion Aura', stats: { armor: [9, 18, 27] } } // its buff

Give a hero an innate ​

innate: 'bulwark': an ability it has from level 1, for no point, whose level is the hero's (or goes up at innateLevels). Usually a passive. Innates.

Give a hero callings ​

callings: { vanguard: 3, keeper: 1 }: what it is good at, 1 to 3. The shop suggests items that suit them; the HUD shows them on the hero panel, the altar's card and the tooltip. Callings.

Give heroes spells ​

spells: ['flash', 'waystone']: two abilities it always has, on D and F, for no mana. The engine's nine: Hero spells.

Make an item, sell it, drop it ​

ts
{ id: 'stormblade', name: 'Stormblade', tier: 'basic', cost: { gold: 400 }, bonus: { stats: { attackDamage: 15 } }, ability: 'stormStrike' }

sells: ['stormblade'] on a building makes a shop; drops: ['healingDraught'] on a unit type drops loot. Recipes, tiers, charges, groups, uniques, tags and the shop window: Items. The engine's own tree: The default set.

Hire units at a tavern ​

ts
{ id: 'tavern', kind: 'building', hires: ['duskblade', 'boneReaver'] /* ... */ }

Whoever has a unit there can hire; a neutral one hires to everyone. The melee starter's altars train their side's four heroes and its tavern hires any of the eight.

Change level and hero limits ​

ts
packs: [heroesPack({ maxHeroes: 1, maxHeroLevel: 20 })]

Reward assists, streaks and buyback ​

Heroes that helped a kill share its experience and gold; a hero on a streak is worth more; a dead hero buys itself back. All on by default, each a HeroSettings option: The hero loop.

Give experience, abilities and items from code ​

ts
import { createItem, giveItem, grantXp, heroesOf, learn } from '@v12-engine/engine'

const [hero] = heroesOf(world, player)
grantXp(world, hero, 500)
learn(world, hero, 'holyLight')
giveItem(world, hero, createItem(world, 'healingDraught'))

Set hero keys and the stats panel ​

ts
export const meleeView: GameView = {
	input: { keys: { abilities: ['Q', 'W', 'E', 'R'], spells: ['D', 'F'], shop: 'P' } },
	hud: { heroStats: ['attackDamage', 'abilityPower', 'armor', 'magicResist', 'attackSpeed', 'abilityHaste', 'critChance', 'moveSpeed'] }
}

hud: { widgets: [{ id: 'heroPanel', when: () => false }] } gives a hero the plain command card. Tooltips come from the ability's description (What an ability says it does). The hero panel shows the callings (HeroPanelInfo.callings, a CallingTag each) and the meter buff (meter).

Give a hero a second form ​

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

A form is a unit type of its own, entered by a morph effect; HeroForm says what of the hero's it takes along (Give my game heroes).

Carry a hero to the next mission ​

See A campaign.

Reference ​

Hero fields (UnitTypeDef.hero, HeroDef) ​

FieldWhat it does
growthStats added each level after the first (stats, and percent)
learnsAbilities it puts points into
spellsAbilities it always has, for no mana, on D and F
innateAn ability it has from level 1, for no point, that grows with it
innateLevelsThe hero levels the innate goes up at ([1, 6, 11, 16]); the hero's own level when left out
callingsWhat it is good at, by calling, 1 to 3 ({ stalker: 3, roamer: 2 })
maxLevelThe level it stops at; the pack's maxHeroLevel (10) when left out
meterA buff whose stacks are shown by its health and mana, as points out of as many as it can have
formsThe forms it takes (a morph effect's into), by unit type: what it learns and keeps in each (HeroForm)

inventory on the unit type gives item slots.

Buildings ​

FieldMakes it
trainsTrain units and heroes
revivesBring fallen heroes back
sellsA shop (Shops)
hiresA tavern or harbour that hires out units

Hero settings (HeroSettings, world.settings.heroes) ​

SettingDefaultWhat it does
xpForLevelExperience each level needs
maxHeroLevel10Highest level
maxHeroes3Heroes a player may have
xpRange20How near a kill a hero must be to share its xp
killXpExperience a kill is worth, for a type without xp
pointsForLevel1Ability points per level
reviveWhat reviving costs, and how long it takes
fallenFor8Seconds a fallen hero is remembered
assistTime10Seconds within which hurting or helping counts as an assist; 0 for none
assistsWhich of the heroes found assist: a game's own rule
assistGoldGold each assist is paid: half the kill's worth, shared
shutdownGoldGold a streak's end pays: none under 3, then 100 and 50 a kill, 500 at most
buybackCostWhat buying a fallen hero back costs: 100 and 40 a level; () => undefined for none
buybackCooldown120Seconds before it may buy back again
callingsthe eightThe callings heroes may have (CallingDef)

A unit type's xp is what killing it is worth; otherwise the rules' killXp works it out.

Hooks, events and commands ​

HookChange
beforeXpamount
canLearncancelled
beforeBuycost, or cancel with a reason
beforePickUp, beforeDropcancelled with a reason

Events: heroLevelUp, heroRevived, inventoryChanged, heroAssisted, killStreak, heroShutdown, boughtBack, itemUndone. The pack's commands: buy, sell, undoBuy, hire, learn, revive, buyback; withoutCommands: ['sell'] drops one.

In the example and the starters ​

  • The melee starter: packages/create/starters/melee/src/melee/heroes.ts (the eight heroes, their abilities, buffs, hooks and effects), items.ts (the default set), index.ts (useDefaults with the three sets).
  • Tests: packages/engine/tests/heroes.test.ts, packages/engine/tests/heroLoop.test.ts, packages/engine/tests/callings.test.ts, packages/engine/tests/heroSpells.test.ts, packages/engine/tests/items.test.ts, apps/example/tests/heroes.test.ts.
  • The tutorial Let's add a hero builds one step by step.