summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XLevelSpawnMgr.cs
blob: e0d5fbbb70291d30aeb3c9c4425073ecfaeaa3b7 (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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
using System;
using System.Collections.Generic;
using System.IO;
using KKSG;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XLevelSpawnMgr : XSingleton<XLevelSpawnMgr>
	{
		public bool HasRobot
		{
			get
			{
				return this._CachedRobotFromServer != null;
			}
		}

		public XLevelSpawnInfo CurrentSpawner
		{
			get
			{
				return this._curSpawner;
			}
		}

		public XAIGlobal AIGlobal
		{
			get
			{
				return this._aiGlobal;
			}
		}

		private float _time = 0f;

		private XLevelSpawnInfo _curSpawner;

		private XAIGlobal _aiGlobal;

		private Dictionary<uint, UnitAppearance> _CachedMonsterFromServer = new Dictionary<uint, UnitAppearance>();

		private UnitAppearance _CachedRobotFromServer = null;

		private RandomBossTable _RandomBossReader = new RandomBossTable();

		public XEntity robot;

		public bool BossExtarScriptExecuting = false;

		public List<uint> MonsterIDs = new List<uint>();

		public bool ForcePreloadOneWave = false;

		public int MaxPreloadCount = 6;

		private List<int> ret = new List<int>();

		public override bool Init()
		{
			XSingleton<XResourceLoaderMgr>.singleton.ReadFile("Table/RandomEntityList", this._RandomBossReader);
			return true;
		}

		public override void Uninit()
		{
		}

		private List<int> GetCollectionEntityID(int RandomID)
		{
			this.ret.Clear();
			for (int i = 0; i < this._RandomBossReader.Table.Length; i++)
			{
				bool flag = this._RandomBossReader.Table[i].RandomID == RandomID;
				if (flag)
				{
					this.ret.Add(this._RandomBossReader.Table[i].EntityID);
				}
			}
			return this.ret;
		}

		public bool OnSceneLoaded(uint sceneID)
		{
			XSingleton<XLevelFinishMgr>.singleton.OnSceneLoaded(sceneID);
			string sceneConfigFile = XSingleton<XSceneMgr>.singleton.GetSceneConfigFile(sceneID);
			bool flag = sceneConfigFile.Length == 0;
			bool result;
			if (flag)
			{
				this._curSpawner = null;
				XSingleton<XLevelScriptMgr>.singleton.ClearWallInfo();
				XSingleton<XLevelScriptMgr>.singleton.Reset();
				result = false;
			}
			else
			{
				this.ReadFromSpawnConfig(sceneID, sceneConfigFile);
				XSingleton<XLevelScriptMgr>.singleton.CommandCount = 0u;
				this.BossExtarScriptExecuting = false;
				result = true;
			}
			return result;
		}

		public void GetMonsterCount(XLevelSpawnInfo spawner, ref int totalMonster, ref int totalBoss)
		{
			bool flag = spawner == null;
			if (!flag)
			{
				int num = 0;
				int num2 = 0;
				for (int i = 0; i < spawner._waves.Count; i++)
				{
					XLevelWave xlevelWave = spawner._waves[i];
					bool flag2 = xlevelWave._spawnType == LevelSpawnType.Spawn_Source_Monster;
					if (flag2)
					{
						XEntityStatistics.RowData byID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(xlevelWave._EnemyID);
						bool flag3 = byID != null && XSingleton<XEntityMgr>.singleton.IsOpponent((uint)byID.Fightgroup);
						if (flag3)
						{
							bool flag4 = 1 == byID.Type;
							if (flag4)
							{
								num += xlevelWave._monsterPos.Count + xlevelWave._roundCount;
								num2 += xlevelWave._monsterPos.Count + xlevelWave._roundCount;
							}
							bool flag5 = 6 == byID.Type || 2 == byID.Type;
							if (flag5)
							{
								num += xlevelWave._monsterPos.Count + xlevelWave._roundCount;
							}
						}
					}
					else
					{
						bool flag6 = xlevelWave._spawnType == LevelSpawnType.Spawn_Source_Random;
						if (flag6)
						{
							num += xlevelWave._monsterPos.Count + xlevelWave._roundCount;
							int randomID = xlevelWave._randomID;
							List<int> collectionEntityID = this.GetCollectionEntityID(randomID);
							bool flag7 = collectionEntityID.Count > 0;
							if (flag7)
							{
								int key = collectionEntityID[0];
								XEntityStatistics.RowData byID2 = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID((uint)key);
								bool flag8 = 1 == byID2.Type;
								if (flag8)
								{
									num2 += xlevelWave._monsterPos.Count + xlevelWave._roundCount;
								}
							}
						}
						else
						{
							num += xlevelWave._monsterPos.Count + xlevelWave._roundCount;
						}
					}
				}
				totalMonster = num;
				totalBoss = num2;
			}
		}

		private void ReadFromSpawnConfig(uint sceneID, string configFile)
		{
			this._time = 0f;
			bool flag = this._curSpawner == null;
			if (flag)
			{
				this._curSpawner = new XLevelSpawnInfo();
			}
			else
			{
				this._curSpawner.Clear();
			}
			Stream stream = XSingleton<XResourceLoaderMgr>.singleton.ReadText("Table/" + configFile, ".txt", true);
			StreamReader streamReader = new StreamReader(stream);
			string text = streamReader.ReadLine();
			int num = int.Parse(text);
			text = streamReader.ReadLine();
			int num2 = int.Parse(text);
			for (int i = 0; i < num2; i++)
			{
				text = streamReader.ReadLine();
				string[] array = text.Split(new char[]
				{
					','
				});
				int key = int.Parse(array[0].Substring(3));
				int value = int.Parse(array[1]);
				bool forcePreloadOneWave = this.ForcePreloadOneWave;
				if (forcePreloadOneWave)
				{
					bool flag2 = i == 0;
					if (flag2)
					{
						this._curSpawner._preloadInfo.Add(key, value);
					}
				}
				else
				{
					bool flag3 = this._curSpawner._preloadInfo.Count < this.MaxPreloadCount;
					if (flag3)
					{
						this._curSpawner._preloadInfo.Add(key, value);
					}
				}
			}
			for (int j = 0; j < num; j++)
			{
				XLevelWave xlevelWave = new XLevelWave();
				xlevelWave.ReadFromFile(streamReader);
				this._curSpawner._waves.Add(xlevelWave);
				XLevelDynamicInfo xlevelDynamicInfo = new XLevelDynamicInfo();
				xlevelDynamicInfo._id = xlevelWave._id;
				xlevelDynamicInfo._TotalCount = xlevelWave._monsterPos.Count + xlevelWave._roundCount;
				xlevelDynamicInfo.Reset();
				this._curSpawner._wavesDynamicInfo.Add(xlevelWave._id, xlevelDynamicInfo);
			}
			XSingleton<XResourceLoaderMgr>.singleton.ClearStream(stream);
			this._time = 0f;
			XSingleton<XLevelScriptMgr>.singleton.PreloadLevelScript(configFile + "_sc");
		}

		public void InitGlobalAI(uint sceneId)
		{
			bool flag = !XSingleton<XGame>.singleton.SyncMode;
			if (flag)
			{
				this._aiGlobal = new XAIGlobal();
				SceneTable.RowData sceneData = XSingleton<XSceneMgr>.singleton.GetSceneData(sceneId);
				bool flag2 = sceneData != null;
				if (flag2)
				{
					this._aiGlobal.InitAIGlobal(sceneData.SceneAI);
				}
				else
				{
					this._aiGlobal.InitAIGlobal("default");
				}
			}
		}

		public void UnInitGlobalAI()
		{
			bool flag = this._aiGlobal != null;
			if (flag)
			{
				this._aiGlobal.UnInitAIGlobal();
				this._aiGlobal = null;
			}
			XSingleton<XLevelAIMgr>.singleton.ClearAIData();
		}

		public void OnLeaveScene()
		{
			bool flag = this._curSpawner != null;
			if (flag)
			{
				this._curSpawner.Clear();
				this._curSpawner = null;
			}
			this.robot = null;
			XSingleton<XLevelFinishMgr>.singleton.OnLeaveScene();
		}

		public XLevelSpawnInfo GetSpawnerBySceneID(uint sceneID)
		{
			return this._curSpawner;
		}

		public void OnMonsterDie(XEntity entity)
		{
			XPlayer xplayer = entity as XPlayer;
			bool flag = entity != null && this._curSpawner != null;
			if (flag)
			{
				this._curSpawner.OnMonsterDie(entity);
			}
		}

		public void OnMonsterSpawn(int waveid)
		{
		}

		public void Update(float delta)
		{
			bool isCurrentLevelFinished = XSingleton<XLevelFinishMgr>.singleton.IsCurrentLevelFinished;
			if (!isCurrentLevelFinished)
			{
				bool needCheckLevelfinishScript = XSingleton<XLevelFinishMgr>.singleton.NeedCheckLevelfinishScript;
				if (!needCheckLevelfinishScript)
				{
					this._time += delta;
					bool flag = this._curSpawner != null;
					if (flag)
					{
						this._curSpawner.Update(this._time);
					}
				}
			}
		}

		public void SetMonster(UnitAppearance monster)
		{
			uint waveID = monster.waveID;
			monster.waveID = waveID - 1u;
			this._CachedMonsterFromServer[monster.waveID] = monster;
		}

		public void CacheServerMonster(List<UnitAppearance> Monsters)
		{
			this._CachedMonsterFromServer.Clear();
			for (int i = 0; i < Monsters.Count; i++)
			{
				this._CachedMonsterFromServer.Add(Monsters[i].waveID, Monsters[i]);
			}
		}

		public void CacheServerRobot(UnitAppearance Robot)
		{
			this._CachedRobotFromServer = Robot;
		}

		public UnitAppearance GetCacheServerMonster(uint wave)
		{
			UnitAppearance unitAppearance;
			bool flag = this._CachedMonsterFromServer.TryGetValue(wave, out unitAppearance);
			UnitAppearance result;
			if (flag)
			{
				result = unitAppearance;
			}
			else
			{
				result = null;
			}
			return result;
		}

		public void CreateRobot(uint sceneid)
		{
			bool flag = this._CachedRobotFromServer == null;
			if (!flag)
			{
				Vector3 sceneStartPos = XSingleton<XSceneMgr>.singleton.GetSceneStartPos(sceneid);
				Vector3 forward = XSingleton<XEntityMgr>.singleton.Player.EngineObject.Forward;
				Vector3 position = sceneStartPos + forward;
				Quaternion sceneStartRot = XSingleton<XSceneMgr>.singleton.GetSceneStartRot(sceneid);
				XAttributes attr = XSingleton<XAttributeMgr>.singleton.InitAttrFromServer(this._CachedRobotFromServer.uID, this._CachedRobotFromServer.nickid, this._CachedRobotFromServer.unitType, this._CachedRobotFromServer.unitName, this._CachedRobotFromServer.attributes, this._CachedRobotFromServer.fightgroup, this._CachedRobotFromServer.isServerControl, this._CachedRobotFromServer.skills, null, new XOutLookAttr((this._CachedRobotFromServer.outlook != null) ? this._CachedRobotFromServer.outlook.guild : null), this._CachedRobotFromServer.level, 0u);
				this.robot = XSingleton<XEntityMgr>.singleton.Add(XSingleton<XEntityMgr>.singleton.CreateRole(attr, position, sceneStartRot, false, false));
				bool isDead = this._CachedRobotFromServer.IsDead;
				if (isDead)
				{
					XSingleton<XDeath>.singleton.DeathDetect(this.robot, null, true);
				}
			}
		}

		public bool ExecuteWaveExtraScript(int wave)
		{
			bool flag = this._curSpawner != null;
			return flag && this._curSpawner.ExecuteWaveExtraScript(wave);
		}

		public void SpawnExternalMonster(uint enemyID, Vector3 pos, int rot = 0)
		{
			bool flag = this._curSpawner != null;
			if (flag)
			{
				this._curSpawner.GenerateExternalSpawnTask(enemyID, pos, rot);
			}
		}

		public void KillAllMonster()
		{
			List<XEntity> opponent = XSingleton<XEntityMgr>.singleton.GetOpponent(XSingleton<XEntityMgr>.singleton.Player);
			for (int i = 0; i < opponent.Count; i++)
			{
				XSingleton<XDeath>.singleton.DeathDetect(opponent[i], null, true);
			}
		}

		public void CacheServerMonsterID(List<uint> idList)
		{
			this.MonsterIDs.Clear();
			for (int i = 0; i < idList.Count; i++)
			{
				this.MonsterIDs.Add(idList[i]);
			}
		}

		public bool QueryMonsterStaticInfo(uint monsterID, ref Vector3 position, ref float face)
		{
			bool flag = this.CurrentSpawner == null;
			return !flag && this.CurrentSpawner.QueryMonsterStaticInfo(monsterID, ref position, ref face);
		}
	}
}