aboutsummaryrefslogtreecommitdiff
path: root/V3/AI/Internal/AbstractAction.cs
blob: 1b5f73ee65054629847688f21943c91f325a7ae5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
namespace V3.AI.Internal
{
    /// <summary>
    /// Abstract implementation of IAction.
    /// </summary>
    public abstract class AbstractAction : IAction
    {
        /// <summary>
        /// The current state of the action.
        /// </summary>
        public ActionState State { get; private set; } = ActionState.Waiting;

        /// <summary>
        /// Start the execution of the action.
        /// </summary>
        public virtual void Start()
        {
            State = ActionState.Executing;
        }

        /// <summary>
        /// Update the execution state.  This method should be repateatingly
        /// called as long as State is Executing.
        /// </summary>
        public virtual void Update()
        {
            if (State != ActionState.Executing)
                return;
            State = GetNextState();
        }

        /// <summary>
        /// Returns the next state of this action.  It is guaranteed that the
        /// current state is Executing.
        /// </summary>
        protected abstract ActionState GetNextState();
    }
}