protected virtual void OnCounterChanged(QuestCounter counter)
 {
     if (IsCounterConditionTrue(counter))
     {
         SetTrue();
     }
 }
Ejemplo n.º 2
0
        public QuestCounter AddCounter(StringField counterName, int initialValue, int minValue, int maxValue, bool randomizeInitialValue, QuestCounterUpdateMode updateMode)
        {
            if (quest.counterList.Find(x => StringField.Equals(x.name, counterName)) != null)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning("Quest Machine: Counter '" + counterName + "' already exists in QuestBuilder.");
                }
                return(null);
            }
            var counter = new QuestCounter(counterName, initialValue, minValue, maxValue, updateMode);

            quest.counterList.Add(counter);
            return(counter);
        }
Ejemplo n.º 3
0
 public void CopyTo(QuestCounter counter)
 {
     if (counter == null)
     {
         Debug.LogWarning("Quest Machine: QuestCounterProxy.CopyTo destination is null.");
         return;
     }
     counter.name = new StringField(name);
     counter.SetValue(val, QuestCounterSetValueMode.DontInformListeners);
     counter.minValue = min;
     counter.maxValue = max;
     counter.randomizeInitialValue = rand;
     counter.updateMode            = mode;
     counter.messageEventList      = QuestCounterMessageEventProxy.CreateList(messages);
 }
Ejemplo n.º 4
0
 public void CopyFrom(QuestCounter counter)
 {
     if (counter == null)
     {
         Debug.LogWarning("Quest Machine: QuestCounterProxy.CopyFrom source is null.");
         return;
     }
     name     = StringField.GetStringValue(counter.name);
     val      = counter.currentValue;
     min      = counter.minValue;
     max      = counter.maxValue;
     rand     = counter.randomizeInitialValue;
     mode     = counter.updateMode;
     messages = QuestCounterMessageEventProxy.NewArray(counter.messageEventList);
 }
Ejemplo n.º 5
0
        public static List <QuestCounter> CreateList(QuestCounterProxy[] countersProxy)
        {
            var list = new List <QuestCounter>();

            if (countersProxy == null)
            {
                Debug.LogWarning("Quest Machine: QuestCounterProxy.CreateList source is null.");
                return(list);
            }
            for (int i = 0; i < countersProxy.Length; i++)
            {
                var counter = new QuestCounter();
                countersProxy[i].CopyTo(counter);
                list.Add(counter);
            }
            return(list);
        }
Ejemplo n.º 6
0
        private static string GetCounterTagValue(QuestCounter counter, CounterTagType tagType)
        {
            if (counter == null)
            {
                return(string.Empty);
            }
            switch (tagType)
            {
            default:
            case CounterTagType.Current:
                return(counter.currentValue.ToString());

            case CounterTagType.Min:
                return(counter.minValue.ToString());

            case CounterTagType.Max:
                return(counter.maxValue.ToString());

            case CounterTagType.AsTime:
                return(SecondsToTimeString(counter.currentValue));
            }
        }
        private string GetCounterButtonValue(QuestCounter counter)
        {
            if (counter == null)
            {
                return(null);
            }
            switch (m_selectedCounterToolbar)
            {
            default:
            case 0:
                return("{#" + counter.name + "}");

            case 1:
                return("{<#" + counter.name + "}");

            case 2:
                return("{>#" + counter.name + "}");

            case 3:
                return("{:" + counter.name + "}");
            }
        }
        protected virtual bool IsCounterConditionTrue(QuestCounter counter)
        {
            if (counter == null)
            {
                return(false);
            }
            if (requiredCounterValue == null)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning("QuestMachine: QuestCounterCondition.OnCounterChanged(" + StringField.GetStringValue(counter.name) + " = " + counter.currentValue + "): requiredCounterValue field is null. Please contact the developer.", quest);
                }
                return(false);
            }
            if (QuestMachine.debug)
            {
                Debug.Log("QuestMachine: QuestCounterCondition.OnCounterChanged(" + StringField.GetStringValue(counter.name) + " = " + counter.currentValue + ")", quest);
            }
            switch (counterValueMode)
            {
            case CounterValueConditionMode.AtLeast:
                if (counter.currentValue >= requiredCounterValue.GetValue(quest))
                {
                    return(true);
                }
                break;

            case CounterValueConditionMode.AtMost:
                if (counter.currentValue <= requiredCounterValue.GetValue(quest))
                {
                    return(true);
                }
                break;
            }
            return(false);
        }
Ejemplo n.º 9
0
 public override void StartChecking(System.Action trueAction)
 {
     base.StartChecking(trueAction);
     m_counter = (quest != null) ? quest.GetCounter(counterIndex) : null;
     QuestTimerManager.RegisterTimer(this);
 }
Ejemplo n.º 10
0
        protected virtual void AddCounterAndNode()
        {
            var quest = QuestEditorWindow.selectedQuest;

            if (quest == null)
            {
                return;
            }

            // Add counter:
            var existingCounter = quest.GetCounter(counterName); // Delete existing first.

            if (existingCounter != null)
            {
                quest.counterList.Remove(existingCounter);
            }
            var counter             = new QuestCounter(new StringField(counterName), Mathf.Max(0, min), min, max, QuestCounterUpdateMode.Messages);
            var messageAndParameter = incrementMessage.Split(':');

            counter.messageEventList.Add(new QuestCounterMessageEvent(new StringField(quest.id),
                                                                      new StringField(messageAndParameter[0]), new StringField(messageAndParameter[1]),
                                                                      QuestCounterMessageEvent.Operation.ModifyByLiteralValue, 1));
            quest.counterList.Add(counter);

            // Add a new node:
            var parentNode = GetParentNode(quest);

            if (parentNode == null)
            {
                return;
            }
            var node = new QuestNode(new StringField(string.Format(hudInstructionsText, min.ToString(), max.ToString())), new StringField(), QuestNodeType.Condition);

            quest.nodeList.Add(node);
            node.childIndexList.AddRange(parentNode.childIndexList);
            parentNode.childIndexList.Clear();
            parentNode.childIndexList.Add(quest.nodeList.Count - 1);
            node.canvasRect = new Rect(parentNode.canvasRect.x + QuestNode.DefaultNodeWidth + 20, parentNode.canvasRect.y, QuestNode.DefaultNodeWidth, QuestNode.DefaultNodeHeight);

            // Add success node if specified:
            if (leadsToSuccess)
            {
                AddSuccessNode(quest, node);
            }

            // Set node's counter condition:
            var condition = ScriptableObjectUtility.CreateScriptableObject <CounterQuestCondition>();

            condition.name                 = "counterCondition";
            condition.counterIndex         = quest.GetCounterIndex(counterName);
            condition.counterValueMode     = CounterValueConditionMode.AtLeast;
            condition.requiredCounterValue = new QuestNumber(max);
            node.conditionSet.conditionList.Add(condition);
            AddAndSaveSubasset(condition);

            // Set node's UI content:
            var stateInfo = node.GetStateInfo(QuestNodeState.Active);

            var hudContentList = stateInfo.GetContentList(QuestContentCategory.HUD);

            AddBodyContent(hudContentList, hudInstructionsText);
            AddBodyContent(hudContentList, hudCountText);

            var journalContentList = stateInfo.GetContentList(QuestContentCategory.Journal);

            AddBodyContent(journalContentList, journalText);

            var dialogueContentList = stateInfo.GetContentList(QuestContentCategory.Dialogue);

            AddBodyContent(dialogueContentList, dialogueText);

            // Add alert action:
            if (!string.IsNullOrEmpty(hudInstructionsText))
            {
                var alertAction = ScriptableObjectUtility.CreateScriptableObject <AlertQuestAction>();
                AddBodyContent(alertAction.contentList, hudInstructionsText);
                stateInfo.actionList.Add(alertAction);
                AddAndSaveSubasset(alertAction);
            }

            // Update quest's internal references:
            quest.SetRuntimeReferences();

            // Refresh editor windows:
            QuestEditorWindow.RepaintNow();              // Quest Editor window.
            QuestEditorWindow.RepaintCurrentEditorNow(); // Inspector.
        }
Ejemplo n.º 11
0
 public QuestCounterProxy(QuestCounter counter)
 {
     CopyFrom(counter);
 }