summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/ReactorSystemType.cs
blob: a1e1fa0b005074f31d6f31b321b10cd41d6fe00e (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
using System;
using System.Collections.Generic;
using System.Linq;
using Hazel;

public class ReactorSystemType : ISystemType, IActivatable
{
	public int UserCount
	{
		get
		{
			int num = 0;
			int num2 = 0;
			foreach (Tuple<byte, byte> tuple in this.UserConsolePairs)
			{
				int num3 = 1 << (int)tuple.Item2;
				if ((num3 & num2) == 0)
				{
					num++;
					num2 |= num3;
				}
			}
			return num;
		}
	}

	public bool IsActive
	{
		get
		{
			return this.Countdown < 10000f;
		}
	}

	private const float SyncRate = 2f;

	private float timer;

	public const byte StartCountdown = 128;

	public const byte AddUserOp = 64;

	public const byte RemoveUserOp = 32;

	public const byte ClearCountdown = 16;

	public const float CountdownStopped = 10000f;

	public const float ReactorDuration = 30f;

	public const byte ConsoleIdMask = 3;

	public const byte RequiredUserCount = 2;

	public float Countdown = 10000f;

	private HashSet<Tuple<byte, byte>> UserConsolePairs = new HashSet<Tuple<byte, byte>>();

	public bool GetConsoleComplete(int consoleId)
	{
		return this.UserConsolePairs.Any((Tuple<byte, byte> kvp) => (int)kvp.Item2 == consoleId);
	}

	public void RepairDamage(PlayerControl player, byte opCode)
	{
		int num = (int)(opCode & 3);
		if (opCode == 128 && !this.IsActive)
		{
			this.Countdown = 30f;
			this.UserConsolePairs.Clear();
			return;
		}
		if (opCode == 16)
		{
			this.Countdown = 10000f;
			return;
		}
		if (opCode.HasAnyBit(64))
		{
			this.UserConsolePairs.Add(new Tuple<byte, byte>(player.PlayerId, (byte)num));
			if (this.UserCount >= 2)
			{
				this.Countdown = 10000f;
				return;
			}
		}
		else if (opCode.HasAnyBit(32))
		{
			this.UserConsolePairs.Remove(new Tuple<byte, byte>(player.PlayerId, (byte)num));
		}
	}

	public bool Detoriorate(float deltaTime)
	{
		if (this.IsActive)
		{
			if (DestroyableSingleton<HudManager>.Instance.ReactorFlash == null)
			{
				PlayerControl.LocalPlayer.AddSystemTask(SystemTypes.Reactor);
			}
			this.Countdown -= deltaTime;
			this.timer += deltaTime;
			if (this.timer > 2f)
			{
				this.timer = 0f;
				return true;
			}
		}
		else if (DestroyableSingleton<HudManager>.Instance.ReactorFlash != null)
		{
			((ReactorShipRoom)ShipStatus.Instance.AllRooms.First((ShipRoom r) => r.RoomId == SystemTypes.Reactor)).StopMeltdown();
		}
		return false;
	}

	public void Serialize(MessageWriter writer, bool initialState)
	{
		writer.Write(this.Countdown);
		writer.WritePacked(this.UserConsolePairs.Count);
		foreach (Tuple<byte, byte> tuple in this.UserConsolePairs)
		{
			writer.Write(tuple.Item1);
			writer.Write(tuple.Item2);
		}
	}

	public void Deserialize(MessageReader reader, bool initialState)
	{
		this.Countdown = reader.ReadSingle();
		this.UserConsolePairs.Clear();
		int num = reader.ReadPackedInt32();
		for (int i = 0; i < num; i++)
		{
			this.UserConsolePairs.Add(new Tuple<byte, byte>(reader.ReadByte(), reader.ReadByte()));
		}
	}
}