# gizgame/combat

Orthogonal combat primitives: stamina gating, directional melee with guard/knockback, forward-cone pulse stun, and telegraphing 1v1 fighter AI.

```gizlang
import * as Combat from "gizgame/combat";
```

## Types

### `Stamina`

```gizlang
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`: `f64`
- `max`: `f64`
- `drain`: `f64`
- `recover`: `f64`
- `exhausted`: `bool`
- `resumeAt`: `f64`

### `MeleeResult`

```gizlang
type MeleeResult = { hit: bool; damage: i64; guarded: bool; knockX: f64; knockZ: f64; stun: f64; }
```

Result of a directional melee strike check.

- `hit`: `bool`
- `damage`: `i64`
- `guarded`: `bool`
- `knockX`: `f64`
- `knockZ`: `f64`
- `stun`: `f64`

### `PulseTarget`

```gizlang
type PulseTarget = { id: i64; x: f64; z: f64; }
```

Target descriptor for a cone pulse stun (e.g., flashlight pulse or EMP).

- `id`: `i64`
- `x`: `f64`
- `z`: `f64`

### `PulseHit`

```gizlang
type PulseHit = { id: i64; knockX: f64; knockZ: f64; stun: f64; }
```

Confirmed pulse stun result for one target.

- `id`: `i64`
- `knockX`: `f64`
- `knockZ`: `f64`
- `stun`: `f64`

### `FighterAI`

```gizlang
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`: `f64`
- `z`: `f64`
- `hp`: `i64`
- `maxHp`: `i64`
- `speed`: `f64`
- `stun`: `f64`
- `guarding`: `bool`
- `telegraph`: `f64`
- `cool`: `f64`
- `strafeDir`: `f64`

### `FighterStep`

```gizlang
type FighterStep = { ai: FighterAI; struckPlayer: bool; damage: i64; }
```

Output of one fighter AI simulation step.

- `ai`: `M218.FighterAI`
- `struckPlayer`: `bool`
- `damage`: `i64`

## Functions

### `makeStamina`

```gizlang
function makeStamina(max: f64 = 100.0, drain: f64 = 22.0, recover: f64 = 14.0, resumeAt: f64 = 20.0): Stamina
```

Stamina of MAX that a sprint drains at DRAIN a second and rest gives back at RECOVER; one exhausted sprints again at RESUMEAT.

### `canSprint`

```gizlang
function canSprint(s: Stamina): bool
```

Returns true only when stamina is not in exhausted cooldown.

### `stepStamina`

```gizlang
function stepStamina(s: Stamina, wantsSprint: bool, dt: f64): Stamina
```

Advances stamina by dt; entering 0 locks sprinting until stamina recovers to resumeAt.

### `facingDot`

```gizlang
function facingDot(yaw: f64, dx: f64, dz: f64): f64
```

Cosine similarity between a character's forward yaw vector and direction (dx, dz).

Effects: fail.

### `resolveMelee`

```gizlang
function resolveMelee(attackerYaw: f64, dx: f64, dz: f64, reach: f64, baseDamage: i64, targetGuarding: bool, minDot: f64 = 0.35): MeleeResult
```

Resolves a melee attack with forward-cone facing check, guard mitigation, knockback, and stun.

Effects: fail.

### `applyPulseStun`

```gizlang
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`

```gizlang
function makeFighterAI(x: f64 = 0.0, z: f64 = -8.0, hp: i64 = 100, speed: f64 = 4.2): FighterAI
```

A fighter at X, Z with HP health that walks at SPEED.

### `stepFighterAI`

```gizlang
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): FighterStep
```

Steps a 1v1 fighter with hitstun lock, telegraph windup, strafing, and ring bounds.

