From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../XMainClient/Buff/XBuffChangeAttribute.cs | 331 +++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/Buff/XBuffChangeAttribute.cs (limited to 'Client/Assets/Scripts/XMainClient/Buff/XBuffChangeAttribute.cs') diff --git a/Client/Assets/Scripts/XMainClient/Buff/XBuffChangeAttribute.cs b/Client/Assets/Scripts/XMainClient/Buff/XBuffChangeAttribute.cs new file mode 100644 index 00000000..764469fa --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Buff/XBuffChangeAttribute.cs @@ -0,0 +1,331 @@ +using System; +using System.Collections.Generic; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XBuffChangeAttribute : BuffEffect + { + private XBuff _buff = null; + + private HashSet m_SetConvertor = new HashSet(default(XFastEnumIntEqualityComparer)); + + private Dictionary m_ConvertorDeltaValue = new Dictionary(); + + private SequenceList m_OriginalAttrs = null; + + private List 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[] convertCoefficient = XSingleton.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.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 seqListRef; + if (flag2) + { + this.m_OriginalAttrs = CommonObjectPool>.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 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.Release(this.m_AdditionalAttrs); + this.m_AdditionalAttrs = null; + } + bool flag8 = this.m_OriginalAttrs != null; + if (flag8) + { + CommonObjectPool>.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 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 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 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.GetEvent(); + @event.AttrKey = attrKey; + @event.DeltaValue = num; + @event.Firer = entity; + XSingleton.singleton.FireEvent(@event); + percentWatcher.Check(); + } + } + } + } +} -- cgit v1.1-26-g67d0