コード例 #1
0
 //判断是否有能够打断计划的动作执行
 private void JudgeInterruptibleHandler()
 {
     foreach (var handler in _interruptibleHandlers)
     {
         if (handler.CanPerformAction())
         {
             DebugMsg.Log(handler.Label + "打断计划");
             _agent.Performer.Interruptible();
             break;
         }
     }
 }
コード例 #2
0
 //更新CurrentGoal对象
 private void UpdateCurrentGoal()
 {
     CurrentGoal = FindGoal();
     if (CurrentGoal != null)
     {
         DebugMsg.Log("CurrentGoal:" + CurrentGoal.Label.ToString());
     }
     else
     {
         DebugMsg.Log("CurrentGoal is null");
     }
 }
コード例 #3
0
 public void HandlerAction()
 {
     if (IsComplete)
     {
         _onComplete();
     }
     else
     {
         _currentActionHandler = _plan.Dequeue();
         DebugMsg.Log("----当前执行动作:" + _currentActionHandler.Label);
         _actionManager.ExcuteHandler(_currentActionHandler.Label);
     }
 }
コード例 #4
0
        public void UpdateData()
        {
            DebugMsg.Log("----" + Label + "激活条件:" + ActiveCondition());

            if (ActiveCondition())
            {
                _onActivate(this);
            }
            else
            {
                _onInactivate(this);
            }
        }
コード例 #5
0
        private void ChangeValue(string key, bool value)
        {
            if (_onChange != null)
            {
                DebugMsg.Log("-----state值被改变了" + key + "  " + value);
            }

            _dataTable[key] = value;
            if (_onChange != null)
            {
                _onChange();
            }
        }
コード例 #6
0
        private void AddHandler(TAction label, Dictionary <TAction, IActionHandler <TAction> > dic)
        {
            var handler = _agent.Maps.GetActionHandler(label);

            if (handler != null)
            {
                dic.Add(label, handler);
                //这里写拉姆达表达式,是为了避免初始化的时候_onActionComplete还是null的
                handler.AddFinishCallBack(() =>
                {
                    DebugMsg.Log("动作完成:   " + label);
                    _onActionComplete(label);
                });
            }
            else
            {
                DebugMsg.LogError("映射文件中未找到对应Handler,标签为:" + label);
            }
        }
コード例 #7
0
ファイル: ActionHandler.cs プロジェクト: JCYTop/Tmp
        protected async void OnComplete(float delayTime = 0)
        {
            if (ExcuteState == ActionExcuteState.EXIT)
            {
                return;
            }
            await Task.Delay(TimeSpan.FromSeconds(delayTime));

            ExcuteState = ActionExcuteState.EXIT;
            DebugMsg.Log("------设置" + Label + "影响");
            if (Action.Effects != null)
            {
                SetAgentData(Action.Effects);
            }
            if (_onFinishAction != null)
            {
                _onFinishAction();
            }
        }
コード例 #8
0
        public IGoal <TGoal> FindGoal()
        {
            //查找优先级最大的那个
            _activeGoals = _activeGoals.OrderByDescending(u => u.GetPriority()).ToList();

            DebugMsg.Log("-----------active goal-----------");
            foreach (IGoal <TGoal> goal in _activeGoals)
            {
                DebugMsg.Log(goal.Label + " 优先级:" + goal.GetPriority());
            }
            DebugMsg.Log("---------------------------------");

            if (_activeGoals.Count > 0)
            {
                return(_activeGoals[0]);
            }
            else
            {
                return(null);
            }
        }
コード例 #9
0
ファイル: Planner.cs プロジェクト: youmuren0613/EntitasDemo
        public Queue <IActionHandler <TAction> > BuildPlan(IGoal <TGoal> goal)
        {
            DebugMsg.Log("制定计划");
            DebugMsg.Log("---------------当前代理状态------------");
            DebugMsg.Log(_agent.AgentState.ToString());
            DebugMsg.Log("---------------------------");

            Queue <IActionHandler <TAction> > plan = new Queue <IActionHandler <TAction> >();

            if (goal == null)
            {
                return(plan);
            }

            TreeNode <TAction> currentNode = Plan(goal);

            if (currentNode == null)
            {
                plan.Enqueue(_agent.ActionManager.GetHandler(_agent.ActionManager.GetDefaultActionLabel()));
                DebugMsg.LogError("当前节点为空,设置当前动作为默认动作");
                return(plan);
            }

            while (currentNode.ID != TreeNode <TAction> .DEFAULT_ID)
            {
                plan.Enqueue(currentNode.ActionHandler);
                currentNode = currentNode.ParentNode;
            }

            DebugMsg.Log("---------------最终生成计划------------");
            foreach (IActionHandler <TAction> handler in plan)
            {
                DebugMsg.Log("计划项:" + handler.Label);
            }
            DebugMsg.Log("---------------当前代理状态------------");
            DebugMsg.Log(_agent.AgentState.ToString());
            DebugMsg.Log("---------------------------");
            DebugMsg.Log("计划结束");
            return(plan);
        }
コード例 #10
0
ファイル: Planner.cs プロジェクト: youmuren0613/EntitasDemo
        public TreeNode <TAction> Plan(IGoal <TGoal> goal)
        {
            Tree <TAction> tree = new Tree <TAction>();
            //初始化树的头节点
            TreeNode <TAction> topNode = CreateTopNode(tree, goal);

            TreeNode <TAction> cheapestNode = null;
            TreeNode <TAction> currentNode  = topNode;
            TreeNode <TAction> subNode      = null;

            while (!IsEnd(currentNode))
            {
                //获取所有的子行为
                List <IActionHandler <TAction> > handlers = GetSubHandlers(currentNode);

                DebugMsg.Log("---------------currentNode:" + currentNode.ID + "-----------------");
                foreach (IActionHandler <TAction> handler in handlers)
                {
                    DebugMsg.Log("计划子行为:" + handler.Label + "  优先级:" + handler.Action.Priority);
                }
                DebugMsg.Log("--------------------------------");

                foreach (IActionHandler <TAction> handler in handlers)
                {
                    subNode = tree.CreateNode(handler);
                    SetNodeState(currentNode, subNode);
                    subNode.Cost       = GetCost(subNode);
                    subNode.ParentNode = currentNode;
                    cheapestNode       = GetCheapestNode(subNode, cheapestNode);
                }

                currentNode  = cheapestNode;
                cheapestNode = null;
            }


            return(currentNode);
        }
コード例 #11
0
 public void UpdateData()
 {
     DebugMsg.Log("GoalManager UpdateData");
     UpdateGoals();
     UpdateCurrentGoal();
 }