summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/ShipStatus.cs
blob: 89fd8da8550e69ce349ed9a027d7f1dfe6e075f6 (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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
using System;
using System.Collections.Generic;
using System.Linq;
using Assets.CoreScripts;
using Hazel;
using InnerNet;
using PowerTools;
using UnityEngine;

//场景中的物件,包含门的开启等,在这里同步
public class ShipStatus : InnerNetObject
{
	public ShipRoom[] AllRooms { get; private set; }

	public Vent[] AllVents { get; private set; }

	public static ShipStatus Instance;

	public Color CameraColor = Color.black;

	public float MaxLightRadius = 100f;

	public float MinLightRadius;

	public float MapScale = 4.4f;

	public Vector2 MapOffset = new Vector2(0.54f, 1.25f);

	public MapBehaviour MapPrefab;

	public Transform SpawnCenter;

	public float SpawnRadius = 1.55f;

	public AudioClip shipHum;

	public NormalPlayerTask[] CommonTasks;

	public NormalPlayerTask[] LongTasks;

	public NormalPlayerTask[] NormalTasks;

	public PlayerTask[] SpecialTasks;

	public AutoOpenDoor[] AllDoors;

	public global::Console[] AllConsoles;

    //c 场景中的门、反应堆等物件的状态
	public Dictionary<SystemTypes, ISystemType> Systems;

	public AnimationClip[] WeaponFires;

	public SpriteAnim WeaponsImage;

	public AnimationClip HatchActive;

	public SpriteAnim Hatch;

	public ParticleSystem HatchParticles;

	public AnimationClip ShieldsActive;

	public SpriteAnim[] ShieldsImages;

	public SpriteRenderer ShieldBorder;

	public Sprite ShieldBorderOn;

	public SpriteRenderer MedScanner;

	private int WeaponFireIdx;

	public float Timer;

	public float EmergencyCooldown;

	private RaycastHit2D[] volumeBuffer = new RaycastHit2D[5];

	public class SystemTypeComparer : IEqualityComparer<SystemTypes>
	{
		public static readonly ShipStatus.SystemTypeComparer Instance = new ShipStatus.SystemTypeComparer();

		public bool Equals(SystemTypes x, SystemTypes y)
		{
			return x == y;
		}

		public int GetHashCode(SystemTypes obj)
		{
			return (int)obj;
		}
	}

	private enum RpcCalls
	{
		CloseDoorsOfType,
		RepairSystem
	}

	public ShipStatus()
	{
        //c 所有的systems
		this.Systems = new Dictionary<SystemTypes, ISystemType>(ShipStatus.SystemTypeComparer.Instance)
		{
			{
				SystemTypes.Electrical,
				new SwitchSystem()
			},
			{
				SystemTypes.MedBay,
				new MedScanSystem()
			},
			{
				SystemTypes.Reactor,
				new ReactorSystemType()
			},
			{
				SystemTypes.LifeSupp,
				new LifeSuppSystemType()
			},
			{
				SystemTypes.Security,
				new SecurityCameraSystemType()
			},
			{
				SystemTypes.Comms,
				new HudOverrideSystemType()
			},
			{
				SystemTypes.Doors,
				new DoorsSystemType()
			}
		};
		this.Systems.Add(SystemTypes.Sabotage, new SabotageSystemType(new IActivatable[]
		{
			(IActivatable)this.Systems[SystemTypes.Comms],
			(IActivatable)this.Systems[SystemTypes.Reactor],
			(IActivatable)this.Systems[SystemTypes.LifeSupp],
			(IActivatable)this.Systems[SystemTypes.Electrical]
		}));
	}

	private void Awake()
	{
		this.AllRooms = base.GetComponentsInChildren<ShipRoom>();
		this.AllConsoles = base.GetComponentsInChildren<global::Console>();
		this.AllVents = base.GetComponentsInChildren<Vent>();
		this.AssignTaskIndexes();
		ShipStatus.Instance = this;
	}

	public void Start()
	{
		Camera.main.backgroundColor = this.CameraColor;
		if (DestroyableSingleton<HudManager>.InstanceExists)
		{
			DestroyableSingleton<HudManager>.Instance.Chat.ForceClosed();
			DestroyableSingleton<HudManager>.Instance.Chat.SetVisible(false);
			DestroyableSingleton<HudManager>.Instance.GameSettings.gameObject.SetActive(false);
		}
		DeconSystem componentInChildren = base.GetComponentInChildren<DeconSystem>();
		if (componentInChildren)
		{
			this.Systems.Add(SystemTypes.Decontamination, componentInChildren);
		}
		SoundManager.Instance.StopAllSound();
		AudioSource audioSource = SoundManager.Instance.PlaySound(this.shipHum, true, 1f);
		if (audioSource)
		{
			audioSource.pitch = 0.8f;
		}
		if (Constants.ShouldPlaySfx())
		{
			for (int i = 0; i < this.AllRooms.Length; i++)
			{
				ShipRoom room = this.AllRooms[i];
				if (room.AmbientSound)
				{
					SoundManager.Instance.PlayDynamicSound("Amb " + room.RoomId, room.AmbientSound, true, delegate(AudioSource player, float dt)
					{
						this.GetAmbientSoundVolume(room, player, dt);
					}, false);
				}
			}
		}
	}

	public override void OnDestroy()
	{
		SoundManager.Instance.StopAllSound();
		base.OnDestroy();
	}

	public Vector2 GetSpawnLocation(int playerId, int numPlayer)
	{
		Vector2 vector = Vector2.up;
		vector = vector.Rotate((float)(playerId - 1) * (360f / (float)numPlayer));
		vector *= this.SpawnRadius;
		return (Vector2)this.SpawnCenter.position + vector + new Vector2(0f, 0.3636f);
	}

	public void StartShields()
	{
		for (int i = 0; i < this.ShieldsImages.Length; i++)
		{
			this.ShieldsImages[i].Play(this.ShieldsActive, 1f);
		}
		this.ShieldBorder.sprite = this.ShieldBorderOn;
	}

	public void FireWeapon()
	{
		if (!this.WeaponsImage.IsPlaying((string)null))
		{
			this.WeaponsImage.Play(this.WeaponFires[this.WeaponFireIdx], 1f);
			this.WeaponFireIdx = (this.WeaponFireIdx + 1) % 2;
		}
	}

	public NormalPlayerTask GetTaskById(byte idx)
	{
		NormalPlayerTask result;
		if ((result = this.CommonTasks.FirstOrDefault((NormalPlayerTask t) => t.Index == (int)idx)) == null)
		{
			result = (this.LongTasks.FirstOrDefault((NormalPlayerTask t) => t.Index == (int)idx) ?? this.NormalTasks.FirstOrDefault((NormalPlayerTask t) => t.Index == (int)idx));
		}
		return result;
	}

	public void OpenHatch()
	{
		if (!this.Hatch.IsPlaying((string)null))
		{
			this.Hatch.Play(this.HatchActive, 1f);
			this.HatchParticles.Play();
		}
	}

	public void CloseDoorsOfType(SystemTypes room)
	{
		(this.Systems[SystemTypes.Doors] as DoorsSystemType).CloseDoorsOfType(room);
		base.SetDirtyBit(65536U);
	}

	public void RepairSystem(SystemTypes systemType, PlayerControl player, byte amount)
	{
		this.Systems[systemType].RepairDamage(player, amount);
		base.SetDirtyBit(1U << (int)systemType);
	}

	internal void SelectInfected()
	{
		List<GameData.PlayerInfo> list = (from pcd in GameData.Instance.AllPlayers
		where !pcd.Disconnected
		select pcd into pc
		where !pc.IsDead
		select pc).ToList<GameData.PlayerInfo>();
		int adjustedNumImpostors = PlayerControl.GameOptions.GetAdjustedNumImpostors(GameData.Instance.PlayerCount);
		list.RemoveDupes<GameData.PlayerInfo>();
		GameData.PlayerInfo[] array = new GameData.PlayerInfo[Mathf.Min(list.Count, adjustedNumImpostors)];
		for (int i = 0; i < array.Length; i++)
		{
			int index = HashRandom.FastNext(list.Count);
			array[i] = list[index];
			list.RemoveAt(index);
		}
		foreach (GameData.PlayerInfo playerInfo in array)
		{
			DestroyableSingleton<Telemetry>.Instance.SelectInfected((int)playerInfo.ColorId, playerInfo.HatId);
		}
		PlayerControl.LocalPlayer.RpcSetInfected(array);
	}

	private void AssignTaskIndexes()
	{
		int num = 0;
		for (int i = 0; i < this.CommonTasks.Length; i++)
		{
			this.CommonTasks[i].Index = num++;
		}
		for (int j = 0; j < this.LongTasks.Length; j++)
		{
			this.LongTasks[j].Index = num++;
		}
		for (int k = 0; k < this.NormalTasks.Length; k++)
		{
			this.NormalTasks[k].Index = num++;
		}
	}

	public void Begin()
	{
		this.AssignTaskIndexes();
		GameOptionsData gameOptions = PlayerControl.GameOptions;
		List<GameData.PlayerInfo> allPlayers = GameData.Instance.AllPlayers;
		HashSet<TaskTypes> hashSet = new HashSet<TaskTypes>();
		List<byte> list = new List<byte>(10);
		List<NormalPlayerTask> list2 = this.CommonTasks.ToList<NormalPlayerTask>();
		list2.Shuffle<NormalPlayerTask>();
		int num = 0;
		this.AddTasksFromList(ref num, gameOptions.NumCommonTasks, list, hashSet, list2);
		for (int i = 0; i < gameOptions.NumCommonTasks; i++)
		{
			if (list2.Count == 0)
			{
				Debug.LogWarning("Not enough common tasks");
				break;
			}
			int index = list2.RandomIdx<NormalPlayerTask>();
			list.Add((byte)list2[index].Index);
			list2.RemoveAt(index);
		}
		List<NormalPlayerTask> list3 = this.LongTasks.ToList<NormalPlayerTask>();
		list3.Shuffle<NormalPlayerTask>();
		List<NormalPlayerTask> list4 = this.NormalTasks.ToList<NormalPlayerTask>();
		list4.Shuffle<NormalPlayerTask>();
		int num2 = 0;
		int num3 = 0;
		int count = gameOptions.NumShortTasks;
		if (gameOptions.NumCommonTasks + gameOptions.NumLongTasks + gameOptions.NumShortTasks == 0)
		{
			count = 1;
		}
		byte b = 0;
		while ((int)b < allPlayers.Count)
		{
			hashSet.Clear();
			list.RemoveRange(gameOptions.NumCommonTasks, list.Count - gameOptions.NumCommonTasks);
			this.AddTasksFromList(ref num2, gameOptions.NumLongTasks, list, hashSet, list3);
			this.AddTasksFromList(ref num3, count, list, hashSet, list4);
			GameData.PlayerInfo playerInfo = allPlayers[(int)b];
			if (playerInfo.Object && !playerInfo.Object.GetComponent<DummyBehaviour>().enabled)
			{
				byte[] taskTypeIds = list.ToArray();
				GameData.Instance.RpcSetTasks(playerInfo.PlayerId, taskTypeIds);
			}
			b += 1;
		}
		base.enabled = true;
	}

	private void AddTasksFromList(ref int start, int count, List<byte> tasks, HashSet<TaskTypes> usedTaskTypes, List<NormalPlayerTask> unusedTasks)
	{
		int num = 0;
		int num2 = 0;
		Func<NormalPlayerTask, bool> <>9__0;
		while (num2 < count && num++ != 1000)
		{
			if (start >= unusedTasks.Count)
			{
				start = 0;
				unusedTasks.Shuffle<NormalPlayerTask>();
				Func<NormalPlayerTask, bool> predicate;
				if ((predicate = <>9__0) == null)
				{
					predicate = (<>9__0 = ((NormalPlayerTask t) => usedTaskTypes.Contains(t.TaskType)));
				}
				if (unusedTasks.All(predicate))
				{
					Debug.Log("Not enough task types");
					usedTaskTypes.Clear();
				}
			}
			int num3 = start;
			start = num3 + 1;
			NormalPlayerTask normalPlayerTask = unusedTasks[num3];
			if (!usedTaskTypes.Add(normalPlayerTask.TaskType))
			{
				num2--;
			}
			else
			{
				tasks.Add((byte)normalPlayerTask.Index);
			}
			num2++;
		}
	}

	public void FixedUpdate()
	{
		if (!AmongUsClient.Instance)
		{
			return;
		}
		this.Timer += Time.fixedDeltaTime;
		this.EmergencyCooldown -= Time.fixedDeltaTime;
		if (GameData.Instance)
		{
			GameData.Instance.RecomputeTaskCounts();
		}
		if (AmongUsClient.Instance.AmHost) //c 只有host检查是否结束游戏,然后广播给其他玩家
		{
			this.CheckEndCriteria();
		}
		if (AmongUsClient.Instance.AmClient)
		{
			for (int i = 0; i < SystemTypeHelpers.AllTypes.Length; i++)
			{
				SystemTypes systemTypes = SystemTypeHelpers.AllTypes[i];
				ISystemType systemType;
				if (this.Systems.TryGetValue(systemTypes, out systemType) && systemType.Detoriorate(Time.fixedDeltaTime))
				{
					base.SetDirtyBit(1U << (int)systemTypes);
				}
			}
		}
	}

	private void GetAmbientSoundVolume(ShipRoom room, AudioSource player, float dt)
	{
		if (!PlayerControl.LocalPlayer)
		{
			player.volume = 0f;
			return;
		}
		Vector2 vector = room.transform.position;
		Vector2 truePosition = PlayerControl.LocalPlayer.GetTruePosition();
		float num = Vector2.Distance(vector, truePosition);
		if (num > 8f)
		{
			player.volume = 0f;
			return;
		}
		Vector2 direction = truePosition - vector;
		int num2 = Physics2D.RaycastNonAlloc(vector, direction, this.volumeBuffer, num, Constants.ShipOnlyMask);
		float num3 = 1f - num / 8f - (float)num2 * 0.25f;
		player.volume = Mathf.Lerp(player.volume, num3 * 0.7f, dt);
	}

	public float CalculateLightRadius(GameData.PlayerInfo player)
	{
		if (player.IsDead)
		{
			return this.MaxLightRadius;
		}
		SwitchSystem switchSystem = (SwitchSystem)this.Systems[SystemTypes.Electrical];
		if (player.IsImpostor)
		{
			return this.MaxLightRadius * PlayerControl.GameOptions.ImpostorLightMod;
		}
		float t = (float)switchSystem.Value / 255f;
		return Mathf.Lerp(this.MinLightRadius, this.MaxLightRadius, t) * PlayerControl.GameOptions.CrewLightMod;
	}

    //c 序列化所有物件的状态
	public override bool Serialize(MessageWriter writer, bool initialState)
	{
		if (initialState)
		{
			(this.Systems[SystemTypes.Doors] as DoorsSystemType).SetDoors(this.AllDoors);
			short num = 0;
			while ((int)num < SystemTypeHelpers.AllTypes.Length)
			{
				SystemTypes key = SystemTypeHelpers.AllTypes[(int)num];
				ISystemType systemType;
				if (this.Systems.TryGetValue(key, out systemType))
				{
					systemType.Serialize(writer, true);
				}
				num += 1;
			}
			return true;
		}
		if (this.DirtyBits != 0U)
		{
			writer.WritePacked(this.DirtyBits);
			short num2 = 0;
			while ((int)num2 < SystemTypeHelpers.AllTypes.Length)
			{
				SystemTypes systemTypes = SystemTypeHelpers.AllTypes[(int)num2];
				ISystemType systemType2;
				if (((ulong)this.DirtyBits & (ulong)(1L << (int)(systemTypes & (SystemTypes)31))) != 0UL && this.Systems.TryGetValue(systemTypes, out systemType2))
				{
					systemType2.Serialize(writer, false);
				}
				num2 += 1;
			}
			this.DirtyBits = 0U;
			return true;
		}
		return false;
	}

	public override void Deserialize(MessageReader reader, bool initialState)
	{
		if (initialState)
		{
			(this.Systems[SystemTypes.Doors] as DoorsSystemType).SetDoors(this.AllDoors);
			short num = 0;
			while ((int)num < SystemTypeHelpers.AllTypes.Length)
			{
				SystemTypes key = (SystemTypes)num;
				ISystemType systemType;
				if (this.Systems.TryGetValue(key, out systemType))
				{
					systemType.Deserialize(reader, true);
				}
				num += 1;
			}
			return;
		}
		uint num2 = reader.ReadPackedUInt32();
		short num3 = 0;
		while ((int)num3 < SystemTypeHelpers.AllTypes.Length)
		{
			SystemTypes systemTypes = SystemTypeHelpers.AllTypes[(int)num3];
			ISystemType systemType2;
			if (((ulong)num2 & (ulong)(1L << (int)(systemTypes & (SystemTypes)31))) != 0UL && this.Systems.TryGetValue(systemTypes, out systemType2))
			{
				systemType2.Deserialize(reader, false);
			}
			num3 += 1;
		}
	}

	private void CheckEndCriteria()
	{
		if (!GameData.Instance)
		{
			return;
		}
		LifeSuppSystemType lifeSuppSystemType = (LifeSuppSystemType)this.Systems[SystemTypes.LifeSupp];
		if (lifeSuppSystemType.Countdown < 0f)
		{
			this.EndGameForSabotage();
			lifeSuppSystemType.Countdown = 10000f;
		}
		ReactorSystemType reactorSystemType = (ReactorSystemType)this.Systems[SystemTypes.Reactor];
		if (reactorSystemType.Countdown < 0f)
		{
			this.EndGameForSabotage();
			reactorSystemType.Countdown = 10000f;
		}
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		for (int i = 0; i < GameData.Instance.PlayerCount; i++)
		{
			GameData.PlayerInfo playerInfo = GameData.Instance.AllPlayers[i];
			if (!playerInfo.Disconnected)
			{
				if (playerInfo.IsImpostor)
				{
					num3++;
				}
				if (!playerInfo.IsDead)
				{
					if (playerInfo.IsImpostor)
					{
						num2++;
					}
					else
					{
						num++;
					}
				}
			}
		}
		if (num2 <= 0 && (!DestroyableSingleton<TutorialManager>.InstanceExists || num3 > 0))
		{
			if (!DestroyableSingleton<TutorialManager>.InstanceExists)
			{
				base.enabled = false;
				ShipStatus.RpcEndGame((TempData.LastDeathReason == DeathReason.Disconnect) ? GameOverReason.ImpostorDisconnect : GameOverReason.HumansByVote, !SaveManager.BoughtNoAds);
				return;
			}
			DestroyableSingleton<HudManager>.Instance.ShowPopUp("Normally The Crew would have just won because The Impostor is dead. For free play, we revive everyone instead.");
			ShipStatus.ReviveEveryone();
			return;
		}
		else
		{
			if (num > num2)
			{
				if (!DestroyableSingleton<TutorialManager>.InstanceExists)
				{
					if (GameData.Instance.TotalTasks <= GameData.Instance.CompletedTasks)
					{
						base.enabled = false;
						ShipStatus.RpcEndGame(GameOverReason.HumansByTask, !SaveManager.BoughtNoAds);
						return;
					}
				}
				else if (PlayerControl.LocalPlayer.myTasks.All((PlayerTask t) => t.IsComplete))
				{
					DestroyableSingleton<HudManager>.Instance.ShowPopUp("Normally The Crew would have just won because the task bar is full. For free play, we issue new tasks instead.");
					this.Begin();
				}
				return;
			}
			if (!DestroyableSingleton<TutorialManager>.InstanceExists)
			{
				base.enabled = false;
				GameOverReason endReason;
				switch (TempData.LastDeathReason)
				{
				case DeathReason.Exile:
					endReason = GameOverReason.ImpostorByVote;
					break;
				case DeathReason.Kill:
					endReason = GameOverReason.ImpostorByKill;
					break;
				default:
					endReason = GameOverReason.HumansDisconnect;
					break;
				}
				ShipStatus.RpcEndGame(endReason, !SaveManager.BoughtNoAds);
				return;
			}
			DestroyableSingleton<HudManager>.Instance.ShowPopUp("Normally The Impostor would have just won because The Crew can no longer win. For free play, we revive everyone instead.");
			ShipStatus.ReviveEveryone();
			return;
		}
	}

	private void EndGameForSabotage()
	{
		if (!DestroyableSingleton<TutorialManager>.InstanceExists)
		{
			base.enabled = false;
			ShipStatus.RpcEndGame(GameOverReason.ImpostorBySabotage, !SaveManager.BoughtNoAds);
			return;
		}
		DestroyableSingleton<HudManager>.Instance.ShowPopUp("Normally The Impostor would have just won because of the critical sabotage. Instead we just shut it off.");
	}

	public bool IsGameOverDueToDeath()
	{
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		for (int i = 0; i < GameData.Instance.PlayerCount; i++)
		{
			GameData.PlayerInfo playerInfo = GameData.Instance.AllPlayers[i];
			if (!playerInfo.Disconnected)
			{
				if (playerInfo.IsImpostor)
				{
					num3++;
				}
				if (!playerInfo.IsDead)
				{
					if (playerInfo.IsImpostor)
					{
						num2++;
					}
					else
					{
						num++;
					}
				}
			}
		}
		return (num2 <= 0 && (!DestroyableSingleton<TutorialManager>.InstanceExists || num3 > 0)) || num <= num2;
	}

	private static void RpcEndGame(GameOverReason endReason, bool showAd)
	{
		MessageWriter messageWriter = AmongUsClient.Instance.StartEndGame();
		messageWriter.Write((byte)endReason);
		messageWriter.Write(showAd);
		AmongUsClient.Instance.FinishEndGame(messageWriter);
	}

	private static void ReviveEveryone()
	{
		for (int i = 0; i < GameData.Instance.PlayerCount; i++)
		{
			GameData.Instance.AllPlayers[i].Object.Revive();
		}
		UnityEngine.Object.FindObjectsOfType<DeadBody>().ForEach(delegate(DeadBody b)
		{
			UnityEngine.Object.Destroy(b.gameObject);
		});
	}

	public bool CheckTaskCompletion()
	{
		if (DestroyableSingleton<TutorialManager>.InstanceExists)
		{
			if (PlayerControl.LocalPlayer.myTasks.All((PlayerTask t) => t.IsComplete))
			{
				DestroyableSingleton<HudManager>.Instance.ShowPopUp("Normally The Crew would have just won because the task bar is full. For free play, we issue new tasks instead.");
				this.Begin();
			}
			return false;
		}
		GameData.Instance.RecomputeTaskCounts();
		if (GameData.Instance.TotalTasks <= GameData.Instance.CompletedTasks)
		{
			base.enabled = false;
			ShipStatus.RpcEndGame(GameOverReason.HumansByTask, !SaveManager.BoughtNoAds);
			return true;
		}
		return false;
	}

    // 关门
	public void RpcCloseDoorsOfType(SystemTypes type)
	{
		if (AmongUsClient.Instance.AmHost)
		{
			this.CloseDoorsOfType(type);
			return;
		}
		MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(this.NetId, 0, SendOption.Reliable, AmongUsClient.Instance.HostId);
		messageWriter.Write((byte)type);
		AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
	}

	public void RpcRepairSystem(SystemTypes systemType, int amount)
	{
		if (AmongUsClient.Instance.AmHost)
		{
			this.RepairSystem(systemType, PlayerControl.LocalPlayer, (byte)amount);
			return;
		}
		MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(this.NetId, 1, SendOption.Reliable, AmongUsClient.Instance.HostId);
		messageWriter.Write((byte)systemType);
		messageWriter.WriteNetObject(PlayerControl.LocalPlayer);
		messageWriter.Write((byte)amount);
		AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
	}

	public override void HandleRpc(byte callId, MessageReader reader)
	{
		if (callId == 0)
		{
			this.CloseDoorsOfType((SystemTypes)reader.ReadByte());
			return;
		}
		if (callId != 1)
		{
			return;
		}
		this.RepairSystem((SystemTypes)reader.ReadByte(), reader.ReadNetObject<PlayerControl>(), reader.ReadByte());
	}
}