Exemple #1
0
        /// <summary>
        ///  Checks to see if the conditions on this node are met, and will set the value on the node
        ///     to reflect our calculations.
        /// </summary>
        /// <param name="convoNode">The conversation node to check eligibility.</param>
        /// <param name="isAttempt">If this check is for an actual attempt - If so, we'll cache the value in the node.</param>
        /// <returns>If the node can execute.</returns>
        public static bool AreConditionsMet(ConversationNode convoNode, bool isAttempt = false)
        {
            // Run through each check, and ensure they all return true.
            //  We'll return as soon as one of the checks is false.
            bool checkSuccessful = true;

            convoNode.RequiredChecks?.ForEach(x =>
            {
                // Don't calculate if we've already failed one.
                if (!checkSuccessful)
                {
                    return;
                }

                // See if this check passed.
                if (dialogueChecks.ContainsKey(x.Key))
                {
                    checkSuccessful = dialogueChecks[x.Key].CanDialogueExecute(x.Params);
                    log.LogMessage($"Dialogue Check { x.Key } Result: [{ checkSuccessful }]");
                }
                else
                {
                    checkSuccessful = false;
                    log.LogMessage($"Dialogue Check { x.Key } Not Found. Checks FAIL.", Logging.Enums.LogLevel.Error);
                }
            });

            // If we're trying to execute this node, lock the condition result in the node.
            if (isAttempt)
            {
                convoNode.SetEnabled(checkSuccessful);
            }

            return(checkSuccessful);
        }