using System; using UnityEngine; public class SwitchMinigame : Minigame { public Color OnColor = Color.green; public Color OffColor = new Color(0.1f, 0.3f, 0.1f); private ShipStatus ship; public SpriteRenderer[] switches; public SpriteRenderer[] lights; public RadioWaveBehaviour top; public HorizontalGauge middle; public FlatWaveBehaviour bottom; public override void Begin(PlayerTask task) { this.ship = UnityEngine.Object.FindObjectOfType(); SwitchSystem switchSystem = this.ship.Systems[SystemTypes.Electrical] as SwitchSystem; for (int i = 0; i < this.switches.Length; i++) { byte b = (byte)(1 << i); int num = (int)(switchSystem.ActualSwitches & b); this.lights[i].color = ((num == (int)(switchSystem.ExpectedSwitches & b)) ? this.OnColor : this.OffColor); this.switches[i].flipY = (num >> i == 0); } } public void FixedUpdate() { if (this.amClosing != Minigame.CloseState.None) { return; } int num = 0; SwitchSystem switchSystem = this.ship.Systems[SystemTypes.Electrical] as SwitchSystem; for (int i = 0; i < this.switches.Length; i++) { byte b = (byte)(1 << i); int num2 = (int)(switchSystem.ActualSwitches & b); if (num2 == (int)(switchSystem.ExpectedSwitches & b)) { num++; this.lights[i].color = this.OnColor; } else { this.lights[i].color = this.OffColor; } this.switches[i].flipY = (num2 >> i == 0); } float num3 = (float)num / (float)this.switches.Length; this.bottom.Center = 0.47f * num3; this.top.NoiseLevel = 1f - num3; this.middle.Value = switchSystem.Level + (Mathf.PerlinNoise(0f, Time.time * 51f) - 0.5f) * 0.04f; if (num == this.switches.Length) { base.StartCoroutine(base.CoStartClose(0.5f)); } } public void FlipSwitch(int switchIdx) { if (this.amClosing != Minigame.CloseState.None) { return; } int num = 0; SwitchSystem switchSystem = this.ship.Systems[SystemTypes.Electrical] as SwitchSystem; for (int i = 0; i < this.switches.Length; i++) { byte b = (byte)(1 << i); if ((switchSystem.ActualSwitches & b) == (switchSystem.ExpectedSwitches & b)) { num++; } } if (num == this.switches.Length) { return; } ShipStatus.Instance.RpcRepairSystem(SystemTypes.Electrical, (int)((byte)switchIdx)); try { ((SabotageTask)this.MyTask).MarkContributed(); } catch { } } }