summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/MapCountOverlay.cs
blob: 571b67618f883cd93ec3f9c8bfbce11af77144a5 (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
using System;
using System.Linq;
using UnityEngine;

public class MapCountOverlay : MonoBehaviour
{
	public AlphaPulse BackgroundColor;

	public TextRenderer SabotageText;

	public CounterArea[] CountAreas;

	private Collider2D[] buffer = new Collider2D[20];

	private ContactFilter2D filter;

	private float timer;

	private bool isSab;

	public void Awake()
	{
		this.filter.useLayerMask = true;
		this.filter.layerMask = Constants.PlayersOnlyMask;
		this.filter.useTriggers = true;
	}

	public void OnEnable()
	{
		this.BackgroundColor.SetColor(PlayerTask.PlayerHasHudTask(PlayerControl.LocalPlayer) ? Palette.DisabledGrey : Color.green);
		this.timer = 1f;
	}

	public void OnDisable()
	{
		for (int i = 0; i < this.CountAreas.Length; i++)
		{
			this.CountAreas[i].UpdateCount(0);
		}
	}

	public void Update()
	{
		this.timer += Time.deltaTime;
		if (this.timer < 0.1f)
		{
			return;
		}
		this.timer = 0f;
		if (!this.isSab && PlayerTask.PlayerHasHudTask(PlayerControl.LocalPlayer))
		{
			this.isSab = true;
			this.BackgroundColor.SetColor(Palette.DisabledGrey);
			this.SabotageText.gameObject.SetActive(true);
			return;
		}
		if (this.isSab && !PlayerTask.PlayerHasHudTask(PlayerControl.LocalPlayer))
		{
			this.isSab = false;
			this.BackgroundColor.SetColor(Color.green);
			this.SabotageText.gameObject.SetActive(false);
		}
		for (int i = 0; i < this.CountAreas.Length; i++)
		{
			CounterArea area = this.CountAreas[i];
			if (!PlayerTask.PlayerHasHudTask(PlayerControl.LocalPlayer))
			{
				int num = ShipStatus.Instance.AllRooms.First((ShipRoom r) => r.RoomId == area.RoomType).roomArea.OverlapCollider(this.filter, this.buffer);
				int num2 = num;
				for (int j = 0; j < num; j++)
				{
					Collider2D collider2D = this.buffer[j];
					if (!(collider2D.tag == "DeadBody"))
					{
						PlayerControl component = collider2D.GetComponent<PlayerControl>();
						if (!component || component.Data == null || component.Data.Disconnected || component.Data.IsDead)
						{
							num2--;
						}
					}
				}
				area.UpdateCount(num2);
			}
			else
			{
				area.UpdateCount(0);
			}
		}
	}
}