private int GetQuestIndex(QuestLine _line) { List <QuestProgress> _quests = new List <QuestProgress>(); _quests.AddRange(QuestManager.Instance.quests); return(_quests.FindIndex((obj) => obj.line.Equals(_line))); }
public QuestChanged(QuestChange _change, QuestLine _quest, int _currentQuest, QuestState _state) { change = _change; quest = _quest; currentQuest = _currentQuest; state = _state; }
public void QuestDeclined(QuestLine _line) { List <QuestProgress> list = new List <QuestProgress>(); list.AddRange(quests); QuestDeactivator( list.FindIndex((obj) => obj.line == _line), QuestState.Declined, questCancelledText, QuestCancelTrigger ); }
public void QuestComplete(QuestLine _line, QuestRewardType[] _types) { int _index = GetQuestIndex(_line); // Quest tasks are handled by QuestData. if (IsQuestComplete(GetQuestIndex(_line))) { QuestProgress quest = quests[_index]; // If quest is started. if (quest.state == QuestState.Started) { // Quest completed. quest.currentQuest++; // Is quest line complete or is there more quests? quest.state = ( (quest.line.quests.Length > quest.currentQuest) ? QuestState.Searching : QuestState.Done ); // Fixing current quest index. if (quest.line.quests.Length == quest.currentQuest) { quest.currentQuest--; } // Each QuestReward type work differently based on RewardType. quest.line.quests[quest.currentQuest].AwardRewards(_types); // TODO Tell player which quest was completed. // Or to save and load progress... // Or to QuestTracker (local, online, session etc.) // Perhaps through event manager? // New idea: EventManager told and QuestProgress checks the quest list. // Quest data is saved by ProgressManager, which handles SaveProgress<T> classes. // Deactivate quest. Debug.Log(string.Format(questCompleteText, quest.line.quests[quest.currentQuest].name)); DeactivateQuest(quest); GS.Data.EventManager.TriggerEvent(QuestCompleteTrigger); return; } } QuestInComplete(_index); }
public void QuestEnd(QuestLine _line, QuestRewardType[] _selection, float _cooldown = -1f) { checkCooldown = Time.time + (_cooldown < 0 ? questCheckCooldown : _cooldown); QuestManager.Instance.QuestComplete(_line, QuestList.Instance.GetSelectedRewards()); }
public void QuestDecline(QuestLine _line, float _cooldown = -1f) { checkCooldown = Time.time + (_cooldown < 0 ? questCheckCooldown : _cooldown); QuestManager.Instance.QuestDeclined(_line); }
public void QuestFailed(QuestLine _line) { QuestDeactivator(GetQuestIndex(_line), QuestState.Failure, questCancelledText, QuestCancelTrigger); }
public void QuestDismissed(QuestLine _line) { QuestDeactivator(GetQuestIndex(_line), QuestState.Dismissed, questCancelledText, QuestCancelTrigger); }
public void QuestAccepted(QuestLine _line) { // Accept quest with QuestProgress. QuestProgress quest; quest.line = null; quest.currentQuest = -1; quest.state = QuestState.Started; quest.tasks = null; // Go through active quests. foreach (QuestProgress _quest in quests) { if (_quest.line == _line) { quest.line = _quest.line; quest.currentQuest = _quest.currentQuest; quest.state = _quest.state; break; } } if (quest.line == null) { // Check if questline has ever appeared before. foreach (QuestProgress _quest in progress.Quests) { if (_quest.line == _line) { quest.line = _quest.line; quest.currentQuest = _quest.currentQuest; quest.state = _quest.state; break; } } // No quest was found! Create new QuestProgress. if (quest.line == null) { quest.line = _line; quest.currentQuest = 0; } } // Populate tasks QuestData data = quest.line.quests[quest.currentQuest]; switch (quest.state) { case QuestState.Started: quest.tasks = data.tasks; break; case QuestState.Declined: quest.state = (data.isRepeatable && data.isDeclinable && data.canRestart ? QuestState.Started : QuestState.Locked); quest.tasks = (quest.state == QuestState.Started ? data.tasks : null); break; case QuestState.Dismissed: quest.state = (data.isRepeatable && data.isDismissable && data.canRestart ? QuestState.Started : QuestState.Locked); quest.tasks = (quest.state == QuestState.Started ? data.tasks : null); break; case QuestState.Failure: quest.state = (data.isRepeatable && data.canRestart ? QuestState.Started : QuestState.Locked); quest.tasks = (quest.state == QuestState.Started ? data.tasks : null); break; case QuestState.Locked: // Quest has been permanently failed and QuestLine is lost. quest.tasks = null; break; default: // Quest was already made. Need to next questline quest. quest.currentQuest++; quest.state = QuestState.Searching; quest.tasks = null; break; } // Add quest progress to active quest list. ActivateQuest(quest); Debug.Log(string.Format(questAcceptedText, quest.line.quests[quest.currentQuest].name), this); GS.Data.EventManager.TriggerEvent(QuestAcceptTrigger); }