diff options
Diffstat (limited to 'Client/Assembly-CSharp/DeconSystem.cs')
-rw-r--r-- | Client/Assembly-CSharp/DeconSystem.cs | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/DeconSystem.cs b/Client/Assembly-CSharp/DeconSystem.cs new file mode 100644 index 0000000..0eb0b9d --- /dev/null +++ b/Client/Assembly-CSharp/DeconSystem.cs @@ -0,0 +1,163 @@ +using System; +using Hazel; +using UnityEngine; + +public class DeconSystem : MonoBehaviour, ISystemType +{ + private const byte HeadUpCmd = 1; + + private const byte HeadDownCmd = 2; + + private const byte HeadUpInsideCmd = 3; + + private const byte HeadDownInsideCmd = 4; + + public ManualDoor UpperDoor; + + public ManualDoor LowerDoor; + + public float DoorOpenTime = 5f; + + public float DeconTime = 5f; + + private DeconSystem.States curState; + + private float timer; + + public TextRenderer FloorText; + + [Flags] + private enum States : byte + { + Idle = 0, + Enter = 1, + Closed = 2, + Exit = 4, + HeadingUp = 8 + } + + public bool Detoriorate(float dt) + { + int num = Mathf.CeilToInt(this.timer); + this.timer = Mathf.Max(0f, this.timer - dt); + int num2 = Mathf.CeilToInt(this.timer); + if (num != num2) + { + if (num2 == 0) + { + if (this.curState.HasFlag(DeconSystem.States.Enter)) + { + this.curState = ((this.curState & ~DeconSystem.States.Enter) | DeconSystem.States.Closed); + this.timer = this.DeconTime; + } + else if (this.curState.HasFlag(DeconSystem.States.Closed)) + { + this.curState = ((this.curState & ~DeconSystem.States.Closed) | DeconSystem.States.Exit); + this.timer = this.DoorOpenTime; + } + else if (this.curState.HasFlag(DeconSystem.States.Exit)) + { + this.curState = DeconSystem.States.Idle; + } + } + this.UpdateDoorsViaState(); + return true; + } + return false; + } + + public void OpenDoor(bool upper) + { + if (this.curState == DeconSystem.States.Idle) + { + ShipStatus.Instance.RpcRepairSystem(SystemTypes.Decontamination, upper ? 2 : 1); + } + } + + public void OpenFromInside(bool upper) + { + if (this.curState == DeconSystem.States.Idle) + { + ShipStatus.Instance.RpcRepairSystem(SystemTypes.Decontamination, upper ? 3 : 4); + } + } + + public void RepairDamage(PlayerControl player, byte amount) + { + if (this.curState != DeconSystem.States.Idle) + { + return; + } + switch (amount) + { + case 1: + this.curState = (DeconSystem.States.Enter | DeconSystem.States.HeadingUp); + this.timer = this.DoorOpenTime; + break; + case 2: + this.curState = DeconSystem.States.Enter; + this.timer = this.DoorOpenTime; + break; + case 3: + this.curState = (DeconSystem.States.Exit | DeconSystem.States.HeadingUp); + this.timer = this.DoorOpenTime; + break; + case 4: + this.curState = DeconSystem.States.Exit; + this.timer = this.DoorOpenTime; + break; + } + this.UpdateDoorsViaState(); + } + + public void Serialize(MessageWriter writer, bool initialState) + { + writer.Write((byte)Mathf.CeilToInt(this.timer)); + writer.Write((byte)this.curState); + } + + public void Deserialize(MessageReader reader, bool initialState) + { + this.timer = (float)reader.ReadByte(); + this.curState = (DeconSystem.States)reader.ReadByte(); + this.UpdateDoorsViaState(); + } + + private void UpdateDoorsViaState() + { + int num = Mathf.CeilToInt(this.timer); + if (num > 0) + { + this.FloorText.Text = string.Join("\n", new object[] + { + num, + num, + num, + num + }); + } + else + { + this.FloorText.Text = string.Empty; + } + if (this.curState.HasFlag(DeconSystem.States.Enter)) + { + bool flag = this.curState.HasFlag(DeconSystem.States.HeadingUp); + this.LowerDoor.SetDoorway(flag); + this.UpperDoor.SetDoorway(!flag); + return; + } + if (this.curState.HasFlag(DeconSystem.States.Closed) || this.curState == DeconSystem.States.Idle) + { + this.LowerDoor.SetDoorway(false); + this.UpperDoor.SetDoorway(false); + return; + } + if (this.curState.HasFlag(DeconSystem.States.Exit)) + { + bool flag2 = this.curState.HasFlag(DeconSystem.States.HeadingUp); + this.LowerDoor.SetDoorway(!flag2); + this.UpperDoor.SetDoorway(flag2); + } + } +} |