예제 #1
0
    private void createPerformActionState()
    {
        performActionState = (FiniteStateMachine, gameObj) =>
        {
            //performs action

            if (!hasActionPlan())
            {
                //no actions
                FiniteStateMachine.Pop();
                FiniteStateMachine.Push(idleState);
                dataProvider.actionsFinished();
                return;
            }

            GOAPAction action = currentActions.Peek();
            if (action.isDone())
            {
                //action done
                currentActions.Dequeue();
            }

            if (hasActionPlan())
            {
                //perform next action
                action = currentActions.Peek();
                bool inRange = action.mustBeInRange() ? action.isInRange() : true;

                if (inRange)
                {
                    //in range
                    bool success = action.perform(gameObj);

                    if (!success)
                    {
                        //action failed
                        FiniteStateMachine.Pop();
                        FiniteStateMachine.Push(idleState);
                        dataProvider.planAborted(action);
                    }
                }
                else
                {
                    //move there first
                    FiniteStateMachine.Push(moveState);
                }
            }
            else
            {
                //no actions left
                FiniteStateMachine.Pop();
                FiniteStateMachine.Push(idleState);
                dataProvider.actionsFinished();
            }
        };
    }
예제 #2
0
    private void createPerformActionState()
    {
        performActionState = (fsm, gameObj) => {
            // Perform the action
            if (!hasActionPlan())
            {
                // No actions to perform
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
                return;
            }

            GOAPAction action = currentActions.Peek();
            if (action.isDone())
            {
                // The action is done. We can remove it, onto the next one!
                currentActions.Dequeue();
            }

            if (hasActionPlan())
            {
                // Perform the next action
                action = currentActions.Peek();
                bool inRange = action.requiresInRange() ? action.isInRange() : true;

                if (inRange)
                {
                    // We're in range, so perform the action
                    bool success = action.perform(gameObj);

                    if (!success)
                    {
                        // Action failed, we need to plan again
                        fsm.popState();
                        fsm.pushState(idleState);
                        dataProvider.planAborted(action);
                    }
                }
                else
                {
                    // We need to move to our target first
                    // Let's make the AI move
                    fsm.pushState(moveToTargetState);
                }
            }
            // If all fails, change back to idleState (planning stage)
            else
            {
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
            }
        };
    }
예제 #3
0
    private void CreatePerformActionState(GOAPComponent aic)
    {
        aic.performActionState = (fsm, obj) =>
        {
            //aic.AnnouncePerformActionState();

            if (!aic.HasActionPlan())
            {
                fsm.popState();
                fsm.pushState(aic.idleState);
                aic.ActionsFinished();
                return;
            }

            GOAPAction action = aic.currentActions.Peek();
            if (action.isDone())
            {
                aic.currentActions.Dequeue();
            }

            if (aic.HasActionPlan())
            {
                action = aic.currentActions.Peek();
                bool inRange = action.requiresInRange() ? action.isInRange() : true;

                if (inRange)
                {
                    bool success = action.perform(obj);
                    if (!success)
                    {
                        fsm.popState();
                        fsm.pushState(aic.idleState);
                        CreateIdleState(aic);
                        aic.PlanAborted(action);
                    }
                }
                else
                {
                    fsm.pushState(aic.moveToState);
                }
            }
            else
            {
                fsm.popState();
                fsm.pushState(aic.idleState);
                aic.ActionsFinished();
            }
        };
    }
예제 #4
0
    private void createPerformActionState()
    {
        performActionState = (fsm, obj) => {
            if (!hasActionPlan())
            {
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.ActionsFinished();
                return;
            }

            GOAPAction action = currentActions.Peek();
            if (action.isDone())
            {
                currentActions.Dequeue();
            }

            if (hasActionPlan())
            {
                action = currentActions.Peek();
                bool inRange = action.requiresInRange() ? action.isInRange() : true;

                if (inRange)
                {
                    bool success = action.perform(obj);
                    if (!success)
                    {
                        fsm.popState();
                        fsm.pushState(idleState);
                        createIdleState();
                        dataProvider.PlanAborted(action);
                    }
                }
                else
                {
                    fsm.pushState(moveToState);
                }
            }
            else
            {
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.ActionsFinished();
            }
        };
    }