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.
- Callings: what a hero is good at; use, rename or replace the engine's eight
- Innates: the passive every hero has from level 1
- Hero spells: the nine the engine brings, and your own
- The hero loop: assists, streaks and shutdowns, buyback
- The eight heroes of the melee starter, every hero spell and every calling, made from the engine's data
- Items: the item system has its own section
Quick start
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
{
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
{ 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 buffGive 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
{ 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
{ 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
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
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
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
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)
| Field | What it does |
|---|---|
growth | Stats added each level after the first (stats, and percent) |
learns | Abilities it puts points into |
spells | Abilities it always has, for no mana, on D and F |
innate | An ability it has from level 1, for no point, that grows with it |
innateLevels | The hero levels the innate goes up at ([1, 6, 11, 16]); the hero's own level when left out |
callings | What it is good at, by calling, 1 to 3 ({ stalker: 3, roamer: 2 }) |
maxLevel | The level it stops at; the pack's maxHeroLevel (10) when left out |
meter | A buff whose stacks are shown by its health and mana, as points out of as many as it can have |
forms | The 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
| Field | Makes it |
|---|---|
trains | Train units and heroes |
revives | Bring fallen heroes back |
sells | A shop (Shops) |
hires | A tavern or harbour that hires out units |
Hero settings (HeroSettings, world.settings.heroes)
| Setting | Default | What it does |
|---|---|---|
xpForLevel | Experience each level needs | |
maxHeroLevel | 10 | Highest level |
maxHeroes | 3 | Heroes a player may have |
xpRange | 20 | How near a kill a hero must be to share its xp |
killXp | Experience a kill is worth, for a type without xp | |
pointsForLevel | 1 | Ability points per level |
revive | What reviving costs, and how long it takes | |
fallenFor | 8 | Seconds a fallen hero is remembered |
assistTime | 10 | Seconds within which hurting or helping counts as an assist; 0 for none |
assists | Which of the heroes found assist: a game's own rule | |
assistGold | Gold each assist is paid: half the kill's worth, shared | |
shutdownGold | Gold a streak's end pays: none under 3, then 100 and 50 a kill, 500 at most | |
buybackCost | What buying a fallen hero back costs: 100 and 40 a level; () => undefined for none | |
buybackCooldown | 120 | Seconds before it may buy back again |
callings | the eight | The 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
| Hook | Change |
|---|---|
beforeXp | amount |
canLearn | cancelled |
beforeBuy | cost, or cancel with a reason |
beforePickUp, beforeDrop | cancelled 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(useDefaultswith 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.