summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/RoomTracker.cs
blob: 3c24ed62fa150ba1fa3773e67a784380f0b1268d (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
using System;
using System.Collections;
using UnityEngine;

public class RoomTracker : MonoBehaviour
{
	public TextRenderer text;

	public float SourceY = -2.5f;

	public float TargetY = -3.25f;

	private Collider2D playerCollider;

	private ContactFilter2D filter;

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

	public ShipRoom LastRoom;

	private Coroutine slideInRoutine;

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

	public void OnDisable()
	{
		this.LastRoom = null;
		Vector3 localPosition = this.text.transform.localPosition;
		localPosition.y = this.TargetY;
		this.text.transform.localPosition = localPosition;
	}

	public void FixedUpdate()
	{
		ShipRoom[] array = null;
		if (LobbyBehaviour.Instance)
		{
			array = LobbyBehaviour.Instance.AllRooms;
		}
		if (ShipStatus.Instance)
		{
			array = ShipStatus.Instance.AllRooms;
		}
		if (array == null)
		{
			return;
		}
		ShipRoom shipRoom = null;
		if (this.LastRoom)
		{
			int hitCount = this.LastRoom.roomArea.OverlapCollider(this.filter, this.buffer);
			if (RoomTracker.CheckHitsForPlayer(this.buffer, hitCount))
			{
				shipRoom = this.LastRoom;
			}
		}
		if (!shipRoom)
		{
			foreach (ShipRoom shipRoom2 in array)
			{
				if (shipRoom2.roomArea)
				{
					int hitCount2 = shipRoom2.roomArea.OverlapCollider(this.filter, this.buffer);
					if (RoomTracker.CheckHitsForPlayer(this.buffer, hitCount2))
					{
						shipRoom = shipRoom2;
					}
				}
			}
		}
		if (shipRoom)
		{
			if (this.LastRoom != shipRoom)
			{
				this.LastRoom = shipRoom;
				if (this.slideInRoutine != null)
				{
					base.StopCoroutine(this.slideInRoutine);
				}
				if (shipRoom.RoomId != SystemTypes.Hallway)
				{
					this.slideInRoutine = base.StartCoroutine(this.CoSlideIn(shipRoom.RoomId));
					return;
				}
				this.slideInRoutine = base.StartCoroutine(this.SlideOut());
				return;
			}
		}
		else if (this.LastRoom)
		{
			this.LastRoom = null;
			if (this.slideInRoutine != null)
			{
				base.StopCoroutine(this.slideInRoutine);
			}
			this.slideInRoutine = base.StartCoroutine(this.SlideOut());
		}
	}

	private IEnumerator CoSlideIn(SystemTypes newRoom)
	{
		yield return this.SlideOut();
		Vector3 tempPos = this.text.transform.localPosition;
		Color tempColor = Color.white;
		this.text.Text = DestroyableSingleton<TranslationController>.Instance.GetString(newRoom);
		float timer = 0f;
		while (timer < 0.25f)
		{
			timer = Mathf.Min(0.25f, timer + Time.deltaTime);
			float t = timer / 0.25f;
			tempPos.y = Mathf.SmoothStep(this.TargetY, this.SourceY, t);
			tempColor.a = Mathf.Lerp(0f, 1f, t);
			this.text.transform.localPosition = tempPos;
			this.text.Color = tempColor;
			yield return null;
		}
		yield break;
	}

	private IEnumerator SlideOut()
	{
		Vector3 tempPos = this.text.transform.localPosition;
		Color tempColor = Color.white;
		float timer = FloatRange.ReverseLerp(tempPos.y, this.SourceY, this.TargetY) * 0.1f;
		while (timer < 0.1f)
		{
			timer = Mathf.Min(0.1f, timer + Time.deltaTime);
			float t = timer / 0.1f;
			tempPos.y = Mathf.SmoothStep(this.SourceY, this.TargetY, t);
			tempColor.a = Mathf.Lerp(1f, 0f, t);
			this.text.transform.localPosition = tempPos;
			this.text.Color = tempColor;
			yield return null;
		}
		yield break;
	}

	private static bool CheckHitsForPlayer(Collider2D[] buffer, int hitCount)
	{
		if (!PlayerControl.LocalPlayer)
		{
			return false;
		}
		for (int i = 0; i < hitCount; i++)
		{
			if (buffer[i].gameObject == PlayerControl.LocalPlayer.gameObject)
			{
				return true;
			}
		}
		return false;
	}
}