BattleSceneDebugHelper.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using System.Linq;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. /// <summary>
  5. /// Debug helper for testing battle scene transitions and victory scenarios
  6. /// </summary>
  7. public class BattleSceneDebugHelper : MonoBehaviour
  8. {
  9. [Header("Debug Controls")]
  10. [Tooltip("Enable debug mode to show additional logging and controls")]
  11. public bool enableDebugMode = true;
  12. [Header("Scene Testing")]
  13. [Tooltip("Name of the map scene to return to")]
  14. public string mapSceneName = "MapScene2";
  15. private void Update()
  16. {
  17. if (!enableDebugMode) return;
  18. // Debug hotkeys
  19. if (Input.GetKeyDown(KeyCode.F1))
  20. {
  21. TestSceneTransition();
  22. }
  23. if (Input.GetKeyDown(KeyCode.F2))
  24. {
  25. ForcePlayerVictory();
  26. }
  27. if (Input.GetKeyDown(KeyCode.F3))
  28. {
  29. TestReturnToMap();
  30. }
  31. }
  32. [ContextMenu("Test Scene Transition")]
  33. public void TestSceneTransition()
  34. {
  35. Debug.Log("🧪 [DEBUG] Testing scene transition to " + mapSceneName);
  36. try
  37. {
  38. SceneManager.LoadScene(mapSceneName);
  39. Debug.Log("✅ Scene transition initiated successfully");
  40. }
  41. catch (System.Exception e)
  42. {
  43. Debug.LogError($"❌ Scene transition failed: {e.Message}");
  44. }
  45. }
  46. [ContextMenu("Force Player Victory")]
  47. public void ForcePlayerVictory()
  48. {
  49. Debug.Log("🧪 [DEBUG] Forcing player victory...");
  50. if (GameManager.Instance != null)
  51. {
  52. // Use the GameManager's test victory method if available
  53. var method = typeof(GameManager).GetMethod("TestBattleVictory",
  54. System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
  55. if (method != null)
  56. {
  57. method.Invoke(GameManager.Instance, null);
  58. Debug.Log("✅ Used GameManager.TestBattleVictory()");
  59. }
  60. else
  61. {
  62. Debug.LogWarning("⚠️ GameManager.TestBattleVictory() method not found");
  63. // Manually kill all enemies
  64. ForceKillAllEnemies();
  65. }
  66. }
  67. else
  68. {
  69. Debug.LogError("❌ GameManager.Instance is null");
  70. }
  71. }
  72. [ContextMenu("Test Return to Map")]
  73. public void TestReturnToMap()
  74. {
  75. Debug.Log("🧪 [DEBUG] Testing return to map via OnLootingComplete...");
  76. if (GameManager.Instance != null)
  77. {
  78. // Call the OnLootingComplete method directly
  79. var method = typeof(GameManager).GetMethod("OnLootingComplete",
  80. System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  81. if (method != null)
  82. {
  83. method.Invoke(GameManager.Instance, null);
  84. Debug.Log("✅ Called OnLootingComplete() via reflection");
  85. }
  86. else
  87. {
  88. Debug.LogError("❌ OnLootingComplete method not found");
  89. }
  90. }
  91. else
  92. {
  93. Debug.LogError("❌ GameManager.Instance is null");
  94. }
  95. }
  96. private void ForceKillAllEnemies()
  97. {
  98. Debug.Log("🧪 [DEBUG] Manually killing all enemies...");
  99. if (GameManager.Instance != null && GameManager.Instance.enemyCharacters != null)
  100. {
  101. foreach (var enemy in GameManager.Instance.enemyCharacters)
  102. {
  103. if (enemy != null)
  104. {
  105. var character = enemy.GetComponent<Character>();
  106. if (character != null && !character.IsDead)
  107. {
  108. character.TakeDamage(1000); // Force death
  109. Debug.Log($"🔪 Killed enemy: {enemy.name}");
  110. }
  111. }
  112. }
  113. }
  114. }
  115. [ContextMenu("Debug Battle State")]
  116. public void DebugBattleState()
  117. {
  118. Debug.Log("🔍 [DEBUG] Current battle state:");
  119. if (GameManager.Instance != null)
  120. {
  121. Debug.Log($" Players: {GameManager.Instance.playerCharacters?.Count ?? 0}");
  122. Debug.Log($" Enemies: {GameManager.Instance.enemyCharacters?.Count ?? 0}");
  123. var alivePlayers = GameManager.Instance.GetAlivePlayers();
  124. var aliveEnemies = GameManager.Instance.enemyCharacters?.Where(e => e != null && !e.GetComponent<Character>()?.IsDead == true).Count() ?? 0;
  125. Debug.Log($" Alive Players: {alivePlayers?.Count ?? 0}");
  126. Debug.Log($" Alive Enemies: {aliveEnemies}");
  127. bool battleShouldEnd = (alivePlayers?.Count ?? 0) == 0 || aliveEnemies == 0;
  128. Debug.Log($" Battle should end: {battleShouldEnd}");
  129. }
  130. else
  131. {
  132. Debug.LogError(" GameManager.Instance is null!");
  133. }
  134. }
  135. private void OnGUI()
  136. {
  137. if (!enableDebugMode) return;
  138. // Simple debug GUI
  139. GUILayout.BeginArea(new Rect(10, 10, 300, 200));
  140. GUILayout.Label("Battle Debug Controls", GUI.skin.box);
  141. if (GUILayout.Button("F1: Test Scene Transition"))
  142. TestSceneTransition();
  143. if (GUILayout.Button("F2: Force Player Victory"))
  144. ForcePlayerVictory();
  145. if (GUILayout.Button("F3: Test Return to Map"))
  146. TestReturnToMap();
  147. if (GUILayout.Button("Debug Battle State"))
  148. DebugBattleState();
  149. GUILayout.Label("Hotkeys: F1, F2, F3");
  150. GUILayout.EndArea();
  151. }
  152. }