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; } }
public void Update(GOAPAgent agent, GameObject obj) { if (_stateStack.Peek() != null) { _stateStack.Peek().Run(agent, this, obj); } }
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); }
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(); } }
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(); } }
public virtual bool IsInRange(GOAPAgent a) { return(Targets.Any(t => (t - a.transform.position).magnitude <= _minRange)); }