Skip to content

Commit

Permalink
Doors idea thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
SebasCapo committed Sep 29, 2020
1 parent 958b98c commit a8f2da9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
38 changes: 34 additions & 4 deletions LightsPlugin/LightsPlugin/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Door, bool> doorsToRestore;

public EventHandlers( Plugin plugin ) {
this.plugin = plugin;
Config = plugin.Config;
doorsToRestore = new Dictionary<Door, bool>();
}

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());
Expand All @@ -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);
Expand Down Expand Up @@ -97,11 +106,32 @@ public IEnumerator<float> 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<Door, bool> pair in doorsToRestore)
pair.Key.SetState(pair.Value);
}
});

}

if(Config.DoBroadcastMessage) {
Expand Down
3 changes: 3 additions & 0 deletions LightsPlugin/LightsPlugin/Lights.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<Reference Include="Exiled.Updater, Version=3.0.2.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\EXILED.2.1.6\lib\net472\Exiled.Updater.dll</HintPath>
</Reference>
<Reference Include="Mirror">
<HintPath>..\..\..\..\..\..\Desktop\2020\Servidores\SCP\SCPSL_Data\Managed\Mirror.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
Expand Down
13 changes: 13 additions & 0 deletions LightsPlugin/LightsPlugin/LightsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Door.DoorTypes> OpenableDoors { get; set; } = new List<Door.DoorTypes> {
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<string> BlacklistedDoors { get; set; } = new List<string> {
"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;
Expand Down

0 comments on commit a8f2da9

Please sign in to comment.