public void UpdateData() { //检测是否需要重新制定计划 //当前计划是否完成 if (planHandler.IsComplete) { DebugMsg.Log("制定新计划"); BuildPlanAndStart(); } //制定计划并开始计划 void BuildPlanAndStart() { if (goalManager.CurrentGoal != null) { DebugMsg.Log("----------------新的目标:" + goalManager.CurrentGoal.Label.ToString()); } //若目标完成则重新寻找目标 var plan = planner.BuildPlan(goalManager.CurrentGoal); if (plan != null && plan.Count > 0) { planHandler.Init(actionManager, plan); planHandler.HandlerAction(); actionManager.IsPerformAction = true; } } }
//制定计划并开始计划 private void BuildPlanAndStart() { if (_goalManager.CurrentGoal != null) { DebugMsg.Log("----------------新的目标:" + _goalManager.CurrentGoal.Label.ToString()); } //若目标完成则重新寻找目标 var plan = _planner.BuildPlan(_goalManager.CurrentGoal); if (plan != null && plan.Count > 0) { _planHandler.Init(_actionManager, plan); _planHandler.StartPlan(); _actionManager.IsPerformAction = true; } }
bool Plan(Dictionary <string, object> world, Dictionary <string, object> goal, Queue <GOAPAction> plan) { // Reset actions foreach (var action in _available) { action.Reset(); } _useable.Clear(); foreach (var action in _available) { if (action.IsPossibleToPerform()) { _useable.Add(action); } } Profiler.BeginSample("Agent_BuildPlan"); // Build graph _planner.BuildPlan(world, _useable, goal, _actions); Profiler.EndSample(); if (_actions.Count == 0) { foreach (var action in _useable) { action.Reset(); } return(false); } else { foreach (var item in _useable) { if (!_actions.Contains(item)) { item.Reset(); } } return(true); } }