diff --git a/LightsPlugin/LightsPlugin/EventHandlers.cs b/LightsPlugin/LightsPlugin/EventHandlers.cs index 557d060..b537ffe 100644 --- a/LightsPlugin/LightsPlugin/EventHandlers.cs +++ b/LightsPlugin/LightsPlugin/EventHandlers.cs @@ -9,20 +9,29 @@ namespace Lights { public class EventHandlers { - public CoroutineHandle automaticHandler, teslaDisabler; + public CoroutineHandle automaticHandler, lightsBack; public Plugin plugin; bool TeslasDisabled; public int count; LightsConfig Config; + Door[] doorsToChange; + Dictionary doorsToRestore; public EventHandlers( Plugin plugin ) { this.plugin = plugin; Config = plugin.Config; + doorsToRestore = new Dictionary(); } public void OnRoundStart() { TeslasDisabled = false; + if(plugin.Config.ModifyDoors) { + doorsToChange = Map.Doors.Where(d => + plugin.Config.OpenableDoors.Contains(d.doorType) + && !plugin.Config.BlacklistedDoors.Any(d.DoorName.Contains)).ToArray(); + } + if(Config.DoAutomaticBlackout) { if(Config.doMultipleBlackouts) automaticHandler = Timing.RunCoroutine(MultipleBlackouts()); @@ -32,7 +41,7 @@ public void OnRoundStart() { public void OnRoundEnd(RoundEndedEventArgs ev) { Timing.KillCoroutines(automaticHandler); - Timing.KillCoroutines(teslaDisabler); + Timing.KillCoroutines(lightsBack); } public void OnDetonate() => Timing.KillCoroutines(automaticHandler); @@ -97,11 +106,32 @@ public IEnumerator SingleBlackout() { public void TurnOffLights(float duration, bool HczOnly) { if(plugin.Config.DisableTeslas) { - Timing.KillCoroutines(teslaDisabler); + Timing.KillCoroutines(lightsBack); TeslasDisabled = true; - teslaDisabler = Timing.CallDelayed(duration, () => TeslasDisabled = false); + if(plugin.Config.ModifyDoors) { + if(!doorsToRestore.IsEmpty()) + doorsToRestore.Clear(); + + foreach(Door d in doorsToChange) { + if(!Warhead.IsInProgress && !d.Networkdestroyed && !d.Networklocked) { + if(plugin.Config.RestoreDoors) + doorsToRestore.Add(d, d.NetworkisOpen); + d.SetState(!d.NetworkisOpen); + } + } + } + + lightsBack = Timing.CallDelayed(duration, () => { + TeslasDisabled = false; + + if(plugin.Config.ModifyDoors && plugin.Config.RestoreDoors) { + foreach(KeyValuePair pair in doorsToRestore) + pair.Key.SetState(pair.Value); + } + }); + } if(Config.DoBroadcastMessage) { diff --git a/LightsPlugin/LightsPlugin/Lights.csproj b/LightsPlugin/LightsPlugin/Lights.csproj index 74ec422..5b2a87d 100644 --- a/LightsPlugin/LightsPlugin/Lights.csproj +++ b/LightsPlugin/LightsPlugin/Lights.csproj @@ -62,6 +62,9 @@ ..\packages\EXILED.2.1.6\lib\net472\Exiled.Updater.dll + + ..\..\..\..\..\..\Desktop\2020\Servidores\SCP\SCPSL_Data\Managed\Mirror.dll + diff --git a/LightsPlugin/LightsPlugin/LightsConfig.cs b/LightsPlugin/LightsPlugin/LightsConfig.cs index 8d1c5c1..35c45a1 100644 --- a/LightsPlugin/LightsPlugin/LightsConfig.cs +++ b/LightsPlugin/LightsPlugin/LightsConfig.cs @@ -27,6 +27,19 @@ public class LightsConfig : IConfig { [Description("Should teslas be disabled during a blackout.")] public bool DisableTeslas { get; set; } = true; + [Description("Should doors be open/closed when a blackout starts?")] + 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)")] + public List OpenableDoors { get; set; } = new List { + Door.DoorTypes.Checkpoint, Door.DoorTypes.HeavyGate, Door.DoorTypes.Standard + }; + [Description("Doors that have the following strings in their name will be ignored. (This and the previous configs will be ignored if 'OpenDoors' is set to 'false')")] + public List BlacklistedDoors { get; set; } = new List { + "106", "173" + }; + [Description("How many seconds should this wait before shutting off the lights for the first time.")] public float startTimerMin { get; set; } = 30f; public float startTimerMax { get; set; } = 45f;