RuntimeQuestCreator.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. /// <summary>
  4. /// Runtime quest creator - creates sample quests that can be added to the guild
  5. /// </summary>
  6. public class RuntimeQuestCreator : MonoBehaviour
  7. {
  8. [Header("Auto-Create Options")]
  9. public bool createQuestsOnStart = true;
  10. public bool addToGuildOnStart = true;
  11. [Header("Debug")]
  12. public bool enableDebugLogs = false;
  13. private void Start()
  14. {
  15. if (createQuestsOnStart)
  16. {
  17. StartCoroutine(CreateSampleQuestsDelayed());
  18. }
  19. }
  20. private System.Collections.IEnumerator CreateSampleQuestsDelayed()
  21. {
  22. // Wait for other systems to initialize
  23. yield return new WaitForSeconds(1f);
  24. CreateSampleQuests();
  25. if (addToGuildOnStart)
  26. {
  27. yield return new WaitForSeconds(0.5f);
  28. AddQuestsToGuild();
  29. }
  30. }
  31. [ContextMenu("Create Sample Quests")]
  32. public void CreateSampleQuests()
  33. {
  34. LogDebug("Creating sample quests...");
  35. var quests = new List<Quest>();
  36. // Create a variety of quests
  37. quests.Add(CreateBanditCampQuest());
  38. quests.Add(CreateMissingMerchantQuest());
  39. quests.Add(CreateArtifactRetrievalQuest());
  40. quests.Add(CreateWolfPackQuest());
  41. quests.Add(CreateDeliveryQuest());
  42. LogDebug($"✅ Created {quests.Count} sample quests");
  43. // Store them for access
  44. foreach (var quest in quests)
  45. {
  46. // You could save these to a list or directly add to guild
  47. LogDebug($"📝 Quest: {quest.questTitle}");
  48. }
  49. }
  50. [ContextMenu("Add Quests to Guild")]
  51. public void AddQuestsToGuild()
  52. {
  53. var guild = FindFirstObjectByType<AdventurersGuild>();
  54. if (guild == null)
  55. {
  56. LogDebug("❌ No AdventurersGuild found!");
  57. return;
  58. }
  59. LogDebug("Adding sample quests to guild...");
  60. // Use the guild's debug method to add a simple quest
  61. // Since we can't access private fields directly, we'll use the debug context menu
  62. LogDebug("Use the guild's 'Create Simple Test Quest' context menu to add quests");
  63. // Alternatively, create quests and try to get them added
  64. var sampleQuests = CreateMultipleTestQuests();
  65. // Force refresh the guild
  66. guild.RefreshQuestBoard();
  67. LogDebug("Guild refresh completed");
  68. }
  69. private List<Quest> CreateMultipleTestQuests()
  70. {
  71. var quests = new List<Quest>();
  72. // Create several test quests with different requirements
  73. for (int i = 0; i < 3; i++)
  74. {
  75. var quest = CreateTestQuest(i);
  76. quests.Add(quest);
  77. }
  78. return quests;
  79. }
  80. private Quest CreateTestQuest(int index)
  81. {
  82. var quest = ScriptableObject.CreateInstance<Quest>();
  83. switch (index)
  84. {
  85. case 0:
  86. quest.questTitle = "Goblin Menace";
  87. quest.questDescription = "Goblins are raiding nearby farms. Drive them back to their caves.";
  88. quest.targetAreaName = "Goblin Caves";
  89. quest.goldReward = 50;
  90. quest.renownReward = 8;
  91. break;
  92. case 1:
  93. quest.questTitle = "Lost Caravan";
  94. quest.questDescription = "A merchant caravan went missing on the mountain pass. Investigate their disappearance.";
  95. quest.targetAreaName = "Mountain Pass";
  96. quest.goldReward = 100;
  97. quest.renownReward = 15;
  98. break;
  99. case 2:
  100. quest.questTitle = "Bandit Hideout";
  101. quest.questDescription = "Bandits have been terrorizing travelers. Find their hideout and bring them to justice.";
  102. quest.targetAreaName = "Dark Forest";
  103. quest.goldReward = 150;
  104. quest.renownReward = 20;
  105. quest.minimumRenown = 5;
  106. break;
  107. }
  108. // Common properties
  109. quest.questType = QuestType.Combat;
  110. quest.difficulty = QuestDifficulty.Easy;
  111. quest.timeLimitDays = 7;
  112. quest.targetMapPosition = new Vector2Int(50 + index * 10, 50 + index * 5);
  113. quest.minimumRenown = index * 2; // Progressive requirements
  114. quest.goals.Add(new QuestGoal
  115. {
  116. description = $"Defeat enemies in {quest.targetAreaName}",
  117. goalType = QuestGoalType.KillEnemies,
  118. targetName = "Enemy",
  119. targetCount = 3 + index * 2
  120. });
  121. return quest;
  122. }
  123. private Quest CreateBanditCampQuest()
  124. {
  125. var quest = ScriptableObject.CreateInstance<Quest>();
  126. quest.questTitle = "Clear the Bandit Camp";
  127. quest.questDescription = "Bandits have been attacking merchants on the main road. Their camp has been spotted in the nearby forest. Clear them out and make the roads safe for trade.";
  128. quest.questType = QuestType.Combat;
  129. quest.difficulty = QuestDifficulty.Easy;
  130. quest.timeLimitDays = 5;
  131. quest.targetAreaName = "Darkwood Forest";
  132. quest.targetMapPosition = new Vector2Int(45, 60);
  133. quest.goldReward = 75;
  134. quest.renownReward = 10;
  135. quest.minimumRenown = 0;
  136. quest.goals.Add(new QuestGoal
  137. {
  138. description = "Defeat 3 Bandits",
  139. goalType = QuestGoalType.KillEnemies,
  140. targetName = "Bandit",
  141. targetCount = 3
  142. });
  143. quest.goals.Add(new QuestGoal
  144. {
  145. description = "Defeat the Bandit Leader",
  146. goalType = QuestGoalType.DefeatBoss,
  147. targetName = "Bandit Chief",
  148. targetCount = 1
  149. });
  150. return quest;
  151. }
  152. private Quest CreateMissingMerchantQuest()
  153. {
  154. var quest = ScriptableObject.CreateInstance<Quest>();
  155. quest.questTitle = "Missing Merchant";
  156. quest.questDescription = "Merchant Harold departed for the next town three days ago but never arrived. His family fears the worst. Find him and bring him home safely.";
  157. quest.questType = QuestType.Rescue;
  158. quest.difficulty = QuestDifficulty.Normal;
  159. quest.timeLimitDays = 7;
  160. quest.targetAreaName = "Whispering Hills";
  161. quest.targetMapPosition = new Vector2Int(65, 45);
  162. quest.goldReward = 120;
  163. quest.renownReward = 15;
  164. quest.minimumRenown = 5;
  165. quest.goals.Add(new QuestGoal
  166. {
  167. description = "Find Merchant Harold",
  168. goalType = QuestGoalType.RescuePerson,
  169. targetName = "Harold",
  170. targetCount = 1
  171. });
  172. return quest;
  173. }
  174. private Quest CreateArtifactRetrievalQuest()
  175. {
  176. var quest = ScriptableObject.CreateInstance<Quest>();
  177. quest.questTitle = "The Crystal of Ages";
  178. quest.questDescription = "An ancient crystal with magical properties has been discovered in ruins to the east. Retrieve it before it falls into the wrong hands.";
  179. quest.questType = QuestType.Retrieval;
  180. quest.difficulty = QuestDifficulty.Normal;
  181. quest.timeLimitDays = 10;
  182. quest.targetAreaName = "Ancient Ruins";
  183. quest.targetMapPosition = new Vector2Int(80, 40);
  184. quest.goldReward = 200;
  185. quest.renownReward = 25;
  186. quest.minimumRenown = 10;
  187. quest.goals.Add(new QuestGoal
  188. {
  189. description = "Retrieve the Crystal of Ages",
  190. goalType = QuestGoalType.CollectItems,
  191. targetName = "Crystal of Ages",
  192. targetCount = 1
  193. });
  194. return quest;
  195. }
  196. private Quest CreateWolfPackQuest()
  197. {
  198. var quest = ScriptableObject.CreateInstance<Quest>();
  199. quest.questTitle = "Wolf Pack Threat";
  200. quest.questDescription = "A large pack of wolves has been attacking livestock near the village. The alpha must be dealt with to scatter the pack.";
  201. quest.questType = QuestType.Combat;
  202. quest.difficulty = QuestDifficulty.Easy;
  203. quest.timeLimitDays = 3;
  204. quest.targetAreaName = "Northern Woods";
  205. quest.targetMapPosition = new Vector2Int(30, 70);
  206. quest.goldReward = 60;
  207. quest.renownReward = 8;
  208. quest.minimumRenown = 0;
  209. quest.goals.Add(new QuestGoal
  210. {
  211. description = "Defeat the Alpha Wolf",
  212. goalType = QuestGoalType.DefeatBoss,
  213. targetName = "Alpha Wolf",
  214. targetCount = 1
  215. });
  216. return quest;
  217. }
  218. private Quest CreateDeliveryQuest()
  219. {
  220. var quest = ScriptableObject.CreateInstance<Quest>();
  221. quest.questTitle = "Urgent Medicine Delivery";
  222. quest.questDescription = "The village healer needs rare herbs delivered to a settlement to the south. Time is of the essence as people are depending on this medicine.";
  223. quest.questType = QuestType.Delivery;
  224. quest.difficulty = QuestDifficulty.Easy;
  225. quest.timeLimitDays = 2;
  226. quest.targetAreaName = "Southern Settlement";
  227. quest.targetMapPosition = new Vector2Int(50, 25);
  228. quest.goldReward = 80;
  229. quest.renownReward = 12;
  230. quest.minimumRenown = 0;
  231. quest.goals.Add(new QuestGoal
  232. {
  233. description = "Deliver medicine to Southern Settlement",
  234. goalType = QuestGoalType.ReachLocation,
  235. targetName = "Southern Settlement",
  236. targetCount = 1
  237. });
  238. return quest;
  239. }
  240. private void LogDebug(string message)
  241. {
  242. if (enableDebugLogs)
  243. {
  244. Debug.Log($"[RuntimeQuestCreator] {message}");
  245. }
  246. }
  247. }