From f5dab6d2f2da227ea0e6e944b1a4690f212a1fd6 Mon Sep 17 00:00:00 2001 From: Ten <32621403+TenDRILLL@users.noreply.github.com> Date: Thu, 20 Jul 2023 19:13:44 +0300 Subject: [PATCH] 1.0.2 --- SigmaWarhead.sln | 5 +- SigmaWarhead/EventHandler.cs | 44 ------------- SigmaWarhead/Plugin.cs | 34 ---------- .../Config.cs | 46 ++++++------- .../EventHandler.cs | 65 +++++++++++++++++++ .../Plugin.cs | 28 ++++++++ SigmaWarhead/packages.config | 3 +- 7 files changed, 120 insertions(+), 105 deletions(-) delete mode 100644 SigmaWarhead/EventHandler.cs delete mode 100644 SigmaWarhead/Plugin.cs rename SigmaWarhead/{ => com.github.tendrilll.sigmawarhead}/Config.cs (58%) create mode 100644 SigmaWarhead/com.github.tendrilll.sigmawarhead/EventHandler.cs create mode 100644 SigmaWarhead/com.github.tendrilll.sigmawarhead/Plugin.cs diff --git a/SigmaWarhead.sln b/SigmaWarhead.sln index 61d7a6d..d528b78 100644 --- a/SigmaWarhead.sln +++ b/SigmaWarhead.sln @@ -1,5 +1,4 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SigmaWarhead", "SigmaWarhead\SigmaWarhead.csproj", "{200E4A7D-0A94-4C5B-9954-91C5E317C652}" EndProject Global @@ -13,4 +12,4 @@ Global {200E4A7D-0A94-4C5B-9954-91C5E317C652}.Release|Any CPU.ActiveCfg = Release|Any CPU {200E4A7D-0A94-4C5B-9954-91C5E317C652}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection -EndGlobal +EndGlobal \ No newline at end of file diff --git a/SigmaWarhead/EventHandler.cs b/SigmaWarhead/EventHandler.cs deleted file mode 100644 index 78a7815..0000000 --- a/SigmaWarhead/EventHandler.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Linq; -using System.Timers; -using PluginAPI.Core; -using PluginAPI.Core.Attributes; -using PluginAPI.Enums; - -namespace SigmaWarhead; - -public class EventHandler -{ - private int TimeToLaunch; - private bool DebugMode; - private string LaunchMessage; - private Timer _launchTimer; - - [PluginEvent(ServerEventType.MapGenerated)] - internal void OnGenerated() - { - TimeToLaunch = SigmaWarhead.Reference.Config.ActivationTime; - DebugMode = SigmaWarhead.Reference.Config.Debug; - LaunchMessage = SigmaWarhead.Reference.Config.CassieLines.FirstOrDefault(x => x.Key == "launch").Value; - - _launchTimer = new Timer(TimeToLaunch * 1000 * 60); - _launchTimer.Elapsed += LaunchSigmaWarhead; - _launchTimer.AutoReset = false; - } - - [PluginEvent(ServerEventType.RoundStart)] - internal void OnRoundStart() - { - _launchTimer.Enabled = true; - if (DebugMode){ Log.Debug("SigmaWarhead armed and will launch in " + TimeToLaunch + " minutes."); } - } - - internal void LaunchSigmaWarhead(Object source, ElapsedEventArgs e) - { - Log.Info("SigmaWarhead launched."); - AlphaWarheadController.Singleton.InstantPrepare(); - AlphaWarheadController.Singleton.StartDetonation(true, true); - AlphaWarheadController.Singleton.IsLocked = true; //There is no escape. - Cassie.Message(LaunchMessage, false, true, true); - } -} diff --git a/SigmaWarhead/Plugin.cs b/SigmaWarhead/Plugin.cs deleted file mode 100644 index e98fc63..0000000 --- a/SigmaWarhead/Plugin.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.IO; -using PluginAPI.Core; -using PluginAPI.Core.Attributes; -using PluginAPI.Enums; -using PluginAPI.Events; - -namespace SigmaWarhead -{ - public class SigmaWarhead - { - public static SigmaWarhead Reference { get; private set; } - public static string DirectoryPath { get; private set; } - - [PluginConfig] - public Config Config; - - [PluginPriority(LoadPriority.Medium)] - [PluginEntryPoint("SigmaWarhead", "1.0.1", "SigmaWarhead", "Ten")] - void Load() - { - if (!Config.IsEnabled) return; - - Reference = this; - DirectoryPath = PluginHandler.Get(this).PluginDirectoryPath; - EventManager.RegisterEvents(this); - - if (!Directory.Exists(DirectoryPath)) - { - Log.Warning("Config directory not found, creating..."); - Directory.CreateDirectory(DirectoryPath); - } - } - } -} \ No newline at end of file diff --git a/SigmaWarhead/Config.cs b/SigmaWarhead/com.github.tendrilll.sigmawarhead/Config.cs similarity index 58% rename from SigmaWarhead/Config.cs rename to SigmaWarhead/com.github.tendrilll.sigmawarhead/Config.cs index be3bee2..8788732 100644 --- a/SigmaWarhead/Config.cs +++ b/SigmaWarhead/com.github.tendrilll.sigmawarhead/Config.cs @@ -1,23 +1,23 @@ -using System.Collections.Generic; -using System.ComponentModel; - -namespace SigmaWarhead -{ - public sealed class Config - { - [Description("Is the Plugin enabled.")] - public bool IsEnabled { get; set; } = true; - - [Description("Debug mode.")] - public bool Debug { get; private set; } = false; - - [Description("C.A.S.S.I.E. voicelines.")] - public Dictionary CassieLines { get; private set; } = new() - { - { "launch", "Automatic .G3 jam_020_5 Sigma .G1 Warhead has been activated by .G6 pitch_0.69 O5 pitch_1.00 . Time until jam_020_3 detonation is .G2 T minus 90 seconds ." } - }; - - [Description("Minutes since start of round to activate Sigma Warhead.")] - public int ActivationTime { get; private set; } = 20; - } -} +using System.Collections.Generic; +using System.ComponentModel; +using Exiled.API.Interfaces; + +namespace SigmaWarhead.com.github.tendrilll.sigmawarhead +{ + public sealed class Config : IConfig + { + [Description("Is the Plugin enabled.")] + public bool IsEnabled { get; set; } = true; + + [Description("Debug mode.")] + public bool Debug { get; set; } = false; + + [Description("C.A.S.S.I.E. voicelines.")] + public Dictionary CassieLines { get; set; } = new(){ + { "launch", "Automatic .G3 jam_020_5 Sigma .G1 Warhead has been activated by .G6 pitch_0.69 O5 pitch_1.00 . Time until jam_020_3 detonation is .G2 T minus 90 seconds ." } + }; + + [Description("Minutes since start of round to activate Sigma Warhead.")] + public int ActivationTime { get; set; } = 20; + } +} \ No newline at end of file diff --git a/SigmaWarhead/com.github.tendrilll.sigmawarhead/EventHandler.cs b/SigmaWarhead/com.github.tendrilll.sigmawarhead/EventHandler.cs new file mode 100644 index 0000000..f1eb6b3 --- /dev/null +++ b/SigmaWarhead/com.github.tendrilll.sigmawarhead/EventHandler.cs @@ -0,0 +1,65 @@ +using System.Linq; +using Exiled.API.Features; +using Exiled.Events.EventArgs.Server; +using Server = Exiled.Events.Handlers.Server; +using MEC; + +namespace SigmaWarhead.com.github.tendrilll.sigmawarhead; + +public class EventHandler{ + private readonly Plugin _main; + private readonly bool _debugMode; + private readonly int TimeToLaunch; + private readonly string LaunchMessage; + CoroutineHandle timer; + + public EventHandler(Plugin plugin){ + _main = plugin; + _debugMode = plugin.Config.Debug; + if (_debugMode) { + Log.Info("Loading EventHandler"); + } + + TimeToLaunch = plugin.Config.ActivationTime; + LaunchMessage = plugin.Config.CassieLines.FirstOrDefault(x => x.Key == "launch").Value; + + Server.RoundStarted += StartSigma; + Server.RestartingRound += StopSigma; + Server.RoundEnded += StopSigma2; + } + + public void UnregisterEvents(){ + Server.RoundStarted -= StartSigma; + Server.RestartingRound -= StopSigma; + Server.RoundEnded -= StopSigma2; + } + + internal void StartSigma(){ + timer = Timing.CallDelayed(TimeToLaunch * 60, LaunchSigmaWarhead); + if (_debugMode) + { + Log.Debug("SigmaWarhead armed and will launch in " + TimeToLaunch + " minutes."); + } + } + + internal void StopSigma(){ + Timing.KillCoroutines(timer); + if (_debugMode){ + Log.Info("SigmaWarhead timer destroyed."); + } + } + + internal void StopSigma2(RoundEndedEventArgs args){ + StopSigma(); + } + + internal void LaunchSigmaWarhead(){ + Log.Info("SigmaWarhead launched."); + Warhead.Controller.StartDetonation(false, true); + Warhead.Controller.ForceTime(90+13); //+13 for the voiceline. Will make detonation time a variable later. + Warhead.IsLocked = true; + Cassie.Clear(); + Cassie.Message(LaunchMessage, false, true, true); + StopSigma(); + } +} \ No newline at end of file diff --git a/SigmaWarhead/com.github.tendrilll.sigmawarhead/Plugin.cs b/SigmaWarhead/com.github.tendrilll.sigmawarhead/Plugin.cs new file mode 100644 index 0000000..ad32828 --- /dev/null +++ b/SigmaWarhead/com.github.tendrilll.sigmawarhead/Plugin.cs @@ -0,0 +1,28 @@ +using System; +using Exiled.API.Features; +using Log = Exiled.API.Features.Log; + +namespace SigmaWarhead.com.github.tendrilll.sigmawarhead { + public class SigmaWarhead : Plugin { + public override string Name => "SigmaWarhead"; + public override string Author => "TenDRILLL"; + public override Version Version => new Version(1, 0, 2); + public EventHandler EventHandler; + + public override void OnEnabled() { + Log.Info("SigmaWarhead loading..."); + if (!Config.IsEnabled) { + Log.Warn("SigmaWarhead disabled from config, unloading..."); + OnDisabled(); + return; + } + EventHandler = new EventHandler(this); + Log.Info("SigmaWarhead loaded."); + } + + public override void OnDisabled() { + EventHandler.UnregisterEvents(); + Log.Info("SigmaWarhead unloaded."); + } + } +} \ No newline at end of file diff --git a/SigmaWarhead/packages.config b/SigmaWarhead/packages.config index 054cdd0..18050df 100644 --- a/SigmaWarhead/packages.config +++ b/SigmaWarhead/packages.config @@ -1,5 +1,6 @@  - + + \ No newline at end of file