SideQuestsManager.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. public class SideQuestsManager : MonoBehaviour
  4. {
  5. [Header("Quest panel")]
  6. [SerializeField]
  7. private PanelQuestBehaviour questPanel;
  8. [Header("Instant gigs")]
  9. [SerializeField]
  10. private InstaGigs instaGigs;
  11. [Header("Locations data")]
  12. [SerializeField]
  13. private DataLocationsInfo dataLocsInfo;
  14. private static SideQuestsManager instance;
  15. private DataTools.Quest currentQuest;
  16. private int currentTask = 0;
  17. private DataTools.Gig generatedGig;
  18. public static SideQuestsManager Instance
  19. {
  20. get
  21. {
  22. return instance;
  23. }
  24. }
  25. void Start ()
  26. {
  27. instance = this;
  28. GameGlobal.Instance.OnLocationChanged += OnLocationChanged;
  29. }
  30. private void OnLocationChanged(Location location)
  31. {
  32. if(currentQuest != null && currentQuest.Tasks != null && currentQuest.Tasks.Count > 0)
  33. {
  34. if(location.ID.ToUpper() == currentQuest.Tasks[currentTask].Action.PropertyId.ToUpper())
  35. {
  36. questPanel.CompleteSideTask(currentTask);
  37. currentTask++;
  38. questPanel.SetSideTask(currentTask);
  39. StartAction();
  40. }
  41. }
  42. }
  43. public void StartAction()
  44. {
  45. if (currentQuest != null && currentQuest.Tasks != null && currentQuest.Tasks.Count > 0)
  46. {
  47. switch(currentQuest.Tasks[currentTask].Action.Type)
  48. {
  49. case DataTools.GameActionType.StartGig:
  50. {
  51. instaGigs.GenerateGigs(currentQuest.Tasks[currentTask].Action.PropertyId, generatedGig);
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. private string ExtendLocationDescription(string loc)
  58. {
  59. string city = "", state = "";
  60. dataLocsInfo.GetLocationData(loc, out city, out state);
  61. loc = WebTools.Phone.TweetBehaviour.Instance.LocationNamePick(loc);
  62. if (city != string.Empty)
  63. {
  64. loc += " in " + city;
  65. }
  66. if (state != string.Empty && state != city)
  67. {
  68. loc += ", " + state;
  69. }
  70. return loc;
  71. }
  72. public bool GenerateQuestForGig(DataTools.Gig gig, bool loc_complete = false)
  73. {
  74. if (currentQuest != null)
  75. {
  76. return false;
  77. }
  78. currentTask = 0;
  79. string gotoDesription = "Go to " + ExtendLocationDescription(gig.Location);
  80. string doGigDescription = "Complete " + gig.Description;
  81. List<DataTools.Task> tasks = new List<DataTools.Task>();
  82. tasks.Add(new DataTools.Task(gotoDesription, new DataTools.GameAction(DataTools.GameActionType.TravelTo, gig.Location), 0));
  83. tasks.Add(new DataTools.Task(doGigDescription, new DataTools.GameAction(DataTools.GameActionType.StartGig, gig.Id), 0));
  84. DataTools.Quest newQuest = new DataTools.Quest(tasks, new DataTools.Currency(), gig.Description);
  85. currentQuest = newQuest;
  86. questPanel.EnableSideQuests(true);
  87. questPanel.SetSideQuest(currentQuest);
  88. questPanel.SetSideTask(0);
  89. generatedGig = gig;
  90. if (GameGlobal.Instance.Location == gig.Location || loc_complete)
  91. {
  92. questPanel.CompleteSideTask(0);
  93. questPanel.SetSideTask(1);
  94. currentTask++;
  95. StartAction();
  96. }
  97. questPanel.ShowSideQuest();
  98. return true;
  99. }
  100. public void CompleteQuest()
  101. {
  102. questPanel.RemoveSideQuest();
  103. questPanel.EnableSideQuests(false);
  104. currentQuest = null;
  105. }
  106. public void GigComleted(string gigId)
  107. {
  108. if (currentQuest != null && currentQuest.Tasks != null && currentQuest.Tasks.Count > 0)
  109. {
  110. if (gigId == currentQuest.Tasks[currentTask].Action.PropertyId)
  111. {
  112. questPanel.CompleteSideTask(currentTask);
  113. currentTask++;
  114. questPanel.SetSideTask(currentTask);
  115. if (currentTask >= currentQuest.Tasks.Count)
  116. {
  117. CompleteQuest();
  118. }
  119. }
  120. }
  121. }
  122. public bool IsSideQuestActive
  123. {
  124. get
  125. {
  126. return currentQuest != null;
  127. }
  128. }
  129. }