Пример #1
0
    private void createPerformActionState()
    {
        performActionState = (fsm, gameObj) => {
            // perform the action
            //Debug.Log("PERFORMstate");

            if (!hasActionPlan())
            {
                // no actions to perform
                Debug.Log("<color=red>Done actions</color>");
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
                return;
            }

            GoapAction action = currentActions.Peek();

            if (action.isDone())
            {
                // the action is done. Remove it so we can perform the next one
                currentActions.Dequeue();
            }

            if (hasActionPlan())
            {
                // perform the next action
                action = currentActions.Peek();
                bool inRange = action.requiresInRange() ? action.isInRange() : true;
                //Debug.Log(inRange);
                if (inRange)
                {
                    // we are 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 there first
                    // push moveTo state
                    fsm.pushState(moveToState);
                }
            }
            else
            {
                // no actions left, move to Plan state
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
            }
        };
    }
Пример #2
0
    private void createPerformActionState()
    {
        performActionState = (fsm, gameObj) => {
            if (!hasActionPlan())
            {
                // No actions
                Debug.Log("<color=red>Done actions</color>");
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
                return;
            }

            GoapAction action = currentActions.Peek();
            if (action.isDone())
            {
                // Action is done
                currentActions.Dequeue();
                metrics["actionsDone"]++;
                if (isSelected)
                {
                    generatePlanPanel();
                }
            }

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

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

                    if (!success)
                    {
                        // Action failed
                        fsm.popState();
                        fsm.pushState(idleState);
                        dataProvider.planAborted(action);
                        metrics["abortedPlans"]++;
                    }
                }
                else
                {
                    // Move to target
                    fsm.pushState(moveToState);
                }
            }
            else
            {
                // No actions
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
            }
        };
    }
Пример #3
0
    private void createPerformActionState()
    {
        performActionState = (fsm, obj) => {
            if (!hasActionPlan())
            {
                //Go find new plan and tell the agent it is finished
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
                return;
            }

            AbstractGOAPAction action = currentActions.Peek();
            if (action.isDone())
            {
                //Take action out of action queue
                currentActions.Dequeue();
            }

            if (hasActionPlan())
            {
                //Set action to the action on top of the queue
                action = currentActions.Peek();
                //Check if you need to be in range
                bool inRange = action.requiresInRange() ? action.isInRange() : true;


                if (inRange)
                {
                    //Check if we could perfrom action if not go to idle state and find a new plan
                    bool success = action.perform(obj);
                    if (!success)
                    {
                        fsm.popState();
                        fsm.pushState(idleState);
                        //ABORT
                        dataProvider.planAborted(action);
                    }
                }
                else
                {
                    fsm.pushState(moveToState);
                }
            }
            else
            {
                //I don't have a plan and need to find one
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.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();
            }
        };
    }
Пример #5
0
    private void createPerformActionState()
    {
        performActionState = (fsm, gameObj) =>
        {
            Profiler.BeginSample("Perform state");
            // perform the action

            if (!hasActionPlan())
            {
                // no actions to perform
                //Debug.Log("<color=red>Done actions</color>");
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
                return;
            }

            GoapAction action = currentActions.Peek();
            if (action.isDone())
            {
                // the action is done. Remove it so we can perform the next one
                currentActions.Dequeue();
            }

            if (hasActionPlan())
            {
                // perform the next action
                action = currentActions.Peek();
                ChangedAction(action);
                currentAction = action;

                //                //Debug.Log("Here's our current action " + action);
                bool inRange = action.requiresInRange() ? action.isInRange() : true;

                if (inRange)
                {
                    // we are in range, so perform the action
                    bool success = action.perform(gameObj);

                    if (!success)
                    {
                        //Debug.Log("<color=red> ACTION FAILED OH NO WHY</color>");
                        // action failed, we need to plan again
                        fsm.popState();
                        fsm.pushState(idleState);
                        dataProvider.planAborted(action);
                    }
                }
                else
                {
                    // we need to move there first
                    // push moveTo state
                    fsm.pushState(moveToState);
                }
            }
            else
            {
                //Debug.Log("Actions completed");
                // no actions left, move to Plan state
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
            }
            Profiler.EndSample();
        };
    }
Пример #6
0
    private void createPerformActionState()
    {
        performActionState = (fsm, gameObj) =>
        {
            // If no action to perform.
            if (!hasActionPlan())
            {
                Debug.Log("<color=green>Done actions</color>");

                // Remove the 'perform' state from the FSM and go back to idle.
                fsm.popState();
                fsm.pushState(idleState);

                // Inform the data provider we finished every actions.
                dataProvider.actionsFinished();
                return;
            }

            GoapAction action = currentActions.Peek();

            // If the current action is done, dequeue it.
            if (action.isDone())
            {
                currentActions.Dequeue();
            }

            // If we still have actions to do.
            if (hasActionPlan())
            {
                // Get the next action to perform.
                action = currentActions.Peek();
                bool inRange = action.requiresInRange() ? action.isInRange : true;

                // If we are in range, try performing the action.
                if (inRange)
                {
                    bool success = action.perform(gameObj);

                    // If the action failed, plan again.
                    if (!success)
                    {
                        // Remove the 'perform' state and go back to 'idle'.
                        fsm.popState();
                        fsm.pushState(idleState);

                        // Tell the data provider plan has been aborted because of action.
                        dataProvider.planAborted(action);
                    }
                }
                else
                {
                    // If we are not in range, use 'moveTo' state.
                    fsm.pushState(moveToState);
                }
            }
            else
            {
                // No more action to perform.

                // Remove the 'perform' state and go back to 'idle'.
                fsm.popState();
                fsm.pushState(idleState);

                // Tell the data provider we finished every actions.
                dataProvider.actionsFinished();
            }
        };
    }