CombatIntegrationTest.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. /// <summary>
  4. /// Test script for the Combat Scene Integration system
  5. /// Use this to verify that the system works correctly
  6. /// </summary>
  7. public class CombatIntegrationTest : MonoBehaviour
  8. {
  9. [Header("Test Configuration")]
  10. [Tooltip("Test terrain type for combat")]
  11. public TerrainType testTerrain = TerrainType.Forest;
  12. [Tooltip("Test feature type")]
  13. public FeatureType testFeature = FeatureType.Road;
  14. [Tooltip("Number of test enemies")]
  15. public int testEnemyCount = 2;
  16. [Tooltip("Test enemy type name")]
  17. public string testEnemyType = "Test Bandit";
  18. [Header("Test Controls")]
  19. [Tooltip("Enable this to run test combat on Start - Creates FastRogue (DEX:20) and SlowTank (DEX:4)")]
  20. public bool runTestOnStart = false;
  21. void Start()
  22. {
  23. if (runTestOnStart)
  24. {
  25. // Delay the test slightly to ensure scene is fully loaded
  26. Invoke(nameof(RunCombatTest), 1f);
  27. }
  28. }
  29. /// <summary>
  30. /// Run a test combat scenario
  31. /// </summary>
  32. [ContextMenu("Run Combat Test")]
  33. public void RunCombatTest()
  34. {
  35. Debug.Log("🧪 Running combat integration test...");
  36. // Create test team data
  37. List<TeamCharacter> testTeam = CreateTestTeam();
  38. // Create test battle data
  39. BattleEventData testBattleData = CreateTestBattleData();
  40. // Create test context
  41. TravelEventContext testContext = CreateTestContext();
  42. // Initialize combat session
  43. CombatDataTransfer.InitializeCombatSession(testBattleData, testContext, testTeam);
  44. // Debug the session
  45. CombatDataTransfer.DebugLogSession();
  46. // Test the CombatSceneManager
  47. TestCombatSceneManager();
  48. Debug.Log("✅ Combat integration test complete!");
  49. }
  50. /// <summary>
  51. /// Create test team data with varied movement speeds
  52. /// </summary>
  53. private List<TeamCharacter> CreateTestTeam()
  54. {
  55. List<TeamCharacter> team = new List<TeamCharacter>();
  56. // Create a FAST character - Very High Dexterity
  57. var fastRogue = new TeamCharacter
  58. {
  59. name = "FastRogue",
  60. isMale = true,
  61. strength = 12,
  62. dexterity = 25, // Very High DEX = Very Fast movement (MovementSpeed = 30 + 15 = 45)
  63. constitution = 14,
  64. wisdom = 12,
  65. perception = 16,
  66. gold = 50,
  67. silver = 25,
  68. copper = 10,
  69. equippedWeapon = "Sword",
  70. equippedArmor = "Leather Armor",
  71. weapons = new List<string> { "Sword", "Bow" },
  72. armor = new List<string> { "Leather Armor" }
  73. };
  74. team.Add(fastRogue);
  75. // Create a SLOW character - Very Low Dexterity
  76. var slowTank = new TeamCharacter
  77. {
  78. name = "SlowTank",
  79. isMale = false,
  80. strength = 16,
  81. dexterity = 1, // Very Low DEX = Very Slow movement (MovementSpeed = 30 + (-10) = 20, but formula should give us ~15)
  82. constitution = 16,
  83. wisdom = 14,
  84. perception = 10,
  85. gold = 45,
  86. silver = 30,
  87. copper = 5,
  88. equippedWeapon = "Sword",
  89. equippedArmor = "Plate Armor",
  90. weapons = new List<string> { "Sword", "Mace" },
  91. armor = new List<string> { "Plate Armor" }
  92. };
  93. team.Add(slowTank);
  94. Debug.Log($"🏷️ Created test team with {team.Count} members - FastRogue (DEX:25) and SlowTank (DEX:1)");
  95. return team;
  96. }
  97. /// <summary>
  98. /// Create test battle data
  99. /// </summary>
  100. private BattleEventData CreateTestBattleData()
  101. {
  102. var battleData = new BattleEventData
  103. {
  104. enemyCount = testEnemyCount,
  105. enemyType = testEnemyType,
  106. battleDescription = $"A test encounter with {testEnemyCount} {testEnemyType}s",
  107. enemyCharacterData = null // Could be set to a real EnemyCharacterData asset
  108. };
  109. Debug.Log($"⚔️ Created test battle data: {battleData.enemyCount}x {battleData.enemyType}");
  110. return battleData;
  111. }
  112. /// <summary>
  113. /// Create test travel context
  114. /// </summary>
  115. private TravelEventContext CreateTestContext()
  116. {
  117. // Create a mock map tile
  118. var mockTile = new MapTile(0, 0)
  119. {
  120. terrainType = testTerrain,
  121. featureType = testFeature
  122. };
  123. var context = new TravelEventContext(Vector2Int.zero, mockTile, null)
  124. {
  125. dayOfJourney = 3,
  126. timeOfDay = 14.5f, // 2:30 PM
  127. currentWeather = Weather.Clear,
  128. teamGold = 150,
  129. teamFood = 75,
  130. teamMorale = 0.8f,
  131. isOnMainRoad = testFeature == FeatureType.Road,
  132. distanceToDestination = 25.5f
  133. };
  134. Debug.Log($"🌍 Created test context: {testTerrain} terrain, {testFeature} feature");
  135. return context;
  136. }
  137. /// <summary>
  138. /// Test the CombatSceneManager functionality
  139. /// </summary>
  140. private void TestCombatSceneManager()
  141. {
  142. // Find CombatSceneManager
  143. var manager = FindFirstObjectByType<MonoBehaviour>();
  144. MonoBehaviour combatManager = null;
  145. // Look for CombatSceneManager by name
  146. var allComponents = FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None);
  147. foreach (var comp in allComponents)
  148. {
  149. if (comp.GetType().Name == "CombatSceneManager")
  150. {
  151. combatManager = comp;
  152. break;
  153. }
  154. }
  155. if (combatManager != null)
  156. {
  157. Debug.Log("✅ Found CombatSceneManager");
  158. // Test getting battle context description
  159. var method = combatManager.GetType().GetMethod("GetBattleContextDescription");
  160. if (method != null)
  161. {
  162. string description = (string)method.Invoke(combatManager, null);
  163. Debug.Log($"📝 Battle context: {description}");
  164. }
  165. }
  166. else
  167. {
  168. Debug.LogWarning("⚠️ CombatSceneManager not found - add it to test scene loading");
  169. }
  170. }
  171. /// <summary>
  172. /// Test data transfer without scene loading
  173. /// </summary>
  174. [ContextMenu("Test Data Transfer Only")]
  175. public void TestDataTransferOnly()
  176. {
  177. Debug.Log("📊 Testing data transfer system...");
  178. // Create test data
  179. List<TeamCharacter> testTeam = CreateTestTeam();
  180. BattleEventData testBattleData = CreateTestBattleData();
  181. TravelEventContext testContext = CreateTestContext();
  182. // Test initialization
  183. CombatDataTransfer.InitializeCombatSession(testBattleData, testContext, testTeam);
  184. // Test session validity
  185. bool hasValidSession = CombatDataTransfer.HasValidSession();
  186. Debug.Log($"🔍 Has valid session: {hasValidSession}");
  187. // Test getting session data
  188. var session = CombatDataTransfer.GetCurrentSession();
  189. if (session != null)
  190. {
  191. Debug.Log($"👥 Player team: {session.playerTeam.Count} members");
  192. Debug.Log($"👹 Enemies: {session.enemies.Count} enemies");
  193. Debug.Log($"🌍 Terrain: {session.battleTerrain}");
  194. Debug.Log($"🌤️ Weather: {session.weather}");
  195. // Test terrain description
  196. string terrainDesc = CombatDataTransfer.GetTerrainDescription(session.battleTerrain, session.battleFeature);
  197. Debug.Log($"📝 Terrain description: {terrainDesc}");
  198. }
  199. // Test legacy compatibility
  200. CombatDataTransfer.PopulateLegacyBattleSetupData();
  201. Debug.Log($"🔧 Legacy data populated: {BattleSetupData.playerSelections.Count} players, {BattleSetupData.enemySelections.Count} enemies");
  202. // Test cleanup
  203. CombatDataTransfer.ClearSession();
  204. Debug.Log($"🧹 Session cleared. Has valid session: {CombatDataTransfer.HasValidSession()}");
  205. Debug.Log("✅ Data transfer test complete!");
  206. }
  207. /// <summary>
  208. /// Test team data loading from various sources
  209. /// </summary>
  210. [ContextMenu("Test Team Data Loading")]
  211. public void TestTeamDataLoading()
  212. {
  213. Debug.Log("👥 Testing team data loading...");
  214. // Test MainTeamSelectScript
  215. var teamSelect = FindFirstObjectByType<MainTeamSelectScript>();
  216. if (teamSelect != null)
  217. {
  218. var characters = teamSelect.GetConfiguredCharacters();
  219. Debug.Log($"📋 MainTeamSelectScript: {characters?.Count ?? 0} characters");
  220. }
  221. else
  222. {
  223. Debug.Log("📋 MainTeamSelectScript: Not found");
  224. }
  225. // Test GameStateManager
  226. if (GameStateManager.Instance != null && GameStateManager.Instance.savedTeam != null)
  227. {
  228. int count = 0;
  229. foreach (var char_ in GameStateManager.Instance.savedTeam)
  230. {
  231. if (char_ != null) count++;
  232. }
  233. Debug.Log($"💾 GameStateManager: {count} characters");
  234. }
  235. else
  236. {
  237. Debug.Log("💾 GameStateManager: Not available or no saved team");
  238. }
  239. // Test PlayerPrefs
  240. int prefCount = 0;
  241. for (int i = 0; i < 4; i++)
  242. {
  243. if (PlayerPrefs.GetInt($"Character{i}_Exists", 0) == 1)
  244. {
  245. prefCount++;
  246. }
  247. }
  248. Debug.Log($"🗃️ PlayerPrefs: {prefCount} characters");
  249. Debug.Log("✅ Team data loading test complete!");
  250. }
  251. /// <summary>
  252. /// Clear test data
  253. /// </summary>
  254. [ContextMenu("Clear Test Data")]
  255. public void ClearTestData()
  256. {
  257. CombatDataTransfer.ClearSession();
  258. BattleSetupData.playerSelections.Clear();
  259. BattleSetupData.enemySelections.Clear();
  260. Debug.Log("🧹 Test data cleared");
  261. }
  262. }