summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XAITarget.cs
blob: b629bf3718823402e5243976c0782f31906753eb (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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
using System;
using System.Collections.Generic;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XAITarget : XSingleton<XAITarget>
	{
		private int SortEnemy(XEntity a, XEntity b)
		{
			bool flag = a == null || b == null;
			int result;
			if (flag)
			{
				result = 0;
			}
			else
			{
				bool flag2 = a.Attributes == null || b.Attributes == null;
				if (flag2)
				{
					result = 0;
				}
				else
				{
					int value = 0;
					XEntityStatistics.RowData byID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(a.Attributes.TypeID);
					bool flag3 = byID != null;
					if (flag3)
					{
						value = (int)byID.aihit;
					}
					int num = 0;
					XEntityStatistics.RowData byID2 = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(b.Attributes.TypeID);
					bool flag4 = byID2 != null;
					if (flag4)
					{
						num = (int)byID2.aihit;
					}
					result = num.CompareTo(value);
				}
			}
			return result;
		}

		public bool ResetTargets(XEntity entity)
		{
			List<XEntity> opponent = XSingleton<XEntityMgr>.singleton.GetOpponent(entity);
			entity.AI.ClearTargets();
			for (int i = 0; i < opponent.Count; i++)
			{
				bool flag = XEntity.ValideEntity(opponent[i]);
				if (flag)
				{
					entity.AI.AddTarget(opponent[i]);
				}
			}
			bool flag2 = entity.AI.TargetsCount == 0;
			bool result;
			if (flag2)
			{
				entity.AI.IsFighting = false;
				result = false;
			}
			else
			{
				result = true;
			}
			return result;
		}

		public bool FindTargetByDistance(XEntity entity, float dist, bool filterImmortal, float angle, float delta, int targettype)
		{
			bool flag = !this.ResetTargets(entity);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = entity.AI.TargetsCount == 0;
				if (flag2)
				{
					entity.AI.IsFighting = false;
					result = false;
				}
				else
				{
					List<XEntity> list = ListPool<XEntity>.Get();
					entity.AI.SortTarget(new Comparison<XEntity>(this.SortEnemy));
					for (int i = 0; i < entity.AI.TargetsCount; i++)
					{
						XEntity target = entity.AI.GetTarget(i);
						bool flag3 = XEntity.ValideEntity(target);
						if (flag3)
						{
							Vector3 position = target.EngineObject.Position;
							Vector3 position2 = entity.EngineObject.Position;
							float magnitude = (position - position2).magnitude;
							bool flag4 = magnitude < dist;
							if (flag4)
							{
								bool flag5 = !filterImmortal || target.Buffs == null || !target.Buffs.IsBuffStateOn(XBuffType.XBuffType_Immortal);
								if (flag5)
								{
									bool flag6 = angle < 180f && angle > 0f;
									if (flag6)
									{
										Vector3 vector = target.EngineObject.Position - entity.EngineObject.Position;
										float num = Vector3.Angle(vector, entity.EngineObject.Forward);
										bool flag7 = num < angle;
										if (flag7)
										{
											bool flag8 = targettype == 0 || targettype == 2;
											if (flag8)
											{
												list.Add(target);
											}
										}
									}
									else
									{
										bool flag9 = targettype == 0 || targettype == 2;
										if (flag9)
										{
											list.Add(target);
										}
									}
								}
							}
						}
					}
					entity.AI.Copy2Target(list);
					ListPool<XEntity>.Release(list);
					bool flag10 = entity.AI.TargetsCount == 0;
					if (flag10)
					{
						entity.AI.IsFighting = false;
						result = false;
					}
					else
					{
						result = true;
					}
				}
			}
			return result;
		}

		public bool FindTargetByHitLevel(XEntity entity, bool filterImmortal)
		{
			this.ResetTargets(entity);
			bool flag = entity.AI.TargetsCount == 0;
			bool result;
			if (flag)
			{
				entity.AI.IsFighting = false;
				result = false;
			}
			else
			{
				List<XEntity> list = ListPool<XEntity>.Get();
				entity.AI.SortTarget(new Comparison<XEntity>(this.SortEnemy));
				int num = -1;
				int i = 0;
				while (i < entity.AI.TargetsCount)
				{
					XEntity target = entity.AI.GetTarget(i);
					bool flag2 = XEntity.ValideEntity(target);
					if (flag2)
					{
						bool syncMode = XSingleton<XGame>.singleton.SyncMode;
						bool flag3;
						if (syncMode)
						{
							flag3 = target.IsServerFighting;
						}
						else
						{
							flag3 = (target.IsFighting || !target.HasAI);
						}
						bool flag4 = !flag3;
						if (!flag4)
						{
							bool flag5 = !filterImmortal || target.Buffs == null || !XSingleton<XAIGeneralMgr>.singleton.IsTargetEntityImmortal(target);
							if (flag5)
							{
								XEntityStatistics.RowData byID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(target.Attributes.TypeID);
								bool flag6 = byID != null;
								if (flag6)
								{
									num = (int)byID.aihit;
									break;
								}
							}
						}
					}
					IL_117:
					i++;
					continue;
					goto IL_117;
				}
				int j = 0;
				while (j < entity.AI.TargetsCount)
				{
					XEntity target2 = entity.AI.GetTarget(j);
					bool flag7 = XEntity.ValideEntity(target2);
					if (flag7)
					{
						bool syncMode2 = XSingleton<XGame>.singleton.SyncMode;
						bool flag8;
						if (syncMode2)
						{
							flag8 = target2.IsServerFighting;
						}
						else
						{
							flag8 = (target2.IsFighting || !target2.HasAI);
						}
						bool flag9 = !flag8;
						if (!flag9)
						{
							Vector3 position = target2.EngineObject.Position;
							Vector3 position2 = entity.EngineObject.Position;
							float magnitude = (position - position2).magnitude;
							int num2 = -1;
							XEntityStatistics.RowData byID2 = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(target2.Attributes.TypeID);
							bool flag10 = byID2 != null;
							if (flag10)
							{
								num2 = (int)byID2.aihit;
							}
							bool flag11 = num2 == num && num2 >= 0;
							if (flag11)
							{
								bool flag12 = !filterImmortal || target2.Buffs == null || !XSingleton<XAIGeneralMgr>.singleton.IsTargetEntityImmortal(target2);
								if (flag12)
								{
									list.Add(target2);
								}
							}
						}
					}
					IL_250:
					j++;
					continue;
					goto IL_250;
				}
				bool flag13 = list.Count == 0 && filterImmortal;
				if (flag13)
				{
					for (int k = 0; k < entity.AI.TargetsCount; k++)
					{
						XEntity target3 = entity.AI.GetTarget(k);
						XEntityStatistics.RowData byID3 = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(target3.Attributes.TypeID);
						bool flag14 = byID3.aihit >= 0 && XSingleton<XAIGeneralMgr>.singleton.IsTargetEntityImmortal(target3) && (target3.IsFighting || target3.IsServerFighting);
						if (flag14)
						{
							list.Add(target3);
						}
					}
				}
				entity.AI.Copy2Target(list);
				ListPool<XEntity>.Release(list);
				bool flag15 = entity.AI.TargetsCount == 0;
				if (flag15)
				{
					entity.AI.IsFighting = false;
					result = false;
				}
				else
				{
					result = true;
				}
			}
			return result;
		}

		public bool FindTargetByHartedList(XEntity entity, bool filterImmortal)
		{
			List<XEntity> hateEntity = entity.AI.EnmityList.GetHateEntity(filterImmortal);
			bool flag = hateEntity.Count == 0;
			bool result;
			if (flag)
			{
				entity.AI.IsFighting = false;
				result = false;
			}
			else
			{
				entity.AI.Copy2Target(hateEntity);
				result = true;
			}
			return result;
		}

		public bool FindTargetByNonImmortal(XEntity entity)
		{
			return true;
		}

		public bool DoSelectNearest(XEntity entity)
		{
			bool flag = entity.AI.TargetsCount == 0;
			bool result;
			if (flag)
			{
				entity.AI.SetTarget(null);
				entity.AI.IsFighting = false;
				result = false;
			}
			else
			{
				float num = float.MaxValue;
				XEntity target = entity.AI.GetTarget(0);
				for (int i = 0; i < entity.AI.TargetsCount; i++)
				{
					XEntity target2 = entity.AI.GetTarget(i);
					float magnitude = (target2.EngineObject.Position - entity.EngineObject.Position).magnitude;
					bool flag2 = magnitude < num;
					if (flag2)
					{
						num = magnitude;
						target = target2;
					}
				}
				entity.AI.SetTarget(target);
				bool flag3 = !entity.AI.IsFighting;
				if (flag3)
				{
					XAIEnterFightEventArgs @event = XEventPool<XAIEnterFightEventArgs>.GetEvent();
					@event.Firer = entity;
					@event.Target = target;
					XSingleton<XEventMgr>.singleton.FireEvent(@event);
				}
				entity.AI.IsFighting = true;
				result = true;
			}
			return result;
		}

		public bool DoSelectFarthest(XEntity entity)
		{
			bool flag = entity.AI.TargetsCount == 0;
			bool result;
			if (flag)
			{
				entity.AI.SetTarget(null);
				entity.AI.IsFighting = false;
				result = false;
			}
			else
			{
				float num = 0f;
				XEntity target = entity.AI.GetTarget(0);
				for (int i = 0; i < entity.AI.TargetsCount; i++)
				{
					XEntity target2 = entity.AI.GetTarget(i);
					float magnitude = (target2.EngineObject.Position - entity.EngineObject.Position).magnitude;
					bool flag2 = magnitude > num;
					if (flag2)
					{
						num = magnitude;
						target = target2;
					}
				}
				entity.AI.SetTarget(target);
				bool flag3 = !entity.AI.IsFighting;
				if (flag3)
				{
					XAIEnterFightEventArgs @event = XEventPool<XAIEnterFightEventArgs>.GetEvent();
					@event.Firer = entity;
					@event.Target = target;
					XSingleton<XEventMgr>.singleton.FireEvent(@event);
				}
				entity.AI.IsFighting = true;
				result = true;
			}
			return result;
		}

		public bool DoSelectRandom(XEntity entity)
		{
			bool flag = entity.AI.TargetsCount == 0;
			bool result;
			if (flag)
			{
				entity.AI.SetTarget(null);
				entity.AI.IsFighting = false;
				result = false;
			}
			else
			{
				int index = XSingleton<XCommon>.singleton.RandomInt(0, entity.AI.TargetsCount);
				XEntity target = entity.AI.GetTarget(index);
				entity.AI.SetTarget(target);
				bool flag2 = !entity.AI.IsFighting;
				if (flag2)
				{
					XAIEnterFightEventArgs @event = XEventPool<XAIEnterFightEventArgs>.GetEvent();
					@event.Firer = entity;
					@event.Target = target;
					XSingleton<XEventMgr>.singleton.FireEvent(@event);
				}
				entity.AI.IsFighting = true;
				result = true;
			}
			return result;
		}

		public XGameObject SelectMoveTargetById(XEntity entity, int objectid)
		{
			List<XEntity> opponent = XSingleton<XEntityMgr>.singleton.GetOpponent(XSingleton<XEntityMgr>.singleton.Player);
			float num = float.MaxValue;
			XGameObject result = null;
			for (int i = 0; i < opponent.Count; i++)
			{
				bool flag = (ulong)opponent[i].Attributes.TypeID == (ulong)((long)objectid);
				if (flag)
				{
					XGameObject engineObject = opponent[i].EngineObject;
					float magnitude = (entity.EngineObject.Position - engineObject.Position).magnitude;
					bool flag2 = magnitude < num;
					if (flag2)
					{
						num = magnitude;
						result = engineObject;
					}
				}
			}
			return result;
		}

		public Transform SelectDoodaTarget(XEntity entity, XDoodadType type)
		{
			List<GameObject> doodadsInScene = XSingleton<XLevelDoodadMgr>.singleton.GetDoodadsInScene(type);
			bool flag = doodadsInScene.Count == 0;
			Transform result;
			if (flag)
			{
				result = null;
			}
			else
			{
				float num = 999999f;
				int num2 = -1;
				for (int i = 0; i < doodadsInScene.Count; i++)
				{
					bool flag2 = doodadsInScene[i] == null;
					if (!flag2)
					{
						float magnitude = (doodadsInScene[i].transform.position - entity.EngineObject.Position).magnitude;
						bool flag3 = magnitude < num;
						if (flag3)
						{
							num = magnitude;
							num2 = i;
						}
					}
				}
				bool flag4 = num2 == -1;
				if (flag4)
				{
					result = null;
				}
				else
				{
					result = doodadsInScene[num2].transform;
				}
			}
			return result;
		}

		public Transform SelectItemTarget(XEntity entity)
		{
			return XSingleton<XAITarget>.singleton.SelectDoodaTarget(entity, XDoodadType.Item);
		}

		public bool SelectTargetBySkillCircle(XEntity entity)
		{
			bool flag = !entity.IsPlayer;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XPlayer xplayer = entity as XPlayer;
				bool flag2 = xplayer == null || xplayer.TargetLocated == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = xplayer.TargetLocated.Target != null;
					if (flag3)
					{
						entity.AI.ClearTargets();
						entity.AI.AddTarget(xplayer.TargetLocated.Target);
						entity.AI.SetTarget(xplayer.TargetLocated.Target);
						result = true;
					}
					else
					{
						entity.AI.SetTarget(null);
						result = false;
					}
				}
			}
			return result;
		}

		public bool ResetHartedList(XEntity entity)
		{
			entity.AI.EnmityList.Reset();
			entity.AI.SetTarget(null);
			return true;
		}
	}
}