Skip to content

The hero loop: assists, streaks, buyback ​

What happens around a hero's kill and death, as a hero arena has it: who helped shares the reward, a hero on a streak is worth more, and a dead hero may buy its way back. All of it is on by default in the heroes pack, each piece a HeroSettings option with a hook for a game's own rule, and off with a number.

Quick start ​

ts
packs: [
	heroesPack({
		assistTime: 10, // seconds within which hurting or helping counts; 0 for no assists
		shutdownGold: (world, victim, streak) => (streak < 3 ? 0 : Math.min(100 + 50 * (streak - 3), 500)),
		buybackCost: (world, hero) => ({ gold: 100 + 40 * (heroOf(hero)?.level ?? 1) }),
		buybackCooldown: 120
	})
]

These are the defaults; leave them out for the same.

Common tasks ​

Share a kill with those who helped ​

Within assistTime seconds, a hero that hurt the victim, or healed, shielded or buffed (no harm) the hero that killed it, assists: it shares the kill's experience wherever it stands and its player is paid assistGold (half the kill's worth, heroKillWorth, shared out). The engine finds them (foundAssists); assists picks which count (only those near, only damage):

ts
heroesPack({ assists: (world, victim, killer, found) => found.filter((hero) => dist(hero.pos, victim.pos) < 20) })

heroAssists(world, victim, killer) is who assists, after the game's rule; the heroAssisted event says each.

Pay for a streak's end ​

A hero's kills since it last died are its streak (HeroTally). Its death pays its killer's player shutdownGold on top of the kill: none under 3, then 100 and 50 more for each kill past it, 500 at most. The killStreak event says a streak grew; heroShutdown says one ended, with the gold.

ts
heroesPack({ shutdownGold: (world, victim, streak) => streak * 75 }) // a game's own curve
heroesPack({ shutdownGold: () => 0 }) // none

Let a dead hero buy itself back ​

buyBack(world, hero), the buyback command, the button on the hero's portrait: its player pays buybackCost (100 and 40 a level), it is back at once at its side's home (where it fell when there is none), and it may not again for buybackCooldown seconds. buybackRefusal names why not (noBuyback, buybackNotReady, too poor); boughtBack says it was.

ts
heroesPack({ buybackCost: () => undefined }) // no buyback in this game
heroesPack({ buybackCost: (world, hero) => ({ gold: 500 }), buybackCooldown: 300 })

Read the tally ​

ts
import { heroTally } from '@v12-engine/engine'

const tally = hero.get(heroTally) // { kills, deaths, assists, streak, buybackAt? }

Sent to everyone who sees the hero, for a scoreboard. The score counts the events (heroAssisted, killStreak, heroShutdown, boughtBack) as it counts kills (Score and stats).

Count a summon's work for its hero ​

heroBehind(world, entity) is the hero behind what did something: itself, or the hero whose summon it is. A kill by a Gravelord's risen counts as his.

Reference ​

HeroSettings, the loop's part ​

SettingDefaultWhat it does
assistTime10Seconds within which hurting or helping assists; 0 for none
assistsall foundWhich of those found assist
assistGoldhalf the kill's worth, sharedGold each assist's player is paid
shutdownGold0 under 3, then 100 + 50 a kill, ≤ 500Gold a streak's end pays the killer's player
buybackCost100 + 40 a levelWhat buying back costs; () => undefined for no buyback
buybackCooldown120Seconds before it may buy back again

Events ​

EventSays
heroAssistedA hero assisted a kill: the hero, the victim, the killer, the gold
killStreakA hero's streak grew
heroShutdownA streak ended: the victim, the streak, the killer, the gold
boughtBackA hero bought itself back, with what it cost

Functions: heroAssists, foundAssists, settleHeroKill, heroKillWorth, heroBehind, buyBack, buybackRefusal. The heroTally component; assistLog keeps who did what to a hero lately.

Tests: packages/engine/tests/heroLoop.test.ts (assists by damage and by help, the streak and shutdown gold, buyback's price and cooldown).