using System; using Goap.Agent.Core; using Phantom.XRMOD.UnityFusion.Runtime; using UnityEngine; namespace Goap.Agent.Runtime { public abstract class AgentActionBase where TActionData : IActionData, new() where TActionProperties : class, IActionProperties, new() { /// /// Gets the action data. /// /// The action data. public IActionData GetData() { return this.CreateData(); } /// /// Creates a new instance of action data. /// /// The created action data. public abstract TActionData CreateData(); /// /// Gets the action properties. /// public abstract TActionProperties Properties { get; } /// /// Called when the action is created. /// public virtual void Created() { } /// /// Called when the action is started (when it is assigned to an agent). /// /// The agent. /// The action data. public void Start(IMonoAgent agent, IActionData data) => this.Start(agent, (TActionData) data); /// /// Called when the action is started (when it is assigned to an agent). /// /// The agent. /// The action data. public virtual void Start(IMonoAgent agent, TActionData data) { } /// /// Called once before performing the action. Don't override this method, override the other BeforePerform method /// instead. /// /// The agent. /// The action data. public void BeforePerform(IMonoAgent agent, IActionData data) => this.BeforePerform(agent, (TActionData) data); /// /// Called once before performing the action. Override this method to implement custom logic. /// /// The agent. /// The action data. public virtual void BeforePerform(IMonoAgent agent, TActionData data) { } /// /// Performs the action. Don't override this method, override the other Perform method instead. /// /// The agent. /// The action data. /// The action context. /// The action run state. public IActionRunState Perform(IMonoAgent agent, IActionData data, IActionContext context) => this.Perform(agent, (TActionData) data, context); /// /// Performs the action with the specified action data. Use this method to implement custom logic. /// /// The agent. /// The action data. /// The action context. /// The action run state. public abstract IActionRunState Perform(IMonoAgent agent, TActionData data, IActionContext context); /// /// Called when the action ends. This is called after the action is completed or stopped. /// /// The agent. /// The action data. public virtual void End(IMonoAgent agent, TActionData data) { } /// /// Called when the action is stopped. Don't override this method, override the other Stop method instead. /// /// The agent. /// The action data. public void Stop(IMonoAgent agent, IActionData data) { this.Stop(agent, (TActionData) data); this.End(agent, (TActionData) data); } /// /// Called when the action is stopped. Use this method to implement custom logic. /// /// The agent. /// The action data. public virtual void Stop(IMonoAgent agent, TActionData data) { } /// /// Called when the action is completed. Don't override this method, override the other Complete method instead. /// /// The agent. /// The action data. public void Complete(IMonoAgent agent, IActionData data) { this.Complete(agent, (TActionData) data); this.End(agent, (TActionData) data); } /// /// Called when the action is completed. Use this method to implement custom logic. /// /// The agent. /// The action data. public virtual void Complete(IMonoAgent agent, TActionData data) { } } }