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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
|
using System;
using UnityEngine;
using XUtliPoolLib;
namespace XMainClient
{
internal sealed class XMoveComponent : XActionStateComponent<XMoveEventArgs>
{
public override uint ID
{
get
{
return XMoveComponent.uuID;
}
}
public override float Speed
{
get
{
return this._begin_inertia ? 0f : this._speed;
}
}
public float AnimSpeed
{
get
{
return this._anim_speed;
}
set
{
this._anim_speed = value;
}
}
public override bool IsUsingCurve
{
get
{
return false;
}
}
public override bool SyncPredicted
{
get
{
return this._entity.IsClientPredicted || base.SyncPredicted;
}
}
public override bool ShouldBePresent
{
get
{
return this._entity.Machine.Previous != XStateDefine.XState_Move;
}
}
public override string PresentCommand
{
get
{
return "ToMove";
}
}
public override string PresentName
{
get
{
return "Move";
}
}
public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("Basic_Move");
private bool _begin_inertia = false;
private bool _stoppage = true;
private float _speed = 0f;
private float _last_speed = 0f;
private float _target_speed = 0f;
private float _anim_speed = 0f;
private float _stoppage_dir = 0f;
private float _acceleration = 0f;
private float _last_angular = 0f;
private Vector3 _move_dir = Vector3.forward;
private Vector3 _destination = Vector3.zero;
private bool _inertia = false;
private bool _overlapped = false;
private uint _track_fx_1 = 0u;
private uint _track_fx_2 = 0u;
private XTimerMgr.ElapsedEventHandler _playTrackFxCb = null;
public XMoveComponent()
{
this._playTrackFxCb = new XTimerMgr.ElapsedEventHandler(this.PlayTrackFx);
}
public override void OnAttachToHost(XObject host)
{
base.OnAttachToHost(host);
this._selfState = XStateDefine.XState_Move;
this._speed = 0f;
this._last_speed = 0f;
this._acceleration = 0f;
this.PrepareAnimations();
}
protected override void EventSubscribe()
{
base.RegisterEvent(XEventDefine.XEvent_Move, new XComponent.XEventHandler(base.OnActionEvent));
base.RegisterEvent(XEventDefine.XEvent_OnMounted, new XComponent.XEventHandler(base.OnMountEvent));
base.RegisterEvent(XEventDefine.XEvent_OnUnMounted, new XComponent.XEventHandler(base.OnMountEvent));
}
protected override bool InnerPermitted(XStateDefine state)
{
bool flag = !this._entity.IsPlayer && this.SyncPredicted;
bool result;
if (flag)
{
result = (state != XStateDefine.XState_Idle || this._stoppage);
}
else
{
result = (base.IsFinished || base.InnerPermitted(state));
}
return result;
}
protected override void Cancel(XStateDefine next)
{
bool flag = next != XStateDefine.XState_Move;
if (flag)
{
XEntity xentity = this._entity.IsTransform ? this._entity.Transformer : this._entity;
xentity.Machine.SetAnimationSpeed(1f);
for (int i = 0; i < xentity.Affiliates.Count; i++)
{
bool flag2 = xentity.Affiliates[i].Ator != null;
if (flag2)
{
xentity.Affiliates[i].Ator.speed = xentity.Ator.speed;
}
}
bool flag3 = xentity.IsMounted && xentity.Mount.Ator != null;
if (flag3)
{
xentity.Mount.Ator.speed = xentity.Ator.speed;
}
this._speed = 0f;
this._last_speed = 0f;
this._acceleration = 0f;
bool flag4 = this._track_fx_1 > 0u;
if (flag4)
{
XSingleton<XTimerMgr>.singleton.KillTimer(this._track_fx_1);
}
bool flag5 = this._track_fx_2 > 0u;
if (flag5)
{
XSingleton<XTimerMgr>.singleton.KillTimer(this._track_fx_2);
}
this._track_fx_1 = 0u;
this._track_fx_2 = 0u;
this._anim_speed = 0f;
bool flag6 = !this._entity.IsPlayer && this.SyncPredicted;
if (flag6)
{
this._entity.Net.ReportRotateAction(XSingleton<XCommon>.singleton.FloatToAngle(this._stoppage_dir));
}
}
}
protected override void Cease()
{
this._begin_inertia = false;
}
public override void OnRejected(XStateDefine current)
{
}
public override string TriggerAnim(string pre)
{
bool isPlayer = this._entity.IsPlayer;
if (isPlayer)
{
bool flag = this._track_fx_1 == 0u;
if (flag)
{
this._track_fx_1 = XSingleton<XTimerMgr>.singleton.SetTimer(0.144f, this._playTrackFxCb, null);
}
bool flag2 = this._track_fx_2 == 0u;
if (flag2)
{
this._track_fx_2 = XSingleton<XTimerMgr>.singleton.SetTimer(0.426f, this._playTrackFxCb, this);
}
}
string text = (base.IsFinished && this._entity.IsPlayer) ? "ToStand" : this.PresentCommand;
bool flag3 = pre != text;
if (flag3)
{
bool flag4 = this._entity.Ator != null;
if (flag4)
{
this._entity.Ator.SetTrigger(text);
}
}
return text;
}
protected override void ActionUpdate(float deltaTime)
{
this._last_speed = this._speed;
bool isFinished = base.IsFinished;
if (!isFinished)
{
bool flag = this._speed == 0f && this._target_speed == 0f;
if (flag)
{
base.Finish();
}
else
{
this._speed += deltaTime * this._acceleration;
bool flag2 = (this._speed - this._target_speed) * this._acceleration > 0f;
if (flag2)
{
this._speed = this._target_speed;
this._acceleration = 0f;
}
bool begin_inertia = this._begin_inertia;
if (!begin_inertia)
{
Vector3 movement = this._move_dir * ((this._speed + this._last_speed) * 0.5f) * deltaTime;
bool flag3 = this._entity.Buffs != null && this._entity.Buffs.IsBuffStateOn(XBuffType.XBuffType_LockFoot);
if (flag3)
{
movement = Vector3.zero;
}
this.CheckMove(ref movement);
bool flag4 = this._entity.IsPlayer || this._entity.IsEnemy;
if (flag4)
{
XSecurityStatistics xsecurityStatistics = XSecurityStatistics.TryGetStatistics(this._entity);
bool flag5 = xsecurityStatistics != null;
if (flag5)
{
xsecurityStatistics.OnMove(movement.magnitude);
}
}
//c 移动
this._entity.ApplyMove(movement);
}
}
this._anim_speed = this._speed;
}
}
public override void PostUpdate(float fDeltaT)
{
bool flag = this._entity.Machine.Current != XStateDefine.XState_Move;
if (!flag)
{
XEntity xentity = this._entity.IsTransform ? this._entity.Transformer : this._entity;
bool flag2 = xentity.Ator == null;
if (!flag2)
{
bool flag3 = XSingleton<XCommon>.singleton.IsLess(this._anim_speed, this._entity.Attributes.WalkSpeed);
if (flag3)
{
xentity.Machine.SetAnimationSpeed(Mathf.Max(0.5f, this._anim_speed / this._entity.Attributes.WalkSpeed));
}
else
{
bool flag4 = XSingleton<XCommon>.singleton.IsGreater(this._anim_speed, this._entity.Attributes.RunSpeed);
if (flag4)
{
xentity.Machine.SetAnimationSpeed(this._anim_speed / this._entity.Attributes.RunSpeed);
}
else
{
xentity.Machine.SetAnimationSpeed(1f);
}
}
float value = this._anim_speed / this._entity.Attributes.RunSpeed;
bool flag5 = xentity.IsMounted && xentity.Mount.Ator != null;
if (flag5)
{
bool hasTurnPresetation = xentity.Mount.HasTurnPresetation;
if (hasTurnPresetation)
{
float num = xentity.Rotate.Angular();
this._last_angular += (num - this._last_angular) * Mathf.Min(1f, fDeltaT * (float)xentity.Mount.AngularSpeed);
}
else
{
this._last_angular = 0f;
}
xentity.Ator.SetFloat("MoveFactor", value);
xentity.Ator.SetFloat("AngleFactor", this._last_angular);
for (int i = 0; i < xentity.Affiliates.Count; i++)
{
bool flag6 = xentity.Affiliates[i].Ator != null;
if (flag6)
{
xentity.Affiliates[i].Ator.speed = xentity.Ator.speed;
xentity.Affiliates[i].Ator.SetFloat("MoveFactor", value);
xentity.Affiliates[i].Ator.SetFloat("AngleFactor", this._last_angular);
}
}
bool flag7 = xentity.IsMounted && xentity.Mount.Ator != null;
if (flag7)
{
xentity.Mount.Ator.speed = xentity.Ator.speed;
xentity.Mount.Ator.SetFloat("MoveFactor", value);
xentity.Mount.Ator.SetFloat("AngleFactor", this._last_angular);
}
}
else
{
this._last_angular = 0f;
xentity.Ator.SetFloat("MoveFactor", value);
xentity.Ator.SetFloat("AngleFactor", 0f);
for (int j = 0; j < xentity.Affiliates.Count; j++)
{
bool flag8 = xentity.Affiliates[j].Ator != null;
if (flag8)
{
xentity.Affiliates[j].Ator.speed = xentity.Ator.speed;
xentity.Affiliates[j].Ator.SetFloat("MoveFactor", value);
xentity.Affiliates[j].Ator.SetFloat("AngleFactor", 0f);
}
}
}
}
}
}
protected override bool OnGetEvent(XMoveEventArgs e, XStateDefine last)
{
this._stoppage = e.Stoppage;
this._stoppage_dir = e.StopTowards;
this._inertia = e.Inertia;
this._target_speed = e.Speed;
this._destination = e.Destination;
this._move_dir = this._destination - this._entity.MoveObj.Position;
this._move_dir.y = 0f;
float sqrMagnitude = this._move_dir.sqrMagnitude;
bool flag = sqrMagnitude == 0f || ((double)sqrMagnitude < 0.001 && this._entity.IsPlayer) || (sqrMagnitude < 0.1f && !this._entity.IsPlayer && this.SyncPredicted && this._stoppage);
if (flag)
{
this._move_dir = this._entity.MoveObj.Forward;
this._target_speed = 0f;
}
this._move_dir.Normalize();
bool flag2 = this._entity.Fly != null;
if (flag2)
{
float num = XSingleton<XScene>.singleton.TerrainY(this._destination);
bool flag3 = this._destination.y - num < this._entity.Fly.MinHeight;
if (flag3)
{
this._destination.y = num + (this._entity.Fly.MinHeight + this._entity.Fly.MaxHeight) * 0.5f;
}
}
bool flag4 = this._entity.IsPlayer && XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.Hall;
if (flag4)
{
XMoveEventArgs @event = XEventPool<XMoveEventArgs>.GetEvent();
@event.Speed = this._target_speed;
@event.Destination = this._destination;
@event.Inertia = this._inertia;
@event.Firer = XSingleton<XGame>.singleton.Doc;
XSingleton<XEventMgr>.singleton.FireEvent(@event);
}
return true;
}
protected override void Begin()
{
this._begin_inertia = false;
bool flag = this._target_speed != this._speed;
if (flag)
{
bool flag2 = this._target_speed > this._speed;
if (flag2)
{
this._acceleration = this._entity.Attributes.RunSpeed * 5f;
}
else
{
this._acceleration = -this._entity.Attributes.RunSpeed * 6f;
}
}
else
{
this._acceleration = 0f;
}
this._entity.Net.ReportRotateAction(this._move_dir);
this._overlapped = false;
Vector3 zero = Vector3.zero;
this.CheckMove(ref zero);
}
protected override void OnMount(XMount mount)
{
bool flag = mount != null;
if (flag)
{
this._entity.OverrideAnimClip("Walk", this._entity.Present.PresentLib.AnimLocation.Replace('/', '_') + mount.Present.PresentLib.Walk + (this._entity.IsCopilotMounted ? "_follow" : ""), true, false);
this._entity.OverrideAnimClip("Run", this._entity.Present.PresentLib.AnimLocation.Replace('/', '_') + mount.Present.PresentLib.Run + (this._entity.IsCopilotMounted ? "_follow" : ""), true, false);
bool hasTurnPresetation = mount.HasTurnPresetation;
if (hasTurnPresetation)
{
this._entity.OverrideAnimClip("RunLeft", this._entity.Present.PresentLib.AnimLocation.Replace('/', '_') + mount.Present.PresentLib.RunLeft + (this._entity.IsCopilotMounted ? "_follow" : ""), true, false);
this._entity.OverrideAnimClip("RunRight", this._entity.Present.PresentLib.AnimLocation.Replace('/', '_') + mount.Present.PresentLib.RunRight + (this._entity.IsCopilotMounted ? "_follow" : ""), true, false);
}
}
else
{
this.PrepareAnimations();
}
this._entity.Machine.TriggerPresent();
}
private void CheckMove(ref Vector3 movement)
{
bool flag = !this._overlapped;
if (flag)
{
this._overlapped = this.Overlapped(ref movement);
bool overlapped = this._overlapped;
if (overlapped)
{
this._target_speed = 0f;
bool flag2 = this._inertia && this._speed > 0f;
if (flag2)
{
this._acceleration = -this._entity.Attributes.RunSpeed * 6f;
this._begin_inertia = true;
}
else
{
this._acceleration = 0f;
base.Finish();
}
}
}
}
private bool Overlapped(ref Vector3 movement)
{
Vector3 vector = this._entity.MoveObj.Position + movement;
vector.y = 0f;
Vector3 destination = this._destination;
destination.y = 0f;
Vector3 vector2 = destination - vector;
bool flag = vector2.sqrMagnitude > 0f;
bool result;
if (flag)
{
float num = Vector3.Angle(vector2, this._move_dir);
bool flag2 = num >= 90f;
if (flag2)
{
movement = this._destination - this._entity.MoveObj.Position;
bool flag3 = this._entity.Fly != null;
if (flag3)
{
movement.y = 0f;
}
result = true;
}
else
{
result = false;
}
}
else
{
result = true;
}
return result;
}
private void PlayTrackFx(object o)
{
bool flag = string.IsNullOrEmpty(this._entity.Present.PresentLib.MoveFx);
if (!flag)
{
uint num = XSingleton<XTimerMgr>.singleton.SetTimer(0.533f, this._playTrackFxCb, o);
bool flag2 = o == null;
if (flag2)
{
this._track_fx_1 = num;
}
else
{
this._track_fx_2 = num;
}
XSingleton<XFxMgr>.singleton.CreateAndPlay(this._entity.Present.PresentLib.MoveFx, this._entity.MoveObj, Vector3.zero, Vector3.one, 1f, false, 0.5f, true);
XSingleton<XAudioMgr>.singleton.PlaySound(this._entity, AudioChannel.Motion, XAudioStateDefine.XState_Audio_Move);
}
}
private void PrepareAnimations()
{
bool isNotEmptyObject = this._entity.EngineObject.IsNotEmptyObject;
if (isNotEmptyObject)
{
bool flag = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.World && !string.IsNullOrEmpty(this._entity.Present.PresentLib.AttackIdle);
if (flag)
{
this._entity.OverrideAnimClip("Walk", this._entity.Present.PresentLib.AttackWalk, true, false);
this._entity.OverrideAnimClip("Run", this._entity.Present.PresentLib.AttackRun, true, false);
this._entity.OverrideAnimClip("RunLeft", this._entity.Present.PresentLib.AttackRunLeft, true, false);
this._entity.OverrideAnimClip("RunRight", this._entity.Present.PresentLib.AttackRunRight, true, false);
}
else
{
this._entity.OverrideAnimClip("Walk", this._entity.Present.PresentLib.Walk, true, false);
this._entity.OverrideAnimClip("Run", this._entity.Present.PresentLib.Run, true, false);
this._entity.OverrideAnimClip("RunLeft", this._entity.Present.PresentLib.RunLeft, true, false);
this._entity.OverrideAnimClip("RunRight", this._entity.Present.PresentLib.RunRight, true, false);
}
}
}
}
}
|