Give heroes spells
A hero spell is an ability every hero has from the start, two a hero (hero.spells), on D and F, for no point and no mana. Take the engine's nine, or write your own.
// in src/rules.ts
import { defaultHeroSpellBuffs, defaultHeroSpells, heroesPack, type Rules } from '@v12-engine/engine'
export const rules: Rules = {
id: 'my-game',
name: 'My game',
units: [
{
id: 'knight',
name: 'Knight',
kind: 'unit',
radius: 0.5,
sight: 10,
stats: { health: 600, mana: 200, moveSpeed: 4 },
hero: { growth: { stats: { health: 50 } }, learns: [], spells: ['flash', 'barrier'] }
}
],
abilities: defaultHeroSpells(),
buffs: defaultHeroSpellBuffs(),
packs: [heroesPack()]
}Done: the knight has Flash on D and Barrier on F from level 1, each on its own long cooldown, with no mana to pay. The other seven are Second Wind, Brand, Wither, Phantom Stride, Purify, Waystone and Reap (every hero spell).
Take some, change one
abilities: [...defaultHeroSpells().filter((spell) => spell.id !== 'reap').map((spell) => (spell.id === 'flash' ? { ...spell, cooldown: 240 } : spell))]Or with the set chooser, so data.json and the editor can choose again: useDefaults(rules, [defaultHeroSpellSet()], { heroSpells: { except: ['reap'], change: { flash: { cooldown: 240 } } } }) (The default set).
Write your own
{
id: 'smokeBomb',
name: 'Smoke Bomb',
description: 'The hero and allies near are unseen for 3 seconds',
tags: ['heroSpell', 'vision'],
target: 'none',
cooldown: 200,
effects: [{ type: 'buff', buff: 'smoked', radius: 5, affects: 'allies' }]
}
// hero: { spells: ['flash', 'smokeBomb'] }Any ability is a hero spell when a hero lists it in spells: give it a cooldown and no manaCost, tag it 'heroSpell' so a search finds it with the rest. Say what it does in general words (heroes, allies, creeps), so it holds in a melee game, a campaign and a lanes map alike. The keys are the view's input.keys.spells (['D', 'F']). Hero spells has how the nine are built.