Exemplo n.º 1
0
    /// <summary>
    /// Creates the state to make the agent perform an action
    /// </summary>
    private void CreatePerformActionState()
    {
        PerformActionState = (a_fFinateStateMachine, a_goObject) =>
        {
            if (!HasActionPlan())
            {
                FinateStateMachine.PopStateStack();
                FinateStateMachine.PushStateToStack(IdleState);
                DataProviderInterface.AllActionsFinished();
                return;
            }
            CS_GOAPAction Action = CurrentlyActiveActions.Peek();
            if (Action.IsActionFinished())
            {
                CurrentlyActiveActions.Dequeue();
            }
            if (HasActionPlan())
            {
                Action = CurrentlyActiveActions.Peek();
                bool bIsInRange = Action.NeedsToBeInRange() ? Action.IsAgentInRange() : true;

                if (bIsInRange)
                {
                    bool bActionPerformSuccess = Action.PerformAction(a_goObject);
                    if (!bActionPerformSuccess)
                    {
                        FinateStateMachine.PopStateStack();
                        FinateStateMachine.PushStateToStack(IdleState);
                        CreateIdleState();
                        DataProviderInterface.AbortPlan(Action);
                    }
                }
                else
                {
                    FinateStateMachine.PushStateToStack(MovingState);
                }
            }
            else
            {
                FinateStateMachine.PopStateStack();
                FinateStateMachine.PushStateToStack(IdleState);
                DataProviderInterface.AllActionsFinished();
            }
        };
    }
Exemplo n.º 2
0
 /// <summary>
 /// Creates the state to move the agent to its destination for the FSM
 /// </summary>
 private void CreateMovingState()
 {
     MovingState = (a_fFinateStateMachine, a_goObject) =>
     {
         CS_GOAPAction Action = CurrentlyActiveActions.Peek();
         if (Action.NeedsToBeInRange() && Action.m_goTarget == null)
         {
             FinateStateMachine.PopStateStack();
             FinateStateMachine.PopStateStack();
             FinateStateMachine.PushStateToStack(IdleState);
             return;
         }
         if (DataProviderInterface.MoveAgentToAction(Action))
         {
             FinateStateMachine.PopStateStack();
         }
     };
 }