Battle kit
@rpgjs/battle-kit is the foundation shared by the battle systems of RPGJS: @rpgjs/turn-battle, @rpgjs/tactical-rpg, and the one you write. It holds what every battle shown in its own scene has to do the same way, whatever its rules, so that the battle systems take the same options and hooks and behave alike in standalone RPG mode and in MMORPG mode.
@rpgjs/common, @rpgjs/client, @rpgjs/server, canvasengine, @canvasengine/presets, pixi.js, pixi-filters. The battle kit is the only battle package that touches the renderer: a battle GUI built on it is made of CanvasEngine components and gets its filters and particle layer from the kit (BattlerLook, ScreenFilters, FxPlayer), never from Pixi.
Standalone RPG and MMORPG
Three entry points
Server: sessions and participants
The server owns every battle.BattleSessions is the registry of the running battles of one battle system: it answers the questions every battle system answers the same way.
Server: hooks, database, players
turnBattle, tactical): a game module implements them with defineModule<RpgServer>({ myBattle: { … } }), and the hooks option of the battle system takes them too. The arguments of call, vetoed and replaced are typed from the hooks interface (BattleHookArgs<MyServerHooks, "onCommand">): a call with the wrong arguments does not compile. A server hook that throws rejects the call (the battle system catches it in its command queue); a client hook that throws is logged and the battle goes on.
Client: screen, controls, cues, hooks
battleControls gives the root of the battle GUI its CanvasEngine controls (<DOMContainer controls={controls}>): A confirms, B or Start goes back, the d-pad or the stick moves, L/R are tabPrev / tabNext. The tab keys are page up / page down unless keyboardControls binds tabPrev / tabNext. A built-in dialog shown over the battle (modalGuiShown()) or a text field the player writes in (the chat) keeps the keys.
The texts of a battle system go through the RPGJS i18n service: register the defaults with the i18n of the module, under keys named after the system (myBattle.*), and read them with engine.t(key, params). The styles of its HUD belong in @rpgjs/ui-css (rpg-ui-<system>-* classes), with stories in its Storybook.
Presentation
Presentation clock
Clock runs tweens and waits on a time you can scale, freeze (hit-stop) or flush. You drive it from your render loop.
Visual Effects
A Visual Effect of a battle is the particle effect of the core (map.playVisualEffect, see VisualEffectOptions of @rpgjs/common) played inside a battle scene, with the moment its target is hit. It uses the same vocabulary: a built-in effect name or a resolved preset, the tuning color, intensity, sizeScale, speedScale, and sounds whose volume goes from 0 to 1 and start is in ms.
effectCues(effect)lists the sounds, the hit and the end in order, when you schedule them yourself.visualEffectsOf(source)copies the effects a source has (effect, or acastEffectand animpactEffect), to spread on a battle beat.
Effect presets and screen impacts (client)
A battle scene is not made of map objects, so it plays its particles withFxPlayer (the runtime of the <Fx> component) in a layer of its own. The emitters that go to the target (pathSpace: "target", at: "target") are aimed by CanvasEngine.
FxPlayer.has(name) tells whether a preset name exists, and FxPlayer.preset(name, look) builds one with its look (color, scale, intensity, lifetime). play and aimed take the look too, plus where it is played: flip, rotation and loop. In a .ce component, give the layer with <Container pixiChildren={[fx.layer]} />.
Sprite looks, screen filters and fonts (client)
A battle component never creates a renderer filter: it drives the ones of the kit from its signals.ScreenFilters does the same for a whole scene (zoomBlur(strength, x, y), chromatic(amount), filters={screen.filters}) when the scene times its impacts itself; ScreenEffects times them for you. imageSize(url) gives the size of a spritesheet image before its battler is drawn.
Colours, floating numbers, aim
elementColor(element)returns the CSS colour of an element (ELEMENT_COLORS, read only, lists them).popupMotion(age),digitMotion(age, index)andpopupLift(age, chars)give the motion of floating damage and heal numbers at a given age in ms.aim(from, to)returns{ flip, rotation }to orient a directional preset towards a point.