Пример #1
0
 protected void CountTrueParents(QuestNodeState requiredState, out int nonoptionalCount, out int optionalCount, out int totalCount)
 {
     nonoptionalCount = 0;
     optionalCount    = 0;
     if (questNode != null && questNode.parentList != null)
     {
         for (int i = 0; i < questNode.parentList.Count; i++)
         {
             var parentNode = questNode.parentList[i];
             if (parentNode == null)
             {
                 continue;
             }
             if (parentNode.GetState() != requiredState)
             {
                 continue;
             }
             if (parentNode.isOptional)
             {
                 optionalCount++;
             }
             else
             {
                 nonoptionalCount++;
             }
         }
     }
     totalCount = nonoptionalCount + optionalCount;
 }
        public static bool GetQuestNodeStateFoldout(QuestNodeState questNodeState, int nodeIndex)
        {
            var list = GetQuestNodeStateFoldoutList(questNodeState);

            VerifyListSize(list, nodeIndex, true);
            return(list[nodeIndex]);
        }
Пример #3
0
 public CallbackArgs(CallbackType callbackType, QuestNodeType questNodeType, Vector2 mousePosition, int clickedIndex)
 {
     this.callbackType  = callbackType;
     this.clickedIndex  = clickedIndex;
     this.questNodeType = questNodeType;
     this.mousePosition = mousePosition;
     this.newState      = QuestNodeState.Inactive;
 }
Пример #4
0
 public CallbackArgs(CallbackType callbackType, int clickedIndex, QuestNodeState newState)
 {
     this.callbackType  = callbackType;
     this.clickedIndex  = -1;
     this.questNodeType = QuestNodeType.Success;
     this.mousePosition = Vector2.zero;
     this.newState      = newState;
 }
Пример #5
0
 public void InitializeAsStartNode(string questID)
 {
     id            = new StringField(questID + ".start");
     internalName  = new StringField("Start");
     nodeType      = QuestNodeType.Start;
     m_state       = QuestNodeState.Inactive;
     stateInfoList = new List <QuestStateInfo>();
     canvasRect    = new Rect(DefaultStartNodeX, DefaultStartNodeY, DefaultNodeWidth, DefaultNodeHeight);
 }
        private static List <bool> GetQuestNodeStateFoldoutList(QuestNodeState questNodeState)
        {
            switch (questNodeState)
            {
            case QuestNodeState.Inactive:
                return(data.inactiveFoldouts);

            case QuestNodeState.Active:
                return(data.activeFoldouts);

            case QuestNodeState.True:
                return(data.trueFoldouts);

            default:
                return(null);
            }
        }
Пример #7
0
 public void CopyFrom(QuestNode node)
 {
     if (node == null)
     {
         Debug.LogWarning("Quest Machine: QuestNodeProxy.CopyFrom source is null.");
         return;
     }
     id       = StringField.GetStringValue(node.id);
     intName  = StringField.GetStringValue(node.internalName);
     type     = node.nodeType;
     optional = node.isOptional;
     state    = node.GetState();
     speaker  = StringField.GetStringValue(node.speaker);
     states   = QuestStateInfoProxy.NewArray(node.stateInfoList);
     conds    = new QuestConditionSetProxy(node.conditionSet);
     tags     = new TagDictionary(node.tagDictionary);
     childIdx = node.childIndexList.ToArray();
     r        = QuestProxy.includeCanvasRect ? ((int)node.canvasRect.x + ";" + (int)node.canvasRect.y + ";" + (int)node.canvasRect.width + ";" + (int)node.canvasRect.height) : string.Empty;
 }
Пример #8
0
        /// <summary>
        /// Sets the quest node to a state. The quest and quest node are specified
        /// in the questID and questNodeID properties.
        /// </summary>
        /// <param name="state">New state.</param>
        public void SetQuestNodeState(QuestNodeState state)
        {
            var quest = QuestMachine.GetQuestInstance(questID);

            if (quest == null)
            {
                if (QuestMachine.debug)
                {
                    Debug.LogWarning("Quest Machine: Can't find quest with ID '" + questID + "' to set the state of node with ID '" + questNodeID + "'.", this);
                }
                return;
            }
            var questNode = quest.GetNode(questNodeID);

            if (questNode == null)
            {
                if (QuestMachine.debug)
                {
                    Debug.LogWarning("Quest Machine: Can't find node with ID '" + questNodeID + "' in quest '" + questID + "' to set its state.", this);
                }
                return;
            }
            questNode.SetState(state);
        }
Пример #9
0
        /// <summary>
        /// Sets a quest node's state.
        /// </summary>
        /// <param name="questID">The quest's ID.</param>
        /// <param name="questNodeID">The quest node's ID.</param>
        /// <param name="state">The quest node's new state.</param>
        public static void SetQuestNodeState(string questID, string questNodeID, QuestNodeState state, string questerID = null)
        {
            var quest = GetQuestInstance(questID, questerID);

            if (quest == null)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning("Quest Machine: SetQuestNodeState(" + questID + ", " + questNodeID + ", " + state + "): Couldn't find a quest with ID '" + questID + "'.");
                }
                return;
            }
            var node = quest.GetNode(questNodeID);

            if (node == null)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning("Quest Machine: SetQuestNodeState(" + questID + ", " + questNodeID + ", " + state + "): Quest doesn't have a node with ID '" + questNodeID + "'.");
                }
                return;
            }
            node.SetState(state);
        }
        public void SetState(QuestNodeState state)
        {
            if (m_State == state)
            {
                return;
            }

            m_State = state;
            SetConditionsActive(state == QuestNodeState.Active);

            switch (m_State)
            {
            case QuestNodeState.Succeeded:
                ExecuteTriggerList(m_SuccessTriggers);
                break;

            case QuestNodeState.Failed:
                ExecuteTriggerList(m_FailedTriggers);
                break;

            default:
                break;
            }
        }
Пример #11
0
 public static QuestStateInfo GetStateInfo(List <QuestStateInfo> stateInfoList, QuestNodeState questNodeState)
 {
     ValidateStateInfoListCount(stateInfoList, GetNumQuestNodeStates());
     return(stateInfoList[(int)questNodeState]);
 }
Пример #12
0
 public static void SetQuestNodeState(StringField questID, StringField questNodeID, QuestNodeState state, string questerID = null)
 {
     SetQuestNodeState(StringField.GetStringValue(questID), StringField.GetStringValue(questNodeID), state, questerID);
 }
 public static void QuestNodeStateChanged(object sender, StringField questID, StringField questNodeID, QuestNodeState state)
 {
     MessageSystem.SendMessage(sender, QuestStateChangedMessage, questID, questNodeID, state);
 }
        public void Draw(SerializedObject serializedObject, SerializedProperty stateInfoProperty, int nodeIndex, QuestNodeState questNodeState)
        {
            if (serializedObject == null || stateInfoProperty == null)
            {
                return;
            }

            var foldout    = QuestEditorPrefs.GetQuestNodeStateFoldout(questNodeState, nodeIndex);
            var newFoldout = QuestEditorUtility.EditorGUILayoutFoldout(questNodeState.ToString(), string.Empty, foldout, false);

            if (newFoldout != foldout)
            {
                QuestEditorPrefs.ToggleQuestNodeStateFoldout(questNodeState, nodeIndex);
            }
            if (!newFoldout)
            {
                return;
            }

            if (m_categorizedContentDrawer == null)
            {
                m_categorizedContentDrawer = new CategorizedQuestContentInspectorGUI();
            }
            if (m_questActionListDrawer == null)
            {
                m_questActionListDrawer = new QuestActionListInspectorGUI(new GUIContent("Actions", "Actions that run when the quest node enters this state."));
            }
            QuestEditorUtility.EditorGUILayoutBeginIndent();

            var categorizedContentListProperty = stateInfoProperty.FindPropertyRelative("m_categorizedContentList");

            m_categorizedContentDrawer.Draw(serializedObject, categorizedContentListProperty);

            var actionListProperty = stateInfoProperty.FindPropertyRelative("m_actionList");

            m_questActionListDrawer.Draw(actionListProperty);

            QuestEditorUtility.EditorGUILayoutEndIndent();
            EditorGUILayout.Space();
        }
Пример #15
0
 /// <summary>
 /// Returns the state info associated with a quest node state.
 /// </summary>
 public QuestStateInfo GetStateInfo(QuestNodeState state)
 {
     return((stateInfoList != null) ? QuestStateInfo.GetStateInfo(stateInfoList, state) : null);
 }
Пример #16
0
 /// <summary>
 /// Sets the internal state value without performing any state change processing.
 /// </summary>
 public void SetStateRaw(QuestNodeState state)
 {
     m_state = state;
 }
Пример #17
0
        /// <summary>
        /// Sets the quest node to a quest state and performs all related activities
        /// such as enabling connections and executing actions. This may cause other
        /// nodes to advance their states, too.
        /// </summary>
        /// <param name="newState">New state.</param>
        public void SetState(QuestNodeState newState, bool informListeners = true)
        {
            if (QuestMachine.debug)
            {
                Debug.Log("Quest Machine: " + ((quest != null) ? quest.GetEditorName() : "Quest") + "." + GetEditorName() + ".SetState(" + newState + ")", quest);
            }

            m_state = newState;

            SetConditionChecking(newState == QuestNodeState.Active);

            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)
                    {
                        continue;
                    }
                    stateInfo.actionList[i].Execute();
                }
            }

            // Notify that state changed:
            QuestMachineMessages.QuestNodeStateChanged(this, quest.id, 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);
                }
            }

            // Handle special node types:
            switch (m_state)
            {
            case QuestNodeState.Active:
                if (nodeType != QuestNodeType.Condition)
                {
                    // Automatically switch non-Condition nodes to True state:
                    SetState(QuestNodeState.True);
                }
                break;

            case QuestNodeState.True:
                // If it's an endpoint, set the overall quest state:
                switch (nodeType)
                {
                case QuestNodeType.Success:
                    if (quest != null)
                    {
                        quest.SetState(QuestState.Successful);
                    }
                    break;

                case QuestNodeType.Failure:
                    if (quest != null)
                    {
                        quest.SetState(QuestState.Failed);
                    }
                    break;
                }
                break;
            }
        }
Пример #18
0
        public static void ToggleQuestNodeStateFoldout(QuestNodeState questNodeState, int nodeIndex)
        {
            var list = GetQuestNodeStateFoldoutList(questNodeState);

            list[nodeIndex] = !GetQuestNodeStateFoldout(questNodeState, nodeIndex);
        }