Esempio n. 1
0
        public void Run(GOAPAgent agent, FSM fsm, GameObject actor)
        {
            if (!agent.Plan.Finished)
            {
                return;
            }

            var plan = agent.Plan;

            if (plan != null && plan.Actions != null && plan.Success)
            {
                agent.CurrentActions = plan.Actions;
                agent.DataProvider.PlanFound(plan.Goal, plan.Actions);

                fsm.PopState();
                fsm.PushState(agent.PerformActionState);
            }
            else
            {
                agent.DataProvider.PlanFailed(plan.Goal);
                fsm.PopState();
                fsm.PushState(agent.IdleState);
                JobController.Instance.AddIdleSolver(agent.DataProvider);
                agent.IsIdle = true;
            }
        }
Esempio n. 2
0
 public void Update(GOAPAgent agent, GameObject obj)
 {
     if (_stateStack.Peek() != null)
     {
         _stateStack.Peek().Run(agent, this, obj);
     }
 }
Esempio n. 3
0
        public void Run(GOAPAgent agent, FSM fsm, GameObject actor)
        {
            var worldState = agent.DataProvider.GetWorldState();
            var goal       = agent.DataProvider.CreateGoalState();

            agent.Plan = agent.Planner.Plan(agent.gameObject, agent.AvailableActions, worldState, goal);
            fsm.PopState();
            fsm.PushState(agent.WaitForPlanState);
        }
Esempio n. 4
0
        public void Run(GOAPAgent agent, FSM fsm, GameObject actor)
        {
            var action = agent.CurrentActions.Peek();

            if (action.RequiresInRange && action.Targets.Count == 0)
            {
                fsm.PopState();
                fsm.PopState();
                fsm.PushState(agent.IdleState);
                return;
            }

            if (agent.DataProvider.MoveAgent(action))
            {
                fsm.PopState();
            }
        }
Esempio n. 5
0
        public void Run(GOAPAgent agent, FSM fsm, GameObject actor)
        {
            if (!agent.HasActionPlan())
            {
                fsm.PopState();
                fsm.PushState(agent.IdleState);
                agent.DataProvider.ActionsFinished();
                return;
            }

            var action = agent.CurrentActions.Peek();

            if (action.IsDone())
            {
                agent.CurrentActions.Dequeue();
            }

            if (agent.HasActionPlan())
            {
                action = agent.CurrentActions.Peek();

                if (!action.RequiresInRange || action.IsInRange(agent))
                {
                    var success = action.Perform(Time.deltaTime, agent.gameObject);
                    if (!success)
                    {
                        fsm.PopState();
                        fsm.PushState(agent.IdleState);
                        agent.DataProvider.PlanAborted(action);
                    }
                }
                else
                {
                    fsm.PushState(agent.MoveToState);
                }
            }
            else
            {
                fsm.PopState();
                fsm.PushState(agent.IdleState);
                agent.DataProvider.ActionsFinished();
            }
        }
Esempio n. 6
0
 public virtual bool IsInRange(GOAPAgent a)
 {
     return(Targets.Any(t => (t - a.transform.position).magnitude <= _minRange));
 }