Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

Abilities

An ability is something a character does from a key or an action-bar slot, such as a spell. Its settings are data that the room and the page share, defined once at module scope and installed on each world from the game’s plugins list. The room judges each cast, so a page cannot cast what its player does not hold, cannot cast past a cooldown, and cannot cast at a target out of range or out of sight.

abilities() needs weapons(), cooldowns(), resources() and characters() in the same plugins list, since a cast flies as a projectile, waits out a cooldown, spends a resource and is made by a character. A world made without one of them throws as it is made, naming the plugin to add, such as abilities() needs weapons(): add weapons() to plugins.

abilities() and the ability names on this page come from @spawnite/engine/abilities, a readable plugin a game can copy as a kit. A cost’s resource comes from @spawnite/engine/resources and a cooldown’s key from @spawnite/engine/cooldowns, as each sample’s imports show.

defineAbility(name, settings) defines an ability once, at module scope, and returns its handle: a value that carries its name and its settings and touches no world. List the handle in abilities({ kinds: [frostNova] }) in the game’s plugins, and the world installs it on the room and on every page as it is made, so the page’s bar and the player’s predicted cast find it.

A plugin that owns an ability installs it instead with registerAbility(writer, handle) in its setup, and a scene effect installs one made at run time the same way; the return takes it off. Two abilities under one name on one world throw, naming both. A cost in a resource the world has not installed throws as the world is made, naming the list to add it to.

The engine’s tests make a world from the following file and read both abilities back:

packages/engine/test/outside/mage.ts
import { definePlugin } from "@spawnite/engine/core";
import { stats } from "@spawnite/engine/stats";
import { weapons } from "@spawnite/engine/weapons";
import { behaviours } from "@spawnite/engine/behaviours";
import { characters } from "@spawnite/engine/characters";
import {
abilities,
AbilityKind,
defineAbility,
} from "@spawnite/engine/abilities";
import { cooldowns } from "@spawnite/engine/cooldowns";
import {
addResource,
defineResource,
resources,
} from "@spawnite/engine/resources";
// Each kind once, at module scope: a handle that carries its name and
// its settings and touches no world. The game's plugins list installs
// them on the room and on every page, so each holds the same settings.
export const mana = defineResource("mana", { maximum: 100, regen: 5 });
export const arcaneBolt = defineAbility("arcane-bolt", {
kind: AbilityKind.Projectile,
label: "Arcane Bolt",
castSeconds: 0.4,
cooldownSeconds: 0,
range: 25,
damage: { min: 20, max: 26, stat: "spellPower" },
projectile: { speed: 14, turnDegrees: 540 },
});
export const frostNova = defineAbility("frost-nova", {
kind: AbilityKind.Area,
label: "Frost Nova",
castSeconds: 0,
cooldownSeconds: 12,
cost: [{ resource: mana, amount: 25 }],
radius: 6,
damage: { min: 25, max: 30, stat: "spellPower" },
slow: { percent: 50, seconds: 3 },
});
// The kit gives every character its mana as it spawns.
export const mageKit = definePlugin(() => ({
name: "mage-kit",
requires: [abilities, resources],
onCharacterSpawn: ({ writer, character }) => {
addResource(writer, character, mana);
},
}));
/** The plugins a game lists in src/game.ts: abilities() with the kit's
* spells, the plugins it requires, with the kit's mana, and the kit. */
export const magePlugins = [
characters(),
stats(),
cooldowns(),
resources({ kinds: [mana] }),
behaviours(),
weapons(),
abilities({ kinds: [arcaneBolt, frostNova] }),
mageKit(),
];

An ability that plays a clip names it in clip in place of castSeconds, and the clip’s release mark is its cast time, as Casting says. The cast time resolves as the world installs the ability, so register the clip with registerClip at module scope, before or after the ability’s definition.

cost names what the cast spends, one entry per resource, by the handles defineResource returns: [{ resource: mana, amount: 25 }], or two entries for two. A resource listed twice is refused as the ability is defined. Left out, the ability is free. The cast holds the cost back under castReservation, so a game’s own action on the same character, holding a cost under its own key, never spends the cast’s or has its own spent by it.

approach and faceTarget set how the caster moves for a cast at a target. Each is true when left out:

  • approach: true walks the caster toward a target past range and casts once it is in range. approach: false refuses the cast with “Out of range”.
  • faceTarget: true turns the caster to face the target as the cast starts. faceTarget: false casts facing wherever it stands.

kind says what the release does:

  • AbilityKind.Projectile launches a projectile at the target, which turns toward the target at turnDegrees a second. It passes through a friendly and through a hostile that is down, to what stands behind.
  • AbilityKind.Area strikes every hostile target within radius of the caster that it has line of sight to. It needs no target.
  • AbilityKind.Chain strikes the target, then jumps to the nearest hostile target within jumpRadius that it has not struck, jumps times. Each jump deals falloff times the damage of the one before it. It never strikes one target twice.

A character casts only the abilities in AbilitiesTrait’s grants list field. Read it with readTrait(entity, AbilitiesTrait)?.grants in a system or useTrait(entity, AbilitiesTrait)?.grants in a view. Each grant has a source:

  • <CharacterSpawn>’s abilities grants abilities for as long as the character is in the world, under the source "player": <CharacterSpawn abilities={[frostNova]} resources={[mana]} />. In a room it holds for every player’s character. A kind the world has not installed is refused at the spawn, naming the list to add it to.
  • grantAbilities(writer, entity, source, names) grants abilities under a source, and revokeAbilities(writer, entity, source) takes off that source’s abilities and no other.
  • An item’s equip.abilities grants abilities while the item is worn: equip: { slot: EquipmentSlot.MainHand, abilities: ["arcane-bolt"] }. Taking the item off takes those abilities off, and cancels a cast of one of them.

The verbs use editList(writer, entity, AbilitiesTrait.fields.grants) and record one change per grant added or removed. Each edit session publishes a new array and leaves an earlier reader’s array unchanged.

An ability strikes a target that stands on the other side from its caster. A target is an entity with the TargetableTrait trait, whose faction names its side: Faction.Hostile, the default, Faction.Friendly or Faction.Neutral. abilities() gives each character TargetableTrait({ faction: Faction.Friendly }) as it spawns. A game puts a character on another side with setTrait(writer, character, TargetableTrait, { faction }) in its own onCharacterSpawn, from a plugin that requires abilities. A caster with no mark counts as Friendly. The rules read the two sides as follows:

  • A Hostile caster strikes a Friendly target, and a Friendly caster a Hostile one. So a player’s bolt strikes a wolf, a wolf’s bolt strikes a player’s character, and a wolf’s nova spares its pack.
  • A Neutral target is never struck, and a Neutral caster strikes nobody.
  • Two entities the team question can tell apart, both with a player behind them or both on a team, are set against each other whatever their marks. The question then spares the allies among them, as it spares them from a weapon’s shot. With no teams(), two players’ characters are allies, so a nova spares the party.
  • The match rules spare a strike wherever they spare a hit, such as across two matches.

A game with sides of its own, such as three tribes at war, puts each NPC on a team with setTeam. Unreal answers the same question between two agents with GetTeamAttitudeTowards.

A target frame names its target with useDisplayName, as Entity says. The caster’s chosen target is the AbilityTargetTrait trait on the caster, which <Targeting> writes, and the cast press carries it to the room.

<Health> alone does not make an entity a target, and neither does an NPC’s faction. A game gives its enemies the trait with a behaviour of its own, as Behaviours describes, and puts it beside <Health>. A system that spawns an enemy adds TargetableTrait among its traits, as the spawner on the Entity page does. The room’s tests mount this dummy in a room’s scene, check that a player’s page holds it as a hostile target and that the room lets a cast target it, and check that an entity with Health alone is no target:

packages/room/test/outside/TrainingDummy.tsx
import {
defineBehaviour,
Entity,
Faction,
Health,
RunContext,
TargetableTrait,
useBehaviour,
Views,
type EntityProps,
} from "@spawnite/engine";
const TargetableBehaviour = defineBehaviour({
name: "targetable",
trait: TargetableTrait,
runsOn: RunContext.Server,
description: "An entity abilities and Targeting can pick.",
});
interface TargetableProps {
/** Whose side it is on: abilities strike a hostile one. */
faction?: Faction | `${Faction}`;
}
export function Targetable({ faction = Faction.Hostile }: TargetableProps) {
useBehaviour(TargetableBehaviour, { faction: faction as Faction });
return null;
}
export function TrainingDummy({ position }: Pick<EntityProps, "position">) {
return (
<Entity position={position}>
<Health maximum={60} />
<Targetable />
<Views>
<mesh>
<cylinderGeometry args={[0.4, 0.4, 1.8]} />
<meshStandardMaterial color="#b08850" />
</mesh>
</Views>
</Entity>
);
}

<AbilityBar /> puts every ability the player holds on a slot and a key, and is the bar most games mount. Under it, useCast() gives a page cast(ability), by its handle or its name, refusal and refusalText. cast sends the cast command with the player’s target. refusal holds why the rules refused the player’s last cast, until the player casts again. refusalText is the line to show for it, such as “Out of range” or “Not enough mana”, or the engine’s own line from commandRefusalLines for a cast refused before any rule read it, such as “Too late” for one that reached the room late:

import { useCast } from "@spawnite/engine/abilities";
export function BoltButton() {
const { cast, refusalText } = useCast();
return (
<>
<button onClick={() => cast("arcane-bolt")}>Arcane Bolt</button>
{refusalText && <p>{refusalText}</p>}
</>
);
}

describeCastRefusal(world, refused) writes the same line from a CastRefusedEvent event, and castRefusalText holds the line for each reason. Each reason is one of the engine’s shared Refusal codes, such as Refusal.CoolingDown and Refusal.OutOfRange, which the cast command declares as its refusals. A game’s own command declares the codes it refuses with too, with its own beside them, as Build a predicted mechanic shows.

What the player’s page shows during a cast

Section titled “What the player’s page shows during a cast”

The cast is a predicted command, abilities.commands.cast: the player’s page runs the cast on the tick the player sends it, and in a room the room runs it on the same tick. The player’s page shows the following on that frame, with no wait for the room:

  • The cost comes off the character’s resource bar, held back as reserved.
  • The cast starts: the character’s CastingTrait, which the bar’s rim, the clip, the charge and the hand’s turn draw from.
  • A refusal shows its line, from the command’s result in useLatestCommandResult(abilities.commands.cast).
  • At the release, the cost is spent and the global cooldown and the ability’s own sweep on the bar.

The room alone decides what the release does: the projectile, the strike, the damage, the slow and every event. The player’s page draws them as the room streams them, a round trip after the release. The room’s answer settles the command: where it agrees, nothing changes, and where it refused the cast or a rule of the room changed the character’s state, the player’s page takes the room’s word. It replays the player’s steps from it, as it does for the character’s movement. A cast at a target out of range, which walks the character there first, starts when the room starts it, as Walk into range and turn says. The clip plays once per cast, as the cast starts on the player’s character, and a refusal of that cast stops it.

A player may send 20 casts a second, past a burst of two, and the player’s page refuses a cast past that too-fast. abilities({ castsPerSecond }) changes it for every ability: any number above 0 and up to 60, such as abilities({ castsPerSecond: 30 }), or 0.5 for one cast every two seconds. The rate is a flood guard, not a game rule: an ability’s cooldown, the global cooldown and its cost are what limit casts in play. Set it to at least twice the fastest a player can honestly cast, and leave it alone otherwise. The room and the player’s page read it from the one plugins list both compose, and the room refuses a page whose list differs.

To make an ability wait for the room, define it with predicted: false. The player’s page then sends its command and starts nothing of it, the room runs it on the tick the player sent it, and the player’s page shows the cast, its cost and its cooldowns as the room’s word arrives, a round trip later. A cast at a target out of range still walks the character toward it at once. Unreal’s Gameplay Ability System gives the same choice as an ability’s net execution policy: local predicted, the default here, or server only. A game played alone runs every cast on its next step either way.

cast sends the cast command, abilities.commands.cast, through the player’s character, with the ability’s name and the target, an entity({ optional: true }) field that is null for an area ability. createCastPayload(world, character, name) writes the same payload for a game’s own sender, which sends it with sendCommand(world, abilities.commands.cast, payload, { entity: character }). useCast does the same, so a game’s own button calls useCast’s cast unless it needs more. The cast starts when all of the following hold:

  • The caster holds the ability and is neither downed nor already casting.
  • The ability’s own cooldown and the global cooldown have run out.
  • The caster has enough of each resource in cost.
  • For a projectile or a chain, the target is alive, hostile, within range, and in line of sight.

Otherwise the command is refused with the reason, and with the resource a cost fell short of as its detail. A cast refused later, after the caster walked into range, is already accepted. Where the world decides outcomes, on the room and in a game played alone, the refusal emits CastRefusedEvent { reason, resource } on the caster with the cast command as its cause. Every page and the devtools hear it, and the casting player’s page alone reads its cause as the request id of that player’s cast. A target past range is not refused at once: the cast waits while the caster walks into range, as Walk into range and turn says.

A started cast is the CastingTrait trait on the caster: the ability, the target’s key, releaseTick, the tick its wind-up releases on, and the cast command’s request id. A wind-up of N steps started on tick T releases on T + N. The cast holds its cost back at its start, in each resource’s reserved. It then runs as follows:

  1. The wind-up. A rooted cast ends the walk the caster is on as it starts, so nothing steers it and it runs down to a stand at its own deceleration. A cast is rooted unless the ability sets rooted: false.
  2. The cancel. The cast is cancelled when the caster goes down, its health reaches 0, the player disconnects, or the caster loses the ability, and, on a rooted cast, when the player presses a move or jump key or sets off on a walk. The cost comes back and no cooldown starts. The player’s page cancels on the player’s own key or walk on the same tick as the room. The page learns that the caster went down from the room, and a press after that is refused on the player’s page as on the room.
  3. The release. For a projectile or a chain, the target is checked again. A target that died or went out of sight fizzles the cast, which returns the cost and starts no cooldown. Otherwise the cost is spent, the global cooldown starts for 1 second, the ability’s own starts when cooldownSeconds is above 0, and, on the room, the ability does what kind says.

Where the world decides outcomes, each cast the cast command starts also emits two events on the caster. CastStartedEvent { ability, target } comes as the cast starts, before an instant cast’s release, with the cast command as its cause for a player’s cast while the player is still in the world. CastEndedEvent { ability, end } comes as it ends, with end one of CastEnd.Released, CastEnd.Cancelled and CastEnd.Fizzled. A caster destroyed mid-cast ends it Cancelled. A cast startCast starts emits both, its start with no cause. A game that starts a sound or a glow on the start stops it on the end, and useEvent hears each once. The player’s own page plays a cast’s clip from LastCastTrait, which useCast reads, since a cast that starts and ends inside one step still shows there.

An ability’s own cooldown runs under the key nameAbilityCooldown(name), ability: and its name, and the global cooldown under globalCooldown. Read either with isCoolingDown(caster, nameAbilityCooldown("fireball")) or findCooldown in a system, and useCooldown(caster, nameAbilityCooldown("fireball")) in a view. defineCooldown("fireball") names a game’s own key, which no ability starts.

The cast time has one source. An ability with a clip releases at the clip’s release mark, which registerClip names in seconds, so the spell leaves on the frame the hands let it go; castSeconds beside a clip throws, as does a clip with no release mark. An ability with no clip gives castSeconds, and castSeconds: 0 is instant: the cast releases in the step it starts, and a move key does not cancel it. spawnite play timeline shows a cast frame by frame with the second under each, which is how a mark is read; the player page says how a look hears the clip’s other marks.

To read casting on the player’s character during the wind-up and after the release with no browser, see Send a command in a run.

A projectile an ability launches carries AbilityProjectileTrait { ability, side, casterPlayer }, which every page is streamed. side is its caster’s side as it was launched and casterPlayer the player behind the caster, so the projectile flies through the caster’s own side and that player’s other entities, and on as it began once its caster is gone.

When the projectile ends, on its target, on cover or at its range, the room emits SpellLandedEvent { ability, at, hit } on the caster: where an impact effect plays. An area ability emits one on the caster as it releases, at its feet and hit null. Two of its bolts ending in one step are two events, as two hits are two DamagedEvents, and useEvent hears each once, as SpellLook does. The room emits SpellStruckEvent { ability, at, from } on each target an ability strikes. from is the caster for a projectile’s hit, or null once the caster is gone, an area’s strikes and a chain’s first, and the link before it for each jump of a chain, so a page draws a beam along the chain.

startCast(step, caster, ability, { target }) starts a cast on a character no player controls, such as a wolf, from a game’s own system. It checks what the cast command checks, in the same order, and holds the cost back the same way. It returns the Refusal, or undefined once the cast started: a truthy answer means it did not start. It differs from the cast command in the following ways:

  • It runs where the world decides outcomes. It takes an AuthoritativeStep, so call it from a system with no runsOn, ordered before: [abilities.systems.cast], as the cast is ordered before the projectiles: a bolt it releases then flies in the same step.
  • A refusal emits no CastRefusedEvent. A game’s loop asks each step, and the caller already holds the answer.
  • A target out of range is refused, never waited on. The game walks its caster closer and asks again.
  • The caster turns at once. It faces its target on the step the cast starts, unless the ability sets faceTarget: false.
  • Each cast takes a request id below 0, new for each cast of that caster, in CastingTrait and LastCastTrait. A page’s own requests are above 0, so useCast plays no clip for one. A game’s view plays an NPC’s clip on CastStartedEvent.

The caster needs the ability, from grantAbilities or an AbilitiesTrait among its prefab’s traits, and each resource the cost names, from addResource. It also needs HealthTrait, and a TargetableTrait that names its side: a wolf with no mark counts as Friendly and strikes its own pack. A rooted cast ends on a walk, so the game starts no walk for its caster while CastingTrait is on it, or defines the ability with rooted: false. A caster that goes down mid-cast cancels the cast, and a target that leaves range mid-cast is still struck, as a player’s is.

startCast throws for an ability the world has not installed. For a character a player may control, one that carries ControlledTrait, it throws in development and returns Refusal.Controlled in a deployed room, which logs it: the player’s page casts through the cast command, which predicts the cast.

The following plugin gives each wolf of a pack a bolt it casts at the nearest player’s character. The room’s tests run it in a real room, where the bolt lands on a player who joined and flies through the wolf in front:

packages/room/test/outside/wolfBolt.ts
import {
ControlledTrait,
createQuery,
definePlugin,
definePrefab,
defineSystem,
defineTrait,
Faction,
findController,
HealthTrait,
Phase,
readEach,
TargetableTrait,
TransformTrait,
type AuthoritativeStep,
type Entity,
} from "@spawnite/engine/core";
import {
abilities,
AbilitiesTrait,
AbilityKind,
CastingTrait,
defineAbility,
startCast,
} from "@spawnite/engine/abilities";
// A wolf that spits a bolt at the nearest player's character, built as a
// creator's plugin is, from the engine's public entries alone.
/** The wolf's bolt: no cost, so the wolf carries no resource. */
export const fangBolt = defineAbility("fang-bolt", {
kind: AbilityKind.Projectile,
label: "Fang Bolt",
castSeconds: 0.5,
cooldownSeconds: 3,
range: 12,
damage: { min: 8, max: 8 },
projectile: { speed: 20, turnDegrees: 360 },
});
/** Marks a wolf of the pack. */
export const PackWolfTrait = defineTrait("packWolf");
/** A wolf: its health, its side, which sets it against every player's
* character and spares its pack, and the bolt it holds. */
export const packWolf = definePrefab("packWolf", {
traits: [
PackWolfTrait,
HealthTrait({ current: 60, maximum: 60 }),
TargetableTrait({ faction: Faction.Hostile }),
AbilitiesTrait({
grants: [{ ability: fangBolt.name, source: "wolf" }],
}),
],
});
const wolves = createQuery(PackWolfTrait, TransformTrait);
const characters = createQuery(ControlledTrait, TransformTrait);
/** The character a player controls nearest to `wolf`, or null. */
function findNearestPrey(step: AuthoritativeStep, wolf: Entity) {
const from = wolf.get(TransformTrait)?.position;
let nearest: Entity | null = null;
let reach = Infinity;
if (!from) return nearest;
readEach(step.world, characters, (_traits, character) => {
const at = character.get(TransformTrait)?.position;
const distance = at ? at.distanceTo(from) : Infinity;
if (distance >= reach || !findController(step.world, character)) return;
nearest = character;
reach = distance;
});
return nearest;
}
/** Each wolf casts its bolt at the nearest player's character. The rules
* refuse a cast out of range, out of sight or still cooling down, so the
* wolf asks each step and reads the answer. */
function spitBolts(step: AuthoritativeStep) {
readEach(step.world, wolves, (_traits, wolf) => {
// A rooted cast ends on a walk, so the wolf starts none while it
// casts: its own movement goes below this line.
if (wolf.has(CastingTrait)) return;
// It answers the refusal, or undefined once the cast started: a
// game walks its wolf closer on Refusal.OutOfRange.
startCast(step, wolf, fangBolt, {
target: findNearestPrey(step, wolf),
});
});
}
export const wolfBolt = definePlugin(() => ({
name: "wolf-bolt",
description: "Each wolf of the pack casts its bolt at the nearest player.",
requires: [abilities],
systems: [
defineSystem({
name: "spit",
phase: Phase.Rules,
// Before the cast, so a bolt started this step winds down in it.
before: [abilities.systems.cast],
run: spitBolts,
}),
],
}));

A cast at a target past range walks the caster into range first, as Diablo’s click to attack does, unless the ability sets approach: false:

  1. cast walks the character toward the target along the navmesh, with the same walk that click to walk sends. In a room, the player’s page walks the character and predicts the walk, and the room runs the walk the player’s page sends.
  2. The cast waits as the PendingCastTrait trait on the caster, and holds nothing back.
  3. The character stops once the target is within 0.9 of range, approachShare, so a target that steps back as it stops is still in range.
  4. The room starts the cast once the character is in range. A rooted cast waits for the character to stop first. The player’s page shows the cast, its cost and its cooldowns as the room’s word arrives, a round trip after the character stops.

A move or jump key drops the pending cast at no cost, as does a click to walk elsewhere, or the target dying or leaving. A target that moves while the character walks is walked to again once the character reaches where the target stood. When the character stands out of range for pendingStandSeconds, 0.5 s, because the navmesh reaches no nearer, the room refuses the cast with “Out of range”.

As a cast at a target starts, the caster turns to face the target over castTurnSeconds, 0.15 s, while the wind-up runs, unless the ability sets faceTarget: false.

As the cast releases, the hand that holds the character’s item turns so the item’s tip points at the target, over whatever the clip did with its wrist. It weights in over the last of the wind-up, 1 at the release and held there as the spell leaves, and back to the clip after. Each ability names its own window: aimHand: { inSeconds: 0.3, holdSeconds: 0.2, outSeconds: 0.2 }, any of the three, the rest filled from the engine’s characterMotion.castAim, 0.15 s each, which aimHand: true or nothing takes whole. The turn starts from the press on the player’s own page, which starts the cast.

The cast writes the turn into HandAimTrait on the caster: its target, its window, the tick it began, the tick it releases, and how it ended, HandAimEnd.Released or HandAimEnd.Cancelled. Every page draws the caster’s hand from those ticks, on the tick it draws the caster at, so another player sees the hold as the spell leaves the caster’s hand. A released aim holds and then fades; a cancelled one fades from where the hand stood. A game’s own mechanic turns the hand the same way: it writes the trait with setTrait in its own predicted system, as the cast does.

A projectile or a chain turns the hand unless the ability sets aimHand: false; an area, with no target, never does. The item says which way its tip points with HeldItem’s forward, [0, 0, -1] unless the item says otherwise, as the player page describes. Unreal aims a weapon with an aim offset or a two-bone IK node driven by the target, Unity with an aim constraint on the hand bone, Godot with a look-at modifier on a bone. Each layers the turn over the clip and weights it in and out, as this does, because a clip is authored with no target.

Diablo walks the character into range and then attacks. Lost Ark and Genshin Impact turn the character toward the target as the player casts. World of Warcraft refuses a cast unless the player faces the target and is in range. Roblox, Unity, Unreal, Godot, PlayCanvas and Phaser leave both to each game. This engine walks and turns, because a player on a phone presses one button and expects the attack to happen.

The room owns an ability’s numbers and the page owns its look. <SpellLook> draws one ability, for every caster and every projectile of it, the player’s and each other player’s alike. The three effects below come from spawnite add asset, which copies each into the game’s src/particles/:

src/components/MageLooks.tsx
import { Particles } from "@spawnite/engine";
import { SpellLook } from "@spawnite/engine/abilities";
import effectBoltBurst from "../particles/bolt-burst.json";
import effectBoltRunes from "../particles/bolt-runes.json";
import effectBoltTrail from "../particles/bolt-trail.json";
export function MageLooks() {
return (
<>
<Particles
effects={[effectBoltBurst, effectBoltRunes, effectBoltTrail]}
/>
<SpellLook
ability="arcane-bolt"
color="#9ecbff"
charge={effectBoltRunes}
chargePosition={[0, 0.8, 0]}
projectile={[effectBoltTrail, effectBoltRunes]}
impact={effectBoltBurst}
/>
</>
);
}

It plays each effect at one moment of the spell:

  • charge plays in the caster’s right hand while it winds the cast up, on the player’s own page from the cast’s start, and stops at its release or its cancel. chargePosition moves it from the hand in the hand’s axes, as HeldItem’s position does, to a staff’s tip, and chargeRotation turns it as HeldItem’s rotation does, so a swirl turns about the staff.
  • projectile rides each projectile of the ability, and model names a registered model drawn there.
  • impact plays once where each projectile ends, on a hit or a fizzle, and at the caster’s feet as an area ability releases.
  • strike plays once on each target the ability strikes: a projectile’s hit, each within an area, and each link of a chain.
  • area mounts its parts at the caster’s feet as an area ability releases, for areaSeconds, 2 by default: a ring that races out, a rune circle, shards. Each part ages from its mount.
  • beam draws from where each strike came from to the target, for beamSeconds, 0.35 by default. It is a function of the two ends, both at the feet, as Roblox’s Beam takes two attachments: beam={({ from, to }) => <SpellBeam from={from} to={to} color="#c9a7ff" />}. A chain draws one beam per jump, from the link before.

Each takes one effect or a list. charge and projectile also take an element, such as a glowing mesh of the game’s own, drawn in the hand or riding the projectile beside the effects: projectile={[effectBoltTrail, <BoltCore />]}. An element that animates reads where it is in its own useFrame. color tints the effects. The scene’s Particles must hold every effect, from the asset library, the three.quarks editor or code. Past that, a game writes its own view that reads the CastingTrait trait, the entities with AbilityProjectileTrait, and the SpellLandedEvent and SpellStruckEvent events, as SpellLook does.

The engine ships the parts a spell is built from, each a glowing mesh with props for its numbers and its colour, and a game’s own element stands in any part’s place:

  • SpellRing races out along the ground to radius over seconds, for area: a nova’s edge.
  • SpellRunes is a rune circle left glowing on the ground, opening in a blink and fading over seconds, for area.
  • SpellShards stand up out of the ground in a ring and sink back, for area.
  • SpellBeam arcs from from to to, both lifted to a body’s middle, and fades, for beam.
  • SpellBolt is a magic bolt for projectile: a bright core, runes orbiting it, and a spiral of shards it lays in the world as it flies, each shrinking away over trailSeconds. radius grows the whole bolt, and each other size, the spacing and the twist has a prop of its own.
  • SpellSpear flies point first with crystals turning round its shaft, for projectile: it turns to face the way its group has moved.
  • SpellSwirl gathers crystals in from wide to tight over a cast’s seconds, for charge at a staff’s tip.
  • createGlowMaterial(color, intensity, opacity) is the lit material each draws with, emitted above 1 so a scene’s bloom takes it.

The mmorpg’s mage composes its three spells from these under SpellLook, as its kit page, wiki/kit/mage.md in the mmorpg’s folder of spawnite/examples, says. Unreal ships Niagara templates for the same reason: a spell’s look is assembled from a few moving parts far more often than drawn from nothing.

Unreal keeps an ability’s look in its Gameplay Cues, apart from the effect that changes the numbers. Unity, Godot, Roblox, PlayCanvas and Phaser leave it to each game. This engine takes Unreal’s split, as one component with a prop for each moment, so an agent writes a finished spell in one element.

Each strike rolls its damage in these steps:

  1. A whole number from damage.min to damage.max, both included, on the world’s seeded stream, so a replay rolls the same.
  2. Scaled by the caster’s stat that damage.stat names, as a percentage: 20 spellPower makes it 1.2 times.
  3. A crit against the caster’s critChance stat, 0.05 by default, multiplies it by its critDamage stat, 1.5 by default.

The strike calls dealDamage with the ability’s name as the hit’s weapon and { crit } as its data. rollAbilityDamage(step, caster, damage) rolls one strike for a game’s own system, on the stream of the world whose step it takes. Damage is the room’s, so it takes the room’s step, and the player’s page never moves the world’s random stream.

A slow leaves a timed modifier on the victim’s moveSpeed stat, which sets MovementTrait.speed. The first slow declares the stat from the victim’s own speed, so the slow runs out back to it.

A game’s own ability system uses the calls the engine’s cast uses. hasLineOfSight(world, looker, target) says whether cover stands between two characters. strikeTarget(step, { caster, victim, name, ability }) deals one strike: the roll, the damage, the ability’s slow and the SpellStruckEvent event. slowCharacter(step, entity, { ability, percent, seconds }) leaves the slow alone. Each of these outcomes takes the room’s step first, as dealDamage and launchProjectile do, so a predicted system calls them inside if (step.authoritative), and a system on the room alone calls them as they are. A game’s own outcome takes authority: Authority first the same way, and a logic component passes the authority useAuthorityEffect hands it. Where a system runs says which step is the room’s.

A game’s own projectile takes a kind for what it flies through and what happens as it ends. defineProjectileKind(name, options), at module scope, returns the kind launchProjectile takes as kind. Its isPassedThrough(world, projectile, entity) answers whether the projectile flies through an entity it would otherwise strike. Its onProjectileEnd(step, projectile, context) runs once on the room’s step as the projectile ends, before it is destroyed, with the reason, the point, the entity hit, the shooter and the launch’s data in ProjectileEndContext. The engine’s own spells use the kind ability, which flies through all but a standing hostile target and emits the two spell events. A kind does not change what counts as cover: a wall stops every projectile.

A slow works through the moveSpeed stat, which sets MovementTrait.speed each step once a slow has declared it. From then on, a write to MovementTrait.speed is overwritten. To change the character’s own speed, set the stat’s base instead, and the modifiers stay on top of it:

// Excerpt of src/systems/slow.ts
import { setStatBase } from "@spawnite/engine";
setStatBase(writer, entity, "moveSpeed", 7);

moveSpeedStat names the stat.

A cast spends resources, such as mana or rage, as damage spends health. The resources page says how to register one, give it to a character and show it.

The devtools’ Inspector has an Abilities section for a caster: each ability’s range, cost, cooldown left and cast state, the target’s reach and sight line, the last refusal, and a switch that draws the range rings and a line to the target. readAbilityInspection(world, caster) reads the same numbers, and spawnite play eval views reads them under "abilities".

Unreal’s Gameplay Ability System keeps the ability, its cost, its cooldown, its target data and its cues apart, all replicated. This engine takes Unreal’s separation, and writes an ability as settings rather than a subclass, so an agent writes one correctly on its first try.