Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEngine;
  6.  
  7. public class QuestController : MonoBehaviour
  8. {
  9.  
  10. #region Singleton
  11. public static QuestController instance;
  12.  
  13. private void Awake()
  14. {
  15. if (instance != null)
  16. {
  17. Debug.LogWarning("There is another instance of QuestController");
  18. return;
  19. }
  20.  
  21. instance = this;
  22.  
  23. quests = new List<Quest>();
  24. activeQuests = new List<Quest>();
  25. }
  26. #endregion
  27.  
  28. private List<Quest> quests;
  29. private List<Quest> activeQuests;
  30.  
  31. public CharacterProps playerProps;
  32. private LevelSystem levelSystem;
  33.  
  34. public QuestUI questUI;
  35.  
  36. private void Start()
  37. {
  38. levelSystem = this.gameObject.GetComponent<LevelSystem>();
  39. }
  40.  
  41.  
  42. public void SendProgressForQuest(string nameOfTarget)
  43. {
  44. foreach(Quest quest in activeQuests)
  45. {
  46. var goal = quest.goal.GetCurrentChoice();
  47. if (goal.target.Equals(nameOfTarget))
  48. {
  49. goal.progress++;
  50.  
  51. if (goal.progress >= goal.quantity)
  52. {
  53. goal.progress = goal.quantity;
  54. goal.done = true;
  55. }
  56. }
  57. }
  58. }
  59.  
  60. public void AddQuest(Quest quest)
  61. {
  62. if (activeQuests.Contains(quest)) { return; }
  63.  
  64. activeQuests.Add(quest);
  65. questUI.UpdateQuestUI();
  66. }
  67.  
  68. public void CompleteQuest(Quest quest)
  69. {
  70. levelSystem.AddExp(quest.reward.exp);
  71. playerProps.coins += quest.reward.coins;
  72.  
  73. Inventory.instance.Add(quest.reward.item);
  74.  
  75. activeQuests.Remove(quest);
  76. questUI.UpdateQuestUI();
  77. }
  78.  
  79. public void AbortQuest(Quest quest)
  80. {
  81. activeQuests.Remove(quest);
  82. questUI.UpdateQuestUI();
  83. }
  84.  
  85. public bool QuestAlreadyActive(Quest quest)
  86. {
  87. return activeQuests.Contains(quest);
  88. }
  89.  
  90. public List<Quest> GetQuests()
  91. {
  92. return activeQuests;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement