123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using System.Collections.Generic;
- using UnityEngine;
- public class SideQuestsManager : MonoBehaviour
- {
- [Header("Quest panel")]
- [SerializeField]
- private PanelQuestBehaviour questPanel;
- [Header("Instant gigs")]
- [SerializeField]
- private InstaGigs instaGigs;
- [Header("Locations data")]
- [SerializeField]
- private DataLocationsInfo dataLocsInfo;
- private static SideQuestsManager instance;
- private DataTools.Quest currentQuest;
- private int currentTask = 0;
- private DataTools.Gig generatedGig;
- public static SideQuestsManager Instance
- {
- get
- {
- return instance;
- }
- }
- void Start ()
- {
- instance = this;
- GameGlobal.Instance.OnLocationChanged += OnLocationChanged;
- }
- private void OnLocationChanged(Location location)
- {
- if(currentQuest != null && currentQuest.Tasks != null && currentQuest.Tasks.Count > 0)
- {
- if(location.ID.ToUpper() == currentQuest.Tasks[currentTask].Action.PropertyId.ToUpper())
- {
- questPanel.CompleteSideTask(currentTask);
- currentTask++;
- questPanel.SetSideTask(currentTask);
- StartAction();
- }
- }
- }
- public void StartAction()
- {
- if (currentQuest != null && currentQuest.Tasks != null && currentQuest.Tasks.Count > 0)
- {
- switch(currentQuest.Tasks[currentTask].Action.Type)
- {
- case DataTools.GameActionType.StartGig:
- {
- instaGigs.GenerateGigs(currentQuest.Tasks[currentTask].Action.PropertyId, generatedGig);
- break;
- }
- }
- }
- }
- private string ExtendLocationDescription(string loc)
- {
- string city = "", state = "";
- dataLocsInfo.GetLocationData(loc, out city, out state);
- loc = WebTools.Phone.TweetBehaviour.Instance.LocationNamePick(loc);
- if (city != string.Empty)
- {
- loc += " in " + city;
- }
- if (state != string.Empty && state != city)
- {
- loc += ", " + state;
- }
- return loc;
- }
- public bool GenerateQuestForGig(DataTools.Gig gig, bool loc_complete = false)
- {
- if (currentQuest != null)
- {
- return false;
- }
- currentTask = 0;
- string gotoDesription = "Go to " + ExtendLocationDescription(gig.Location);
- string doGigDescription = "Complete " + gig.Description;
- List<DataTools.Task> tasks = new List<DataTools.Task>();
- tasks.Add(new DataTools.Task(gotoDesription, new DataTools.GameAction(DataTools.GameActionType.TravelTo, gig.Location), 0));
- tasks.Add(new DataTools.Task(doGigDescription, new DataTools.GameAction(DataTools.GameActionType.StartGig, gig.Id), 0));
- DataTools.Quest newQuest = new DataTools.Quest(tasks, new DataTools.Currency(), gig.Description);
- currentQuest = newQuest;
- questPanel.EnableSideQuests(true);
- questPanel.SetSideQuest(currentQuest);
- questPanel.SetSideTask(0);
- generatedGig = gig;
- if (GameGlobal.Instance.Location == gig.Location || loc_complete)
- {
- questPanel.CompleteSideTask(0);
- questPanel.SetSideTask(1);
- currentTask++;
- StartAction();
- }
- questPanel.ShowSideQuest();
- return true;
- }
- public void CompleteQuest()
- {
- questPanel.RemoveSideQuest();
- questPanel.EnableSideQuests(false);
- currentQuest = null;
- }
- public void GigComleted(string gigId)
- {
- if (currentQuest != null && currentQuest.Tasks != null && currentQuest.Tasks.Count > 0)
- {
- if (gigId == currentQuest.Tasks[currentTask].Action.PropertyId)
- {
- questPanel.CompleteSideTask(currentTask);
- currentTask++;
- questPanel.SetSideTask(currentTask);
- if (currentTask >= currentQuest.Tasks.Count)
- {
- CompleteQuest();
- }
- }
- }
- }
- public bool IsSideQuestActive
- {
- get
- {
- return currentQuest != null;
- }
- }
- }
|