// Copyright (c) Pixel Crushers. All rights reserved. using UnityEngine; using System.Collections.Generic; namespace PixelCrushers.QuestMachine { /// /// Abstract base class for quest conditions. /// public abstract class QuestCondition : QuestSubasset { /// /// Delegate to call when the condition becomes true. /// protected System.Action trueAction = delegate { }; private bool m_isChecking = false; [HideInInspector] [SerializeField] private bool m_alreadyTrue = false; /// /// True if the condition is currently monitoring the requirements that would make it true. /// protected virtual bool isChecking { get { return m_isChecking; } set { m_isChecking = value; } } public virtual bool alreadyTrue { get { return m_alreadyTrue; } set { m_alreadyTrue = value; } } public override void SetRuntimeReferences(Quest quest, QuestNode questNode) { base.SetRuntimeReferences(quest, questNode); isChecking = false; } /// /// Tells the condition to start checking; when true, call SetTrue(). /// /// The method to invoke when the condition becomes true. public virtual void StartChecking(System.Action trueAction) { isChecking = true; this.trueAction = trueAction; } /// /// Tells the condition to stop checking. /// public virtual void StopChecking() { isChecking = false; } /// /// Sets the condition true, invoking the trueAction. /// Also stops checking. /// public virtual void SetTrue() { if (alreadyTrue) return; if (QuestMachine.debug) Debug.Log("Quest Machine: " + GetType().Name + ".SetTrue()", quest); alreadyTrue = true; StopChecking(); trueAction(); } } }