public void LinkQuest(StateQuest sQuest) { myQuest = sQuest.Quest; questNameText.text = sQuest.Quest.Title; //questProgressText.text = sQuest.Score.ToString(); //circularBar.fillAmount = (float) sQuest.Score; int checkpointsFinished = 0; int checkpointsTotal = 0; foreach (StateCheckPoint stateCheckpoint in sQuest.Checkpoints) { if (stateCheckpoint.Status == StatusCheckPoint.FINISHED) { checkpointsFinished++; } checkpointsTotal++; } float progress = checkpointsFinished / checkpointsTotal; circularBar.fillAmount = progress; questProgressText.text = "" + Mathf.Ceil(progress * 100) + "%"; badges = Controller.Instance.User.Badges; List <CheckPoint> checkpoints = myQuest.Checkpoints; FillBadgesList(checkpoints); }
public IEnumerator TryReStartQuest() { if (selectedQuest != null && user != null) { if (GeoManager.Instance.IsUserNear(selectedQuest.Geolocalisation)) { Quest fetchedQuest = null; SetLoaderCircle(true); yield return(HTTPHelper.Instance.GetQuest(selectedQuest.Id, value => fetchedQuest = value)); SetLoaderCircle(false); selectedQuest = fetchedQuest; user.Quests[fetchedQuest.Id] = new StateQuest(selectedQuest); currentQuest = user.Quests[fetchedQuest.Id]; currentState = questState; SceneManager.LoadScene("GameImageScene"); } else { Error("Vous êtes trop loin pour lancer cette quête."); } } }
/// <summary> /// Adds a quest to the quests began if it does not exists already for this user. /// </summary> /// <param name="q">The quest.</param> /// <returns> /// True if a <see cref="StateQuest"/> was added, false else. /// </returns> public bool AddQuest(Quest q) { if (quests.ContainsKey(q.Id)) { return(false); } else { StateQuest newStateQuest = new StateQuest(q); quests.Add(q.Id, newStateQuest); return(true); } }
//TODO: clean up /// <summary> /// Checks the quest and modifies the users xp accordingly to the status of the quest. /// </summary> /// <param name="q">The quest.</param> /// deprecated do not use public void CheckQuest(Quest q) { if (quests.ContainsKey(q.Id)) //if the quest has begun { StateQuest sq = quests[q.Id]; //if the quest is currently done we can lose xp if it has changed (x-1) //if the quest is unaccomplished, we can win xp by finishing it (x1) int done_coeff = sq.Done ? -1 : 1; if (sq.Done != sq.CheckQuest()) //if the status has changed xp must change { //xp += sq.Quest.Value * done_coeff; } } }
public IEnumerator ToDictState(string json, Action <Dictionary <string, StateQuest> > d) { Dictionary <string, StateQuest> dic = new Dictionary <string, StateQuest>(); JArray jsonQuest = JArray.Parse(json); for (int i = 0; i < jsonQuest.Count; i++) { JObject tokenQuest = JObject.Parse(jsonQuest[0].ToString()); StateQuest sq = null; yield return(JSONHelper.Instance.ToStateQuest(tokenQuest.ToString(), value => sq = value)); dic.Add(sq.Quest.Id, sq); } d(dic); }
void Start() { if (instance == null) { instance = this; currentQuest = Controller.Instance.CurrentQuest; questProgress = CheckQuestProgress(); currentCheckpoint = currentQuest.Checkpoints[questProgress]; checkpointProgress = 0; checkpointStartTime = System.DateTime.Now; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); }
public static JObject ToJson(StateQuest quest) { JArray jsonCheckpoints = new JArray(); foreach (var questCheckpoint in quest.Checkpoints) { jsonCheckpoints.Add(JSONHelper.ToJson(questCheckpoint)); } JObject jsonState = new JObject( new JProperty("_idQuest", quest.Quest.Id), new JProperty("state", quest.Done ? "DONE" : "IN_PROGRESS"), new JProperty("stats", new JObject( new JProperty("earnedXP", quest.Score), new JProperty("timeElapsed", quest.TimeElapsed) )), new JProperty("checkpoints", jsonCheckpoints) ); return(jsonState); }