/// <summary> /// Creates performActionState for the FSM. This state is used to make the AI Agent perform an action. /// </summary> private void CreatePerformActionState() { _performActionState = (fsm, obj) => { if (!HasActionPlan()) { _AIAgent.ActionsFinished(); fsm.ClearState(); fsm.PushState(_idleState); return; } GOAPAction action = _currentActions.Peek(); if (action.IsDone()) { // If action is done, remove it to perform the next one. _currentActions.Dequeue(); } if (HasActionPlan()) { action = _currentActions.Peek(); bool inRange = action.RequiresInRange() ? action.IsInRange() : true; if (inRange) { bool success = action.Perform(obj, _AIAgent.DataHolder); if (!success) { _AIAgent.PlanAborted(action); fsm.ClearState(); fsm.PushState(_idleState); } } else { fsm.PushState(_moveToState); } } else { _AIAgent.ActionsFinished(); fsm.ClearState(); fsm.PushState(_idleState); } }; }
/// <summary> /// Creates moveToState for the FSM. This state is used to move the Ai Agent to its destination. /// </summary> private void CreateMoveToState() { _moveToState = (fsm, gameObject) => { GOAPAction action = _currentActions.Peek(); if (action.RequiresInRange() && action._target == null) { fsm.ClearState(); fsm.PushState(_idleState); return; } if (_AIAgent.MoveAgent(action)) { fsm.PopState(); } }; }