public override bool Init(int aiId) { if (!base.Init(aiId)) { return(false); } // 解析idle状态默认行为 AIGoal goal = CommonAI.ParseGoalXML(this, mRes.commonIdle); if (goal != null) { mStateIdle.AddCommand(goal); } return(true); }
static public AIGoal ParseGoalXML(CommonAI ai, string xmlData) { if (xmlData == null) { return(null); } if (xmlData.Length == 0) { return(null); } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlData); XmlNode node = xmlDoc.FirstChild; if (node.Name != "root") { return(null); } bool loop = node.Attributes["loop"] != null?System.Convert.ToBoolean(node.Attributes["loop"].Value) : false; AIGoalCompositeGoal rootGoal = new AIGoalCompositeGoal(ai, loop); XmlNodeList nodeList = node.ChildNodes; for (int i = 0; i < nodeList.Count; i++) { AIGoal goal = ParseGoalNode(ai, nodeList[i]); if (goal == null) { return(null); } rootGoal.AddSubGoal(goal); } return(rootGoal); }
static public AIGoal ParseGoalNode(CommonAI ai, XmlNode node) { if (ai == null) { return(null); } if (node == null) { return(null); } if (node.Name == "walk") { if (node.Attributes["x"] == null || node.Attributes["y"] == null || node.Attributes["z"] == null) { return(null); } float x = System.Convert.ToSingle(node.Attributes["x"].Value); float y = System.Convert.ToSingle(node.Attributes["y"].Value); float z = System.Convert.ToSingle(node.Attributes["z"].Value); Vector3f tarPos = new Vector3f(x, y, z); return(new AIGoalWalk(ai, tarPos)); } else if (node.Name == "run") { if (node.Attributes["x"] == null || node.Attributes["y"] == null || node.Attributes["z"] == null) { return(null); } float x = System.Convert.ToSingle(node.Attributes["x"].Value); float y = System.Convert.ToSingle(node.Attributes["y"].Value); float z = System.Convert.ToSingle(node.Attributes["z"].Value); Vector3f tarPos = new Vector3f(x, y, z); return(new AIGoalRun(ai, tarPos)); } else if (node.Name == "wait") { if (node.Attributes["time"] == null) { return(null); } uint millisecond = System.Convert.ToUInt32(node.Attributes["time"].Value); return(new AIGoalWait(ai, millisecond)); } else if (node.Name == "useskilltoposition") { if (node.Attributes["x"] == null || node.Attributes["y"] == null || node.Attributes["z"] == null || node.Attributes["skillid"] == null) { return(null); } float x = System.Convert.ToSingle(node.Attributes["x"].Value); float y = System.Convert.ToSingle(node.Attributes["y"].Value); float z = System.Convert.ToSingle(node.Attributes["z"].Value); int skillId = System.Convert.ToInt32(node.Attributes["skillid"].Value); Vector3f tarPos = new Vector3f(x, y, z); return(new AIGoalUseSkillToPosition(ai, skillId, tarPos)); } else if (node.Name == "say") { if (node.Attributes["talkid"] == null) { return(null); } int talkid = System.Convert.ToInt32(node.Attributes["talkid"].Value); return(new AIGoalSay(ai, talkid)); } else if (node.Name == "randmoveradius") { if (node.Attributes["minr"] == null || node.Attributes["maxr"] == null) { return(null); } float minRadius = System.Convert.ToSingle(node.Attributes["minr"].Value); float maxRadius = System.Convert.ToSingle(node.Attributes["maxr"].Value); return(new AIGoalRandMoveRadius(ai, minRadius, maxRadius)); } else if (node.Name == "stand") { if (node.Attributes["mintime"] == null || node.Attributes["maxtime"] == null) { return(null); } uint minMillisecond = System.Convert.ToUInt32(node.Attributes["mintime"].Value); uint maxMillisecond = System.Convert.ToUInt32(node.Attributes["maxtime"].Value); return(new AIGoalStand(ai, minMillisecond, maxMillisecond)); } else if (node.Name == "destoryself") { return(new AIGoalDestorySelf(ai)); } else if (node.Name == "turnto") { if (node.Attributes["x"] == null || node.Attributes["y"] == null || node.Attributes["z"] == null) { return(null); } float x = System.Convert.ToSingle(node.Attributes["x"].Value); float y = System.Convert.ToSingle(node.Attributes["y"].Value); float z = System.Convert.ToSingle(node.Attributes["z"].Value); Vector3f tarPos = new Vector3f(x, y, z); return(new AIGoalTurnToPosition(ai, tarPos)); } else if (node.Name == "ani") { if (node.Attributes["name"] == null) { return(null); } string name = node.Attributes["name"].Value; return(new AIGoalPlayAni(ai, name)); } return(null); }
public AIStateCombat(CommonAI ai) : base(ai) { }
public AIStateGoHome(CommonAI ai) : base(ai) { }
public AIState(CommonAI ai) { mAI = ai; mGoalQueue = new AIGoalCompositeGoal(mAI, false); }
public AIStateIdle(CommonAI ai) : base(ai) { }