summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XEndureComponent.cs
blob: 63850e93c0ee02a3e7b8458084a700b9d23a74f3 (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
using System;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient
{
	internal sealed class XEndureComponent : XComponent
	{
		public override uint ID
		{
			get
			{
				return XEndureComponent.uuID;
			}
		}

		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("Endure");

		private static readonly string _endure_curve = "Curve/Endure_forward";

		private static IXCurve _curve_v = null;

		private static float _total = 0f;

		private float _last_offset = 0f;

		private float _delta_x = 0f;

		private float _delta_z = 0f;

		private float _delta_cumulation_x = 0f;

		private float _delta_cumulation_z = 0f;

		private float _elapsed = 0f;

		private bool _bEndure = false;

		private XFx _fx = null;

		private XFx _hit_fx = null;

		private Vector3 _direction = Vector3.zero;

		private XWoozyComponent woo = null;

		static XEndureComponent()
		{
			IXCurve curve = XSingleton<XResourceLoaderMgr>.singleton.GetCurve(XEndureComponent._endure_curve);
			XEndureComponent._curve_v = curve;
			XEndureComponent._total = XEndureComponent._curve_v.GetTime(XEndureComponent._curve_v.length - 1);
		}

		protected override void EventSubscribe()
		{
			base.RegisterEvent(XEventDefine.XEvent_Endure, new XComponent.XEventHandler(this.OnEndure));
		}

		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
			this._bEndure = false;
			this._last_offset = 0f;
			this._delta_x = 0f;
			this._delta_z = 0f;
			this._delta_cumulation_x = 0f;
			this._delta_cumulation_z = 0f;
		}

		public override void OnDetachFromHost()
		{
			bool flag = this._fx != null;
			if (flag)
			{
				XSingleton<XFxMgr>.singleton.DestroyFx(this._fx, true);
				this._fx = null;
			}
			bool flag2 = this._hit_fx != null;
			if (flag2)
			{
				XSingleton<XFxMgr>.singleton.DestroyFx(this._hit_fx, true);
				this._hit_fx = null;
			}
			base.OnDetachFromHost();
		}

		public override void Attached()
		{
			base.Attached();
			this.woo = (this._entity.GetXComponent(XWoozyComponent.uuID) as XWoozyComponent);
		}

		private bool OnEndure(XEventArgs e)
		{
			XEndureEventArgs xendureEventArgs = e as XEndureEventArgs;
			this.PlayFx(xendureEventArgs.Fx, true, ref this._fx);
			bool flag = !string.IsNullOrEmpty(this._entity.Present.PresentLib.HitFx);
			if (flag)
			{
				this.PlayFx(this._entity.Present.PresentLib.HitFx, true, ref this._hit_fx);
			}
			XSingleton<XAudioMgr>.singleton.PlaySound(this._entity, AudioChannel.Behit, XAudioStateDefine.XState_Audio_Bati, false, (xendureEventArgs.HitFrom == null) ? null : new XAudioExParam(xendureEventArgs.HitFrom));
			bool bEndure = this._bEndure;
			bool result;
			if (bEndure)
			{
				result = true;
			}
			else
			{
				this._bEndure = true;
				this._elapsed = 0f;
				this._direction = xendureEventArgs.Dir;
				this._delta_cumulation_x = 0f;
				this._delta_cumulation_z = 0f;
				result = true;
			}
			return result;
		}

		public override void Update(float fDeltaT)
		{
			bool bEndure = this._bEndure;
			if (bEndure)
			{
				this._elapsed += fDeltaT;
				bool flag = this._elapsed > XEndureComponent._total;
				if (flag)
				{
					this._elapsed = XEndureComponent._total;
					bool flag2 = this._fx != null;
					if (flag2)
					{
						XSingleton<XFxMgr>.singleton.DestroyFx(this._fx, true);
						this._fx = null;
					}
					bool flag3 = this._hit_fx != null;
					if (flag3)
					{
						XSingleton<XFxMgr>.singleton.DestroyFx(this._hit_fx, true);
						this._hit_fx = null;
					}
					bool flag4 = !this._entity.IsRole;
					if (flag4)
					{
						this.MoveImpl(new Vector3(-this._delta_cumulation_x, 0f, -this._delta_cumulation_z));
					}
					this._delta_cumulation_x = 0f;
					this._delta_cumulation_z = 0f;
					this._bEndure = false;
				}
				else
				{
					bool flag5 = !this._entity.IsRole;
					if (flag5)
					{
						this.CalcDeltaPos();
						this.MoveImpl(new Vector3(this._delta_x, 0f, this._delta_z));
					}
				}
			}
		}

		private void MoveImpl(Vector3 delta)
		{
			bool flag = this.woo != null && this.woo.InTransfer;
			if (!flag)
			{
				float num = 0f;
				Vector3 vector = this._entity.MoveObj.Position + delta;
				bool flag2 = this._entity.Fly == null && XSingleton<XScene>.singleton.TryGetTerrainY(vector, out num) && num >= 0f;
				if (flag2)
				{
					bool flag3 = XSingleton<XScene>.singleton.CheckDynamicBlock(this._entity.MoveObj.Position, vector);
					if (flag3)
					{
						bool flag4 = !this._entity.GravityDisabled;
						if (flag4)
						{
							vector.y = num + ((this._entity.MoveObj != null && this._entity.MoveObj.EnableCC) ? 0.25f : 0.05f);
							this._entity.MoveObj.Position = vector;
							bool flag5 = this._entity.MoveObj != null;
							if (flag5)
							{
								this._entity.MoveObj.Move(Vector3.down);
							}
						}
						else
						{
							this._entity.MoveObj.Position = vector;
						}
						this._delta_cumulation_x += delta.x;
						this._delta_cumulation_z += delta.z;
					}
				}
			}
		}

		private void CalcDeltaPos()
		{
			float num = XEndureComponent._curve_v.Evaluate(this._elapsed);
			Vector3 vector = this._direction * (num - this._last_offset);
			this._delta_x = vector.x;
			this._delta_z = vector.z;
			this._last_offset = num;
		}

		private void PlayFx(string fx, bool follow, ref XFx xfx)
		{
			bool flag = fx == null || fx.Length == 0;
			if (!flag)
			{
				bool flag2 = xfx != null && xfx.FxName != fx;
				if (flag2)
				{
					XSingleton<XFxMgr>.singleton.DestroyFx(xfx, true);
					xfx = null;
				}
				bool flag3 = XEntity.FilterFx(this._entity, XFxMgr.FilterFxDis0);
				if (!flag3)
				{
					bool flag4 = xfx == null;
					if (flag4)
					{
						xfx = XSingleton<XFxMgr>.singleton.CreateFx(fx, null, true);
					}
					xfx.DelayDestroy = 0.5f;
					xfx.Play(this._entity.EngineObject, Vector3.zero, Vector3.one, 1f, follow, false, "", this._entity.Height * 0.5f);
				}
			}
		}
	}
}