summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/AI/AIRunTimeTreeMgr.cs
blob: d93b0db6a1bd21f0f52004d749b645342621b0a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using XUtliPoolLib;

namespace XMainClient
{
	internal class AIRunTimeTreeMgr : XSingleton<AIRunTimeTreeMgr>
	{
		private Dictionary<string, AIRunTimeRootNode> _behavior_tree = new Dictionary<string, AIRunTimeRootNode>();

		private AIRunTimeRootNode LoadAITree(Stream content, string key)
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(content);
			XSingleton<XResourceLoaderMgr>.singleton.ClearStream(content);
			XmlElement documentElement = xmlDocument.DocumentElement;
			AIRunTimeRootNode airunTimeRootNode = this.LoadOneNode(documentElement.FirstChild as XmlElement) as AIRunTimeRootNode;
			this._behavior_tree[key] = airunTimeRootNode;
			return airunTimeRootNode;
		}

		public AIRunTimeRootNode GetBehavior(string name)
		{
			AIRunTimeRootNode result = null;
			bool flag = !this._behavior_tree.TryGetValue(name, out result);
			if (flag)
			{
				result = this.LoadAITree(XSingleton<XResourceLoaderMgr>.singleton.ReadText("Table/AITree/" + name, ".xml", true), name);
			}
			return result;
		}

		private AIRunTimeNodeBase LoadOneNode(XmlElement element)
		{
			bool flag = element == null;
			AIRunTimeNodeBase result;
			if (flag)
			{
				result = null;
			}
			else
			{
				AIRunTimeNodeBase airunTimeNodeBase = AINodeFactory.CreateAINodeByName(element.Name, element);
				bool flag2 = element.Name == "ConditionalEvaluator";
				if (flag2)
				{
					AIRunTimeNodeBase airunTimeNodeBase2 = AINodeFactory.CreateAINodeByName((airunTimeNodeBase as AIRunTimeConditionalEvaluator).ConditionNodeName, element);
					bool flag3 = airunTimeNodeBase2 != null;
					if (flag3)
					{
						(airunTimeNodeBase as AIRunTimeConditionalEvaluator).AddConditionNode(airunTimeNodeBase2);
					}
				}
				for (int i = 0; i < element.ChildNodes.Count; i++)
				{
					AIRunTimeNodeBase airunTimeNodeBase3 = this.LoadOneNode(element.ChildNodes[i] as XmlElement);
					bool flag4 = airunTimeNodeBase3 != null;
					if (flag4)
					{
						airunTimeNodeBase.AddChild(airunTimeNodeBase3);
					}
				}
				result = airunTimeNodeBase;
			}
			return result;
		}
	}
}