예제 #1
0
 private void SetParent(QuestNode parent)
 {
     if (parent == null)
     {
         return;
     }
     if (parentList == null)
     {
         parentList = new List <QuestNode>();
     }
     parentList.Add(parent);
     if (parent.isOptional)
     {
         if (optionalParentList == null)
         {
             optionalParentList = new List <QuestNode>();
         }
         optionalParentList.Add(parent);
     }
     else
     {
         if (nonoptionalParentList == null)
         {
             nonoptionalParentList = new List <QuestNode>();
         }
         nonoptionalParentList.Add(parent);
     }
     parent.stateChanged -= OnParentStateChange;
     parent.stateChanged += OnParentStateChange;
 }
        protected void AddSuccessNode(Quest quest, QuestNode node)
        {
            if (node == null)
            {
                return;
            }
            foreach (var index in node.childIndexList)
            {
                if (!(0 <= index && index < quest.nodeList.Count))
                {
                    continue;
                }
                var checkNode = quest.nodeList[index];
                if (checkNode.nodeType == QuestNodeType.Success)
                {
                    return;                                              // Already leads to success. Do nothing.
                }
            }
            for (int i = 0; i < quest.nodeList.Count; i++)
            {
                if (quest.nodeList[i].nodeType == QuestNodeType.Success)
                {
                    node.childIndexList.Add(i); // Add link to existing success node.
                    return;
                }
            }
            // Otherwise add new success node:
            var successNode = new QuestNode(new StringField("Success"), new StringField(), QuestNodeType.Success);

            quest.nodeList.Add(successNode);
            node.childIndexList.Add(quest.nodeList.Count - 1);
            successNode.canvasRect = new Rect(node.canvasRect.x, node.canvasRect.y + 10 + QuestNode.DefaultNodeHeight, QuestNode.DefaultNodeWidth, QuestNode.DefaultNodeHeight);
        }
예제 #3
0
        public QuestNode AddNode(QuestNode parent, StringField id, StringField internalName, QuestNodeType nodeType, bool isOptional = false)
        {
            if (parent == null)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning("Quest Machine: QuestBuilder.AddNode must be provided a valid parent node.");
                }
                return(null);
            }
            if (parent.childIndexList == null)
            {
                return(null);
            }
            parent.childIndexList.Add(quest.nodeList.Count);
            var node = new QuestNode(id, internalName, nodeType, isOptional);

            node.canvasRect = new Rect(parent.canvasRect.x, parent.canvasRect.y + 20 + QuestNode.DefaultNodeHeight, QuestNode.DefaultNodeWidth, QuestNode.DefaultNodeHeight);
            quest.nodeList.Add(node);
            QuestStateInfo.ValidateStateInfoListCount(node.stateInfoList);
            QuestStateInfo.ValidateCategorizedContentListCount(node.stateInfoList[(int)QuestNodeState.Active].categorizedContentList);
            QuestStateInfo.ValidateCategorizedContentListCount(node.stateInfoList[(int)QuestNodeState.Inactive].categorizedContentList);
            QuestStateInfo.ValidateCategorizedContentListCount(node.stateInfoList[(int)QuestNodeState.True].categorizedContentList);
            return(node);
        }
예제 #4
0
        public QuestNode AddDiscussQuestNode(QuestNode parent, QuestMessageParticipant targetSpecifier, StringField targetID, bool isOptional = false)
        {
            var node = AddConditionNode(parent, "talkTo" + targetID, "Talk to " + targetID, ConditionCountMode.All, isOptional);

            AddMessageCondition(node, QuestMessageParticipant.Quester, new StringField(), targetSpecifier, targetID, new StringField(QuestMachineMessages.DiscussedQuestMessage), quest.id);
            return(node);
        }
예제 #5
0
 public void CopyTo(QuestNode node)
 {
     if (node == null)
     {
         Debug.LogWarning("Quest Machine: QuestNodeProxy.CopyTo destination is null.");
         return;
     }
     node.id             = new StringField(id);
     node.internalName   = new StringField(intName);
     node.nodeType       = type;
     node.isOptional     = optional;
     node.speaker        = new StringField(speaker);
     node.stateInfoList  = QuestStateInfoProxy.CreateList(states);
     node.conditionSet   = conds.CreateConditionSet();
     node.tagDictionary  = new TagDictionary(tags);
     node.childIndexList = new List <int>(childIdx);
     if (QuestProxy.includeCanvasRect && !string.IsNullOrEmpty(r))
     {
         var fields = r.Split(';');
         if (fields.Length == 4)
         {
             node.canvasRect = new Rect(SafeConvert.ToFloat(fields[0]), SafeConvert.ToFloat(fields[1]), SafeConvert.ToFloat(fields[2]), SafeConvert.ToFloat(fields[3]));
         }
     }
 }
예제 #6
0
 /// <summary>
 /// Invoked by parent when parent's state changes.
 /// </summary>
 /// <param name="parent">Parent node whose state changed.</param>
 private void OnParentStateChange(QuestNode parent)
 {
     if (parent != null && parent.GetState() == QuestNodeState.True && quest != null && quest.GetState() == QuestState.Active && GetState() != QuestNodeState.True)
     {
         SetState(QuestNodeState.Active);
     }
 }
예제 #7
0
 public MessageQuestCondition AddMessageCondition(QuestNode node,
                                                  QuestMessageParticipant senderSpecifier, string senderID,
                                                  QuestMessageParticipant targetSpecifier, string targetID,
                                                  string message, string parameter, MessageValue value = null)
 {
     return(AddMessageCondition(node, senderSpecifier, new StringField(targetID), targetSpecifier, new StringField(targetID),
                                new StringField(message), new StringField(parameter), value));
 }
 private void MoveTextToTextTable(QuestNode node, TextTable textTable)
 {
     if (node == null)
     {
         return;
     }
     MoveTextToTextTable(node.stateInfoList, textTable);
 }
예제 #9
0
 private void DeleteNodeConditionSubassets(QuestNode node)
 {
     if (node == null)
     {
         return;
     }
     DeleteSubassetsFromList(node.conditionSet.conditionList);
 }
예제 #10
0
 public static void AddQuestTagsToTextTable(QuestNode node, TextTable textTable)
 {
     if (node == null)
     {
         return;
     }
     AddQuestTagsToTextTable(node.stateInfoList, textTable);
 }
예제 #11
0
 private static void AddNodeSubassetsToList(QuestNode questNode, List <QuestSubasset> subassets)
 {
     if (questNode == null || subassets == null)
     {
         return;
     }
     AddConditionSetSubassetsToList(questNode.conditionSet, subassets);
     AddStateInfoListSubassetsToList(questNode.stateInfoList, subassets);
 }
예제 #12
0
 public override void SetRuntimeReferences(Quest quest, QuestNode questNode)
 {
     base.SetRuntimeReferences(quest, questNode);
     for (int i = 0; i < contentList.Count; i++)
     {
         if (contentList[i] != null)
         {
             contentList[i].SetRuntimeReferences(quest, questNode);
         }
     }
 }
예제 #13
0
        public CounterQuestCondition AddCounterCondition(QuestNode node, StringField counterName, CounterValueConditionMode conditionMode, QuestNumber requiredValue)
        {
            var condition = CounterQuestCondition.CreateInstance <CounterQuestCondition>();

            condition.name                 = "counterCondition";
            condition.counterIndex         = quest.GetCounterIndex(counterName);
            condition.counterValueMode     = conditionMode;
            condition.requiredCounterValue = requiredValue;
            node.conditionSet.conditionList.Add(condition);
            return(condition);
        }
예제 #14
0
 public void CloneSubassetsInto(QuestNode copy)
 {
     // Assumes lists are identical except subassets haven't been copied.
     if (copy == null)
     {
         return;
     }
     conditionSet.CloneSubassetsInto(copy.conditionSet);
     QuestStateInfo.CloneSubassets(stateInfoList, copy.stateInfoList);
     tagDictionary.CopyInto(copy.tagDictionary);
 }
예제 #15
0
        public QuestNode AddConditionNode(QuestNode parent, StringField id, StringField internalName, ConditionCountMode conditionCountMode = ConditionCountMode.All, bool isOptional = false)
        {
            var node = AddNode(parent, id, internalName, QuestNodeType.Condition, isOptional);

            if (node == null)
            {
                return(null);
            }
            node.conditionSet.conditionCountMode = conditionCountMode;
            return(node);
        }
예제 #16
0
        /// <summary>
        /// Adds actions to set up the quest giver's quest indicators to the return node.
        /// </summary>
        protected virtual void AddReturnNodeIndicators(QuestBuilder questBuilder, QuestNode returnNode, List <QuestAction> actionList, QuestEntity entity)
        {
            // Indicator when active:
            var indicatorAction = questBuilder.CreateSetIndicatorAction(questBuilder.quest.id, entity.id, QuestIndicatorState.Talk);

            actionList.Add(indicatorAction);

            // Indicator when true:
            indicatorAction = questBuilder.CreateSetIndicatorAction(questBuilder.quest.id, entity.id, QuestIndicatorState.None);
            actionList      = returnNode.GetStateInfo(QuestNodeState.True).actionList;
            actionList.Add(indicatorAction);
        }
예제 #17
0
        private static void WriteQuestNodeDataToStream(BinaryWriter binaryWriter, QuestNode node)
        {
            if (node == null)
            {
                return;
            }
            var state = node.GetState();

            binaryWriter.Write((byte)state);
            WriteConditionSetDataToStream(binaryWriter, node.conditionSet);
            WriteTagDictionaryToStream(binaryWriter, node.tagDictionary, StringField.GetStringValue(node.internalName));
        }
예제 #18
0
        protected void OnParentStateChange(QuestNode parentNode)
        {
            if (QuestMachine.debug)
            {
                Debug.Log("Quest Machine: ParentCountQuestCondition.OnParentStateChange(" + ((parentNode != null) ? parentNode.GetEditorName() : "null") + ")", quest);
            }
            var parentIsTrue = (parentNode != null && parentNode.GetState() == QuestNodeState.True);

            if (parentIsTrue)
            {
                CheckTrueParentCount();
            }
        }
 public void SetRuntimeReferences(Quest quest, QuestNode questNode)
 {
     if (conditionList == null)
     {
         return;
     }
     for (int i = 0; i < conditionList.Count; i++)
     {
         if (conditionList[i] != null)
         {
             conditionList[i].SetRuntimeReferences(quest, questNode);
         }
     }
 }
 public override void SetRuntimeReferences(Quest quest, QuestNode questNode)
 {
     base.SetRuntimeReferences(quest, questNode);
     if (actionList == null)
     {
         return;
     }
     for (int i = 0; i < actionList.Count; i++)
     {
         if (actionList[i] == null)
         {
             continue;
         }
         actionList[i].SetRuntimeReferences(quest, questNode);
     }
 }
예제 #21
0
        public static List <QuestNode> CreateList(QuestNodeProxy[] nodesProxy)
        {
            var list = new List <QuestNode>();

            if (nodesProxy == null)
            {
                Debug.LogWarning("Quest Machine: QuestNodeProxy.CreateList source is null.");
                return(list);
            }
            for (int i = 0; i < nodesProxy.Length; i++)
            {
                var node = new QuestNode();
                nodesProxy[i].CopyTo(node);
                list.Add(node);
            }
            return(list);
        }
예제 #22
0
 private void DeleteNodeStateInfoListSubassets(QuestNode node)
 {
     if (node == null)
     {
         return;
     }
     for (int i = 0; i < node.stateInfoList.Count; i++)
     {
         var stateInfo = node.stateInfoList[i];
         if (stateInfo == null)
         {
             continue;
         }
         DeleteSubassetsFromList(stateInfo.actionList);
         DeleteCategorizedContentListSubassets(stateInfo.categorizedContentList);
     }
 }
예제 #23
0
        /// <summary>
        /// Returns a new instance of the quest, including new instances of all subassets
        /// such as QuestAction, QuestCondition, and QuestContent subassets.
        /// </summary>
        public Quest Clone()
        {
            var clone = Instantiate(this);

            SetRuntimeReferences(); // Fix original's references since Instantiate calls OnEnable > SetRuntimeReferences while clone's fields still point to original.
            clone.isInstance    = true;
            clone.originalAsset = originalAsset;
            autostartConditionSet.CloneSubassetsInto(clone.autostartConditionSet);
            offerConditionSet.CloneSubassetsInto(clone.offerConditionSet);
            clone.offerConditionsUnmetContentList = QuestSubasset.CloneList(offerConditionsUnmetContentList);
            clone.offerContentList = QuestSubasset.CloneList(offerContentList);
            QuestStateInfo.CloneSubassets(stateInfoList, clone.stateInfoList);
            QuestNode.CloneSubassets(nodeList, clone.nodeList);
            tagDictionary.CopyInto(clone.tagDictionary);
            clone.SetRuntimeReferences();
            return(clone);
        }
예제 #24
0
        public MessageQuestCondition AddMessageCondition(QuestNode node,
                                                         QuestMessageParticipant senderSpecifier, StringField senderID,
                                                         QuestMessageParticipant targetSpecifier, StringField targetID,
                                                         StringField message, StringField parameter, MessageValue value = null)
        {
            var condition = MessageQuestCondition.CreateInstance <MessageQuestCondition>();

            condition.name            = "messageCondition";
            condition.senderSpecifier = senderSpecifier;
            condition.senderID        = senderID;
            condition.targetSpecifier = targetSpecifier;
            condition.targetID        = targetID;
            condition.message         = message;
            condition.parameter       = parameter;
            condition.value           = (value != null) ? value : new MessageValue();
            node.conditionSet.conditionList.Add(condition);
            return(condition);
        }
예제 #25
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;
 }
예제 #26
0
 private void OnDestroy()
 {
     if (isInstance && Application.isPlaying)
     {
         QuestMachine.UnregisterQuestInstance(this);
         SetState(QuestState.Disabled);
         if (autostartConditionSet != null)
         {
             autostartConditionSet.DestroySubassets();
         }
         if (offerConditionSet != null)
         {
             offerConditionSet.DestroySubassets();
         }
         QuestSubasset.DestroyList(offerConditionsUnmetContentList);
         QuestSubasset.DestroyList(offerContentList);
         QuestStateInfo.DestroyListSubassets(stateInfoList);
         QuestNode.DestroyListSubassets(nodeList);
     }
 }
예제 #27
0
        /// <summary>
        /// Adds the text for a step.
        /// </summary>
        protected virtual void AddStepNodeText(QuestBuilder questBuilder, QuestNode conditionNode, QuestStateInfo activeState, string targetEntity, string targetDescriptor, string domainName, string counterName, int requiredCounterValue, PlanStep step)
        {
            // Text for condition node's Active state:
            var taskText     = ReplaceStepTags(step.action.actionText.activeText.dialogueText.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue);
            var bodyText     = questBuilder.CreateBodyContent(taskText);
            var dialogueList = activeState.categorizedContentList[(int)QuestContentCategory.Dialogue];

            dialogueList.contentList.Add(bodyText);

            var jrlText     = ReplaceStepTags(step.action.actionText.activeText.journalText.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue);
            var jrlbodyText = questBuilder.CreateBodyContent(jrlText);
            var journalList = activeState.categorizedContentList[(int)QuestContentCategory.Journal];

            journalList.contentList.Add(jrlbodyText);

            var hudText     = ReplaceStepTags(step.action.actionText.activeText.hudText.value, targetEntity, targetDescriptor, domainName, counterName, requiredCounterValue);
            var hudbodyText = questBuilder.CreateBodyContent(hudText);
            var hudList     = activeState.categorizedContentList[(int)QuestContentCategory.HUD];

            hudList.contentList.Add(hudbodyText);
        }
예제 #28
0
        /// <summary>
        /// Adds UI content to the return node.
        /// </summary>
        protected virtual void AddReturnNodeText(QuestBuilder questBuilder, QuestNode returnNode, QuestGiver questGiver, string mainTargetEntity, string mainTargetDescriptor, string domainName, PlanStep goal, string hudText)
        {
            var stateInfo = returnNode.stateInfoList[(int)QuestNodeState.Active];

            QuestStateInfo.ValidateCategorizedContentListCount(stateInfo.categorizedContentList);
            var successText  = ReplaceStepTags(StringField.GetStringValue(goal.action.actionText.successText), mainTargetEntity, mainTargetDescriptor, domainName, string.Empty, 0);
            var bodyText     = questBuilder.CreateBodyContent(successText);
            var dialogueList = returnNode.stateInfoList[(int)QuestNodeState.Active].categorizedContentList[(int)QuestContentCategory.Dialogue];

            dialogueList.contentList.Add(bodyText);

            var jrlText     = "{Return to} " + questGiver.displayName;
            var jrlBodyText = questBuilder.CreateBodyContent(jrlText);
            var journalList = returnNode.stateInfoList[(int)QuestNodeState.Active].categorizedContentList[(int)QuestContentCategory.Journal];

            journalList.contentList.Add(jrlBodyText);

            var hudBodyText = questBuilder.CreateBodyContent(hudText);
            var hudList     = returnNode.stateInfoList[(int)QuestNodeState.Active].categorizedContentList[(int)QuestContentCategory.HUD];

            hudList.contentList.Add(hudBodyText);
        }
예제 #29
0
        /// <summary>
        /// Initializes a quest to empty starting values. Invoked when object is
        /// created by ScriptableObjectUtility.CreateInstance.
        /// </summary>
        public void Initialize()
        {
            // (isInstance & originalAsset are not set here.)
            var instanceID = GetInstanceID();

            id                              = new StringField("Quest" + instanceID);
            title                           = new StringField("Quest " + instanceID);
            icon                            = null;
            group                           = new StringField();
            labels                          = new List <StringField>();
            questGiverID                    = new StringField();
            isTrackable                     = true;
            showInTrackHUD                  = true;
            isAbandonable                   = false;
            rememberIfAbandoned             = false;
            autostartConditionSet           = new QuestConditionSet();
            offerConditionSet               = new QuestConditionSet();
            offerConditionsUnmetContentList = new List <QuestContent>();
            offerContentList                = new List <QuestContent>();
            maxTimes                        = 1;
            timesAccepted                   = 0;
            cooldownSeconds                 = 3600;
            cooldownSecondsRemaining        = 0;
            m_state                         = QuestState.WaitingToStart;
            var numStates = Enum.GetNames(typeof(QuestState)).Length;

            stateInfoList = new List <QuestStateInfo>();
            for (int i = 0; i < numStates; i++)
            {
                stateInfoList.Add(new QuestStateInfo());
            }
            counterList = new List <QuestCounter>();
            var startNode = new QuestNode();

            startNode.InitializeAsStartNode(id.value);
            nodeList = new List <QuestNode>();
            nodeList.Add(startNode);
        }
예제 #30
0
 public void SetRuntimeReferences(Quest quest, QuestNode questNode)
 {
     if (actionList != null)
     {
         for (int i = 0; i < actionList.Count; i++)
         {
             if (actionList[i] != null)
             {
                 actionList[i].SetRuntimeReferences(quest, questNode);
             }
         }
     }
     if (categorizedContentList != null)
     {
         for (int i = 0; i < categorizedContentList.Count; i++)
         {
             if (categorizedContentList[i] != null)
             {
                 categorizedContentList[i].SetRuntimeReferences(quest, questNode);
             }
         }
     }
 }