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

namespace XMainClient
{
	public sealed class XSceneTransfer : MonoBehaviour
	{
		private uint _loading_scene_id = 0u;

		public void TransferScene(uint sceneid)
		{
			this._loading_scene_id = sceneid;
			base.StartCoroutine(this.TransferLevelInMainCity());
		}

		private IEnumerator TransferLevelInMainCity()
		{
			XSingleton<XScene>.singleton.OnSceneBeginLoad(this._loading_scene_id);
			XSingleton<XScene>.singleton.OnSceneLoaded(this._loading_scene_id);
			XSingleton<XGameUI>.singleton.m_uiTool.EnableUILoadingUpdate(true);
			XSingleton<XScene>.singleton.RefreshScenMustTransform();
			this.CreatePlayer(this._loading_scene_id);
			while (XSingleton<XEntityMgr>.singleton.Player.Equipment != null && XSingleton<XEntityMgr>.singleton.Player.Equipment.IsLoadingPart())
			{
				yield return null;
			}
			this.DocPreload(this._loading_scene_id);
			yield return null;
			this.PreLoadSceneMonster(this._loading_scene_id);
			yield return null;
			this.PlaceSceneNpc(this._loading_scene_id);
			yield return null;
			this.ResetLevelAirWall();
			yield return null;
			XSingleton<XGame>.singleton.OnEnterScene(this._loading_scene_id, true);
			SceneType sceneType = XSingleton<XSceneMgr>.singleton.GetSceneType(this._loading_scene_id);
			AsyncSceneAnimationRequest asar = XSingleton<XSceneMgr>.singleton.ShowSceneLoadAnim(sceneType);
			while (asar != null && !asar.IsDone)
			{
				XSingleton<XSceneMgr>.singleton.UpdateSceneLoadAnim(asar, sceneType);
				yield return null;
			}
			RpcC2G_DoEnterScene DoEnterSceneRpc = new RpcC2G_DoEnterScene();
			DoEnterSceneRpc.oArg.sceneid = XSingleton<XScene>.singleton.SceneID;
			XSingleton<XClientNetwork>.singleton.Send(DoEnterSceneRpc);
			XSingleton<XScene>.singleton.bSceneLoadedRpcSend = true;
			while (!XSingleton<XScene>.singleton.bSceneServerReady)
			{
				bool flag = XSingleton<XScene>.singleton.Error > ErrorCode.ERR_SUCCESS;
				if (flag)
				{
					XSingleton<UiUtility>.singleton.OnFatalErrorClosed(XSingleton<XScene>.singleton.Error);
					XSingleton<XScene>.singleton.Error = ErrorCode.ERR_SUCCESS;
					XSingleton<XClientNetwork>.singleton.CloseOnServerErrorNtf = false;
					break;
				}
				bool flag2 = XSingleton<XScene>.singleton.SceneEntranceConfig != null;
				if (flag2)
				{
					DlgBase<XPkLoadingView, XPkLoadingBehaviour>.singleton.HidePkLoading();
					DlgBase<XMultiPkLoadingView, XMultiPkLoadingBehaviour>.singleton.HidePkLoading();
					DlgBase<XTeamLeagueLoadingView, XTeamLeagueLoadingBehaviour>.singleton.HidePkLoading();
					XSingleton<XScene>.singleton.TriggerScene();
					break;
				}
				yield return null;
			}
			bool bSceneServerReady = XSingleton<XScene>.singleton.bSceneServerReady;
			if (bSceneServerReady)
			{
				this.PlayBGM(this._loading_scene_id);
				DlgBase<XPkLoadingView, XPkLoadingBehaviour>.singleton.HidePkLoading();
				DlgBase<XMultiPkLoadingView, XMultiPkLoadingBehaviour>.singleton.HidePkLoading();
				DlgBase<XTeamLeagueLoadingView, XTeamLeagueLoadingBehaviour>.singleton.HidePkLoading();
				XAutoFade.FadeIn(1f, true);
				XSingleton<XScene>.singleton.TriggerScene();
			}
			bool flag3 = XSingleton<XScene>.singleton.SceneEntranceConfig != null;
			if (flag3)
			{
				XSingleton<XScene>.singleton.SceneEnterTo(true);
			}
			XSingleton<XGame>.singleton.switchScene = false;
			yield break;
		}

		private void CreatePlayer(uint sceneID)
		{
			XSingleton<XDebug>.singleton.AddLog("Preload Player", null, null, null, null, null, XDebugColor.XDebug_None);
			XSingleton<XEntityMgr>.singleton.Add(XSingleton<XEntityMgr>.singleton.CreatePlayer(Vector3.zero, Quaternion.identity, false, XSingleton<XScene>.singleton.IsMustTransform));
		}

		private void PreLoadSceneMonster(uint sceneID)
		{
			List<uint> list = new List<uint>();
			XLevelSpawnInfo spawnerBySceneID = XSingleton<XLevelSpawnMgr>.singleton.GetSpawnerBySceneID(sceneID);
			bool flag = spawnerBySceneID != null;
			if (flag)
			{
				Dictionary<int, int> dictionary = new Dictionary<int, int>();
				foreach (KeyValuePair<int, int> keyValuePair in spawnerBySceneID._preloadInfo)
				{
					bool flag2 = keyValuePair.Key == 0;
					if (!flag2)
					{
						dictionary.Add(keyValuePair.Key, keyValuePair.Value);
					}
				}
				for (int i = 0; i < XSingleton<XLevelSpawnMgr>.singleton.MonsterIDs.Count; i++)
				{
					bool flag3 = XSingleton<XLevelSpawnMgr>.singleton.MonsterIDs[i] == 0u;
					if (!flag3)
					{
						bool flag4 = !dictionary.ContainsKey((int)XSingleton<XLevelSpawnMgr>.singleton.MonsterIDs[i]);
						if (flag4)
						{
							dictionary.Add((int)XSingleton<XLevelSpawnMgr>.singleton.MonsterIDs[i], 1);
						}
					}
				}
				foreach (KeyValuePair<int, int> keyValuePair2 in dictionary)
				{
					uint key = (uint)keyValuePair2.Key;
					XEntityStatistics.RowData byID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(key);
					bool flag5 = byID == null;
					if (!flag5)
					{
						string prefab = XSingleton<XEntityMgr>.singleton.EntityInfo.GetByPresentID(byID.PresentID).Prefab;
						bool flag6 = !list.Contains(byID.PresentID);
						if (flag6)
						{
							XSingleton<XEntityMgr>.singleton.PreloadTemp(byID.PresentID, key, (EntitySpecies)byID.Type);
							list.Add(byID.PresentID);
						}
					}
				}
			}
		}

		private void PlaceSceneNpc(uint sceneID)
		{
			List<uint> npcs = XSingleton<XEntityMgr>.singleton.GetNpcs(sceneID);
			bool flag = npcs != null;
			if (flag)
			{
				XTaskDocument specificDocument = XDocuments.GetSpecificDocument<XTaskDocument>(XTaskDocument.uuID);
				for (int i = 0; i < npcs.Count; i++)
				{
					bool flag2 = !specificDocument.ShouldNpcExist(npcs[i]);
					if (!flag2)
					{
						XSingleton<XEntityMgr>.singleton.CreateNpc(npcs[i], true);
					}
				}
			}
		}

		private void ResetLevelAirWall()
		{
			XSingleton<XLevelScriptMgr>.singleton.ResetAirWallState();
		}

		private void DocPreload(uint sceneid)
		{
			for (int i = 0; i < XSingleton<XGame>.singleton.Doc.Components.Count; i++)
			{
				XSingleton<XGame>.singleton.Doc.Components[i].OnEnterScene();
			}
		}

		private void PlayBGM(uint sceneid)
		{
			string sceneBGM = XSingleton<XSceneMgr>.singleton.GetSceneBGM(sceneid);
			XSingleton<XAudioMgr>.singleton.PlayBGM(sceneBGM);
		}
	}
}