From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/Buff/XBuffRegenerate.cs | 258 +++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/Buff/XBuffRegenerate.cs (limited to 'Client/Assets/Scripts/XMainClient/Buff/XBuffRegenerate.cs') diff --git a/Client/Assets/Scripts/XMainClient/Buff/XBuffRegenerate.cs b/Client/Assets/Scripts/XMainClient/Buff/XBuffRegenerate.cs new file mode 100644 index 00000000..50816624 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Buff/XBuffRegenerate.cs @@ -0,0 +1,258 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XBuffRegenerate : BuffEffect + { + private XBuff _buff = null; + + private XBuffComponent _component = null; + + private uint _TimeToken = 0u; + + private List _Dots = null; + + private float _StartTime; + + private float _NextTime; + + private XTimerMgr.AccurateElapsedEventHandler _onTimeCb = null; + + public static bool TryCreate(CombatEffectHelper pEffectHelper, XBuff buff) + { + bool flag = pEffectHelper.BuffInfo.BuffDOT.Count == 0 && !pEffectHelper.bHasEffect(CombatEffectType.CET_Buff_DOTorHOT); + bool result; + if (flag) + { + result = false; + } + else + { + buff.AddEffect(new XBuffRegenerate(buff)); + result = true; + } + return result; + } + + public XBuffRegenerate(XBuff buff) + { + this._buff = buff; + this._onTimeCb = new XTimerMgr.AccurateElapsedEventHandler(this.OnTimer); + } + + private void ConvertSpecialBuff(DotTimeInfo info) + { + bool flag = info.attrID == XAttributeDefine.XAttr_MaxHP_Percent; + if (flag) + { + info.attrID = XAttributeDefine.XAttr_CurrentHP_Basic; + info.attrValue *= this._component.Entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxHP_Total) / 100.0; + } + } + + private double _GetCasterAttr(XEntity caster, int attrID, int attrValue) + { + bool flag = caster != null && !caster.Deprecated; + double result; + if (flag) + { + result = caster.Attributes.GetAttr((XAttributeDefine)attrID) * (double)attrValue / 100.0; + } + else + { + result = 0.0; + } + return result; + } + + public override void OnAdd(XEntity entity, CombatEffectHelper pEffectHelper) + { + bool isDummy = entity.IsDummy; + if (!isDummy) + { + this._NextTime = float.MaxValue; + this._StartTime = Time.time; + this._component = entity.Buffs; + XEntity xentity = null; + SequenceList sequenceList = null; + SequenceList sequenceList2 = null; + bool flag = pEffectHelper.bHasEffect(CombatEffectType.CET_Buff_DOTorHOT); + ISeqListRef seqListRef; + ISeqListRef seqListRef2; + if (flag) + { + sequenceList = CommonObjectPool>.Get(); + sequenceList2 = CommonObjectPool>.Get(); + sequenceList.Reset(3); + sequenceList2.Reset(2); + sequenceList.Append(this._buff.BuffInfo.BuffDOT, 3); + sequenceList2.Append(this._buff.BuffInfo.BuffDOTValueFromCaster, 2); + bool buffRegenerate = pEffectHelper.GetBuffRegenerate(sequenceList, sequenceList2); + if (buffRegenerate) + { + seqListRef = sequenceList; + seqListRef2 = sequenceList2; + } + else + { + XSingleton.singleton.AddErrorLog("Data error when get dothot for buff ", this._buff.BuffInfo.BuffID.ToString(), null, null, null, null); + seqListRef = this._buff.BuffInfo.BuffDOT; + seqListRef2 = this._buff.BuffInfo.BuffDOTValueFromCaster; + CommonObjectPool>.Release(sequenceList2); + CommonObjectPool>.Release(sequenceList); + sequenceList2 = null; + sequenceList = null; + } + } + else + { + seqListRef = this._buff.BuffInfo.BuffDOT; + seqListRef2 = this._buff.BuffInfo.BuffDOTValueFromCaster; + } + int count = seqListRef.Count; + bool flag2 = seqListRef2.Count == count; + if (flag2) + { + xentity = XSingleton.singleton.GetEntity(this._buff.CasterID); + bool flag3 = sequenceList != null; + if (flag3) + { + for (int i = 0; i < count; i++) + { + bool flag4 = sequenceList2[i, 0] != 0; + if (flag4) + { + sequenceList[i, 1] = (float)this._GetCasterAttr(xentity, sequenceList2[i, 0], sequenceList2[i, 1]); + } + } + } + } + bool flag5 = sequenceList != null; + if (flag5) + { + pEffectHelper.Merge(sequenceList, 1); + count = seqListRef.Count; + } + this._Dots = new List(); + for (int j = 0; j < count; j++) + { + DotTimeInfo dotTimeInfo = new DotTimeInfo(); + dotTimeInfo.attrID = (XAttributeDefine)seqListRef[j, 0]; + dotTimeInfo.attrValue = (double)seqListRef[j, 1]; + dotTimeInfo.interval = Math.Max(XSingleton.singleton.BuffMinRegenerateInterval * 1000f, seqListRef[j, 2]); + dotTimeInfo.tickCount = 0; + dotTimeInfo.totalCount = (int)(this._buff.BuffInfo.BuffDuration * 1000f / seqListRef[j, 2]); + dotTimeInfo.timeleft = dotTimeInfo.interval; + bool flag6 = xentity != null && sequenceList == null; + if (flag6) + { + bool flag7 = seqListRef2[j, 0] != 0; + if (flag7) + { + dotTimeInfo.attrValue = this._GetCasterAttr(xentity, seqListRef2[j, 0], seqListRef2[j, 1]); + } + } + this.ConvertSpecialBuff(dotTimeInfo); + this._Dots.Add(dotTimeInfo); + this._NextTime = Math.Min(dotTimeInfo.timeleft, this._NextTime); + } + bool flag8 = sequenceList2 != null; + if (flag8) + { + CommonObjectPool>.Release(sequenceList2); + } + bool flag9 = sequenceList != null; + if (flag9) + { + CommonObjectPool>.Release(sequenceList); + } + this._TimeToken = XSingleton.singleton.SetTimerAccurate(this._NextTime * 0.001f, this._onTimeCb, null); + } + } + + public override void OnRemove(XEntity entity, bool IsReplaced) + { + bool isDummy = entity.IsDummy; + if (!isDummy) + { + XSingleton.singleton.KillTimer(this._TimeToken); + bool flag = entity.IsDead || entity.Deprecated; + if (!flag) + { + bool flag2 = !IsReplaced; + if (flag2) + { + float time = Time.time; + for (int i = 0; i < this._Dots.Count; i++) + { + DotTimeInfo dotTimeInfo = this._Dots[i]; + int num = Mathf.Min((int)((time - this._StartTime) * 1000f / dotTimeInfo.interval), dotTimeInfo.totalCount); + for (int j = dotTimeInfo.tickCount; j < num; j++) + { + bool flag3 = dotTimeInfo.attrID == XAttributeDefine.XAttr_CurrentHP_Basic && dotTimeInfo.attrValue < 0.0; + if (flag3) + { + XCombat.ProjectExternalDamage(-dotTimeInfo.attrValue, this._buff.CasterID, this._component.Entity, !this._buff.BuffInfo.DontShowText, 0); + } + else + { + XAttrChangeEventArgs @event = XEventPool.GetEvent(); + @event.AttrKey = dotTimeInfo.attrID; + @event.DeltaValue = dotTimeInfo.attrValue; + @event.CasterID = this._buff.CasterID; + @event.bShowHUD = !this._buff.BuffInfo.DontShowText; + @event.Firer = this._component.Entity; + XSingleton.singleton.FireEvent(@event); + } + } + } + } + } + } + } + + public void OnTimer(object o, float delay) + { + float num = float.MaxValue; + for (int i = 0; i < this._Dots.Count; i++) + { + DotTimeInfo dotTimeInfo = this._Dots[i]; + dotTimeInfo.timeleft -= this._NextTime + delay * 1000f; + while (dotTimeInfo.tickCount <= dotTimeInfo.totalCount && dotTimeInfo.timeleft <= 0f) + { + dotTimeInfo.tickCount++; + dotTimeInfo.timeleft += dotTimeInfo.interval; + bool flag = dotTimeInfo.attrID == XAttributeDefine.XAttr_CurrentHP_Basic && dotTimeInfo.attrValue < 0.0; + if (flag) + { + XCombat.ProjectExternalDamage(-dotTimeInfo.attrValue, this._buff.CasterID, this._component.Entity, !this._buff.BuffInfo.DontShowText, 0); + } + else + { + XAttrChangeEventArgs @event = XEventPool.GetEvent(); + @event.AttrKey = dotTimeInfo.attrID; + @event.DeltaValue = dotTimeInfo.attrValue; + @event.CasterID = this._buff.CasterID; + @event.bShowHUD = !this._buff.BuffInfo.DontShowText; + @event.Firer = this._component.Entity; + XSingleton.singleton.FireEvent(@event); + } + } + bool flag2 = dotTimeInfo.timeleft > 0f; + if (flag2) + { + num = Math.Min(num, dotTimeInfo.timeleft); + } + } + bool flag3 = base.bValid && num != float.MaxValue && num > 0f; + if (flag3) + { + this._NextTime = num; + this._TimeToken = XSingleton.singleton.SetTimerAccurate(this._NextTime * 0.001f, this._onTimeCb, o); + } + } + } +} -- cgit v1.1-26-g67d0