summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XSuperArmorComponent.cs
blob: c9d1465103183022fab18a032c836126adb1a44c (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
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<XCommon>.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<XGame>.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<XAttrChangeEventArgs>.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<XEventMgr>.singleton.FireEvent(@event);
			this._entity.Attributes.IsSuperArmorBroken = false;
			this._woozyOn = false;
			XArmorRecoverArgs event2 = XEventPool<XArmorRecoverArgs>.GetEvent();
			event2.Firer = this._entity;
			XSingleton<XEventMgr>.singleton.FireEvent(event2);
			XArmorRecoverArgs event3 = XEventPool<XArmorRecoverArgs>.GetEvent();
			event3.Firer = XSingleton<XGame>.singleton.Doc;
			event3.Self = this._entity;
			XSingleton<XEventMgr>.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<XArmorBrokenArgs>.GetEvent();
				@event.Firer = this._entity;
				XSingleton<XEventMgr>.singleton.FireEvent(@event);
				XArmorBrokenArgs event2 = XEventPool<XArmorBrokenArgs>.GetEvent();
				event2.Firer = XSingleton<XGame>.singleton.Doc;
				event2.Self = this._entity;
				XSingleton<XEventMgr>.singleton.FireEvent(event2);
				bool flag2 = !XSingleton<XGame>.singleton.SyncMode;
				if (flag2)
				{
					bool flag3 = this._recoveryTimeLimit > 0f;
					if (flag3)
					{
						this._timeToken = XSingleton<XTimerMgr>.singleton.SetTimer(this._recoveryTimeLimit, new XTimerMgr.ElapsedEventHandler(this.OnTimer), null);
					}
					XEntityStatistics.RowData byID = XSingleton<XEntityMgr>.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<XBuffAddEventArgs>.GetEvent();
							event3.xBuffDesc.BuffID = byID.SuperArmorBrokenBuff[0];
							event3.xBuffDesc.BuffLevel = byID.SuperArmorBrokenBuff[1];
							event3.Firer = this._entity;
							event3.xBuffDesc.CasterID = this._entity.ID;
							XSingleton<XEventMgr>.singleton.FireEvent(event3);
						}
					}
				}
			}
		}

		private double GetRateByState()
		{
			KKSG.XQTEState qtespecificPhase = this._entity.GetQTESpecificPhase();
			bool flag = qtespecificPhase > KKSG.XQTEState.QTE_None;
			if (flag)
			{
				int num = XSingleton<XEntityMgr>.singleton.SuperArmorCoffTable.Table.Length;
				int i = 0;
				while (i < num)
				{
					SuperArmorRecoveryCoffTable.RowData rowData = XSingleton<XEntityMgr>.singleton.SuperArmorCoffTable.Table[i];
					bool flag2 = rowData.Value == XFastEnumIntEqualityComparer<KKSG.XQTEState>.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<XGame>.singleton.SyncMode;
				if (flag)
				{
					double attr = this._entity.Attributes.GetAttr(XAttributeDefine.XAttr_SuperArmorRecovery_Total);
					double rateByState = this.GetRateByState();
					XAttrChangeEventArgs @event = XEventPool<XAttrChangeEventArgs>.GetEvent();
					@event.AttrKey = XAttributeDefine.XAttr_CurrentSuperArmor_Basic;
					@event.DeltaValue = attr * rateByState * (double)fDeltaT;
					@event.Firer = this._entity;
					XSingleton<XEventMgr>.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<XDebug>.singleton.AddLog("Stop Broken State", null, null, null, null, null, XDebugColor.XDebug_None);
					this._entity.Attributes.IsSuperArmorBroken = false;
					this._woozyOn = false;
					XArmorRecoverArgs event2 = XEventPool<XArmorRecoverArgs>.GetEvent();
					event2.Firer = this._entity;
					XSingleton<XEventMgr>.singleton.FireEvent(event2);
					XArmorRecoverArgs event3 = XEventPool<XArmorRecoverArgs>.GetEvent();
					event3.Firer = XSingleton<XGame>.singleton.Doc;
					event3.Self = this._entity;
					XSingleton<XEventMgr>.singleton.FireEvent(event3);
					XSingleton<XTimerMgr>.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<XGame>.singleton.SyncMode;
			if (flag)
			{
				XEntityStatistics.RowData byID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(this._entity.TypeID);
				bool flag2 = byID != null && byID.SuperArmorBrokenBuff[0] != 0 && byID.SuperArmorBrokenBuff[1] != 0;
				if (flag2)
				{
					XBuffRemoveEventArgs @event = XEventPool<XBuffRemoveEventArgs>.GetEvent();
					@event.xBuffID = byID.SuperArmorBrokenBuff[0];
					@event.Firer = this._entity;
					XSingleton<XEventMgr>.singleton.FireEvent(@event);
				}
			}
			this._woozyOn = false;
			return true;
		}

		protected bool OnWoozyEvent(XEventArgs e)
		{
			this._woozyOn = true;
			return true;
		}

		public override void OnDetachFromHost()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this._timeToken);
			base.OnDetachFromHost();
		}
	}
}