Beispiel #1
0
    public void CrearEstadoActuar()


    {
        ActState = (fsm, gameObj) =>
        {
            //ejecutar la accion
            if (AccionesActuales.Count <= 0)    // no tengo un plan
            {
                fsm.popState();
                fsm.pushState(idleState);
                goapData.ActionsFinished();
                return;
            }
            //si si tengo acciones entronces objetco la primeroa

            GoapAction accion = AccionesActuales.Peek();
            if (accion.isDone())
            {
                //si ya se termino la accion la lquito
                AccionesActuales.Dequeue();
            }
            //si no ha terminad oy quedan acciones hay que ejecutrarl
            if (AccionesActuales.Count > 0)
            {
                accion = AccionesActuales.Peek();
                //verifico si requiere estar en un rango}(cerca de su objetivo)
                bool enRango = accion.requiresInRange() ? accion.IsInRange() : true;
                if (enRango)
                {
                    bool exito = accion.Perform(gameObj);
                    // sil a accion no se ejecuto
                    if (!exito)
                    {
                        //planeo otra vez
                        fsm.popState();
                        //sjalgo de acturar y vuelvo a idle
                        fsm.pushState(idleState);

                        goapData.PlanAborted(accion);
                    }
                }

                else
                {
                    //no esta en donde deberia estar, no esta en rango
                    Debug.Log("estoy lejos del objetivo");
                    fsm.pushState(MoveState);
                }
            }
            else
            {
                //no quedan acciones, entonces puedo volver a planear
                fsm.popState();
                fsm.pushState(idleState);

                goapData.ActionsFinished();
            }
        };
    }
Beispiel #2
0
        /// <summary>
        /// Preforms the action if the agent is in range
        /// </summary>
        private void CreatePerformActionState()
        {
            prefromActionState = (fsm, gameObj) =>
            {
                // perform the action

                if (!HasActionPlan())
                {
                    // no actions to perform
                    Debug.Log("<color=red>Done actions</color>");
                    fsm.PopState();
                    fsm.PushState(idleState);
                    dataProvider.ActionFinished();
                    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;

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

                        if (!success)
                        {
                            // action failed, we need to plan again
                            fsm.PopState();
                            fsm.PushState(idleState);
                            Debug.LogWarning(gameObj.name + " could not prefrom the action, " + action + ". The agent (" + gameObject.name + ") is now going to abort plan.");
                            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.ActionFinished();
                }
            };
        }
        private void CreatePerformActionState()
        {
            PerformActionState = (fsm, agent) =>
            {
                if (!HasActionPlan())
                {
                    fsm.PopState();
                    fsm.PushState(IdleState);
                    DataProvider.ActionsFinished();
                }

                GOAPAction action = CurrentActions.Peek();
                if (action.IsDone())
                {
                    AddThought("Completed action " + action.ToString(), Color.DarkOrange);
                    CurrentActions.Dequeue();
                }

                if (HasActionPlan())
                {
                    action = CurrentActions.Peek();
                    bool InRange = action.RequiresInRange() ? action.InRange : true;

                    if (InRange)
                    {
                        bool Success = action.Run(agent);

                        if (!Success)
                        {
                            fsm.PopState();
                            fsm.PushState(IdleState);
                            DataProvider.PlanAborted(action);
                        }
                    }
                    else
                    {
                        fsm.PushState(MoveToState);
                        AddThought("Moving to " + action.Target.Name, Color.DarkOliveGreen);
                    }
                }
                else
                {
                    fsm.PopState();
                    fsm.PushState(IdleState);
                    DataProvider.ActionsFinished();
                }
            };
        }
Beispiel #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();
            }
        };
    }
Beispiel #5
0
    private void CrearEstadoActuar()
    {
        ActState = (fsm, gameObj) =>
        {
            // Ejecutar la acción
            if (AccionesActuales.Count <= 0) // No tengo un plan
            {
                // No hay acciones que hacer, puedo ir a Idle
                fsm.popState(); // salir de actuar
                fsm.pushState(idleState);

                goapData.ActionsFinished();

                return;
            }

            // Si si tengo accioens, entonces obtengo la primera
            GoapAction accion = AccionesActuales.Peek();
            if (accion.isDone())
            {
                // si ya se terminó la acción, la quito
                AccionesActuales.Dequeue();
            }
            // Si no ha terminado y quedan acciones, hay que ejecutarla
            if (AccionesActuales.Count > 0)
            {
                accion = AccionesActuales.Peek();

                // Verifico si requiere estar en rango (cerca de su objetivo)
                bool enRango = accion.requiresInRange() ? accion.IsInRange() : true;

                if (enRango) // Ya está donde debe de estar
                {
                    bool exito = accion.Perform(gameObj);

                    // Si la acción no se ejecutó
                    if (!exito)
                    {
                        // Planeo otra vez
                        fsm.popState(); // salgo de actuar
                        fsm.pushState(idleState);

                        goapData.PlanAborted(accion);
                    }
                }
                else
                {
                    // No está en donde debería estar, no está en rango
                    Debug.Log("Estoy lejos del objetivo");
                    fsm.pushState(MoveState);
                }
            } // if
            else
            {
                // No quedan acciones, entonces puedo volver a planear
                fsm.popState();
                fsm.pushState(idleState);

                goapData.ActionsFinished();
            }
        };
    }