2. Two abilities
Goal: Holy Light, made of the engine's effects, and Judgement, which strikes an enemy and heals the knight for as much, with an effect of your own.
Build one from the engine's effects
// src/campaign/units.ts
export const abilities: AbilityDef[] = [
{
id: 'holyLight',
name: 'Holy Light',
description: 'Heals a friendly unit for 150, 250 or 350',
hotkey: 'Q',
target: 'unit',
targets: { allies: true, self: true },
manaCost: 50,
cooldown: 6,
range: 8,
castTime: 0.3,
effects: [{ type: 'heal', amount: [150, 250, 350] }]
},
{
id: 'warCry',
name: 'War Cry',
description: 'Friends within 7 hit harder and faster for 10 seconds',
hotkey: 'W',
target: 'none',
manaCost: 60,
cooldown: 20,
effects: [{ type: 'buff', buff: 'rallied', radius: 7, affects: 'allies', duration: 10 }]
}
]amount: [150, 250, 350] is a number per level (Scaled); three levels unless maxLevel says. A buff effect puts a BuffDef (rallied: percent: { attackDamage: 0.2, attackSpeed: 0.15 }) on everyone affects names within radius, for duration.
Write an effect of your own
No engine effect heals for the damage done, so declare a new type and write it:
import { defineEffect, type EffectType, type Scaled, type Scaling, scaled } from '@v12-engine/engine'
declare module '@v12-engine/engine' {
interface EffectTypes {
'campaign.judgement': { amount: Scaled; scaling?: Scaling }
}
}
/** A number a level (`Scaled`): the level's, or the last for a level past the list */
const atLevel = (amount: Scaled | undefined, level: number): number =>
Array.isArray(amount) ? amount[Math.min(level, amount.length) - 1] : (amount ?? 0)
/** Effects the engine does not have */
export const effects: EffectType[] = [
/** Judgement: the enemy struck, and the caster healed for what it took */
defineEffect({ type: 'campaign.judgement', run: ({ world, caster, target, level }, effect) => {
if (!target?.alive) return
const amount = scaled(world, caster, atLevel(effect.amount, level), effect.scaling, level)
const before = target.health
world.damage(target, amount, caster, { damageType: 'magic' })
world.heal(caster, Math.max(0, before - Math.max(target.health, 0)), caster)
} })
]world.damage and world.heal apply armour, death, bounty and experience as any hit would. scaled applies the caster's ability power. List effects in the rules, then name the type in the ability:
{
id: 'judgement',
name: 'Judgement',
description: 'Strikes an enemy for 120, 200 or 280 and heals the knight for as much',
hotkey: 'E',
target: 'unit',
targets: { enemies: true },
manaCost: 70,
cooldown: 10,
range: 6,
castTime: 0.4,
effects: [{ type: 'campaign.judgement', amount: [120, 200, 280] }]
}Give them a look
// src/campaign/view/index.ts
export const effects: AbilityLooks = {
holyLight: { color: [1, 0.95, 0.45] },
warCry: { color: [1, 0.6, 0.2], style: 'burst', options: { count: 60, ring: 7, shape: 'about' } },
rallied: { color: [1, 0.6, 0.2], aura: 'glow' },
judgement: { color: [1, 0.85, 0.35], style: 'burst', options: { count: 40, rise: 2, shape: 'rise' } }
}A buff with aura glows on whoever has it. For effects with lights and shakes, see Show an effect.
Next: 3. An item and a shop.