using System; using System.Collections; using System.Collections.Generic; using System.Linq; using Gaia; using UnityEngine; using PixelCrushers; using PixelCrushers.QuestMachine; namespace Beyond { public class QuestStateEventLoader : Singleton { public bool trigger = false; private void Awake() { SaveSystem.saveDataApplied += SaveSystemOnSaveDataApplied; } private void SaveSystemOnSaveDataApplied() { SaveSystem.saveDataApplied -= SaveSystemOnSaveDataApplied; if (trigger) TriggerActiveQuestSceneEvent(); } private void TriggerActiveQuestSceneEvent() { if (Player.Instance.QuestJournal.questList.Count == 0) return; List questList = new List(Player.Instance.QuestJournal.questList); for (int i = 0; i < questList.Count; i++) { Quest currentQuest = questList[i]; if (currentQuest == null) { Debug.LogError("Quest after load is null"); continue; } if (!currentQuest.isTrackable) { continue; } switch (currentQuest.GetState()) { case QuestState.Active: for (int nodeIndex = 0; nodeIndex < currentQuest.nodeList.Count; nodeIndex++) { QuestNode currentNode = currentQuest.nodeList[nodeIndex]; QuestStateInfo stateInfo = currentNode.GetStateInfo(currentNode.GetState()); for (int j = 0; j < stateInfo.actionList.Count; j++) { stateInfo.actionList[j]?.Execute(); if (currentNode.GetState() == QuestNodeState.Active) { break; } } } break; case QuestState.Successful: for (int nodeIndex = 0; nodeIndex < currentQuest.nodeList.Count; nodeIndex++) { QuestStateInfo finishedQuestStateInfo = currentQuest.nodeList[nodeIndex] .GetStateInfo(currentQuest.nodeList[nodeIndex].GetState()); for (int actionIndex = 0; actionIndex < finishedQuestStateInfo.actionList.Count; actionIndex++) { finishedQuestStateInfo.actionList[actionIndex]?.Execute(); } } break; } } } } }