예제 #1
0
        //------------------------------------------------------------------
        // Load:

        private static void ReadQuestDataFromStream(BinaryReader binaryReader, Quest quest)
        {
            if (quest == null)
            {
                return;
            }
            var state = (QuestState)binaryReader.ReadByte();

            ReadTagDictionaryFromStream(binaryReader, quest.tagDictionary, quest.name);
            quest.questGiverID.value       = binaryReader.ReadString();
            quest.timesAccepted            = binaryReader.ReadInt32();
            quest.cooldownSecondsRemaining = (float)binaryReader.ReadDouble();
            quest.showInTrackHUD           = binaryReader.ReadBoolean();
            ReadConditionSetDataFromStream(binaryReader, quest.autostartConditionSet);
            ReadConditionSetDataFromStream(binaryReader, quest.offerConditionSet);
            if (state == QuestState.WaitingToStart)
            {
                quest.SetState(state, false);
                return;
            }

            // Don't load the info below if waiting to start:
            for (int i = 0; i < quest.counterList.Count; i++)
            {
                quest.counterList[i].SetValue(binaryReader.ReadInt32(), QuestCounterSetValueMode.DontInformListeners);
            }
            for (int i = 0; i < quest.nodeList.Count; i++)
            {
                ReadQuestNodeDataFromStream(binaryReader, quest.nodeList[i]);
            }
            ReadQuestIndicatorsFromStream(binaryReader, quest.indicatorStates);
            quest.SetRuntimeReferences();
            quest.SetState(state, false);
            QuestMachineMessages.QuestStateChanged(quest, quest.id, quest.GetState());
        }
예제 #2
0
        /// <summary>
        /// Sets the quest state. This may also affect the states of the quest's nodes.
        /// </summary>
        /// <param name="newState">The new quest state.</param>
        public void SetState(QuestState newState, bool informListeners = true)
        {
            if (QuestMachine.debug)
            {
                Debug.Log("Quest Machine: " + GetEditorName() + ".SetState(" + newState + ", informListeners=" + informListeners + ")", this);
            }

            m_state = newState;

            SetStartChecking(newState == QuestState.WaitingToStart);
            SetCounterListeners(newState == QuestState.Active || (newState == QuestState.WaitingToStart && (hasAutostartConditions || hasOfferConditions)));
            if (newState != QuestState.Active)
            {
                StopNodeListeners();
            }

            if (!informListeners)
            {
                return;
            }

            // Execute state actions:
            var stateInfo = GetStateInfo(m_state);

            if (stateInfo != null && stateInfo.actionList != null)
            {
                for (int i = 0; i < stateInfo.actionList.Count; i++)
                {
                    if (stateInfo.actionList[i] != null)
                    {
                        stateInfo.actionList[i].Execute();
                    }
                }
            }

            // Notify that state changed:
            QuestMachineMessages.QuestStateChanged(this, id, m_state);
            try
            {
                stateChanged(this);
            }
            catch (Exception e) // Don't let exceptions in user-added events break our code.
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogException(e);
                }
            }

            // If going active, activate the start node:
            if (m_state == QuestState.Active && startNode != null)
            {
                startNode.SetState(QuestNodeState.Active);
            }

            // If inactive, clear the indicators:
            if (m_state != QuestState.Active)
            {
                ClearQuestIndicatorStates();
            }

            // If done, set all active nodes to inactive:
            if (m_state == QuestState.Successful || m_state == QuestState.Failed || m_state == QuestState.Abandoned)
            {
                for (int i = 0; i < nodeList.Count; i++)
                {
                    if (nodeList[i].GetState() == QuestNodeState.Active)
                    {
                        nodeList[i].SetState(QuestNodeState.Inactive);
                    }
                }
            }
        }