- **CoA 1: Initiative Roll:** Upon starting combat, all active units must be sorted into the turnQueue based on their Speed stat (Highest First)
- **CoA 2: Turn Start Hygiene:** When a unit's turn begins:
- Their `currentAP` must reset to `baseAP`
- Status effects (DoTs) must tick
- Cooldowns must decrement
- **CoA 3: Cycling:** Calling `endTurn()` must move the `activeUnitId` to the next in the queue. If the queue is empty, increment round and re-roll/reset the queue
- **CoA 1: Validation:** Moving to a tile must fail if:
- The tile is blocked/occupied
- No path exists
- The unit has insufficient AP for the _entire_ path
- **CoA 2: Execution:** A successful move must:
- Update the Unit's position in the UnitManager
- Update the VoxelGrid occupancy map
- Deduct the correct AP cost (including terrain modifiers)
- **CoA 3: Path Snapping:** If the user clicks a tile, but the unit only has AP to reach halfway, the system should allow moving to the _furthest reachable tile_ on that path (optional QoL)
## **3. Implementation Requirements**
### **The Turn System**
Create `src/systems/TurnSystem.js`. It should manage the CombatState.
1. Implement `startCombat(units)`: Sorts units by speed into turnQueue and sets phase to TURN_START
2. Implement `startTurn()`: Refills the active unit's AP, processes cooldowns/statuses, and sets phase to WAITING_FOR_INPUT
3. Implement `endTurn()`: Rotates the queue. If queue is empty, start new Round
4. It should accept the UnitManager in the constructor to access unit stats