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

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

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

		private float m_timerToken;

		private XFx m_xfxObj;

		private bool m_inInherit = false;

		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
			bool flag = this.m_xfxObj == null;
			if (flag)
			{
				this.m_xfxObj = XSingleton<XFxMgr>.singleton.CreateFx("Effects/FX_Particle/UIfx/UI_cg_st", null, true);
				this.m_xfxObj.Play(this._entity.EngineObject, Vector3.zero, Vector3.one, 1f, true, false, "", 0f);
			}
			bool isPlayer = this._entity.IsPlayer;
			if (isPlayer)
			{
				XCameraActionEventArgs @event = XEventPool<XCameraActionEventArgs>.GetEvent();
				@event.XRotate = XSingleton<XScene>.singleton.GameCamera.Root_R_X_Default;
				float angle = float.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("GuildInheritCameraDesdir"));
				float degree = float.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("GuildInheritCameraDegree"));
				@event.YRotate = XSingleton<XCommon>.singleton.AngleToFloat(XSingleton<XCommon>.singleton.HorizontalRotateVetor3(XSingleton<XCommon>.singleton.FloatToAngle(angle), degree, true));
				@event.Firer = XSingleton<XScene>.singleton.GameCamera;
				XSingleton<XEventMgr>.singleton.FireEvent(@event);
			}
		}

		public override void OnDetachFromHost()
		{
			bool flag = this.m_xfxObj != null;
			if (flag)
			{
				XSingleton<XFxMgr>.singleton.DestroyFx(this.m_xfxObj, true);
				this.m_xfxObj = null;
			}
			bool flag2 = this._entity != null && this._entity.IsPlayer;
			if (flag2)
			{
				XRole xrole = this._entity as XRole;
				xrole.PlayStateBack();
				XCameraMotionEndEventArgs @event = XEventPool<XCameraMotionEndEventArgs>.GetEvent();
				@event.Target = this._entity;
				@event.Firer = XSingleton<XScene>.singleton.GameCamera;
				XSingleton<XEventMgr>.singleton.FireEvent(@event);
			}
			base.OnDetachFromHost();
		}

		public override void Update(float fDeltaT)
		{
			base.Update(fDeltaT);
			bool flag = this.m_timerToken > 0f;
			if (flag)
			{
				this.m_timerToken -= fDeltaT;
			}
			else
			{
				bool inInherit = this.m_inInherit;
				if (inInherit)
				{
					this.StopInheritAction();
				}
				else
				{
					this.StartInheritAction();
				}
			}
		}

		private void StartInheritAction()
		{
			XRole xrole = this._entity as XRole;
			int randomNumber = this.GetRandomNumber(2, 0);
			string targetName = this.GetTargetName(randomNumber);
			bool flag = !string.IsNullOrEmpty(targetName);
			if (flag)
			{
				this.m_timerToken = xrole.PlaySpecifiedAnimationGetLength(this.GetTargetName(randomNumber));
			}
			else
			{
				this.m_timerToken = 5f;
			}
			this.m_inInherit = true;
		}

		private void StopInheritAction()
		{
			this.m_inInherit = false;
			this.m_timerToken = (float)this.GetRandomNumber(5, 2);
			XRole xrole = this._entity as XRole;
			xrole.PlayStateBack();
		}

		private int GetRandomNumber(int max, int min = 0)
		{
			System.Random random = new System.Random();
			int num = random.Next(min, max);
			return num + 1;
		}

		private string GetTargetName(int index)
		{
			string result = this._entity.Present.PresentLib.InheritActionOne;
			if (index != 1)
			{
				if (index == 2)
				{
					result = this._entity.Present.PresentLib.InheritActionTwo;
				}
			}
			else
			{
				result = this._entity.Present.PresentLib.InheritActionOne;
			}
			return result;
		}
	}
}