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 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> UserConsolePairs = new HashSet>(); public bool GetConsoleComplete(int consoleId) { return this.UserConsolePairs.Any((Tuple 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(player.PlayerId, (byte)num)); if (this.UserCount >= 2) { this.Countdown = 10000f; return; } } else if (opCode.HasAnyBit(32)) { this.UserConsolePairs.Remove(new Tuple(player.PlayerId, (byte)num)); } } public bool Detoriorate(float deltaTime) { if (this.IsActive) { if (DestroyableSingleton.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.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 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(reader.ReadByte(), reader.ReadByte())); } } }