summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XRadioDocument.cs
blob: b13feaad44276f66736b73c9109e307e3d589c84 (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
using System;
using System.Collections.Generic;
using KKSG;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUpdater;
using XUtliPoolLib;

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

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

		public List<string> hostlist = new List<string>();

		public List<ulong> hostIDs = new List<ulong>();

		private bool mJoinBigRoomSucc = false;

		public bool isHost = false;

		public XRadioDocument.BigRoomState roomState = XRadioDocument.BigRoomState.OutRoom;

		private bool startLoop = false;

		private float acc_time = 0f;

		private float all_time = 0f;

		private int TimeOut = 8;

		private bool cacheRadioOpen = false;

		public enum BigRoomState
		{
			OutRoom,
			Processing,
			InRoom
		}

		protected override void OnReconnected(XReconnectedEventArgs arg)
		{
		}

		public override void Update(float fDeltaT)
		{
			base.Update(fDeltaT);
			bool flag = this.startLoop;
			if (flag)
			{
				this.acc_time += fDeltaT;
				this.all_time += fDeltaT;
				bool flag2 = this.all_time > (float)this.TimeOut && !this.mJoinBigRoomSucc;
				if (flag2)
				{
					this.startLoop = false;
					this.mJoinBigRoomSucc = false;
					this.roomState = XRadioDocument.BigRoomState.OutRoom;
					DlgBase<RadioDlg, RadioBehaviour>.singleton.Refresh(false);
					XSingleton<XDebug>.singleton.AddGreenLog("join room timeout, Apollo error!", null, null, null, null, null);
					XSingleton<UiUtility>.singleton.ShowSystemTip(XSingleton<XStringTable>.singleton.GetString("FM_ENTER_OVERTIME"), "fece00");
				}
				bool flag3 = this.acc_time > 0.4f;
				if (flag3)
				{
					bool flag4 = !this.mJoinBigRoomSucc;
					if (flag4)
					{
						IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
						bool joinRoomBigResult = xapolloManager.GetJoinRoomBigResult();
						if (joinRoomBigResult)
						{
							this.startLoop = false;
							this.mJoinBigRoomSucc = true;
							xapolloManager.openMusic = true;
							xapolloManager.openSpeak = false;
							this.roomState = XRadioDocument.BigRoomState.InRoom;
							this.MuteSounds(false);
							DlgBase<RadioDlg, RadioBehaviour>.singleton.Refresh(true);
							DlgBase<RadioDlg, RadioBehaviour>.singleton.UpdateHostInfo();
							XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FM_ENTER_SUCCESS"), "fece00");
							XSingleton<XChatIFlyMgr>.singleton.StopAutoPlay();
							XSingleton<XChatIFlyMgr>.singleton.EnableAutoPlay(false);
						}
					}
					this.acc_time = 0f;
				}
			}
		}

		public override void OnDetachFromHost()
		{
			this.cacheRadioOpen = false;
			this.QuitApolloBigRoom();
			base.OnDetachFromHost();
		}

		public override void OnEnterScene()
		{
			base.OnEnterScene();
			bool flag = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.World;
			if (flag)
			{
				XChatDocument specificDocument = XDocuments.GetSpecificDocument<XChatDocument>(XChatDocument.uuID);
				bool flag2 = specificDocument.GetBattleRaw().real > 0;
				if (flag2)
				{
					bool flag3 = this.roomState == XRadioDocument.BigRoomState.InRoom;
					if (flag3)
					{
						this.cacheRadioOpen = true;
					}
					this.QuitBigRoom();
				}
			}
			else
			{
				bool flag4 = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.Hall;
				if (flag4)
				{
					bool flag5 = this.cacheRadioOpen;
					if (flag5)
					{
						bool flag6 = this.roomState == XRadioDocument.BigRoomState.OutRoom;
						if (flag6)
						{
							this.JoinBigRoom();
							this.cacheRadioOpen = false;
						}
					}
				}
			}
		}

		public void UpdateHost(List<string> names, List<ulong> roles)
		{
			bool flag = names != null;
			if (flag)
			{
				this.hostlist = names;
				this.hostIDs = roles;
			}
			bool flag2 = DlgBase<RadioDlg, RadioBehaviour>.singleton.IsVisible();
			if (flag2)
			{
				DlgBase<RadioDlg, RadioBehaviour>.singleton.UpdateHostInfo();
			}
		}

		public void MuteSounds(bool mute)
		{
			bool flag = this.roomState == XRadioDocument.BigRoomState.InRoom;
			if (flag)
			{
				IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
				if (mute)
				{
					xapolloManager.SetMusicVolum(0);
				}
				else
				{
					XOptionsDocument specificDocument = XDocuments.GetSpecificDocument<XOptionsDocument>(XOptionsDocument.uuID);
					int @int = XSingleton<XGlobalConfig>.singleton.GetInt("SetSpeakerVolume");
					xapolloManager.SetMusicVolum((int)((float)@int * specificDocument.voiceVolme));
				}
			}
		}

		public void JoinBigRoom()
		{
			bool flag = !this.mJoinBigRoomSucc && !this.startLoop;
			if (flag)
			{
				this.roomState = XRadioDocument.BigRoomState.Processing;
				XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FM_ENTERING"), "fece00");
				RpcC2M_JoinFmRoom rpc = new RpcC2M_JoinFmRoom();
				XSingleton<XClientNetwork>.singleton.Send(rpc);
			}
		}

		public void ProcessJoinBigRoom(JoinLargeRoomReply reply)
		{
			this.acc_time = 0f;
			this.all_time = 0f;
			this.startLoop = true;
			this.mJoinBigRoomSucc = false;
			XSingleton<XDebug>.singleton.AddLog("url:", reply.url, " bussinessid:" + reply.bussniessid, " role:" + reply.key, null, null, XDebugColor.XDebug_None);
			XSingleton<XDebug>.singleton.AddLog("roomid: ", reply.roomid.ToString(), " roomkey:", reply.roomkey.ToString(), null, null, XDebugColor.XDebug_None);
			IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
			xapolloManager.SetRealtimeMode();
			xapolloManager.JoinBigRoom(reply.url, (int)reply.key, reply.bussniessid, (long)reply.roomid, (long)reply.roomkey, (short)reply.memberid);
		}

		public void ProcessTimeOut()
		{
			this.mJoinBigRoomSucc = false;
			this.roomState = XRadioDocument.BigRoomState.OutRoom;
			DlgBase<RadioDlg, RadioBehaviour>.singleton.Refresh(false);
		}

		public void QuitBigRoom()
		{
			this.QuitApolloBigRoom();
			PtcC2M_LeaveLargeRoom proto = new PtcC2M_LeaveLargeRoom();
			XSingleton<XClientNetwork>.singleton.Send(proto);
		}

		private void QuitApolloBigRoom()
		{
			try
			{
				this.startLoop = false;
				this.mJoinBigRoomSucc = false;
				bool flag = this.roomState == XRadioDocument.BigRoomState.InRoom;
				if (flag)
				{
					IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
					bool flag2 = xapolloManager != null;
					if (flag2)
					{
						xapolloManager.openSpeak = false;
						xapolloManager.QuitBigRoom();
					}
				}
				this.roomState = XRadioDocument.BigRoomState.OutRoom;
				bool flag3 = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.Hall;
				if (flag3)
				{
					XSingleton<XChatIFlyMgr>.singleton.EnableAutoPlay(true);
					XSingleton<XChatIFlyMgr>.singleton.StartAutoPlay(true, true);
				}
			}
			catch (Exception ex)
			{
				XSingleton<XDebug>.singleton.AddLog(ex.StackTrace.ToString(), null, null, null, null, null, XDebugColor.XDebug_None);
			}
		}

		public bool isHosting()
		{
			IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
			return this.roomState != XRadioDocument.BigRoomState.OutRoom && this.isHost && xapolloManager.openSpeak;
		}
	}
}