Page 1 of 1

Quest Condition Counting

Posted: Thu Jan 17, 2019 6:05 am
by fbit
Hello everybody!

I noticed QuestMachine uses a counting mechanism when checking if the conditions for a questnode etc. are met. However, it would be handy if QuestMachine could keep track of all the different conditions and only count a true condition if it had not already been true.

I refer to the following code in the class QuestConditionSet:

Code: Select all

private void OnTrueCondition()
        {
            numTrueConditions++;
            if (areConditionsMet) SetTrue();
        }
        
public bool areConditionsMet
        {
            get
            {
                if (conditionList == null || conditionList.Count == 0) return true;
                switch (conditionCountMode)
                {
                    case ConditionCountMode.All:
                        return (numTrueConditions >= conditionList.Count);
                    case ConditionCountMode.Any:
                        return (numTrueConditions > 0);
                    case ConditionCountMode.Min:
                        return (numTrueConditions >= minConditionCount);
                    default:
                        if (Debug.isDebugBuild) Debug.LogWarning("Quest Machine: Internal error. Unrecognized condition count mode '" + conditionCountMode + "'. Please contact the developer.");
                        return false;
                }
            }
        }
And to explain my problem a bit further: I want a questnode to become "true" when condition1 and condition2 are met. Currently, the questnode would also become "true" if condition1 is met two times and condition2 is still false.

I thought about removing true conditions from the quest condition set, but maybe you don't always want this behaviour... anyway, is it possible to add a feature like this or should I use custom quest conditions for that?

Re: Quest Condition Counting

Posted: Thu Jan 17, 2019 9:31 am
by Tony Li
Hi,

A condition should only become true once. This will keep the count correct. However, the current version has a bug that's already fixed in the commits for the next update. The QuestCondition class has 3 methods: StartChecking(), StopChecking(), and SetTrue(). The base SetTrue() method is supposed to call StopChecking() but it wasn't. It does now.

Re: Quest Condition Counting

Posted: Fri Jan 18, 2019 8:21 am
by fbit
Hi Tony,
Tony Li wrote: Thu Jan 17, 2019 9:31 am The base SetTrue() method is supposed to call StopChecking() but it wasn't. It does now.
Ah, I see, thanks for the information!

Re: Quest Condition Counting

Posted: Wed Jan 23, 2019 6:10 am
by fbit
I've just found out that you can reset QuestConditionSet.numTrueConditions as it has a public setter!

So, in case anyone is interested:
if you want to have a QuestCondition that refreshes its state on a certain event, reset QuestConditionSet.numTrueConditions when the event is fired and do not call StopChecking() on that QuestCondition.

At least, this is what worked for me :D