private void CreateIdleState() { idleState = (fsm, gameObj) => { // GOAP Planning Dictionary <string, object> worldState = agent.WorldState(); Dictionary <string, object> goal = agent.CreateGoalState(); Queue <GoapAction> plan = GoapPlanner.Plan(gameObject, availableActions, worldState, goal); if (plan != null) { currentPlan = plan; agent.PlanFound(goal, plan); fsm.PopState(); fsm.PushState(performActionState); } else { Debug.Log("<color=orange>Failed Plan:</color>" + goal); agent.PlanFailed(goal); fsm.PopState(); fsm.PushState(idleState); } }; }
private void CreateIdleState() { idleState = (fsm, gameObj) => { // GOAP planning // get the world state and the goal we want to plan for HashSet <KeyValuePair <string, object> > worldState = dataProvider.GetWorldState(); HashSet <KeyValuePair <string, object> > goal = dataProvider.CreateGoalState(); // Plan Queue <GoapAction> plan = planner.plan(gameObject, availableActions, worldState, goal); if (plan != null) { // we have a plan, hooray! currentActions = plan; dataProvider.PlanFound(goal, plan); fsm.popState(); // switch to PerformAction state fsm.pushState(performActionState); } else { // ugh, we couldn't get a plan Debug.Log("Failed Plan: " + goal); dataProvider.PlanFailed(goal); fsm.popState(); // switch back to IdleAction state fsm.pushState(idleState); } }; }
void CreateIdleState() { idleState = (fsm, gameObj) => { HashSet <KeyValuePair <string, object> > worldState = dataProvider.GetWorldState(); HashSet <KeyValuePair <string, object> > goal = dataProvider.CreateGoalState(); Queue <GoapAction> plan = planner.Plan(gameObject, availableActions, worldState, goal); if (plan != null) { currentActions = plan; dataProvider.PlanFound(goal, plan); fsm.PopState(); fsm.PushState(performActionState); } else { Debug.Log("<color=orange>Failed Plan</color>" + PrettyPrint(goal)); dataProvider.PlanFailed(goal); fsm.PopState(); fsm.PushState(idleState); } }; }
void CreateIdleState() { _idleState = (fsm, gameObj) => { // GOAP planning // get the world state and the goal we want to plan for var worldState = _dataProvider.GetWorldState(); var goal = _dataProvider.CreateGoalState(); // Plan Queue <GoapAction> plan = _planner.Plan(gameObject, _availableActions, worldState, goal); if (plan != null) { // we have a plan, hooray! _currentActions = plan; _dataProvider.PlanFound(goal, plan); fsm.PopState(); // move to PerformAction state fsm.PushState(_performActionState); } else { // ugh, we couldn't get a plan Debug.Log($"<color=orange>Failed Plan:</color>{PrettyPrint(goal)}"); _dataProvider.PlanFailed(goal); fsm.PopState(); // move back to IdleAction state fsm.PushState(_idleState); } }; }
private void createIdleState() { _idleState = (fsm, gameObj) => { // GOAP planning // get the world state and the goal we want to plan for Dictionary <string, object> worldState = _dataProvider.GetWorldState(); Dictionary <Int64, Int64> resourceState = _dataProvider.GetResourceState(); Dictionary <string, object> goal = _dataProvider.CreateGoalState(); Dictionary <Int64, Int64> resourceGoal = _dataProvider.CreateResourceGoal(); loadActions(); // Plan Queue <GoapAction> plan = _planner.Plan(this, _availableActions, worldState, resourceState, goal, resourceGoal); if (plan != null) { // we have a plan, hooray! _currentActions = plan; _dataProvider.PlanFound(goal, plan); fsm.popState(); // move to PerformAction state fsm.pushState(_performActionState); } else { // ugh, we couldn't get a plan // Console.WriteLine("<color=orange>Failed Plan:</color>" + PrettyPrint(goal)); _dataProvider.PlanFailed(goal); fsm.popState(); // move back to IdleAction state fsm.pushState(_idleState); } }; }
private void CreatePlanningState() { planningState = (fsm, gameObj) => { Dictionary <string, object> worldState = worldDataProvider.GetWorldState(); Dictionary <string, object> goalState = worldDataProvider.CreateGoalState(); Queue <GAction> plan = planner.Plan(this, availableActions, worldState, goalState); if (plan != null) { currentActions = plan; worldDataProvider.PlanFound(goalState, plan); fsm.PopState(); fsm.PushState(performActionState); } else { Debug.Log("Planning failed! Goal: " + goalState); worldDataProvider.PlanFailed(goalState); fsm.PopState(); fsm.PushState(planningState); } }; }
//bool isPlanning = false; //HashSet<KeyValuePair<string, object>> worldState; //HashSet<KeyValuePair<string, object>> goal; void CreateIdleState() { idleState = (fsm, gameObj) => { HashSet <KeyValuePair <string, object> > worldState = dataProvider.GetWorldState(); HashSet <KeyValuePair <string, object> > goal = dataProvider.CreateGoalState(); Queue <GoapAction> plan = planner.Plan(gameObject, availableActions, worldState, goal); if (plan != null) { currentActions = plan; dataProvider.PlanFound(goal, plan); fsm.PopState(); fsm.PushState(performActionState); } else { Debug.Log("<color=orange>Failed Plan</color>" + PrettyPrint(goal)); dataProvider.PlanFailed(goal); fsm.PopState(); fsm.PushState(idleState); } //if (!isPlanning) //{ // worldState = dataProvider.GetWorldState(); // goal = dataProvider.CreateGoalState(); // planner.donePlanning = false; // planner.finalPlan = null; // StartCoroutine(planner.Plan(gameObject, availableActions, worldState, goal, this)); // isPlanning = true; //} //else //{ // if (planner.donePlanning) // { // if (planner.finalPlan != null) // { // currentActions = planner.finalPlan; // dataProvider.PlanFound(goal, planner.finalPlan); // fsm.PopState(); // fsm.PushState(performActionState); // } // else // { // Debug.Log("<color=orange>Failed Plan</color>" + PrettyPrint(goal)); // dataProvider.PlanFailed(goal); // fsm.PopState(); // fsm.PushState(idleState); // } // isPlanning = false; // } //} }; }
/// <summary> /// 创建空闲状态 /// </summary> private void CreateIdleState() { idleState = (fsm, gameObj) => { // GOAP planning // GOAP计划 // get the world state and the goal we want to plan for //获得世界状态和我们想要计划的目标 var worldState = dataProvider.GetWorldState(); //创建目标状态 var goals = dataProvider.CreateGoalState(); // search enable Plan //搜索启用计划 Queue <GoapAction> plan = null; KeyValuePair <string, bool> lastGoal = new KeyValuePair <string, bool>(); foreach (var goal in goals) { lastGoal = goal; plan = planner.Plan(gameObject, availableActions, worldState, goal, dataProvider); if (plan != null) { break; } } if (plan != null) { // we have a plan, hooray! //我们有个计划,万岁! currentActions = plan; dataProvider.PlanFound(lastGoal, plan); //移动到“执行操作”状态 fsm.popState(); // move to PerformAction state fsm.pushState(performActionState); } else { // ugh, we couldn't get a plan //呃,我们无法得到一个计划 Debug.Log("<color=orange>失败的计划:</color>" + PrettyPrint(goals)); dataProvider.PlanFailed(goals); //返回空闲操作状态 fsm.popState(); // move back to IdleAction state fsm.pushState(idleState); } }; }
/// <summary> /// Implementation of <see cref="IAction"/> interface. Calls the Plan method of the <see cref="GoapPlanner"/>. /// </summary> public void Execute() { // get the world state and the goal we want to plan for var worldState = _dataProvider.GetWorldState(); var goal = _dataProvider.CreateGoalState(); // Plan var plan = _planner.Plan(_agent.gameObject, _agent.GetAvailableActions(), worldState, goal); if (plan != null)// we have a plan, hooray! { _agent.SetCurrentActions(plan); _dataProvider.PlanFound(goal, plan); } else// ugh, we couldn't get a plan { _dataProvider.PlanFailed(goal); } }
private void createIdleState() { idleState = (fsm, obj) => { HashSet <KeyValuePair <string, object> > worldState = dataProvider.GetWorldState(); HashSet <KeyValuePair <string, object> > goal = dataProvider.CreateGoalState(); Queue <GoapAction> plan = planner.plan(gameObject, availableActions, worldState, goal); if (plan != null) { currentActions = plan; dataProvider.PlanFound(goal, plan); fsm.popState(); fsm.pushState(performActionState); } else { dataProvider.PlanFailed(goal); fsm.popState(); fsm.pushState(idleState); } }; }
private void CreateIdleState() { _idleState = (fsm, gameObject) => { Debug.Log("Making plan --"); // GOAP Planning -- What're you gonna do?! // get world state and goal we want to plan for var worldState = _dataProvider.GetWorldState(); var goal = _dataProvider.CreateGoalState(); // PLAN Queue <GOAPAction> plan = _planner.Plan(gameObject, _availableActions, worldState, goal); if (plan != null) { Debug.Log("-- plan made"); // plan created, success _currentActions = plan; _dataProvider.PlanFound(goal, plan); _fsm.PopState(); _fsm.PushState(_performState); } else { Debug.Log("-- plan unable to be made"); // plan could not be created _dataProvider.PlanFailed(goal); _fsm.PopState(); _fsm.PushState(_idleState); } }; }