Skip to content

Commit

Permalink
Door idea thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
SebasCapo committed Sep 29, 2020
1 parent a8f2da9 commit cbe708e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions LightsPlugin/LightsPlugin/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ namespace Lights {

public class EventHandlers {
public CoroutineHandle automaticHandler, lightsBack;
Dictionary<Door, bool> doorsToRestore;
public Plugin plugin;
Door[] doorsToChange;
bool TeslasDisabled;
public int count;
LightsConfig Config;
Door[] doorsToChange;
Dictionary<Door, bool> doorsToRestore;
public int count;

public EventHandlers( Plugin plugin ) {
this.plugin = plugin;
Config = plugin.Config;

doorsToRestore = new Dictionary<Door, bool>();
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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<Door, bool> pair in doorsToRestore)
pair.Key.SetState(pair.Value);
}
Expand Down
2 changes: 1 addition & 1 deletion LightsPlugin/LightsPlugin/LightsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Door.DoorTypes> OpenableDoors { get; set; } = new List<Door.DoorTypes> {
Door.DoorTypes.Checkpoint, Door.DoorTypes.HeavyGate, Door.DoorTypes.Standard
};
Expand Down

0 comments on commit cbe708e

Please sign in to comment.