gizgame/combat
Orthogonal combat primitives: stamina gating, directional melee with guard/knockback, forward-cone pulse stun, and telegraphing 1v1 fighter AI.
import * as Combat from "gizgame/combat";Types
Stamina
type Stamina = { value: f64; max: f64; drain: f64; recover: f64; exhausted: bool; resumeAt: f64; }Stamina state with exhaustion hysteresis so depleted stamina actually gates sprinting.
value:f64max:f64drain:f64recover:f64exhausted:boolresumeAt:f64
MeleeResult
type MeleeResult = { hit: bool; damage: i64; guarded: bool; knockX: f64; knockZ: f64; stun: f64; }Result of a directional melee strike check.
hit:booldamage:i64guarded:boolknockX:f64knockZ:f64stun:f64
PulseTarget
type PulseTarget = { id: i64; x: f64; z: f64; }Target descriptor for a cone pulse stun (e.g., flashlight pulse or EMP).
id:i64x:f64z:f64
PulseHit
type PulseHit = { id: i64; knockX: f64; knockZ: f64; stun: f64; }Confirmed pulse stun result for one target.
id:i64knockX:f64knockZ:f64stun:f64
FighterAI
type FighterAI = { x: f64; z: f64; hp: i64; maxHp: i64; speed: f64; stun: f64; guarding: bool; telegraph: f64; cool: f64; strafeDir: f64; }State for a 1v1 fighter opponent with stun, telegraph windup, guard, and strafing.
x:f64z:f64hp:i64maxHp:i64speed:f64stun:f64guarding:booltelegraph:f64cool:f64strafeDir:f64
FighterStep
type FighterStep = { ai: FighterAI; struckPlayer: bool; damage: i64; }Output of one fighter AI simulation step.
ai:M218.FighterAIstruckPlayer:booldamage:i64
Functions
makeStamina
function makeStamina(max: f64 = 100.0, drain: f64 = 22.0, recover: f64 = 14.0, resumeAt: f64 = 20.0): StaminaStamina of MAX that a sprint drains at DRAIN a second and rest gives back at RECOVER; one exhausted sprints again at RESUMEAT.
canSprint
function canSprint(s: Stamina): boolReturns true only when stamina is not in exhausted cooldown.
stepStamina
function stepStamina(s: Stamina, wantsSprint: bool, dt: f64): StaminaAdvances stamina by dt; entering 0 locks sprinting until stamina recovers to resumeAt.
facingDot
function facingDot(yaw: f64, dx: f64, dz: f64): f64Cosine similarity between a character's forward yaw vector and direction (dx, dz).
Effects: fail.
resolveMelee
function resolveMelee(attackerYaw: f64, dx: f64, dz: f64, reach: f64, baseDamage: i64, targetGuarding: bool, minDot: f64 = 0.35): MeleeResultResolves a melee attack with forward-cone facing check, guard mitigation, knockback, and stun.
Effects: fail.
applyPulseStun
function applyPulseStun(px: f64, pz: f64, yaw: f64, maxRange: f64, stunSeconds: f64, knockSpeed: f64, targets: Vec<PulseTarget>, minDot: f64 = 0.2): Vec<PulseHit>Applies a forward-cone stun and knockback pulse to all targets within range and facing cone.
Effects: fail, alloc.
makeFighterAI
function makeFighterAI(x: f64 = 0.0, z: f64 = -8.0, hp: i64 = 100, speed: f64 = 4.2): FighterAIA fighter at X, Z with HP health that walks at SPEED.
stepFighterAI
function stepFighterAI(ai: FighterAI, px: f64, pz: f64, dt: f64, attackDamage: i64, minX: f64 = -9.0, maxX: f64 = 9.0, minZ: f64 = -13.0, maxZ: f64 = 5.0): FighterStepSteps a 1v1 fighter with hitstun lock, telegraph windup, strafing, and ring bounds.