summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/Components/ActionStates/XActionStateComponent.cs
blob: 89a214fe559f11563dead2d2535542c0a4025d5a (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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using System;
using XUtliPoolLib;

namespace XMainClient
{
	internal abstract class XActionStateComponent<T> : XComponent, IXStateTransform, IXInterface where T : XActionArgs
	{
		public virtual bool SyncPredicted
		{
			get
			{
				return !XSingleton<XGame>.singleton.SyncMode;
			}
		}

		public virtual float Speed
		{
			get
			{
				throw new NotImplementedException();
			}
		}

		public XStateDefine SelfState
		{
			get
			{
				return this._selfState;
			}
		}

		public bool IsStopped
		{
			get
			{
				return this._bStopped;
			}
		}

		public bool IsFinished
		{
			get
			{
				return this._bFinished || this._bStopped;
			}
		}

		public virtual bool ShouldBePresent
		{
			get
			{
				return true;
			}
		}

		public long Token
		{
			get
			{
				return this._stateToken;
			}
		}

		protected long SelfToken
		{
			get
			{
				return this._selfToken;
			}
		}

		public virtual int CollisionLayer
		{
			get
			{
				return this._entity.DefaultLayer;
			}
		}

		public abstract string PresentCommand { get; }

		public abstract string PresentName { get; }

		public bool Deprecated { get; set; }

		public abstract bool IsUsingCurve { get; }

		protected XStateDefine _selfState = XStateDefine.XState_Idle;

		private bool _bFinished = true;

		private bool _bStopped = false;

		private long _stateToken = 0L;

		private long _selfToken = 0L;

		public override void OnDetachFromHost()
		{
			bool flag = this.SelfState != XStateDefine.XState_Idle && this._entity.Machine.Current == this.SelfState;
			if (flag)
			{
				this._entity.Machine.ForceToDefaultState(true);
			}
			base.OnDetachFromHost();
		}

		public bool IsPermitted(XStateDefine state)
		{
			bool flag = this.IsFinished && this._selfState != XStateDefine.XState_Move;
			return flag || this.InnerPermitted(state);
		}

		public virtual void OnRejected(XStateDefine current)
		{
		}

		public void StateUpdate(float deltaTime)
		{
			bool flag = this.SelfState != this._entity.Machine.Default && this.IsFinished;
			if (flag)
			{
				this.Finish();
			}
			else
			{
				this.ActionUpdate(deltaTime);
			}
		}

		private void Start()
		{
			this.Begin();
		}

		public void Stop(XStateDefine next)
		{
			bool flag = !this._bStopped;
			if (flag)
			{
				this._bStopped = true;
				this.Finish();
				this.Cancel(next);
			}
		}

		public virtual void OnGetPermission()
		{
			this._bStopped = false;
			this._bFinished = false;
		}

		public virtual string TriggerAnim(string pre)
		{
			string presentCommand = this.PresentCommand;
			bool flag = pre != presentCommand;
			if (flag)
			{
				bool flag2 = this._entity.Ator != null;
				if (flag2)
				{
					this._entity.Ator.SetTrigger(presentCommand);
				}
			}
			return presentCommand;
		}

		protected void Finish()
		{
			bool flag = !this._bFinished;
			if (flag)
			{
				this._bFinished = true;
				this.Cease();
			}
		}

		protected virtual void Cease()
		{
		}

		protected virtual void Begin()
		{
		}

		protected virtual void Cancel(XStateDefine next)
		{
		}

		protected virtual void OnMount(XMount mount)
		{
		}

		protected virtual bool SelfCheck(T args)
		{
			return true;
		}

		protected bool GetPermission(T e)
		{
			bool flag = (this._entity.Skill == null || this._entity.Skill.CanPerformAction(this.SelfState, e)) && (this._entity.Machine == null || this._entity.Machine.TryTransferToState(this));
			bool flag2 = flag;
			if (flag2)
			{
				this._stateToken = e.Token;
				this._selfToken = XSingleton<XCommon>.singleton.UniqueToken;
			}
			return flag;
		}

		protected virtual bool InnerPermitted(XStateDefine state)
		{
			return this._entity.Machine.StatePermitted(this._selfState, state);
		}

		protected bool OnActionEvent(XEventArgs e)
		{
			T e2 = e as T;
			XStateDefine last = this._entity.Machine.Current;
			bool permission = this.GetPermission(e2);
			if (permission)
			{
				this.OnGetEvent(e2, last);
				this.Start();
			}
			return true;
		}

		protected bool OnMountEvent(XEventArgs e)
		{
			bool flag = e is XOnMountedEventArgs;
			if (flag)
			{
				this.OnMount(this._entity.Mount);
			}
			else
			{
				bool flag2 = e is XOnUnMountedEventArgs;
				if (flag2)
				{
					this.OnMount(null);
				}
			}
			return true;
		}

		protected abstract bool OnGetEvent(T e, XStateDefine last);

		protected virtual void ActionUpdate(float deltaTime)
		{
		}
	}
}