This guide explains how to implement the new combat event system that allows players to fight combat encounters and loads the BattleScene with team data (characters, weapons, etc.) and terrain information (plains, mountain, road, etc.).
Assets/Scripts/BattleSetup/CombatDataTransfer.csAssets/Scripts/BattleSetup/CombatSceneManager.csAssets/Scripts/BattleScene/EnhancedBattleSetup.csAssets/Scripts/Events/CombatEventIntegration.cs (modified)Create the Manager GameObject:
In your MapScene2 (or main travel scene):
1. Create an empty GameObject
2. Name it "CombatSceneManager"
3. Add the CombatSceneManager component
Configure the Manager:
In the CombatSceneManager inspector:
- Battle Scene Name: "BattleScene" (or your battle scene name)
- Show Debug Logs: ✓ (recommended for testing)
- Terrain Generator: (will auto-find BFMTerrainGenerator)
Enhance Battle Setup:
In your BattleScene:
1. Find the GameObject with BattleSetup component
2. Add the EnhancedBattleSetup component to the same GameObject
3. Configure the component settings
Configure Enhanced Setup:
In the EnhancedBattleSetup inspector:
- Use Enhanced Setup: ✓
- Battle Context Text: (drag a UI Text element for battle info)
- Terrain Generator: (will auto-find BFMTerrainGenerator)
- Show Debug Logs: ✓ (recommended for testing)
Check CombatEventIntegration:
In your MapScene2:
1. Find the GameObject with CombatEventIntegration component
2. Ensure it's properly configured with popup references
3. The system will automatically use the new CombatSceneManager
Player travels on map → Travel Event System → Combat Event occurs → Combat popup appears
Player clicks "ATTACK!" → CombatEventIntegration → CombatSceneManager → Battle scene loads
1. CombatDataTransfer.InitializeCombatSession() is called
2. Team data is collected from MainTeamSelectScript/GameStateManager/PlayerPrefs
3. Enemy data is extracted from combat event
4. Terrain and weather information is captured
5. Legacy BattleSetupData is populated for compatibility
6. Battle scene is loaded
1. EnhancedBattleSetup detects combat session data
2. Terrain is configured based on travel location
3. UI is updated with battle context
4. Character placement proceeds using existing BattleSetup
5. Enhanced stats are applied to characters
Battle completes → EnhancedBattleSetup.EndBattleSession() → Return to map scene
"Battle on a well-traveled road in open grasslands"
"Battle in dense woodland during evening (clear weather)"
"Battle at a stone bridge in rocky mountain terrain"
TeamCharacter → TeamCharacterCombatData:
- Name, gender, core stats (STR, DEX, CON, WIS, PER)
- Combat stats (HP, AC) calculated from attributes
- Equipment (weapons, armor)
- Resources (gold, silver, copper)
EnemyCharacterData → EnemyCombatData:
- Enemy name and type
- Health, armor class, threat level
- Preferred weapons
- Source data reference
TravelEventContext → CombatSessionData:
- Battle location coordinates
- Terrain type and features
- Weather conditions
- Time of day
1. MainTeamSelectScript.GetConfiguredCharacters() (if in scene)
2. GameStateManager.Instance.savedTeam (persistent data)
3. PlayerPrefs (fallback for individual character data)
"No team members found" Error:
Solution: Ensure team data is saved properly:
- Create characters in Team Select scene
- Click "Save Game" or "Proceed to Battle"
- Check GameStateManager.Instance.savedTeam is populated
"CombatSceneManager not found" Warning:
Solution: Add CombatSceneManager to your map scene:
- Create empty GameObject in MapScene2
- Add CombatSceneManager component
- Configure battle scene name
Terrain not changing in battle:
Solution: Ensure BFMTerrainGenerator is properly set up:
- Add BFMTerrainGenerator to battle scene
- Assign to EnhancedBattleSetup.terrainGenerator field
- Check terrain type conversion in logs
Battle scene not loading:
Solution: Check Build Settings:
- Ensure "BattleScene" is added to Build Settings
- Verify scene name matches CombatSceneManager.battleSceneName
- Check console for scene loading errors
Enable Debug Logs:
- CombatSceneManager: showDebugLogs = true
- EnhancedBattleSetup: showDebugLogs = true
Use Context Menu Commands:
- CombatSceneManager: "Start Test Combat"
- EnhancedBattleSetup: "Debug Combat Session"
Check Combat Session Data:
CombatDataTransfer.DebugLogSession(); // Call in console or script
1. Start game → Create team → Travel on map
2. Trigger combat event (wait for random or use debug)
3. Choose "ATTACK!" in combat popup
4. Verify battle scene loads with correct terrain
5. Check console logs for data transfer info
1. Travel to different terrain types (forest, mountain, plains)
2. Trigger combat in each location
3. Verify battle terrain matches travel terrain
4. Check UI shows correct battle context
1. Create characters with different equipment
2. Start combat and check character stats in battle
3. Verify weapons and armor are properly equipped
4. Check combat stats (HP, AC) are calculated correctly
This combat integration system provides:
✅ Rich Data Transfer: Team stats, equipment, and environmental context
✅ Terrain-Based Battles: Dynamic battle environments based on travel location
✅ Seamless Integration: Works with existing combat and travel systems
✅ Robust Fallbacks: Graceful degradation when components are missing
✅ Debug Support: Comprehensive logging and testing tools
The system transforms simple combat events into rich, contextual battle experiences that reflect where and when the fight takes place, while maintaining full compatibility with existing game systems.