From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/XSuperArmorComponent.cs | 221 +++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XSuperArmorComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XSuperArmorComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XSuperArmorComponent.cs b/Client/Assets/Scripts/XMainClient/XSuperArmorComponent.cs new file mode 100644 index 00000000..c9d14651 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XSuperArmorComponent.cs @@ -0,0 +1,221 @@ +using System; +using KKSG; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XSuperArmorComponent : XComponent + { + public override uint ID + { + get + { + return XSuperArmorComponent.uuID; + } + } + + private bool _woozyOn = false; + + private float _recoveryTimeLimit = 0f; + + private uint _timeToken = 0u; + + public new static readonly uint uuID = XSingleton.singleton.XHash("XSuperArmorComponent"); + + private static readonly int BossType = 1; + + private static readonly int EliteType = 6; + + public override void Attached() + { + this.SetRecoveryTimeLimit(this._entity.Attributes.SuperArmorRecoveryTimeLimit); + } + + public void SetRecoveryTimeLimit(double second) + { + this._recoveryTimeLimit = (float)second; + } + + public override void Update(float fDeltaT) + { + bool syncMode = XSingleton.singleton.SyncMode; + if (!syncMode) + { + bool isSuperArmorBroken = this._entity.Attributes.IsSuperArmorBroken; + if (isSuperArmorBroken) + { + this.RecoverySuperArmor(fDeltaT); + } + else + { + this.CheckSuperArmorBroken(); + } + } + } + + private void OnTimer(object o) + { + XAttrChangeEventArgs @event = XEventPool.GetEvent(); + @event.AttrKey = XAttributeDefine.XAttr_CurrentSuperArmor_Basic; + @event.DeltaValue = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxSuperArmor_Basic) - this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentSuperArmor_Basic) + 1.0; + @event.Firer = this._entity; + XSingleton.singleton.FireEvent(@event); + this._entity.Attributes.IsSuperArmorBroken = false; + this._woozyOn = false; + XArmorRecoverArgs event2 = XEventPool.GetEvent(); + event2.Firer = this._entity; + XSingleton.singleton.FireEvent(event2); + XArmorRecoverArgs event3 = XEventPool.GetEvent(); + event3.Firer = XSingleton.singleton.Doc; + event3.Self = this._entity; + XSingleton.singleton.FireEvent(event3); + } + + private void CheckSuperArmorBroken() + { + bool flag = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentSuperArmor_Basic) <= 0.0 && this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentHP_Basic) > 0.0; + if (flag) + { + this._woozyOn = false; + this._entity.Attributes.IsSuperArmorBroken = true; + XArmorBrokenArgs @event = XEventPool.GetEvent(); + @event.Firer = this._entity; + XSingleton.singleton.FireEvent(@event); + XArmorBrokenArgs event2 = XEventPool.GetEvent(); + event2.Firer = XSingleton.singleton.Doc; + event2.Self = this._entity; + XSingleton.singleton.FireEvent(event2); + bool flag2 = !XSingleton.singleton.SyncMode; + if (flag2) + { + bool flag3 = this._recoveryTimeLimit > 0f; + if (flag3) + { + this._timeToken = XSingleton.singleton.SetTimer(this._recoveryTimeLimit, new XTimerMgr.ElapsedEventHandler(this.OnTimer), null); + } + XEntityStatistics.RowData byID = XSingleton.singleton.EntityStatistics.GetByID(this._entity.TypeID); + bool flag4 = byID != null; + if (flag4) + { + bool flag5 = byID.SuperArmorBrokenBuff[0] != 0 && byID.SuperArmorBrokenBuff[1] != 0; + if (flag5) + { + XBuffAddEventArgs event3 = XEventPool.GetEvent(); + event3.xBuffDesc.BuffID = byID.SuperArmorBrokenBuff[0]; + event3.xBuffDesc.BuffLevel = byID.SuperArmorBrokenBuff[1]; + event3.Firer = this._entity; + event3.xBuffDesc.CasterID = this._entity.ID; + XSingleton.singleton.FireEvent(event3); + } + } + } + } + } + + private double GetRateByState() + { + KKSG.XQTEState qtespecificPhase = this._entity.GetQTESpecificPhase(); + bool flag = qtespecificPhase > KKSG.XQTEState.QTE_None; + if (flag) + { + int num = XSingleton.singleton.SuperArmorCoffTable.Table.Length; + int i = 0; + while (i < num) + { + SuperArmorRecoveryCoffTable.RowData rowData = XSingleton.singleton.SuperArmorCoffTable.Table[i]; + bool flag2 = rowData.Value == XFastEnumIntEqualityComparer.ToInt(qtespecificPhase); + if (flag2) + { + bool flag3 = this._entity.IsBoss && rowData.monster_type == XSuperArmorComponent.BossType; + if (flag3) + { + return rowData.SupRecoveryChange; + } + bool flag4 = this._entity.IsElite && rowData.monster_type == XSuperArmorComponent.EliteType; + if (flag4) + { + return rowData.SupRecoveryChange; + } + return rowData.SupRecoveryChange; + } + else + { + i++; + } + } + } + return 1.0; + } + + private void RecoverySuperArmor(float fDeltaT) + { + bool woozyOn = this._woozyOn; + if (woozyOn) + { + bool flag = !XSingleton.singleton.SyncMode; + if (flag) + { + double attr = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_SuperArmorRecovery_Total); + double rateByState = this.GetRateByState(); + XAttrChangeEventArgs @event = XEventPool.GetEvent(); + @event.AttrKey = XAttributeDefine.XAttr_CurrentSuperArmor_Basic; + @event.DeltaValue = attr * rateByState * (double)fDeltaT; + @event.Firer = this._entity; + XSingleton.singleton.FireEvent(@event); + } + bool flag2 = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentSuperArmor_Basic) == this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxSuperArmor_Basic) && this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentHP_Basic) > 0.0; + if (flag2) + { + XSingleton.singleton.AddLog("Stop Broken State", null, null, null, null, null, XDebugColor.XDebug_None); + this._entity.Attributes.IsSuperArmorBroken = false; + this._woozyOn = false; + XArmorRecoverArgs event2 = XEventPool.GetEvent(); + event2.Firer = this._entity; + XSingleton.singleton.FireEvent(event2); + XArmorRecoverArgs event3 = XEventPool.GetEvent(); + event3.Firer = XSingleton.singleton.Doc; + event3.Self = this._entity; + XSingleton.singleton.FireEvent(event3); + XSingleton.singleton.KillTimer(this._timeToken); + } + } + } + + protected override void EventSubscribe() + { + base.RegisterEvent(XEventDefine.XEvent_WoozyOn, new XComponent.XEventHandler(this.OnWoozyEvent)); + base.RegisterEvent(XEventDefine.XEvent_WoozyOff, new XComponent.XEventHandler(this.OnWoozyOffEvent)); + } + + protected bool OnWoozyOffEvent(XEventArgs e) + { + bool flag = !XSingleton.singleton.SyncMode; + if (flag) + { + XEntityStatistics.RowData byID = XSingleton.singleton.EntityStatistics.GetByID(this._entity.TypeID); + bool flag2 = byID != null && byID.SuperArmorBrokenBuff[0] != 0 && byID.SuperArmorBrokenBuff[1] != 0; + if (flag2) + { + XBuffRemoveEventArgs @event = XEventPool.GetEvent(); + @event.xBuffID = byID.SuperArmorBrokenBuff[0]; + @event.Firer = this._entity; + XSingleton.singleton.FireEvent(@event); + } + } + this._woozyOn = false; + return true; + } + + protected bool OnWoozyEvent(XEventArgs e) + { + this._woozyOn = true; + return true; + } + + public override void OnDetachFromHost() + { + XSingleton.singleton.KillTimer(this._timeToken); + base.OnDetachFromHost(); + } + } +} -- cgit v1.1-26-g67d0