summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/AI/AIRuntimeSetDest.cs
blob: dcb0fee09fb05de91e73d1f2226edfb88cdb12e7 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using System.Xml;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient
{
	internal class AIRuntimeSetDest : AIRunTimeNodeAction
	{
		private string _final_dest_name;

		private string _target_name;

		private string _nav_name;

		private string _born_pos_name;

		private Vector3 _born_pos;

		private string _tick_count_name;

		private float _random_max;

		private float _adjust_angle;

		private string _adjust_length_name;

		private float _adjust_value;

		private int _adjust_dir;

		private int _set_dest_type;

		public AIRuntimeSetDest(XmlElement node) : base(node)
		{
			this._final_dest_name = node.GetAttribute("Shared_FinalDestName");
			this._target_name = node.GetAttribute("Shared_TargetName");
			this._nav_name = node.GetAttribute("Shared_NavName");
			this._born_pos_name = node.GetAttribute("Shared_BornPosName");
			this._tick_count_name = node.GetAttribute("Shared_TickCountName");
			this._random_max = float.Parse(node.GetAttribute("RandomMax"));
			this._adjust_angle = float.Parse(node.GetAttribute("AdjustAngle"));
			this._adjust_length_name = node.GetAttribute("Shared_AdjustLengthName");
			this._adjust_value = float.Parse(node.GetAttribute("Shared_AdjustLengthmValue"));
			this._adjust_dir = int.Parse(node.GetAttribute("AdjustDir"));
			this._set_dest_type = int.Parse(node.GetAttribute("SetDestType"));
			string attribute = node.GetAttribute("Shared_BornPosmValue");
			float num = float.Parse(attribute.Split(new char[]
			{
				':'
			})[0]);
			float num2 = float.Parse(attribute.Split(new char[]
			{
				':'
			})[1]);
			float num3 = float.Parse(attribute.Split(new char[]
			{
				':'
			})[2]);
			this._born_pos = new Vector3(num, num2, num3);
		}

		public override bool Update(XEntity entity)
		{
			Vector3 vector = entity.AI.AIData.GetVector3ByName(this._final_dest_name, Vector3.zero);
			XGameObject xgameObjectByName = entity.AI.AIData.GetXGameObjectByName(this._target_name);
			Transform transformByName = entity.AI.AIData.GetTransformByName(this._nav_name);
			Vector3 vector2 = entity.AI.AIData.GetVector3ByName(this._born_pos_name, Vector3.zero);
			int intByName = entity.AI.AIData.GetIntByName(this._tick_count_name, 0);
			float floatByName = entity.AI.AIData.GetFloatByName(this._adjust_length_name, this._adjust_value);
			bool flag = string.IsNullOrEmpty(this._born_pos_name);
			if (flag)
			{
				vector2 = this._born_pos;
			}
			Vector3 vector3 = new Vector3(1f, 0f, 1f);
			//vector3= new Vector3(1f, 0f, 1f);
			int num = XFastEnumIntEqualityComparer<SetDestWay>.ToInt(SetDestWay.Target);
			bool flag2 = this._set_dest_type == XFastEnumIntEqualityComparer<SetDestWay>.ToInt(SetDestWay.Target);
			if (flag2)
			{
				bool flag3 = xgameObjectByName == null;
				if (flag3)
				{
					return false;
				}
				vector = xgameObjectByName.Position;
			}
			else
			{
				bool flag4 = this._set_dest_type == XFastEnumIntEqualityComparer<SetDestWay>.ToInt(SetDestWay.BornPos);
				if (flag4)
				{
					vector = vector2;
				}
				else
				{
					bool flag5 = this._set_dest_type == XFastEnumIntEqualityComparer<SetDestWay>.ToInt(SetDestWay.NavPos);
					if (flag5)
					{
						bool flag6 = transformByName == null;
						if (flag6)
						{
							return false;
						}
						vector = transformByName.position;
					}
				}
			}
			bool flag7 = floatByName != 0f;
			if (flag7)
			{
				Vector3 vector4 = Vector3.zero;
				bool flag8 = this._adjust_dir == XFastEnumIntEqualityComparer<AdjustDirection>.ToInt(AdjustDirection.TargetDir);
				if (flag8)
				{
					vector4 = entity.EngineObject.Position - vector;
				}
				else
				{
					bool flag9 = this._adjust_dir == XFastEnumIntEqualityComparer<AdjustDirection>.ToInt(AdjustDirection.TargetFace) && xgameObjectByName != null;
					if (flag9)
					{
						vector4 = xgameObjectByName.Forward.normalized;
					}
					else
					{
						bool flag10 = this._adjust_dir == XFastEnumIntEqualityComparer<AdjustDirection>.ToInt(AdjustDirection.SelfFace);
						if (flag10)
						{
							vector4 = entity.EngineObject.Forward.normalized;
						}
					}
				}
				Vector3 vector5 = vector + (Quaternion.Euler(new Vector3(0f, (float)(intByName % 2) * this._adjust_angle * 2f - this._adjust_angle, 0f)) * vector4).normalized * floatByName;
				bool flag11 = !XSingleton<XAIGeneralMgr>.singleton.IsPointInMap(vector5);
				if (flag11)
				{
					for (int i = 0; i < 18; i++)
					{
						float num2 = this._adjust_angle + (float)(i * 10);
						vector5 = vector + (Quaternion.Euler(new Vector3(0f, (float)(intByName % 2) * num2 * 2f - num2, 0f)) * vector4).normalized * floatByName;
						bool flag12 = XSingleton<XAIGeneralMgr>.singleton.IsPointInMap(vector5);
						if (flag12)
						{
							break;
						}
						num2 = this._adjust_angle - (float)(i * 10);
						vector5 = vector + (Quaternion.Euler(new Vector3(0f, (float)(intByName % 2) * num2 * 2f - num2, 0f)) * vector4).normalized * floatByName;
						bool flag13 = XSingleton<XAIGeneralMgr>.singleton.IsPointInMap(vector5);
						if (flag13)
						{
							break;
						}
					}
				}
				vector = vector5;
			}
			bool flag14 = this._random_max > 0f;
			if (flag14)
			{
				vector3.x = XSingleton<XCommon>.singleton.RandomFloat(-0.5f, 0.5f);
				vector3.z = XSingleton<XCommon>.singleton.RandomFloat(-0.5f, 0.5f);
				vector += this._random_max * vector3.normalized;
			}
			entity.AI.AIData.SetVector3ByName(this._final_dest_name, vector);
			return true;
		}
	}
}