summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/Buff/XBuffAuraCheck.cs
blob: a89f8be5ebe8868030ff7d503ebd1cd3b741de96 (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
using System;
using System.Collections.Generic;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XBuffAuraCheck : BuffEffect
	{
		private XBuff _buff = null;

		private XEntity _entity = null;

		private XBuffAuraCheck.ShapeType _type = XBuffAuraCheck.ShapeType.BACT_CIRCLE;

		private bool m_effectexcept = false;

		private bool m_effectexceptself = false;

		private float _sqrRadius = 0f;

		private float _sqrExclusiveRadius = 0f;

		private float _halfWidth = 0f;

		private float _halfHeight = 0f;

		private float _halfExclusiveWidth = 0f;

		private float _halfExclusiveHeight = 0f;

		private float _startTime = 0f;

		private float _interval = 0f;

		private uint _TimeToken = 0u;

		private HashSet<uint> _EffectGroups = null;

		private XTimerMgr.ElapsedEventHandler _timeCb = null;

		private enum ShapeType
		{
			BACT_CIRCLE,
			BACT_RECTANGLE
		}

		public static bool TryCreate(BuffTable.RowData rowData, XBuff buff)
		{
			bool flag = rowData.AuraAddBuffID.Count == 0;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				buff.AddEffect(new XBuffAuraCheck(buff));
				result = true;
			}
			return result;
		}

		public XBuffAuraCheck(XBuff buff)
		{
			this._buff = buff;
			this._type = (XBuffAuraCheck.ShapeType)this._GetParam(0);
			this._startTime = this._GetParam(1);
			this._interval = Mathf.Max(XSingleton<XGlobalConfig>.singleton.BuffMinAuraInterval, this._GetParam(2));
			short[] effectGroup = buff.BuffInfo.EffectGroup;
			this._timeCb = new XTimerMgr.ElapsedEventHandler(this.OnTimer);
			bool flag = effectGroup != null;
			if (flag)
			{
				for (int i = 0; i < effectGroup.Length; i++)
				{
					bool flag2 = effectGroup[i] == -1;
					if (flag2)
					{
						this.m_effectexcept = true;
					}
					else
					{
						bool flag3 = effectGroup[i] == -2;
						if (flag3)
						{
							this.m_effectexcept = true;
							this.m_effectexceptself = true;
						}
						else
						{
							bool flag4 = this._EffectGroups == null;
							if (flag4)
							{
								this._EffectGroups = new HashSet<uint>();
							}
							this._EffectGroups.Add((uint)effectGroup[i]);
						}
					}
				}
			}
		}

		public override void OnAdd(XEntity entity, CombatEffectHelper pEffectHelper)
		{
			this._entity = entity;
			XBuffAuraCheck.ShapeType type = this._type;
			if (type != XBuffAuraCheck.ShapeType.BACT_CIRCLE)
			{
				if (type == XBuffAuraCheck.ShapeType.BACT_RECTANGLE)
				{
					this._halfWidth = this._GetParam(3) / 2f;
					this._halfHeight = this._GetParam(4) / 2f;
					this._halfExclusiveWidth = this._GetParam(5) / 2f;
					this._halfExclusiveHeight = this._GetParam(6) / 2f;
				}
			}
			else
			{
				float num = this._GetParam(3);
				num += pEffectHelper.GetBuffAuraRadius();
				this._sqrRadius = num * num;
				float num2 = this._GetParam(4);
				this._sqrExclusiveRadius = num2 * num2;
			}
			bool flag = this._entity == null || this._entity.IsDummy;
			if (flag)
			{
				this._EffectGroups = null;
			}
			else
			{
				bool effectexcept = this.m_effectexcept;
				if (effectexcept)
				{
					bool effectexceptself = this.m_effectexceptself;
					if (effectexceptself)
					{
						bool flag2 = this._EffectGroups == null;
						if (flag2)
						{
							this._EffectGroups = new HashSet<uint>();
						}
						this._EffectGroups.Add(this._entity.Attributes.FightGroup);
					}
				}
				else
				{
					bool flag3 = this._EffectGroups == null;
					if (flag3)
					{
						this._EffectGroups = new HashSet<uint>();
					}
					bool flag4 = this._EffectGroups.Count == 0;
					if (flag4)
					{
						this._EffectGroups.Add(this._entity.Attributes.FightGroup);
					}
				}
			}
			bool flag5 = this._startTime <= 0f;
			if (flag5)
			{
				this._timeCb(null);
			}
			else
			{
				this._TimeToken = XSingleton<XTimerMgr>.singleton.SetTimer(this._startTime, this._timeCb, null);
			}
		}

		public override void OnRemove(XEntity entity, bool IsReplaced)
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this._TimeToken);
		}

		public void OnTimer(object o)
		{
			bool isDummy = this._entity.IsDummy;
			if (isDummy)
			{
				this._AddBuffs(this._entity);
			}
			else
			{
				List<XEntity> all = XSingleton<XEntityMgr>.singleton.GetAll();
				Vector3 forward = this._entity.MoveObj.Forward;
				Vector3 vector = XSingleton<XCommon>.singleton.HorizontalRotateVetor3(forward, 90f, true);
				Vector3 position = this._entity.MoveObj.Position;
				for (int i = 0; i < all.Count; i++)
				{
					XEntity xentity = all[i];
					bool flag = xentity.IsDead || xentity.Deprecated;
					if (!flag)
					{
						bool flag2 = xentity.Attributes == null || !this._CanAttack(xentity.Attributes.FightGroup);
						if (!flag2)
						{
							XBuffAuraCheck.ShapeType type = this._type;
							if (type != XBuffAuraCheck.ShapeType.BACT_CIRCLE)
							{
								if (type == XBuffAuraCheck.ShapeType.BACT_RECTANGLE)
								{
									Vector3 vector2 = xentity.MoveObj.Position - position;
									bool flag3 = this._halfWidth > 0f || this._halfExclusiveWidth > 0f;
									if (flag3)
									{
										float num = Math.Abs(Vector3.Dot(vector2, forward));
										bool flag4 = this._halfWidth > 0f && num > this._halfWidth;
										if (flag4)
										{
											goto IL_284;
										}
										bool flag5 = this._halfExclusiveWidth > 0f && num < this._halfExclusiveWidth;
										if (flag5)
										{
											goto IL_284;
										}
									}
									bool flag6 = this._halfHeight > 0f || this._halfExclusiveHeight > 0f;
									if (flag6)
									{
										float num2 = Math.Abs(Vector3.Dot(vector2, vector));
										bool flag7 = this._halfHeight > 0f && num2 > this._halfHeight;
										if (flag7)
										{
											goto IL_284;
										}
										bool flag8 = this._halfExclusiveHeight > 0f && num2 < this._halfExclusiveHeight;
										if (flag8)
										{
											goto IL_284;
										}
									}
								}
							}
							else
							{
								bool flag9 = this._sqrRadius > 0f || this._sqrExclusiveRadius > 0f;
								if (flag9)
								{
									float num3 = Vector3.SqrMagnitude(position - xentity.MoveObj.Position);
									bool flag10 = this._sqrRadius > 0f && num3 > this._sqrRadius;
									if (flag10)
									{
										goto IL_284;
									}
									bool flag11 = this._sqrExclusiveRadius > 0f && num3 < this._sqrExclusiveRadius;
									if (flag11)
									{
										goto IL_284;
									}
								}
							}
							this._AddBuffs(xentity);
						}
					}
					IL_284:;
				}
				bool bValid = base.bValid;
				if (bValid)
				{
					this._TimeToken = XSingleton<XTimerMgr>.singleton.SetTimer(this._interval, this._timeCb, o);
				}
			}
		}

		private void _AddBuffs(XEntity entity)
		{
			for (int i = 0; i < this._buff.BuffInfo.AuraAddBuffID.Count; i++)
			{
				XBuffAddEventArgs @event = XEventPool<XBuffAddEventArgs>.GetEvent();
				@event.xBuffDesc.BuffID = this._buff.BuffInfo.AuraAddBuffID[i, 0];
				@event.xBuffDesc.BuffLevel = this._buff.BuffInfo.AuraAddBuffID[i, 1];
				@event.Firer = entity;
				@event.xBuffDesc.CasterID = this._buff.CasterID;
				@event.xBuffDesc.SkillID = this._buff.SkillID;
				XSingleton<XEventMgr>.singleton.FireEvent(@event);
			}
		}

		private bool _CanAttack(uint fightGroup)
		{
			bool effectexcept = this.m_effectexcept;
			bool result;
			if (effectexcept)
			{
				result = (this._EffectGroups == null || !this._EffectGroups.Contains(fightGroup));
			}
			else
			{
				result = (this._EffectGroups != null && this._EffectGroups.Contains(fightGroup));
			}
			return result;
		}

		private float _GetParam(int index)
		{
			bool flag = this._buff.BuffInfo.AuraParams == null || this._buff.BuffInfo.AuraParams.Length <= index;
			float result;
			if (flag)
			{
				result = 0f;
			}
			else
			{
				result = this._buff.BuffInfo.AuraParams[index];
			}
			return result;
		}
	}
}