Exemple #1
0
        //action
        public static void Log(Agent pAgent, string btMsg, EActionResult actionResult, LogMode mode)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                //BEHAVIAC_PROFILE("LogManager.LogAction");
                if (!System.Object.ReferenceEquals(pAgent, null) && pAgent.IsMasked())
                {
                    if (!string.IsNullOrEmpty(btMsg))
                    {
                        string agentClassName = pAgent.GetClassTypeName();

                        agentClassName = agentClassName.Replace(".", "::");

                        string agentName = agentClassName;
                        agentName += "#";
                        agentName += pAgent.GetName();

                        string actionResultStr = "";
                        if (actionResult == EActionResult.EAR_success)
                        {
                            actionResultStr = "success";
                        }
                        else if (actionResult == EActionResult.EAR_failure)
                        {
                            actionResultStr = "failure";
                        }
                        else
                        {
                            //although actionResult can be EAR_none or EAR_all, but, as this is the real result of an action
                            //it can only be success or failure
                            //when it is EAR_none, it is for update
                            if (actionResult == behaviac.EActionResult.EAR_none && mode == behaviac.LogMode.ELM_tick)
                            {
                                actionResultStr = "running";
                            }
                            else
                            {
                                actionResultStr = "none";
                            }
                        }

                        if (mode == LogMode.ELM_continue)
                        {
                            //[continue]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:enter [all/success/failure] [1]
                            int count = Workspace.GetActionCount(btMsg);
                            Debug.Check(count > 0);
                            string buffer = string.Format("[continue]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else if (mode == LogMode.ELM_breaked)
                        {
                            //[breaked]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:enter [all/success/failure] [1]
                            int count = Workspace.GetActionCount(btMsg);
                            Debug.Check(count > 0);
                            string buffer = string.Format("[breaked]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else if (mode == LogMode.ELM_tick)
                        {
                            //[tick]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:enter [all/success/failure] [1]
                            //[tick]Ship.Ship_1 ships\suicide.xml.BehaviorTreeTask[0]:update [1]
                            //[tick]Ship.Ship_1 ships\suicide.xml.Selector[1]:enter [all/success/failure] [1]
                            //[tick]Ship.Ship_1 ships\suicide.xml.Selector[1]:update [1]
                            int count = Workspace.UpdateActionCount(btMsg);

                            string buffer = string.Format("[tick]{0} {1} [{2}] [{3}]\n", agentName, btMsg, actionResultStr, count);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else if (mode == LogMode.ELM_jump)
                        {
                            string buffer = string.Format("[jump]{0} {1}\n", agentName, btMsg);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else if (mode == LogMode.ELM_return)
                        {
                            string buffer = string.Format("[return]{0} {1}\n", agentName, btMsg);

                            Output(pAgent, buffer);
                            SocketUtils.SendText(buffer);
                        }
                        else
                        {
                            Debug.Check(false);
                        }
                    }
                }
            }
#endif
        }