Team Mode¶
A complete two-team competitive game mode.
Overview¶
Team Mode divides players into two teams (Blue and Red) with:
- Automatic team balancing (clan-aware)
- Friendly fire prevention
- Troop donations between teammates
- Team-colored territories
- ELO rewards based on team performance
Files¶
src/examples/team-mode/
├── manifest.json # Mod metadata
├── gameplay.ts # Main mod class
├── config.ts # Game mechanics overrides
├── executions/
│ └── donate.ts # Troop donation logic
├── ui/
│ └── buttons/
│ └── donate/
├── schedulerJobs/
│ └── rank-decay.ts # Background ELO decay
└── utils/
├── shared.ts # Types and constants
└── team-logic.ts # Team assignment logic
Main Mod Class¶
The main gameplay file extends Mod and implements all lifecycle hooks:
Configuration¶
The Team Mode config can customize combat mechanics. This example uses defaults:
Key Features¶
Friendly Fire Prevention¶
Attacks on teammates are blocked via action hooks. The registerActions method:
Intent Handlers¶
Custom UI buttons send intents that are processed by registerIntentHandlers:
Lifecycle Hooks¶
Game Initialization¶
Player Added¶
Game End¶
Troop Donations¶
The DonateExecution validates teams and handles cooldowns:
Shared Constants¶
Centralized constants avoid magic strings and make refactoring safer:
Intent Names¶
State Keys¶
Types¶
Helper Functions¶
State Structure¶
The mod uses modState for in-game team tracking:
// Teams - array of player IDs per team
modState.set('teams', { blue: ['player1'], red: ['player2'] });
// Player to team mapping - quick lookup
modState.set('playerTeam', { player1: 'blue', player2: 'red' });
// Donation cooldowns - prevent spam
modState.set('donateCooldowns', { donate_p1_p2: 1234 }); // tick number
// Clan assignments - keep clans together
modState.set('clanTeam', { clan123: 'blue' });
Try It¶
Build and test the Team Mode: