aboutsummaryrefslogtreecommitdiff
path: root/V3/AI/Internal/AbstractAction.cs
diff options
context:
space:
mode:
Diffstat (limited to 'V3/AI/Internal/AbstractAction.cs')
-rw-r--r--V3/AI/Internal/AbstractAction.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/V3/AI/Internal/AbstractAction.cs b/V3/AI/Internal/AbstractAction.cs
new file mode 100644
index 0000000..1b5f73e
--- /dev/null
+++ b/V3/AI/Internal/AbstractAction.cs
@@ -0,0 +1,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();
+ }
+}