summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/Vent.cs
blob: ce9c525762d566723afe6aa4c75ec3b6ef07d748 (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
using System;
using PowerTools;
using UnityEngine;

public class Vent : MonoBehaviour, IUsable
{
	public float UsableDistance
	{
		get
		{
			return 0.75f;
		}
	}

	public float PercentCool
	{
		get
		{
			return 0f;
		}
	}

	public int Id;

	public Vent Left;

	public Vent Right;

	public ButtonBehavior[] Buttons;

	public AnimationClip EnterVentAnim;

	public AnimationClip ExitVentAnim;

	private static readonly Vector3 CollOffset = new Vector3(0f, -0.3636057f, 0f);

	private SpriteRenderer myRend;

	private void Start()
	{
		this.SetButtons(false);
		this.myRend = base.GetComponent<SpriteRenderer>();
	}

	public void SetButtons(bool enabled)
	{
		Vent[] array = new Vent[]
		{
			this.Right,
			this.Left
		};
		for (int i = 0; i < this.Buttons.Length; i++)
		{
			ButtonBehavior buttonBehavior = this.Buttons[i];
			if (enabled)
			{
				Vent vent = array[i];
				if (vent)
				{
					buttonBehavior.gameObject.SetActive(true);
					Vector3 localPosition = (vent.transform.position - base.transform.position).normalized * 0.7f;
					localPosition.y -= 0.08f;
					localPosition.z = -10f;
					buttonBehavior.transform.localPosition = localPosition;
					buttonBehavior.transform.LookAt2d(vent.transform);
				}
				else
				{
					buttonBehavior.gameObject.SetActive(false);
				}
			}
			else
			{
				buttonBehavior.gameObject.SetActive(false);
			}
		}
	}

	public float CanUse(GameData.PlayerInfo pc, out bool canUse, out bool couldUse)
	{
		float num = float.MaxValue;
		PlayerControl @object = pc.Object;
		couldUse = (pc.IsImpostor && !pc.IsDead && (@object.CanMove || @object.inVent));
		canUse = couldUse;
		if (canUse)
		{
			num = Vector2.Distance(@object.GetTruePosition(), base.transform.position);
			canUse &= (num <= this.UsableDistance);
		}
		return num;
	}

	public void SetOutline(bool on, bool mainTarget)
	{
		this.myRend.material.SetFloat("_Outline", (float)(on ? 1 : 0));
		this.myRend.material.SetColor("_OutlineColor", Color.red);
		this.myRend.material.SetColor("_AddColor", mainTarget ? Color.red : Color.clear);
	}

	public void ClickRight()
	{
		if (this.Right)
		{
			Vent.DoMove(this.Right.transform.position - Vent.CollOffset);
			this.SetButtons(false);
			this.Right.SetButtons(true);
		}
	}

	public void ClickLeft()
	{
		if (this.Left)
		{
			Vent.DoMove(this.Left.transform.position - Vent.CollOffset);
			this.SetButtons(false);
			this.Left.SetButtons(true);
		}
	}

	private static void DoMove(Vector3 pos)
	{
		PlayerControl.LocalPlayer.NetTransform.RpcSnapTo(pos);
		if (Constants.ShouldPlaySfx())
		{
			SoundManager.Instance.PlaySound(PlayerControl.LocalPlayer.VentMoveSounds.Random<AudioClip>(), false, 1f).pitch = FloatRange.Next(0.8f, 1.2f);
		}
	}

	public void Use()
	{
		bool flag;
		bool flag2;
		this.CanUse(PlayerControl.LocalPlayer.Data, out flag, out flag2);
		if (!flag)
		{
			return;
		}
		PlayerControl localPlayer = PlayerControl.LocalPlayer;
		if (Constants.ShouldPlaySfx())
		{
			SoundManager.Instance.StopSound(localPlayer.VentEnterSound);
			SoundManager.Instance.PlaySound(localPlayer.VentEnterSound, false, 1f).pitch = FloatRange.Next(0.8f, 1.2f);
		}
		if (localPlayer.inVent)
		{
			localPlayer.MyPhysics.RpcExitVent(this.Id);
			this.SetButtons(false);
			return;
		}
		localPlayer.MyPhysics.RpcEnterVent(this.Id);
		this.SetButtons(true);
	}

	internal void EnterVent()
	{
		base.GetComponent<SpriteAnim>().Play(this.EnterVentAnim, 1f);
	}

	internal void ExitVent()
	{
		base.GetComponent<SpriteAnim>().Play(this.ExitVentAnim, 1f);
	}
}