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
|
using System;
using XUtliPoolLib;
namespace XMainClient
{
internal sealed class XStateMachine : XComponent, IAnimStateMachine
{
public override uint ID
{
get
{
return XStateMachine.uuID;
}
}
public IXStateTransform State
{
get
{
return this._current;
}
}
public XStateDefine Current
{
get
{
return this._current.SelfState;
}
}
public XStateDefine Previous
{
get
{
return this._previous.SelfState;
}
}
public XStateDefine Default
{
get
{
return this._default.SelfState;
}
}
public long ActionToken
{
get
{
return this._current.Token;
}
}
public int CollisionLayer
{
get
{
return this._current.CollisionLayer;
}
}
public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("StateMachine");
private IXStateTransform _current = null;
private IXStateTransform _default = null;
private IXStateTransform _previous = null;
private string _pre_command = null;
private static bool[,] _bStateMap = null;
private bool _bTrigger = false;
public static bool _EnableAtor = true;
public override void OnAttachToHost(XObject host)
{
base.OnAttachToHost(host);
this.BuildStateMap();
bool flag = host is XEntity;
if (flag)
{
XEntity xentity = host as XEntity;
bool flag2 = xentity.Ator != null;
if (flag2)
{
xentity.Ator.SetStateMachine(this);
}
}
}
public void SetDefaultState(IXStateTransform def)
{
this._default = def;
this._current = def;
this._previous = def;
def.OnGetPermission();
}
public bool CanAct(XStateDefine state)
{
bool flag = (base.Enabled && this._current.IsPermitted(state)) || state == XStateDefine.XState_Death;
return flag && (!this._entity.IsMounted || !this._entity.IsCopilotMounted);
}
public bool CanAct(IXStateTransform next)
{
return this.CanAct(next.SelfState);
}
public bool StatePermitted(XStateDefine src, XStateDefine des)
{
bool flag = XStateMachine._bStateMap == null;
return !flag && XStateMachine._bStateMap[(int)src, (int)des];
}
public void ForceToDefaultState(bool ignoredeath)
{
bool flag = ignoredeath || this._current.SelfState != XStateDefine.XState_Death;
if (flag)
{
bool flag2 = this._current != this._default;
if (flag2)
{
this._current.Stop(this._default.SelfState);
this.TransferToDefaultState();
}
}
}
public void Stop()
{
this._current.Stop(this._default.SelfState);
}
public override void Update(float fDeltaT)
{
this._current.StateUpdate(fDeltaT);
bool isFinished = this._current.IsFinished;
if (isFinished)
{
bool syncPredicted = this._current.SyncPredicted;
if (syncPredicted)
{
this.TransferToDefaultState();
}
}
}
public override void PostUpdate(float fDeltaT)
{
bool flag = this._bTrigger && this._entity.Ator != null && !this._entity.Ator.IsInTransition(0);
if (flag)
{
this._pre_command = this._current.TriggerAnim(this._pre_command);
this.AnimationUpdate(this._entity, this._pre_command);
this._bTrigger = false;
}
}
private void AnimationUpdate(XEntity entity, string pre_command)
{
entity = (entity.IsTransform ? entity.Transformer : entity);
float transitionDuration = (this._current.SelfState == XStateDefine.XState_Idle) ? 0.5f : 0.05f;
for (int i = 0; i < entity.Affiliates.Count; i++)
{
bool flag = entity.Affiliates[i].MirrorState && entity.Affiliates[i].Ator != null;
if (flag)
{
entity.Affiliates[i].Ator.CrossFade(this._current.PresentName, transitionDuration, 0, 0f);
}
}
bool flag2 = entity.IsMounted && !entity.IsCopilotMounted;
if (flag2)
{
bool flag3 = entity.Mount.Ator != null;
if (flag3)
{
entity.Mount.Ator.CrossFade(this._current.PresentName, transitionDuration, 0, 0f);
}
bool flag4 = entity.Mount.Copilot != null;
if (flag4)
{
this.AnimationUpdate(entity.Mount.Copilot, pre_command);
}
}
}
public void OnAnimationOverrided()
{
bool flag = this._default != null;
if (flag)
{
this._pre_command = this._default.PresentCommand;
}
}
public void TriggerPresent()
{
this._bTrigger = true;
}
public void SetAnimationSpeed(float speed)
{
bool flag = this._entity.Ator != null && this._entity.Skill != null && !this._entity.Skill.IsCasting();
if (flag)
{
this._entity.Ator.speed = speed;
}
}
public bool TryTransferToState(IXStateTransform next)
{
bool flag = this.CanAct(next.SelfState);
bool result;
if (flag)
{
result = this.TransferToState(next);
}
else
{
next.OnRejected(this._current.SelfState);
result = false;
}
return result;
}
public bool TransferToState(IXStateTransform next)
{
bool flag = this._current.SelfState != next.SelfState || next.SelfState != XStateDefine.XState_Move;
if (flag)
{
this._current.Stop(next.SelfState);
}
this._previous = this._current;
this._current = next;
this._current.OnGetPermission();
bool flag2 = this._previous.SelfState != this._current.SelfState || !this._bTrigger;
if (flag2)
{
this._bTrigger = this._current.ShouldBePresent;
}
return true;
}
private void TransferToDefaultState()
{
XIdleEventArgs @event = XEventPool<XIdleEventArgs>.GetEvent();
@event.Firer = this._host;
XSingleton<XEventMgr>.singleton.FireEvent(@event);
}
private void BuildStateMap()
{
bool flag = XStateMachine._bStateMap == null;
if (flag)
{
XStateMachine._bStateMap = new bool[,]
{
{
false,
true,
true,
true,
true,
true,
true,
true
},
{
true,
true,
true,
true,
true,
true,
true,
true
},
{
false,
false,
false,
true,
true,
true,
true,
false
},
{
false,
false,
false,
false,
true,
true,
true,
false
},
{
false,
false,
false,
false,
true,
false,
true,
false
},
{
false,
false,
false,
false,
true,
true,
true,
false
},
{
false,
false,
false,
false,
false,
false,
false,
false
},
{
false,
true,
false,
false,
true,
true,
true,
true
}
};
}
}
public void UpdateCollisionLayer()
{
this._entity.SetCollisionLayer(this._current.CollisionLayer);
}
}
}
|