---
name: attack-token-queue
description: Implement the AAA Attack Token System (Crowd Combat Director) used in Sifu, Batman Arkham, and Ghost of Tsushima so 10 surrounded enemies feel tense and menacing without dogpiling or stun-locking the player in 1 second. Covers central token budgets, global telegraph stagger, outer-ring orbit slots, anti-starvation priority scoring, and instant token release on parry/stagger.
---

# Attack Token System — Multi-Enemy Crowd Combat Director (EP30)

## Core Problem: Why Raw "Every Enemy Attacks on Cooldown" Ruins Action Games
When an AI agent writes melee enemy AI naively (`if (dist < range && cd <= 0) attack()`), surrounding the player with 10 enemies causes all 10 to lunge and land overlapping hit-frames within `150ms`. Players get deleted in `~1.5s` with zero readable counterplay, even with fast parry/dodge reflexes.

## 5 Production Rules (Ship-Ready Architecture)

1. **Rule 01 — Central Attack Token Pool (`maxTokens = 1..2`)**:
   - Enemies NEVER attack autonomously. To transition from `orbit` to `approach -> windup -> strike`, an enemy must borrow an Attack Token from the Combat Director (`activeTokens < maxTokens`).
   - Heavy enemies can optionally cost `2` tokens; light grunts cost `1`.
2. **Rule 02 — Global Telegraph Stagger (`staggerMs >= 340ms`)**:
   - Even when `maxTokens = 2`, the Director enforces a minimum `340ms` gap between token grants so two attacks NEVER connect on the same frame — enabling crisp *Parry -> Parry* chains like *Sifu* and *Sekiro*.
3. **Rule 03 — Outer-Ring Orbit & Taunt Slots**:
   - Tokenless enemies hold evenly-spaced angular slots on an outer waiting circle (`ringRadius`), pacing, circling, and telegraphing threat visually without crowding or blocking the camera.
4. **Rule 04 — Anti-Starvation Priority Scoring**:
   - Rank waiting candidates by `distBonus + waitMs * 0.65 - recentAttackerPenalty` so the crowd rotates naturally instead of one grunt monopolizing every token.
5. **Rule 05 — Guaranteed Token Release on Strike, Parry, Stagger, or Death**:
   - Always release borrowed tokens in a single cleanup hook whenever an attacker finishes its strike, gets parried/staggered, dies, or leaves range — preventing leaked tokens that freeze the room.

## Verification Checklist
- [ ] Across a 10-second 10-enemy wave with `maxTokens = 2`, `peakConcurrentAttackers <= 2` on 100% of frames.
- [ ] Zero overlapping unavoidable hits (`unfairOverlapHits === 0`) under `staggerMs >= 340ms`.
- [ ] Parrying an attacker immediately frees its token and puts the enemy into `staggered`.
- [ ] Switching to `free-for-all` mode clearly demonstrates why uncoordinated crowds melt players in `< 2.5s`.
