Combat & Simulation Design
This document details the hybrid combat system, character AI, viewer input overrides, and the client-simulation/server-validation architecture.
🎮 Simulation Responsibility Split
Instead of a resource-heavy server-authoritative loop where the backend runs physics and positions, CROSS uses a Hybrid Authoritative Model to minimize server CPU costs and latency.
graph TD subgraph Streamer Client Godot SC[Run Physics & Collisions] -->|Render Positions & Anim| SC1[Run Character Combat AI] SC1 -->|Broadcast Combat Log Events| MS end subgraph Viewer Interfaces VI[Chat / Extension / Standalone] -->|Send Commands: attack, skill 1| MS[Master Server] end MS -->|Queue & Forward Inputs| SC MS -->|Validate logs, calculate XP/Loot| DB[(PostgreSQL)]
1. The Combat AI (Streamer Client Side)
The heavy lifting of moving, pathfinding, targeting, and casting spells is handled by the Streamer’s local Godot Client.
- Autonomous Behavior: If a character is in
Combatstate, the local AI takes control:- Movement: Pathfinds toward the nearest enemy (or targets within interception range).
- Attacking: Automatically executes basic attacks based on weapon speed.
- Healers/Supports: Searches for the ally with the lowest current HP percentage and auto-casts heals.
- Skill Casting: Auto-casts offensive/defensive spells as soon as their individual cooldowns expire.
- Chat Command Fallbacks: Chat users can steer the AI with basic targeting modifiers if they choose:
!attack most-hp: Targets the enemy with the highest health.!attack most-dmg: Targets the enemy dealing the most damage to the base.
2. Viewer Input & Cooldown Overrides
When a viewer interacts via the Standalone Client or the Twitch Extension, their manual actions override the default combat AI.
- Manual Commands: The viewer sends explicit action requests to the Master Server:
attack <entity_id>(Change target)goto <position>(Force move)skill <skill_id>(Queue ability, e.g.,skill 1)use <item_id>(Queue item consumption, e.g.,use 2)
- Queueing & Global Cooldown (GCD):
- Manual commands bypass the AI auto-caster.
- When the client receives a manual command (like
skill 1), it queues it. As soon as the character’s Global Cooldown (GCD) or the specific skill’s cooldown expires, the queued manual skill is executed immediately, taking priority over any AI-selected spell.
3. Server-Side Calculations & State Validation
To ensure total security and cheat prevention without running a full physics loop, the Master Server is the sole authority on math, health values, items, and combat stats. It does not track player coordinates, but it dictates all combat outcomes.
The Request-Response Combat Loop:
When the Godot client’s physics and collision engine detects that a character or enemy is in range to act, it sends a request to the Master Server. The server calculates the mathematical outcome and sends back the result.
Streamer Client (Godot) Master Server
| |
| ---- [REQUEST: Viewer A attacks Mob B] -----> |
| | -- Calculates weapon/stat formulas
| <--- [RESPONSE: Damage Dealt: 20] ----------- |
| |
| ---- [REQUEST: Viewer C heals Viewer A] ----> |
| | -- Calculates healing power
| <--- [RESPONSE: Viewer A HP set to 120] ----- |
| |
| ---- [REQUEST: Viewer A attacks Mob B] -----> |
| | -- Hits, detects Mob B HP <= 0
| <--- [RESPONSE: Mob B Died (Loot/XP info)] -- |
- Session State Tracking: The server tracks the current HP of all spawned mobs and active viewer characters in a channel’s combat session.
- Strict Server Math Validation:
- Cooldown Checks: If the client requests
"Viewer A uses Fireball"but the server’s database tracks that Fireball is still on cooldown for Viewer A, the server rejects the request. - Stat-Locked Outcomes: Damage ranges, critical hits, block chance, and healing amounts are calculated on the server using the database records of the players’ equipment. The client cannot “tell” the server how much damage was dealt; it can only request an attack trigger.
- Cooldown Checks: If the client requests
- Reward Dispersion: When the server registers that all mobs in a wave have died, it tallies the validated damage/healing statistics to award gold, XP, and materials to the contributing players’ databases.