From cbe708e7589e91ddce969402c216c4a952b6d18e Mon Sep 17 00:00:00 2001 From: SebasCapo Date: Tue, 29 Sep 2020 11:57:30 -0300 Subject: [PATCH] Door idea thingy --- LightsPlugin/LightsPlugin/EventHandlers.cs | 17 +++++++++-------- LightsPlugin/LightsPlugin/LightsConfig.cs | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/LightsPlugin/LightsPlugin/EventHandlers.cs b/LightsPlugin/LightsPlugin/EventHandlers.cs index b537ffe..6ce3d66 100644 --- a/LightsPlugin/LightsPlugin/EventHandlers.cs +++ b/LightsPlugin/LightsPlugin/EventHandlers.cs @@ -10,16 +10,17 @@ namespace Lights { public class EventHandlers { public CoroutineHandle automaticHandler, lightsBack; + Dictionary doorsToRestore; public Plugin plugin; + Door[] doorsToChange; bool TeslasDisabled; - public int count; LightsConfig Config; - Door[] doorsToChange; - Dictionary doorsToRestore; + public int count; public EventHandlers( Plugin plugin ) { this.plugin = plugin; Config = plugin.Config; + doorsToRestore = new Dictionary(); } @@ -28,8 +29,8 @@ public void OnRoundStart() { if(plugin.Config.ModifyDoors) { doorsToChange = Map.Doors.Where(d => - plugin.Config.OpenableDoors.Contains(d.doorType) - && !plugin.Config.BlacklistedDoors.Any(d.DoorName.Contains)).ToArray(); + Config.OpenableDoors.Contains(d.doorType) + && !Config.BlacklistedDoors.Any(d.DoorName.Contains)).ToArray(); } if(Config.DoAutomaticBlackout) { @@ -110,13 +111,13 @@ public void TurnOffLights(float duration, bool HczOnly) { TeslasDisabled = true; - if(plugin.Config.ModifyDoors) { + if(Config.ModifyDoors) { if(!doorsToRestore.IsEmpty()) doorsToRestore.Clear(); foreach(Door d in doorsToChange) { if(!Warhead.IsInProgress && !d.Networkdestroyed && !d.Networklocked) { - if(plugin.Config.RestoreDoors) + if(Config.RestoreDoors) doorsToRestore.Add(d, d.NetworkisOpen); d.SetState(!d.NetworkisOpen); } @@ -126,7 +127,7 @@ public void TurnOffLights(float duration, bool HczOnly) { lightsBack = Timing.CallDelayed(duration, () => { TeslasDisabled = false; - if(plugin.Config.ModifyDoors && plugin.Config.RestoreDoors) { + if(Config.ModifyDoors && Config.RestoreDoors) { foreach(KeyValuePair pair in doorsToRestore) pair.Key.SetState(pair.Value); } diff --git a/LightsPlugin/LightsPlugin/LightsConfig.cs b/LightsPlugin/LightsPlugin/LightsConfig.cs index 35c45a1..21ae8b6 100644 --- a/LightsPlugin/LightsPlugin/LightsConfig.cs +++ b/LightsPlugin/LightsPlugin/LightsConfig.cs @@ -31,7 +31,7 @@ public class LightsConfig : IConfig { public bool ModifyDoors { get; set; } = false; [Description("Should the doors go back to their original state when lights come back? (This may cause issues to your server performance, clients won't be affected by this)")] public bool RestoreDoors { get; set; } = true; - [Description("Types of Door that can be open during blackout. (Types: Standard, HeavyGate & Checkpoint)")] + [Description("Types of Door that can be open by the blackout. (Types: Standard, HeavyGate & Checkpoint)")] public List OpenableDoors { get; set; } = new List { Door.DoorTypes.Checkpoint, Door.DoorTypes.HeavyGate, Door.DoorTypes.Standard };