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

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

		private HashSet<XAttributeDefine> m_SetConvertor = new HashSet<XAttributeDefine>(default(XFastEnumIntEqualityComparer<XAttributeDefine>));

		private Dictionary<int, double> m_ConvertorDeltaValue = new Dictionary<int, double>();

		private SequenceList<float> m_OriginalAttrs = null;

		private List<XAttrPair> m_AdditionalAttrs = null;

		private bool m_bChanging;

		private XEntity m_Entity;

		public static bool TryCreate(CombatEffectHelper helper, XBuff buff)
		{
			bool flag = helper.BuffInfo.BuffChangeAttribute.Count == 0 && !helper.bHasEffect(CombatEffectType.CET_Buff_ChangeAttribute);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				buff.AddEffect(new XBuffChangeAttribute(buff));
				result = true;
			}
			return result;
		}

		public XBuffChangeAttribute(XBuff buff)
		{
			this._buff = buff;
		}

		private void _Convert(int attrID, double deltaValue)
		{
			bool flag = this.m_Entity == null || this.m_Entity.Attributes == null;
			if (!flag)
			{
				bool flag2 = !this.m_Entity.IsRole;
				if (!flag2)
				{
					int basicTypeID = (int)this.m_Entity.Attributes.BasicTypeID;
					bool flag3 = !XAttributeCommon.IsFirstLevelAttr((XAttributeDefine)attrID);
					if (!flag3)
					{
						int basicAttr = XAttributeCommon.GetBasicAttr(attrID);
						XTuple<int, double>[] convertCoefficient = XSingleton<XPowerPointCalculator>.singleton.GetConvertCoefficient(basicAttr, basicTypeID);
						bool flag4 = convertCoefficient == null;
						if (!flag4)
						{
							bool flag5 = XAttributeCommon.IsPercentRange(attrID);
							if (flag5)
							{
								deltaValue *= 0.01 * this.m_Entity.Attributes.GetAttr((XAttributeDefine)basicAttr);
							}
							bool flag6 = Math.Abs(deltaValue) < 1E-06;
							if (!flag6)
							{
								bool flag7 = this.m_AdditionalAttrs == null;
								if (flag7)
								{
									this.m_AdditionalAttrs = ListPool<XAttrPair>.Get();
								}
								for (int i = 0; i < convertCoefficient.Length; i++)
								{
									XAttributeDefine item = (XAttributeDefine)convertCoefficient[i].Item1;
									double value = convertCoefficient[i].Item2 * deltaValue;
									XAttributeDefine attrCurAttr = XAttributeCommon.GetAttrCurAttr(item);
									bool flag8 = attrCurAttr != XAttributeDefine.XAttr_Invalid;
									if (flag8)
									{
										bool flag9 = deltaValue > 0.0;
										if (flag9)
										{
											this.m_AdditionalAttrs.Add(new XAttrPair(item, value));
											this.m_AdditionalAttrs.Add(new XAttrPair(attrCurAttr, value));
										}
										else
										{
											this.m_AdditionalAttrs.Add(new XAttrPair(attrCurAttr, value));
											this.m_AdditionalAttrs.Add(new XAttrPair(item, value));
										}
									}
									else
									{
										this.m_AdditionalAttrs.Add(new XAttrPair(item, value));
									}
								}
							}
						}
					}
				}
			}
		}

		public override void OnAdd(XEntity entity, CombatEffectHelper pEffectHelper)
		{
			this.m_Entity = entity;
			bool flag = entity.IsDummy || entity.IsDead;
			if (!flag)
			{
				this.m_bChanging = true;
				bool flag2 = pEffectHelper.bHasEffect(CombatEffectType.CET_Buff_ChangeAttribute);
				ISeqListRef<float> seqListRef;
				if (flag2)
				{
					this.m_OriginalAttrs = CommonObjectPool<SequenceList<float>>.Get();
					this.m_OriginalAttrs.Reset(3);
					this.m_OriginalAttrs.Append(this._buff.BuffInfo.BuffChangeAttribute, 3);
					pEffectHelper.GetBuffChangeAttribute(this.m_OriginalAttrs);
					seqListRef = this.m_OriginalAttrs;
				}
				else
				{
					seqListRef = this._buff.BuffInfo.BuffChangeAttribute;
				}
				for (int i = 0; i < seqListRef.Count; i++)
				{
					XAttributeDefine attrKey = (XAttributeDefine)seqListRef[i, 0];
					double num = (double)seqListRef[i, 1];
					bool flag3 = seqListRef[i, 2] != 0f;
					if (flag3)
					{
						XAttributeDefine xattributeDefine = (XAttributeDefine)seqListRef[i, 2];
						num *= entity.Attributes.GetAttr(xattributeDefine);
						this.m_ConvertorDeltaValue[i] = num;
						this.m_SetConvertor.Add(xattributeDefine);
					}
					XBuffChangeAttribute.ChangeAttribute(entity.Attributes, attrKey, num);
					this._Convert((int)seqListRef[i, 0], num);
				}
				bool flag4 = this.m_AdditionalAttrs != null;
				if (flag4)
				{
					for (int j = 0; j < this.m_AdditionalAttrs.Count; j++)
					{
						XBuffChangeAttribute.ChangeAttribute(entity.Attributes, this.m_AdditionalAttrs[j].AttrID, this.m_AdditionalAttrs[j].AttrValue);
					}
				}
				this.m_bChanging = false;
			}
		}

		public override void OnRemove(XEntity entity, bool IsReplaced)
		{
			bool flag = entity.IsDummy || entity.IsDead;
			if (!flag)
			{
				this.m_bChanging = true;
				XSecurityBuffInfo xsecurityBuffInfo = XSecurityBuffInfo.TryGetStatistics(entity);
				bool flag2 = this.m_AdditionalAttrs != null;
				if (flag2)
				{
					for (int i = this.m_AdditionalAttrs.Count - 1; i >= 0; i--)
					{
						bool flag3 = xsecurityBuffInfo != null;
						if (flag3)
						{
							xsecurityBuffInfo.OnAttributeChanged(entity.Attributes, this._buff, this.m_AdditionalAttrs[i].AttrID, this.m_AdditionalAttrs[i].AttrValue);
						}
						XBuffChangeAttribute.ChangeAttribute(entity.Attributes, this.m_AdditionalAttrs[i].AttrID, -this.m_AdditionalAttrs[i].AttrValue);
					}
				}
				ISeqListRef<float> seqListRef = this.m_OriginalAttrs;
				bool flag4 = seqListRef == null;
				if (flag4)
				{
					seqListRef = this._buff.BuffInfo.BuffChangeAttribute;
				}
				for (int j = seqListRef.Count - 1; j >= 0; j--)
				{
					XAttributeDefine xattributeDefine = (XAttributeDefine)seqListRef[j, 0];
					double num = (double)(-(double)seqListRef[j, 1]);
					bool flag5 = seqListRef[j, 2] != 0f && this.m_ConvertorDeltaValue.ContainsKey(j);
					if (flag5)
					{
						num = -this.m_ConvertorDeltaValue[j];
					}
					bool flag6 = xsecurityBuffInfo != null;
					if (flag6)
					{
						xsecurityBuffInfo.OnAttributeChanged(entity.Attributes, this._buff, xattributeDefine, -num);
					}
					XBuffChangeAttribute.ChangeAttribute(entity.Attributes, xattributeDefine, num);
				}
				this.m_bChanging = false;
				this._buff = null;
				bool flag7 = this.m_AdditionalAttrs != null;
				if (flag7)
				{
					ListPool<XAttrPair>.Release(this.m_AdditionalAttrs);
					this.m_AdditionalAttrs = null;
				}
				bool flag8 = this.m_OriginalAttrs != null;
				if (flag8)
				{
					CommonObjectPool<SequenceList<float>>.Release(this.m_OriginalAttrs);
					this.m_OriginalAttrs = null;
				}
			}
		}

		public override void OnBattleEnd(XEntity entity)
		{
			base.OnBattleEnd(entity);
			bool flag = entity.IsDummy || entity.IsDead;
			if (!flag)
			{
				XSecurityBuffInfo xsecurityBuffInfo = XSecurityBuffInfo.TryGetStatistics(entity);
				bool flag2 = xsecurityBuffInfo == null;
				if (!flag2)
				{
					bool flag3 = this.m_AdditionalAttrs != null;
					if (flag3)
					{
						for (int i = this.m_AdditionalAttrs.Count - 1; i >= 0; i--)
						{
							bool flag4 = xsecurityBuffInfo != null;
							if (flag4)
							{
								xsecurityBuffInfo.OnAttributeChanged(entity.Attributes, this._buff, this.m_AdditionalAttrs[i].AttrID, this.m_AdditionalAttrs[i].AttrValue);
							}
						}
					}
					ISeqListRef<float> seqListRef = this.m_OriginalAttrs;
					bool flag5 = seqListRef == null;
					if (flag5)
					{
						seqListRef = this._buff.BuffInfo.BuffChangeAttribute;
					}
					for (int j = seqListRef.Count - 1; j >= 0; j--)
					{
						XAttributeDefine attr = (XAttributeDefine)seqListRef[j, 0];
						double num = (double)(-(double)seqListRef[j, 1]);
						bool flag6 = seqListRef[j, 2] != 0f && this.m_ConvertorDeltaValue.ContainsKey(j);
						if (flag6)
						{
							num = -this.m_ConvertorDeltaValue[j];
						}
						bool flag7 = xsecurityBuffInfo != null;
						if (flag7)
						{
							xsecurityBuffInfo.OnAttributeChanged(entity.Attributes, this._buff, attr, -num);
						}
					}
				}
			}
		}

		public override void OnAttributeChanged(XAttrChangeEventArgs e)
		{
			base.OnAttributeChanged(e);
			bool flag = this.m_Entity.IsDummy || this.m_Entity.IsDead;
			if (!flag)
			{
				bool bChanging = this.m_bChanging;
				if (!bChanging)
				{
					bool flag2 = !this.m_SetConvertor.Contains(e.AttrKey) || this.m_ConvertorDeltaValue.Count == 0;
					if (!flag2)
					{
						this.m_bChanging = true;
						ISeqListRef<float> seqListRef = this.m_OriginalAttrs;
						bool flag3 = seqListRef == null;
						if (flag3)
						{
							seqListRef = this._buff.BuffInfo.BuffChangeAttribute;
						}
						for (int i = 0; i < seqListRef.Count; i++)
						{
							bool flag4 = seqListRef[i, 2] == 0f;
							if (!flag4)
							{
								XAttributeDefine xattributeDefine = (XAttributeDefine)seqListRef[i, 2];
								bool flag5 = xattributeDefine != e.AttrKey;
								if (!flag5)
								{
									double num;
									bool flag6 = !this.m_ConvertorDeltaValue.TryGetValue(i, out num);
									if (!flag6)
									{
										double num2 = (double)seqListRef[i, 1];
										num2 *= this.m_Entity.Attributes.GetAttr(xattributeDefine);
										XAttributeDefine attrKey = (XAttributeDefine)seqListRef[i, 0];
										double num3 = num2 - num;
										Dictionary<int, double> convertorDeltaValue = this.m_ConvertorDeltaValue;
										int key = i;
										convertorDeltaValue[key] += num3;
										XBuffChangeAttribute.ChangeAttribute(this.m_Entity.Attributes, attrKey, num3);
									}
								}
							}
						}
						this.m_bChanging = false;
					}
				}
			}
		}

		public static void ChangeAttribute(XAttributes attributes, XAttributeDefine attrKey, double attrValue)
		{
			bool flag = attributes == null || attributes.Entity == null;
			if (!flag)
			{
				XEntity entity = attributes.Entity;
				PercentWatcher percentWatcher = new PercentWatcher(attributes, attrKey, attrValue / 100.0);
				double num = XCombat.CheckChangeHPLimit(attrKey, attrValue, entity, true, true);
				bool flag2 = num == 0.0;
				if (!flag2)
				{
					XAttrChangeEventArgs @event = XEventPool<XAttrChangeEventArgs>.GetEvent();
					@event.AttrKey = attrKey;
					@event.DeltaValue = num;
					@event.Firer = entity;
					XSingleton<XEventMgr>.singleton.FireEvent(@event);
					percentWatcher.Check();
				}
			}
		}
	}
}