// GOAP Planning State public void IdleState() { State = AgentState.Planning; // Get the world state and the goal we want to plan for Dictionary <string, bool> worldState = agentImplementation.GetWorldState(); Dictionary <string, bool> goal = agentImplementation.GetGoalState(goalIndex); // Clear previous plan ( actions ) currentPlan.Clear(); // Find new plan currentPlan = planner.Plan(gameObject, availableActions, worldState, goal, goalIndex == 0 ? "Eliminate" : "Find Enemy"); if (HasActionPlan()) { CurrentPlanTextual = Utilities.GetCollectionString(currentPlan.ToList()); goalIndex = 0; // Plan Available - Change State ChangeState(FSMKeys.PERFORM_STATE); } else { Debug.LogError("IdleState: Failed Plan | Goal Index:: " + goalIndex + "\n"); // Loop between goal index 0 and maximum number of goals goalIndex = (int)Mathf.Repeat(++goalIndex, agentImplementation.GetGoalsCount()); // Plan Not Available - Loop State ChangeState(FSMKeys.IDLE_STATE); } }