# Combat Event Popup Setup Guide

## Overview
The combat event popup system has been enhanced to support two setup methods. The popup now includes comprehensive debugging to help identify any setup issues.

## Setup Options

### Option 1: Direct Component Setup (Recommended for Testing)
1. Find your **TravelEventSystem** GameObject in the scene
2. Add the **CombatEventIntegration** component to it
3. Add the **CombatEventPopup** component to the same GameObject
4. The system will automatically detect and connect the components

### Option 2: Prefab-Based Setup (Production Ready)
1. Create a prefab containing the **CombatEventPopup** component
2. Add **CombatEventIntegration** to your **TravelEventSystem** GameObject
3. Assign your popup prefab to the **Combat Popup Prefab** field
4. The system will instantiate the popup when needed

## Verification Steps

### 1. Check Console for Initialization Messages
When the scene starts, you should see:
```
🔧 Combat Event Integration starting...
📦 Instantiating combat popup from prefab... (if using prefab)
✅ Combat Event Integration initialized successfully
```

### 2. Test Combat Event Triggering
When a combat event occurs, you should see debug messages like:
```
🔍 Attempting to find CombatEventIntegration component...
🎯 Found CombatEventIntegration via FindObjectsByType
📞 Calling ShowCombatChoicePopup method...
🎭 Showing combat choice popup: A group of bandits blocks your path!
```

### 3. Verify Component Attachment
In the Inspector, ensure:
- **TravelEventSystem** GameObject has **CombatEventIntegration** component
- **CombatEventIntegration** component has either:
  - **Combat Event Popup** field assigned (Option 1), OR
  - **Combat Popup Prefab** field assigned (Option 2)

## Troubleshooting

### No Popup Appears
1. **Check Console**: Look for initialization error messages
2. **Verify Components**: Ensure CombatEventIntegration is on TravelEventSystem GameObject
3. **Check References**: Ensure either popup component or prefab is assigned
4. **Test in Play Mode**: The system only works when the scene is playing

### Error Messages
- `❌ Combat Event Integration requires TravelEventSystem on the same GameObject!`
  - Solution: Add CombatEventIntegration to the same GameObject as TravelEventSystem

- `❌ Combat popup prefab does not contain CombatEventPopup component!`
  - Solution: Ensure your prefab has the CombatEventPopup component

- `❌ Combat Event Integration requires a CombatEventPopup component or prefab!`
  - Solution: Either add CombatEventPopup component to scene or assign a prefab

### Component Not Found During Events
If you see `⚠️ CombatEventIntegration component not found via FindObjectsByType`:
1. Ensure CombatEventIntegration is actually added to a GameObject in the scene
2. Check that the GameObject is active
3. Verify the component is enabled

## Testing the System

### Manual Test Steps
1. Start the game in Play mode
2. Initiate travel between locations
3. If combat events don't trigger naturally, you can:
   - Modify travel event probabilities in the Inspector
   - Add multiple enemy types to locations
   - Test with shorter travel distances

### Debug Information
The system now provides extensive debugging:
- Component discovery process
- Method invocation attempts
- Popup display calls
- Event handling flow

## Quick Setup Checklist
- [ ] TravelEventSystem GameObject exists in scene
- [ ] CombatEventIntegration component added to TravelEventSystem
- [ ] Either CombatEventPopup component OR prefab assigned
- [ ] EnemyCharacterData assets created and assigned to locations
- [ ] Console shows successful initialization message
- [ ] Test travel triggers combat events with popup

## Recent Enhancements
- **Flexible Setup**: Support for both direct component and prefab-based setup
- **Enhanced Debugging**: Comprehensive logging throughout the integration process
- **Better Error Handling**: Clear error messages with solutions
- **Automatic Detection**: System automatically finds and connects components when possible
