Skip to content

Commit

Permalink
Bugfixes for tesla gates and nuke
Browse files Browse the repository at this point in the history
  • Loading branch information
ThijsNameIsTaken committed Jan 5, 2023
1 parent 634403e commit 25f3540
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions LightsOut/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using Exiled.API.Enums;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Player;
using Exiled.Events.EventArgs.Warhead;
using Server = Exiled.Events.Handlers.Server;
using Player = Exiled.Events.Handlers.Player;
using Warhead = Exiled.Events.Handlers.Warhead;
using MEC;

namespace LightsOut
Expand All @@ -15,12 +17,14 @@ public class Main : Plugin<Config>

public override string Name { get; } = "LightsOut";
public override string Author { get; } = "ThijsNameIsTaken";
public override Version Version { get; } = new Version(1, 0, 1);
public override Version Version { get; } = new Version(1, 0, 2);
public override Version RequiredExiledVersion { get; } = new Version(6, 0, 0);

private static readonly Main Singleton = new();

public bool eventActive = false;
private bool eventActive;
private bool warheadActive;


private Main()
{
Expand All @@ -35,6 +39,8 @@ public override void OnEnabled()
Server.RestartingRound += OnRestartingRound;
Server.RoundStarted += OnStartingRound;
Player.TriggeringTesla += OnTriggeringTesla;
Warhead.Starting += OnWarheadStarting;
Warhead.Stopping += OnWarheadStopping;

base.OnEnabled();
}
Expand All @@ -44,28 +50,43 @@ public override void OnDisabled()
Server.RestartingRound -= OnRestartingRound;
Server.RoundStarted -= OnStartingRound;
Player.TriggeringTesla -= OnTriggeringTesla;
Warhead.Starting -= OnWarheadStarting;
Warhead.Stopping -= OnWarheadStopping;

base.OnDisabled();
}

private CoroutineHandle _coroutine;
private void OnWarheadStarting(StartingEventArgs ev)
{
warheadActive = true;
}

private void OnWarheadStopping(StoppingEventArgs ev)
{
warheadActive = false;
}

private CoroutineHandle LightsCoroutine;

private void OnRestartingRound()
{
if (_coroutine.IsRunning) Timing.KillCoroutines(_coroutine);
if (LightsCoroutine.IsRunning) Timing.KillCoroutines(LightsCoroutine);
}

private void OnStartingRound()
{
bool activeTrigger = UnityEngine.Random.Range(0, 100) < Config.ActivationChance;
Log.Debug($"LightsOut event active this round: {activeTrigger}");
if (activeTrigger == true) _coroutine = Timing.RunCoroutine(Lights());
if (activeTrigger == true) LightsCoroutine = Timing.RunCoroutine(Lights());
}

private void OnTriggeringTesla(TriggeringTeslaEventArgs ev)
{
if (eventActive == false) return;
if (Config.KeepTeslaEnabled == true) return;
if (Config.KeepTeslaEnabled || eventActive == false)
{
ev.IsAllowed = true;
return;
}
ev.IsInIdleRange = false;
ev.IsAllowed = false;
}
Expand All @@ -82,7 +103,7 @@ private IEnumerator<float> Lights()
int activeTime = UnityEngine.Random.Range(Config.MinRandomBlackoutTime, Config.MaxRandomBlackoutTime);
float waitTime = Cassie.CalculateDuration(Config.CassieMessage, true);

switch (Warhead.IsInProgress)
switch (warheadActive)
{
case true:
Log.Debug($"Event skipped due to warhead sequence");
Expand All @@ -97,7 +118,7 @@ private IEnumerator<float> Lights()
Cassie.Message(Config.CassieMessage, false, Config.CassieSoundAlarm, true);
}

if (Config.CassieWaitForToggle == true)
if (Config.CassieWaitForToggle)
{
while (Cassie.IsSpeaking)
{
Expand Down

0 comments on commit 25f3540

Please sign in to comment.