Skip to main content

Attack Token System (Why 10 Enemies Attack One by One)

If all 10 enemies attack whenever their cooldown hits zero, overlapping hit-frames delete the player in under 2 seconds. Play this 60fps Canvas Action Director to tune Attack Token caps, telegraph stagger, and anti-starvation rotation, then install the SKILL.md.

GAME PRESETS:
HP: 100/100Parry: 0Hits: 0Overlaps: 0
Live Director Tuning0.0s

10s HEADLESS A/B FAIRNESS PROOF

🔴 Free-For-All
Survived: 1.45s
Peak Mob: 10
Overlaps: 9
🎫 Token (2)
Survived: 10s
Peak Mob: 2
Fair %: 100%
LIVE TOKEN QUEUE LOG
Waiting for first attack token...
01

Central Attack Token Pool (max 1-2 concurrent attackers) prevents 1.5s mob stun-lock

02

Global 340ms Telegraph Stagger eliminates unparryable same-frame double hits

03

Tokenless mobs circle evenly on an outer taunt ring — tense visuals, fair readability

04

Parrying or staggering immediately recycles the token with zero token-leak deadlocks

Installable Agent Skill · Free

Drop straight into Claude Code, Cursor, or Codex

Paste into your AI agent chat
Read https://gameskill.dev/labs/attack-token-queue/skill.md and apply this skill to my game
Go Deeper · Companion GameSkill Pro Kit

Companion pack "Roguelike Combat & Boss Kit" ships runnable JS/TS + Godot 4 (.gd) + Unity (.cs) source code — unlock all 12 multi-engine Pro packs + 84 commercial WAV SFX + 8 2D VFX shaders from $8.25/mo ($99/yr, save 36%) or $12.9/mo.

Full SKILL.md Specification & Verification Checklist

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.

ENGINEERING BREAKDOWN & BENCHMARK

Why Naive AI Implementations Fail (Measured Benchmark)

When every mob runs an independent `if dist < range and cd <= 0: attack()`, 10 surrounding enemies sync up and deal overlapping frames within 150ms, melting the player in 1.4 seconds with zero readable parry window. A central Combat Director leasing max 1–2 Attack Tokens with a >= 340ms telegraph stagger keeps crowd combat intense and fair.

10-second 10-mob arena benchmark: Free-For-All = 6+ simultaneous hits, player melts in <3s vs 2-Token Director = 0 overlapping hits, full parry chain survival.

PRODUCTION CODE · GODOT 4 · UNITY C# · TYPESCRIPT

Reference Implementation in Godot 4, Unity C#, and TypeScript

Godot 4 (GDScript)

attack_token_director.gd
class_name AttackTokenDirector
extends Node

@export var max_tokens: int = 2
@export var min_stagger_ms: int = 340

var _active_holders: Dictionary = {} # enemy_id -> token_cost
var _last_grant_ms: int = -9999

func active_token_count() -> int:
	var total := 0
	for cost in _active_holders.values():
		total += int(cost)
	return total

func request_token(enemy_id: int, cost: int = 1) -> bool:
	var now := Time.get_ticks_msec()
	if _active_holders.has(enemy_id):
		return true
	if now - _last_grant_ms < min_stagger_ms:
		return false
	if active_token_count() + cost > max_tokens:
		return false
	_active_holders[enemy_id] = cost
	_last_grant_ms = now
	return true

func release_token(enemy_id: int) -> void:
	_active_holders.erase(enemy_id)

Unity (C#)

AttackTokenDirector.cs
using System.Collections.Generic;
using UnityEngine;

public class AttackTokenDirector : MonoBehaviour
{
    [SerializeField] private int maxTokens = 2;
    [SerializeField] private float minStaggerSec = 0.34f;

    private readonly Dictionary<int, int> _holders = new();
    private int _usedTokens;
    private float _lastGrantTime = -10f;

    public bool TryAcquireToken(int enemyId, int cost = 1)
    {
        if (_holders.ContainsKey(enemyId)) return true;
        if (Time.time - _lastGrantTime < minStaggerSec) return false;
        if (_usedTokens + cost > maxTokens) return false;

        _holders[enemyId] = cost;
        _usedTokens += cost;
        _lastGrantTime = Time.time;
        return true;
    }

    public void ReleaseToken(int enemyId)
    {
        if (_holders.Remove(enemyId, out int cost))
            _usedTokens = Mathf.Max(0, _usedTokens - cost);
    }
}

TypeScript (Web / Phaser)

attack-token-pool.ts
export class AttackTokenPool {
  private holders = new Map<string, number>();
  private lastGrantMs = -Infinity;

  constructor(private maxTokens = 2, private minStaggerMs = 340) {}

  request(enemyId: string, nowMs: number, cost = 1): boolean {
    if (this.holders.has(enemyId)) return true;
    if (nowMs - this.lastGrantMs < this.minStaggerMs) return false;
    const used = [...this.holders.values()].reduce((a, b) => a + b, 0);
    if (used + cost > this.maxTokens) return false;
    this.holders.set(enemyId, cost);
    this.lastGrantMs = nowMs;
    return true;
  }

  release(enemyId: string): void {
    this.holders.delete(enemyId);
  }
}

DEVELOPER FAQ

Tuning, Edge Cases & Engine Integration FAQ

How many attack tokens should a 1-vs-many action game allow at once?

Use `maxTokens = 1` for cinematic Batman Arkham / Assassin’s Creed counter combat, and `maxTokens = 2` with a `340–450ms` telegraph stagger for faster parry-chain games like Sifu or Ghost of Tsushima.

How do you prevent tokenless enemies from standing around awkwardly?

Assign waiting mobs to evenly spaced angular orbit slots around `ringRadius`, play strafing/taunt animations, and dynamically score candidates by `waitTime + proximity - recentAttackerPenalty` so the crowd rotates cleanly.

What causes Attack Token leaks in production games?

Forgetting to release tokens when an attacker is interrupted mid-windup (parried, staggered, frozen, knocked out of range, or killed). Centralize `releaseToken(enemyId)` inside a single state-exit / cleanup hook and add a max-lease timeout safety net.

Can heavy enemies consume more than one Attack Token?

Yes—charging `cost = 2` for heavy/unblockable attackers automatically clears the floor of light grunts during a boss or brute slam without writing special-case crowd logic.

Related Engine Hubs, Guides & Production Kits

More interactive labs in this track

Extracted from a real game · Zhaoshi Wulin

Every formula in these labs ships inside our upcoming Steam wuxia deckbuilder

3 martial-arts characters, 39 enemies, 70 relics, 19 kungfu finishers built in Godot with AI agents. Every time we solve a hard design or feel problem, we turn it into an interactive lab and skill here.