TravelEventSystemSetup.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using UnityEngine;
  2. /// <summary>
  3. /// Setup script to easily add the Travel Event System to your existing travel setup
  4. /// This component should be added to the same GameObject as TeamTravelSystem
  5. /// </summary>
  6. public class TravelEventSystemSetup : MonoBehaviour
  7. {
  8. [Header("Event System Setup")]
  9. [Tooltip("Automatically create and configure the travel event system")]
  10. public bool autoSetupEventSystem = true;
  11. [Header("Event Configuration")]
  12. [Range(0f, 1f)]
  13. [Tooltip("Base chance for events to occur (15% recommended)")]
  14. public float eventChance = 0.15f;
  15. [Range(1, 10)]
  16. [Tooltip("Check for events every N tiles traveled")]
  17. public int tilesPerCheck = 3;
  18. [Tooltip("Enable debug logging for events")]
  19. public bool enableDebugLogs = true;
  20. [Header("Default Events")]
  21. [Tooltip("Create default ScriptableObject events automatically")]
  22. public bool createDefaultEvents = true;
  23. void Start()
  24. {
  25. if (autoSetupEventSystem)
  26. {
  27. SetupEventSystem();
  28. }
  29. }
  30. [ContextMenu("Setup Event System")]
  31. public void SetupEventSystem()
  32. {
  33. // Check if TravelEventSystem already exists
  34. TravelEventSystem existingSystem = GetComponent<TravelEventSystem>();
  35. if (existingSystem != null)
  36. {
  37. Debug.Log("✅ TravelEventSystem already exists on this GameObject");
  38. ConfigureExistingSystem(existingSystem);
  39. return;
  40. }
  41. // Add TravelEventSystem component
  42. TravelEventSystem eventSystem = gameObject.AddComponent<TravelEventSystem>();
  43. // Configure the system
  44. eventSystem.enableEvents = true;
  45. eventSystem.baseEventChance = eventChance;
  46. eventSystem.tilesPerEventCheck = tilesPerCheck;
  47. eventSystem.showDebugLogs = enableDebugLogs;
  48. Debug.Log("✅ TravelEventSystem added and configured");
  49. // Create default events if requested
  50. if (createDefaultEvents)
  51. {
  52. CreateDefaultEventAssets();
  53. }
  54. // Verify integration
  55. VerifyIntegration();
  56. }
  57. private void ConfigureExistingSystem(TravelEventSystem eventSystem)
  58. {
  59. eventSystem.baseEventChance = eventChance;
  60. eventSystem.tilesPerEventCheck = tilesPerCheck;
  61. eventSystem.showDebugLogs = enableDebugLogs;
  62. Debug.Log("🔧 Updated existing TravelEventSystem configuration");
  63. }
  64. [ContextMenu("Create Default Events")]
  65. public void CreateDefaultEventAssets()
  66. {
  67. // This would create ScriptableObject assets in the Resources folder
  68. // For now, we'll just log what would be created
  69. string[] defaultEvents = {
  70. "Forest Ambush Event",
  71. "Mountain Ambush Event",
  72. "Traveling Merchant Event",
  73. "Road Patrol Event",
  74. "Hidden Cache Event",
  75. "Wild Animal Event",
  76. "Rest Site Event",
  77. "Weather Hazard Event"
  78. };
  79. Debug.Log("📦 Default events that should be created:");
  80. foreach (string eventName in defaultEvents)
  81. {
  82. Debug.Log($" - {eventName}");
  83. }
  84. Debug.Log("💡 To create these events:");
  85. Debug.Log(" 1. Right-click in Project window");
  86. Debug.Log(" 2. Go to Create > RPG > Travel Events");
  87. Debug.Log(" 3. Choose the event type you want");
  88. Debug.Log(" 4. Configure the event settings");
  89. Debug.Log(" 5. Add to the Available Events list in TravelEventSystem");
  90. }
  91. private void VerifyIntegration()
  92. {
  93. Debug.Log("🔍 Verifying Travel Event System Integration...");
  94. // Check for required components
  95. TeamTravelSystem travelSystem = GetComponent<TeamTravelSystem>();
  96. if (travelSystem == null)
  97. {
  98. Debug.LogError("❌ TeamTravelSystem not found! TravelEventSystem requires TeamTravelSystem on the same GameObject.");
  99. return;
  100. }
  101. SimpleTeamPlacement teamPlacement = FindFirstObjectByType<SimpleTeamPlacement>();
  102. if (teamPlacement == null)
  103. {
  104. Debug.LogWarning("⚠️ SimpleTeamPlacement not found in scene. Events may not work properly.");
  105. }
  106. MapMaker2 mapMaker = FindFirstObjectByType<MapMaker2>();
  107. if (mapMaker == null)
  108. {
  109. Debug.LogWarning("⚠️ MapMaker2 not found in scene. Events may not work properly.");
  110. }
  111. TravelEventSystem eventSystem = GetComponent<TravelEventSystem>();
  112. if (eventSystem != null && eventSystem.availableEvents.Count == 0)
  113. {
  114. Debug.LogWarning("⚠️ No events assigned to TravelEventSystem. Create and assign travel events for the system to work.");
  115. }
  116. Debug.Log("✅ Integration verification complete");
  117. }
  118. [ContextMenu("Test Event System")]
  119. public void TestEventSystem()
  120. {
  121. TravelEventSystem eventSystem = GetComponent<TravelEventSystem>();
  122. if (eventSystem == null)
  123. {
  124. Debug.LogError("❌ No TravelEventSystem found. Run Setup Event System first.");
  125. return;
  126. }
  127. Debug.Log("🎲 Testing travel event system...");
  128. eventSystem.TriggerEventCheck();
  129. }
  130. void OnValidate()
  131. {
  132. // Clamp values
  133. eventChance = Mathf.Clamp01(eventChance);
  134. tilesPerCheck = Mathf.Clamp(tilesPerCheck, 1, 10);
  135. }
  136. }
  137. /// <summary>
  138. /// Helper script to create example travel events for testing
  139. /// Add this to any GameObject to quickly create test events
  140. /// </summary>
  141. public class TravelEventExampleCreator : MonoBehaviour
  142. {
  143. [ContextMenu("Create Example Events")]
  144. public void CreateExampleEvents()
  145. {
  146. Debug.Log("🎭 Creating example travel events...");
  147. // This demonstrates how to create events at runtime for testing
  148. CreateExampleAmbushEvent();
  149. CreateExampleMerchantEvent();
  150. CreateExampleDiscoveryEvent();
  151. Debug.Log("✅ Example events created. Check the TravelEventSystem component.");
  152. }
  153. private void CreateExampleAmbushEvent()
  154. {
  155. var ambushEvent = ScriptableObject.CreateInstance<CombatTravelEvent>();
  156. ambushEvent.eventName = "Test Forest Ambush";
  157. ambushEvent.eventDescription = "A test ambush event for debugging";
  158. ambushEvent.eventType = EventType.Combat;
  159. ambushEvent.rarity = EventRarity.Common;
  160. // Set terrain preferences
  161. ambushEvent.forestChance = 0.9f;
  162. ambushEvent.roadChance = 0.2f;
  163. ambushEvent.townChance = 0.1f;
  164. // Add to event system if available
  165. TravelEventSystem eventSystem = FindFirstObjectByType<TravelEventSystem>();
  166. if (eventSystem != null)
  167. {
  168. eventSystem.availableEvents.Add(ambushEvent);
  169. Debug.Log("➕ Added test ambush event");
  170. }
  171. }
  172. private void CreateExampleMerchantEvent()
  173. {
  174. var merchantEvent = ScriptableObject.CreateInstance<TradingTravelEvent>();
  175. merchantEvent.eventName = "Test Traveling Merchant";
  176. merchantEvent.eventDescription = "A test merchant event for debugging";
  177. merchantEvent.eventType = EventType.Trading;
  178. merchantEvent.rarity = EventRarity.Common;
  179. // Set terrain preferences
  180. merchantEvent.roadChance = 0.8f;
  181. merchantEvent.townChance = 0.7f;
  182. merchantEvent.forestChance = 0.3f;
  183. // Add to event system if available
  184. TravelEventSystem eventSystem = FindFirstObjectByType<TravelEventSystem>();
  185. if (eventSystem != null)
  186. {
  187. eventSystem.availableEvents.Add(merchantEvent);
  188. Debug.Log("➕ Added test merchant event");
  189. }
  190. }
  191. private void CreateExampleDiscoveryEvent()
  192. {
  193. var discoveryEvent = ScriptableObject.CreateInstance<DiscoveryTravelEvent>();
  194. discoveryEvent.eventName = "Test Hidden Treasure";
  195. discoveryEvent.eventDescription = "A test discovery event for debugging";
  196. discoveryEvent.eventType = EventType.Discovery;
  197. discoveryEvent.rarity = EventRarity.Uncommon;
  198. // Set terrain preferences
  199. discoveryEvent.forestChance = 0.7f;
  200. discoveryEvent.mountainChance = 0.8f;
  201. discoveryEvent.roadChance = 0.2f;
  202. // Add to event system if available
  203. TravelEventSystem eventSystem = FindFirstObjectByType<TravelEventSystem>();
  204. if (eventSystem != null)
  205. {
  206. eventSystem.availableEvents.Add(discoveryEvent);
  207. Debug.Log("➕ Added test discovery event");
  208. }
  209. }
  210. }