public QuestDefinition GetNextAvailableQuest(int chapterNumber = -1) { Quest quest = null; QuestDefinition result = null; List <QuestDefinition> validQuests = GetValidQuests(chapterNumber); for (int i = 0; i < validQuests.Count; i++) { QuestDefinition questDefinition = validQuests[i]; foreach (Quest availableQuest in AvailableQuests) { if (availableQuest.Definition.name == questDefinition.name) { quest = availableQuest; break; } } if (quest == null || quest.State == Quest.QuestState.Locked || quest.TimesCompleted == 0) { result = questDefinition; break; } quest = null; } return(result); }
public Quest(QuestDefinition dQuest, Mascot mascot) { dispatcher = Service.Get <EventDispatcher>(); Definition = dQuest; Mascot = mascot; QuestSubFsms = new Dictionary <string, Fsm>(); state = QuestState.Locked; resetQuestItems(); }
private IEnumerator applyReceivedQuestStates(QuestServiceEvents.QuestStatesRecieved evt) { while (!QuestPlayerIsReady) { yield return(null); } CPDataEntityCollection dataEntityCollection = Service.Get <CPDataEntityCollection>(); foreach (QuestState questState in evt.QuestStates) { if (!questToMascotMap.TryGetValue(questState.questId, out var value)) { continue; } QuestDefinition questDefinition = knownQuests[questState.questId]; if (questDefinition.Prototyped) { continue; } Quest quest = GetQuest(questDefinition, value); if (quest == null) { continue; } if (questState.status == QuestStatus.ACTIVE && (ActiveQuest == null || ActiveQuest != quest) && !quest.IsActivating && pendingQuest != quest && quest.Definition.IsPausable) { trace(Time.time + ": applyReceivedQuestStates() setting " + quest.Id + " to SUSPENDED"); Service.Get <INetworkServicesManager>().QuestService.SetStatus(questState.questId, QuestStatus.SUSPENDED); continue; } trace(Time.time + ": applyReceivedQuestStates() quest.UpdateState()"); quest.UpdateState(questState); if (quest.State == Quest.QuestState.Suspended) { if (!value.ResumableQuests.Contains(quest)) { value.ResumableQuests.Add(quest); } } else if (quest == ActiveQuest && !quest.IsActivating) { trace(Time.time + ": applyReceivedQuestStates() calling RestoreAsync()"); GameObjectReferenceData component = dataEntityCollection.GetComponent <GameObjectReferenceData>(dataEntityCollection.LocalPlayerHandle); if (component != null) { quest.RestoreAsync(component.GameObject); } } if (quest.TimesCompleted == 0 && (quest.State == Quest.QuestState.Available || quest.State == Quest.QuestState.Suspended)) { AdventureReminderTutorial.SetAvailableAdventureTimestamp(value.Name); } } dispatcher.DispatchEvent(default(QuestEvents.QuestSyncCompleted)); IsQuestDataRecieved = true; }
public void UpdateLockedState() { bool flag = false; if (Definition.isMemberOnly && !Service.Get <CPDataEntityCollection>().IsLocalPlayerMember()) { flag = true; } if (!flag) { int num = Service.Get <ProgressionService>().MascotLevel(Definition.Mascot.name); if (num < Definition.LevelRequirement) { flag = true; } } if (!flag) { Mascot mascot = null; QuestDefinition questDefinition = null; bool flag2 = false; bool flag3 = false; for (int i = 0; i < Definition.CompletedQuestRequirement.Length; i++) { questDefinition = Definition.CompletedQuestRequirement[i]; mascot = Service.Get <MascotService>().GetMascot(questDefinition.Mascot.name); foreach (Quest availableQuest in mascot.AvailableQuests) { if (availableQuest.Definition.name == questDefinition.name) { flag2 = true; if (availableQuest.TimesCompleted == 0) { flag3 = true; break; } } } } if (flag3 || !flag2) { flag = true; } } if (!flag && unlockedTimeMilliseconds > Service.Get <INetworkServicesManager>().GameTimeMilliseconds) { flag = true; } if (!flag) { state = QuestState.Available; } }
public List <QuestDefinition> GetValidQuests(int chapterNumber = -1) { List <QuestDefinition> list = new List <QuestDefinition>(); for (int i = 0; i < KnownQuests.Length; i++) { QuestDefinition questDefinition = KnownQuests[i]; if (!questDefinition.Prototyped && (chapterNumber == -1 || questDefinition.ChapterNumber == chapterNumber)) { list.Add(KnownQuests[i]); } } return(list); }
public QuestService(Manifest manifest, PersistentBreadcrumbTypeDefinitionKey breadcrumbType) { this.breadcrumbType = breadcrumbType; dispatcher = Service.Get <EventDispatcher>(); MascotService mascotService = Service.Get <MascotService>(); List <QuestDefinition> list = new List <QuestDefinition>(); ScriptableObject[] assets = manifest.Assets; foreach (ScriptableObject scriptableObject in assets) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(scriptableObject.name); Mascot mascot = mascotService.GetMascot(fileNameWithoutExtension); ScriptableObject[] assets2 = ((Manifest)scriptableObject).Assets; foreach (ScriptableObject scriptableObject2 in assets2) { QuestDefinition questDefinition = (QuestDefinition)scriptableObject2; knownQuests[scriptableObject2.name] = questDefinition; questToMascotMap[scriptableObject2.name] = mascot; list.Add(questDefinition); } mascot.KnownQuests = list.ToArray(); list.Clear(); } eventChannel = new EventChannel(dispatcher); eventChannel.AddListener <QuestEvents.SuspendQuest>(onSuspendQuestRequest); eventChannel.AddListener <QuestEvents.ResumeQuest>(onResumeQuestRequest); eventChannel.AddListener <QuestEvents.StartQuest>(onStartQuestRequest); eventChannel.AddListener <QuestEvents.ReplayQuest>(onReplayQuestRequest); eventChannel.AddListener <QuestEvents.RestartQuest>(onRestartQuestRequest); eventChannel.AddListener <SplashScreenEvents.SplashScreenOpened>(onSplashScreenOpened); eventChannel.AddListener <SplashScreenEvents.SplashScreenClosed>(onSplashScreenClosed); eventChannel.AddListener <QuestEvents.QuestUpdated>(onQuestUpdated); eventChannel.AddListener <QuestEvents.QuestInitializationComplete>(onQuestInitializationComplete); eventChannel.AddListener <RewardEvents.RewardPopupComplete>(onRewardPopupComplete); eventChannel.AddListener <QuestEvents.SetPlayerOutOfWorld>(onSetPlayerOutOfWorld); eventChannel.AddListener <SceneTransitionEvents.TransitionStart>(onSceneTransition); eventChannel.AddListener <QuestEvents.RegisterQuestSubFsm>(onRegisterQuestSubFsm); eventChannel.AddListener <InWorldUIEvents.DisableActionIndicators>(onDisableActionIndicators); eventChannel.AddListener <InWorldUIEvents.EnableActionIndicators>(onEnableActionIndicators); eventChannel.AddListener <QuestServiceEvents.QuestStatesRecieved>(onQuestStatesReceived); eventChannel.AddListener <QuestServiceErrors.QuestProgressionError>(onQuestProgressionError); eventChannel.AddListener <ProgressionEvents.LevelUp>(onLevelUp); updateQuestGivers(0); timeLockedCheckTimer = new Timer(2f, repeat: true, delegate { onTimerTick(); }); CoroutineRunner.StartPersistent(timeLockedCheckTimer.Start(), this, "timeLockedQuestTimer"); }
public Quest GetQuest(QuestDefinition questDef, Mascot mascot = null, bool createIfNotFound = true) { if (!availableQuests.TryGetValue(questDef.name, out var value) && createIfNotFound) { if (mascot == null) { mascot = questToMascotMap[questDef.name]; } trace("Creating quest {0}", questDef.name); value = new Quest(questDef, mascot); availableQuests[questDef.name] = value; mascot.AvailableQuests.Add(value); value.StateChanged += onQuestStateChanged; } return(value); }
private void updateQuestGivers(int playerLevel) { trace("Updating quest givers for playerlevel {0}", playerLevel); foreach (KeyValuePair <string, QuestDefinition> knownQuest in knownQuests) { if (availableQuests.ContainsKey(knownQuest.Key)) { continue; } QuestDefinition value = knownQuest.Value; bool flag = playerLevel >= value.LevelRequirement; if (flag) { trace("Checking completed requirements for quest {0}", knownQuest.Key); QuestDefinition[] completedQuestRequirement = value.CompletedQuestRequirement; foreach (QuestDefinition questDefinition in completedQuestRequirement) { if (availableQuests.TryGetValue(questDefinition.name, out var value2)) { if (value2.State != Quest.QuestState.Completed) { flag = false; break; } continue; } flag = false; break; } } if (flag) { Mascot mascot = questToMascotMap[value.name]; GetQuest(value, mascot); } } }
private void showGivingQuestDialog(Mascot mascot) { DialogList dialogList = null; bool flag = false; bool flag2 = false; bool flag3 = true; QuestDefinition questDefinition = null; Quest quest = null; for (int i = 0; i < mascot.KnownQuests.Length; i++) { questDefinition = mascot.KnownQuests[i]; if (questDefinition.Prototyped) { continue; } for (int j = 0; j < mascot.AvailableQuests.Count; j++) { if (mascot.AvailableQuests[j].Definition.Title == questDefinition.Title) { quest = mascot.AvailableQuests[j]; break; } } if (quest != null && quest.TimesCompleted == 0) { flag3 = false; if (quest.State != Quest.QuestState.Locked && (!questDefinition.isMemberOnly || Service.Get <CPDataEntityCollection>().IsLocalPlayerMember())) { dialogList = Definition.QuestGiverDialog; break; } } if (quest == null || quest.State == Quest.QuestState.Locked) { int num = Service.Get <ProgressionService>().MascotLevel(mascot.Definition.name); if (questDefinition.LevelRequirement > num) { flag2 = true; } else { flag = true; } flag3 = false; } quest = null; } if (dialogList == null && !Service.Get <CPDataEntityCollection>().IsLocalPlayerMember()) { dialogList = Definition.QuestGiverDialogMemberLocked; } else if (flag3) { dialogList = Definition.QuestGiverDialogAllComplete; } else if (dialogList == null) { if (flag) { dialogList = Definition.QuestGiverDialogTimeLocked; } else if (flag2) { dialogList = Definition.QuestGiverDialogLevelLocked; } } if (dialogList == null || dialogList.Entries.Length == 0) { dialogList = Definition.QuestGiverDialog; } showDialog(dialogList.SelectRandom(), false); }