summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XCameraSoloComponent.cs
blob: b4d52220d14f8f5bc79689b7f1a34a884b31fe9e (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
using System;
using UnityEngine;
using XUtliPoolLib;

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

		public XCameraSoloComponent.XCameraSoloState SoloState
		{
			get
			{
				return this._solo_state;
			}
		}

		public float SoloInitAngle
		{
			get
			{
				return this._init_angle;
			}
		}

		public XEntity Target
		{
			get
			{
				return this._target;
			}
		}

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

		private XCameraEx _camera_host = null;

		private XCameraMotionData _motion = new XCameraMotionData();

		private XEmpty _anchor = null;

		private XEntity _target = null;

		private float _rotate_y = 0f;

		private float _init_angle = 0f;

		private float _base_angle = 0f;

		private float _targetRadius = 0f;

		private bool _first_execute = false;

		private Vector3 _base_direction = Vector3.forward;

		private Vector3 _base_position = Vector3.zero;

		private Vector3 _base_location = Vector3.zero;

		private Vector3 _last_location = Vector3.zero;

		private XCameraSoloComponent.XCameraSoloState _solo_state = XCameraSoloComponent.XCameraSoloState.Stop;

		public enum XCameraSoloState
		{
			Prepared,
			Triggered,
			Executing,
			Stop
		}

		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
			this._motion.AutoSync_At_Begin = true;
			this._motion.Coordinate = CameraMotionSpace.World;
			this._motion.Follow_Position = true;
			this._motion.LookAt_Target = false;
			this._motion.At = 0f;
			this._motion.Motion = "Animation/Main_Camera/Main_Camera_Idle";
			this._camera_host = (this._host as XCameraEx);
			this._solo_state = XCameraSoloComponent.XCameraSoloState.Stop;
			this._anchor = XSingleton<XEntityMgr>.singleton.CreateEmpty();
		}

		public override void OnDetachFromHost()
		{
			this._camera_host = null;
			base.OnDetachFromHost();
		}

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

		protected bool OnSolo(XEventArgs e)
		{
			bool flag = !XCameraEx.OperationH || XSingleton<XOperationData>.singleton.OffSolo;
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				XCameraSoloEventArgs xcameraSoloEventArgs = e as XCameraSoloEventArgs;
				this._target = xcameraSoloEventArgs.Target;
				bool flag2 = !XEntity.ValideEntity(this._target);
				if (flag2)
				{
					result = true;
				}
				else
				{
					Vector3 position = this._target.EngineObject.Position;
					this._last_location = position;
					this._targetRadius = this._target.Radius;
					this._base_position = XSingleton<XEntityMgr>.singleton.Player.EngineObject.Position;
					this._base_position.y = XSingleton<XScene>.singleton.TerrainY(position);
					this._base_direction = XSingleton<XCommon>.singleton.Horizontal(this._target.EngineObject.Position - this._base_position);
					this._base_angle = XSingleton<XCommon>.singleton.AngleToFloat(this._base_direction);
					this._base_location = this._camera_host.CameraTrans.position;
					this._init_angle = this._base_angle;
					this.CalibrateAnchor(this._init_angle);
					this._solo_state = XCameraSoloComponent.XCameraSoloState.Prepared;
					this.Start();
					result = true;
				}
			}
			return result;
		}

		public void Start()
		{
			this._first_execute = true;
			XCameraMotionEventArgs @event = XEventPool<XCameraMotionEventArgs>.GetEvent();
			@event.Motion = this._motion;
			@event.Target = this._anchor;
			@event.Trigger = "ToSolo";
			@event.Firer = this._camera_host;
			XSingleton<XEventMgr>.singleton.FireEvent(@event);
			bool flag = this._target != null && this._target.IsBoss;
			if (flag)
			{
				XSingleton<XAudioMgr>.singleton.PlayBGM("Audio/mapambience/bossnew");
			}
		}

		public void Go()
		{
			this._solo_state = XCameraSoloComponent.XCameraSoloState.Triggered;
		}

		public override void Update(float fDeltaT)
		{
			XCameraSoloComponent.XCameraSoloState solo_state = this._solo_state;
			if (solo_state != XCameraSoloComponent.XCameraSoloState.Triggered)
			{
				if (solo_state == XCameraSoloComponent.XCameraSoloState.Executing)
				{
					bool flag = XEntity.ValideEntity(this._target);
					if (flag)
					{
						this.Execution(this._target.RadiusCenter, fDeltaT);
						this._last_location = this._target.RadiusCenter;
					}
					else
					{
						bool flag2 = XSingleton<XSceneMgr>.singleton.Is1V1Scene();
						if (flag2)
						{
							this.Execution(this._last_location, fDeltaT);
						}
						else
						{
							this.Stop();
						}
					}
				}
			}
			else
			{
				bool rootReady = this._camera_host.RootReady;
				if (rootReady)
				{
					this._solo_state = XCameraSoloComponent.XCameraSoloState.Executing;
				}
			}
		}

		private void Execution(Vector3 position, float fDeltaT)
		{
			bool first_execute = this._first_execute;
			if (first_execute)
			{
				this._base_position = XSingleton<XEntityMgr>.singleton.Player.EngineObject.Position;
				this._first_execute = false;
			}
			else
			{
				Vector3 vector = XSingleton<XEntityMgr>.singleton.Player.EngineObject.Position - this._base_position;
				Vector3 vector2 = Vector3.Project(vector, this._base_direction);
				Vector3 vector3 = Vector3.Project(vector, Vector3.up);
				Vector3 vector4 = Vector3.Project(vector, Vector3.Cross(this._base_direction, Vector3.up));
				float num = (Vector3.Angle(vector2, this._base_direction) > 90f) ? 6f : 3f;
				this._base_position += vector2 * Mathf.Min(1f, num * fDeltaT);
				this._base_position += vector3 * Mathf.Min(1f, 2f * fDeltaT);
				this._base_position += vector4 * Mathf.Min(1f, 2f * fDeltaT);
			}
			Vector3 vector5 = XSingleton<XCommon>.singleton.Horizontal(position - this._base_position);
			float num2 = Vector3.Angle(vector5, this._base_direction);
			bool flag = XSingleton<XCommon>.singleton.Clockwise(this._base_direction, vector5);
			if (flag)
			{
				num2 = -num2;
			}
			this._base_angle += (0f - num2) * Mathf.Min(1f, this.Palstance(position) * fDeltaT);
			this._base_direction = XSingleton<XCommon>.singleton.FloatToAngle(this._base_angle);
			float num3 = XSingleton<XCommon>.singleton.AngleToFloat(this._base_direction);
			this._rotate_y = num3 - this._init_angle;
			this._camera_host.YRotateExBarely(this._rotate_y);
			this.CalibrateAnchor(num3);
		}

		public override void PostUpdate(float fDeltaT)
		{
			bool flag = this._solo_state == XCameraSoloComponent.XCameraSoloState.Executing;
			if (flag)
			{
				Vector3 eulerAngles = this._camera_host.CameraTrans.rotation.eulerAngles;
				Vector3 vector = Quaternion.Euler(eulerAngles) * Vector3.forward;
				this._camera_host.Offset += (this._camera_host.TargetOffset - this._camera_host.Offset) * Mathf.Min(1f, fDeltaT * 4f);
				this._base_location = this._camera_host.Anchor - vector * this._camera_host.Offset;
			}
		}

		private float Palstance(Vector3 targetPosition)
		{
			Vector3 vector = targetPosition - this._base_position;
			vector.y = 0f;
			float num = vector.magnitude - this._targetRadius - XSingleton<XEntityMgr>.singleton.Player.Radius;
			float num2 = 2f;
			float num3 = 4f;
			return (num > num3) ? num2 : ((num > 0f) ? (Mathf.Sin(num / num3 * 1.57079637f) * num2) : 0f);
		}

		private void CalibrateAnchor(float y)
		{
			this._anchor.EngineObject.Position = this._base_position;
			this._anchor.EngineObject.Rotation = Quaternion.Euler(0f, y, 0f);
		}

		public void Stop()
		{
			bool flag = this._camera_host == null || this._solo_state == XCameraSoloComponent.XCameraSoloState.Stop;
			if (!flag)
			{
				this._target = null;
				this._solo_state = XCameraSoloComponent.XCameraSoloState.Stop;
				XCameraMotionEndEventArgs @event = XEventPool<XCameraMotionEndEventArgs>.GetEvent();
				@event.Firer = this._camera_host;
				@event.Target = this._anchor;
				XSingleton<XEventMgr>.singleton.FireEvent(@event);
				this._camera_host.AdjustRoot();
				this._camera_host.TargetOffset = this._camera_host.DefaultOffset;
			}
		}
	}
}