summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XLocateTargetComponent.cs
blob: 5993b87b00072087a38894dec95ab205b224e331 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
using System;
using System.Collections.Generic;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XLocateTargetComponent : XComponent
	{
		public override uint ID
		{
			get
			{
				return XLocateTargetComponent.uuID;
			}
		}

		public XEntity Target
		{
			get
			{
				return XEntity.ValideEntity(this._last_target) ? this._last_target : (XEntity.ValideEntity(this._last_pre_target) ? this._last_pre_target : null);
			}
		}

		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("XLocateTarget");

		private bool _spectator = false;

		private Vector3 _last_forward = Vector3.zero;

		private XEntity _last_pre_target = null;

		private XEntity _last_target = null;

		private List<float> _elapsed = new List<float>();

		private List<float> _angle = new List<float>();

		private float _scene_specified = 0f;

		protected override void EventSubscribe()
		{
		}

		public override void Attached()
		{
			this._spectator = (XSingleton<XScene>.singleton.bSpectator && this._entity.IsPlayer);
			this._elapsed.Clear();
			this._angle.Clear();
			this._scene_specified = XSingleton<XSceneMgr>.singleton.SpecifiedTargetLocatedRange(XSingleton<XScene>.singleton.SceneID);
		}

		public override void OnDetachFromHost()
		{
			base.OnDetachFromHost();
		}

		public override void Update(float fDeltaT)
		{
			bool flag = this.Target != null;
			int i;
			for (i = 0; i < this._elapsed.Count; i++)
			{
				bool flag2 = Vector3.Angle(this._entity.EngineObject.Forward, XSingleton<XCommon>.singleton.FloatToAngle(this._angle[i])) < XSingleton<XOperationData>.singleton.WithinScope * 0.5f;
				if (flag2)
				{
					List<float> elapsed = this._elapsed;
					int index = i;
					elapsed[index] += fDeltaT;
					bool flag3 = this._elapsed[i] > 0.1f;
					if (flag3)
					{
						bool flag4 = this._last_forward.sqrMagnitude == 0f || Vector3.Angle(this._last_forward, XSingleton<XCommon>.singleton.FloatToAngle(this._angle[i])) > 30f || this._elapsed[i] > 0.5f;
						if (flag4)
						{
							break;
						}
					}
				}
				else
				{
					this._elapsed.RemoveAt(i);
					this._angle.RemoveAt(i);
					i--;
				}
			}
			bool flag5 = i < this._elapsed.Count;
			if (flag5)
			{
				this.Locate(this._entity.EngineObject.Forward, this._entity.EngineObject.Position, true);
				this._elapsed.Clear();
				this._angle.Clear();
			}
			else
			{
				float item = XSingleton<XCommon>.singleton.AngleToFloat(this._entity.EngineObject.Forward);
				bool flag6 = !this._angle.Contains(item);
				if (flag6)
				{
					this._elapsed.Add(0f);
					this._angle.Add(item);
				}
			}
		}

		public XEntity Locate(Vector3 forward, Vector3 pos, bool routine = false)
		{
			bool flag = false;
			XEntity xentity = null;
			bool flag2 = xentity != null && !xentity.IsRole && xentity.Buffs != null && xentity.Buffs.IsBuffStateOn(XBuffType.XBuffType_Immortal);
			if (flag2)
			{
				xentity = null;
			}
			bool flag3 = xentity == null;
			if (flag3)
			{
				xentity = XSkillCore.FindTargetAt(pos, forward, (this._scene_specified > 0f) ? this._scene_specified : XSingleton<XOperationData>.singleton.ProfRangeLong, 0f, (float)(XSingleton<XOperationData>.singleton.ProfScope >> 1), this._spectator ? (this._entity as XPlayer).WatchTo : this._entity, true);
				bool flag4 = xentity != null && !xentity.IsRole && xentity.Buffs != null && xentity.Buffs.IsBuffStateOn(XBuffType.XBuffType_Immortal);
				if (flag4)
				{
					xentity = null;
				}
				bool flag5 = xentity == null;
				if (flag5)
				{
					xentity = ((XSingleton<XOperationData>.singleton.OperationMode == XOperationMode.X25D) ? null : this.AssistLocate(forward, pos));
					bool flag6 = xentity != null && !xentity.IsRole && xentity.Buffs != null && xentity.Buffs.IsBuffStateOn(XBuffType.XBuffType_Immortal);
					if (flag6)
					{
						xentity = null;
					}
					bool flag7 = xentity != null;
					if (flag7)
					{
						flag = true;
					}
					else
					{
						xentity = XSkillCore.FindTargetAt(pos, forward, (this._scene_specified > 0f) ? this._scene_specified : XSingleton<XOperationData>.singleton.ProfRangeAll, 0f, 180f, this._spectator ? (this._entity as XPlayer).WatchTo : this._entity, true);
						bool flag8 = xentity != null;
						if (flag8)
						{
							bool isPuppet = xentity.IsPuppet;
							if (isPuppet)
							{
								xentity = null;
							}
							else
							{
								flag = true;
							}
						}
					}
				}
				else
				{
					flag = true;
				}
			}
			bool flag9 = xentity != null && xentity.IsVisible;
			if (flag9)
			{
				XSingleton<XTutorialHelper>.singleton.MeetEnemy = true;
				bool flag10 = flag;
				if (flag10)
				{
					this.Highlight(null, ref this._last_target, Color.red);
					this.Highlight(xentity, ref this._last_pre_target, Color.black);
				}
				else
				{
					this.Highlight(null, ref this._last_pre_target, Color.black);
					this.Highlight(xentity, ref this._last_target, Color.red);
				}
				this._last_forward = forward;
			}
			else
			{
				xentity = null;
				this.Highlight(null, ref this._last_target, Color.red);
				this.Highlight(null, ref this._last_pre_target, Color.black);
				this._last_forward = Vector3.zero;
			}
			return xentity;
		}

		private XEntity AssistLocate(Vector3 forward, Vector3 pos)
		{
			Vector3 forward2 = XSingleton<XScene>.singleton.GameCamera.CameraTrans.forward;
			forward2.y = 0f;
			forward2.Normalize();
			float num = Vector3.Angle(forward2, forward);
			float num2 = XSingleton<XCommon>.singleton.Clockwise(forward2, forward) ? (-XSingleton<XOperationData>.singleton.AssistAngle) : XSingleton<XOperationData>.singleton.AssistAngle;
			bool flag = num < XSingleton<XOperationData>.singleton.AssistAngle;
			if (flag)
			{
				num = XSingleton<XOperationData>.singleton.AssistAngle;
				Vector3 vector = XSingleton<XCommon>.singleton.HorizontalRotateVetor3(forward2, num2, true);
				forward = Vector3.Reflect(-vector, forward2);
			}
			num += XSingleton<XOperationData>.singleton.AssistAngle;
			num2 = ((num2 > 0f) ? num : (-num)) * 0.5f;
			forward = XSingleton<XCommon>.singleton.HorizontalRotateVetor3(forward, num2, false);
			return XSkillCore.FindTargetAt(pos, forward, (this._scene_specified > 0f) ? this._scene_specified : XSingleton<XOperationData>.singleton.ProfRangeLong, 0f, Mathf.Abs(num2), this._spectator ? (this._entity as XPlayer).WatchTo : this._entity, true);
		}

		private void Highlight(XEntity target, ref XEntity last, Color color)
		{
			bool flag = target != null && target != last;
			if (flag)
			{
				bool flag2 = last != null;
				if (flag2)
				{
				}
				last = target;
			}
			else
			{
				bool flag3 = target == null && last != null;
				if (flag3)
				{
					last = null;
				}
			}
		}

		public override void PostUpdate(float fDeltaT)
		{
			bool flag = !XSingleton<XScene>.singleton.bSpectator && this._entity.IsPlayer;
			if (flag)
			{
				bool flag2 = DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IsLoaded();
				if (flag2)
				{
					DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.BattleTargetHandler.ShowTargetFx(XEntity.ValideEntity(this._last_target), this._last_target);
					DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.BattleTargetHandler.ShowPretargetFx(XEntity.ValideEntity(this._last_pre_target), this._last_pre_target);
				}
				bool flag3 = DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded();
				if (flag3)
				{
					DlgBase<BattleMain, BattleMainBehaviour>.singleton.BattleTargetHandler.ShowTargetFx(XEntity.ValideEntity(this._last_target), this._last_target);
					DlgBase<BattleMain, BattleMainBehaviour>.singleton.BattleTargetHandler.ShowPretargetFx(XEntity.ValideEntity(this._last_pre_target), this._last_pre_target);
				}
			}
		}
	}
}