QuestSystemDebugger.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using UnityEngine;
  2. using System.Linq;
  3. /// <summary>
  4. /// Simple debug script to help troubleshoot quest system issues
  5. /// </summary>
  6. public class QuestSystemDebugger : MonoBehaviour
  7. {
  8. [Header("Debug Options")]
  9. public bool enableDebugLogs = false;
  10. public bool autoDebugOnStart = false;
  11. private void Start()
  12. {
  13. if (autoDebugOnStart)
  14. {
  15. // Wait a frame to ensure all systems are initialized
  16. Invoke(nameof(DebugQuestSystem), 0.5f);
  17. }
  18. }
  19. [ContextMenu("Debug Quest System")]
  20. public void DebugQuestSystem()
  21. {
  22. LogDebug("=== QUEST SYSTEM DEBUG ===");
  23. // Check QuestManager
  24. DebugQuestManager();
  25. // Check AdventurersGuild
  26. DebugAdventurersGuild();
  27. // Check Quest Assets
  28. DebugQuestAssets();
  29. LogDebug("=== DEBUG COMPLETE ===");
  30. }
  31. private void DebugQuestManager()
  32. {
  33. LogDebug("--- QuestManager ---");
  34. if (QuestManager.Instance == null)
  35. {
  36. LogDebug("❌ QuestManager.Instance is NULL!");
  37. return;
  38. }
  39. LogDebug($"✅ QuestManager found");
  40. LogDebug($"📊 Current Renown: {QuestManager.Instance.GetRenown()}");
  41. LogDebug($"📋 Active Quests: {QuestManager.Instance.GetActiveQuests().Count}");
  42. LogDebug($"🎯 Can Accept More: {QuestManager.Instance.CanAcceptMoreQuests()}");
  43. }
  44. private void DebugAdventurersGuild()
  45. {
  46. LogDebug("--- AdventurersGuild ---");
  47. var guild = FindFirstObjectByType<AdventurersGuild>();
  48. if (guild == null)
  49. {
  50. LogDebug("❌ AdventurersGuild component not found!");
  51. return;
  52. }
  53. LogDebug($"✅ AdventurersGuild found");
  54. var questBoard = guild.GetQuestBoard();
  55. LogDebug($"📋 Quest Board Count: {questBoard.Count}");
  56. if (questBoard.Count > 0)
  57. {
  58. LogDebug("📝 Quest Board Contents:");
  59. foreach (var quest in questBoard)
  60. {
  61. LogDebug($" - {quest.questTitle} (Renown: {quest.minimumRenown}, Reward: {quest.goldReward}g)");
  62. }
  63. }
  64. else
  65. {
  66. LogDebug("⚠️ Quest Board is empty - calling RefreshQuestBoard()");
  67. guild.RefreshQuestBoard();
  68. var refreshedBoard = guild.GetQuestBoard();
  69. LogDebug($"📋 After refresh: {refreshedBoard.Count} quests");
  70. }
  71. }
  72. private void DebugQuestAssets()
  73. {
  74. LogDebug("--- Quest Assets ---");
  75. // Check Resources folder for quests
  76. var allQuests = Resources.LoadAll<Quest>("");
  77. LogDebug($"📚 Total Quest assets in Resources: {allQuests.Length}");
  78. if (allQuests.Length > 0)
  79. {
  80. LogDebug("📝 Available Quest Assets:");
  81. foreach (var quest in allQuests)
  82. {
  83. LogDebug($" - {quest.questTitle} (Min Renown: {quest.minimumRenown}, File: {quest.name})");
  84. }
  85. }
  86. else
  87. {
  88. LogDebug("⚠️ No Quest assets found in Resources folder!");
  89. }
  90. // Check specific subfolders
  91. var questSubfolders = new string[] { "Quests", "Quests/Combat", "Quests/Rescue", "Quests/Retrieval", "Quests/Exploration" };
  92. foreach (var folder in questSubfolders)
  93. {
  94. var folderQuests = Resources.LoadAll<Quest>(folder);
  95. if (folderQuests.Length > 0)
  96. {
  97. LogDebug($"📁 {folder}: {folderQuests.Length} quests");
  98. }
  99. }
  100. }
  101. [ContextMenu("Create Test Quest")]
  102. public void CreateTestQuest()
  103. {
  104. LogDebug("Creating runtime test quest...");
  105. if (QuestManager.Instance == null)
  106. {
  107. LogDebug("❌ QuestManager not found!");
  108. return;
  109. }
  110. var testQuest = ScriptableObject.CreateInstance<Quest>();
  111. testQuest.questTitle = "Debug Test Quest";
  112. testQuest.questDescription = "A simple test quest for debugging the quest system.";
  113. testQuest.questType = QuestType.Combat;
  114. testQuest.difficulty = QuestDifficulty.Easy;
  115. testQuest.timeLimitDays = 7;
  116. testQuest.targetAreaName = "Test Area";
  117. testQuest.targetMapPosition = new Vector2Int(50, 50);
  118. testQuest.goldReward = 100;
  119. testQuest.renownReward = 10;
  120. testQuest.minimumRenown = 0; // Ensure it's available to new players
  121. testQuest.goals.Add(new QuestGoal
  122. {
  123. description = "Test objective",
  124. goalType = QuestGoalType.KillEnemies,
  125. targetName = "TestEnemy",
  126. targetCount = 1
  127. });
  128. bool accepted = QuestManager.Instance.AcceptQuest(testQuest);
  129. LogDebug($"Test quest acceptance: {(accepted ? "✅ SUCCESS" : "❌ FAILED")}");
  130. }
  131. [ContextMenu("Add Renown")]
  132. public void AddTestRenown()
  133. {
  134. if (QuestManager.Instance != null)
  135. {
  136. // Use reflection or debug method to add renown
  137. LogDebug("Adding test renown (this is a debug feature)");
  138. // In a real implementation, you'd need a way to modify renown for testing
  139. }
  140. }
  141. private void LogDebug(string message)
  142. {
  143. if (enableDebugLogs)
  144. {
  145. Debug.Log($"[QuestDebugger] {message}");
  146. }
  147. }
  148. }