From e0aac349d086347848d4861598f0e5538a7aa831 Mon Sep 17 00:00:00 2001 From: ragge Date: Sun, 24 Sep 2023 22:55:47 +0200 Subject: [PATCH] 1.0.0 Initial Release --- .gitignore | 398 ++++++++++++++++++ LICENSE => LICENSE.md | 2 +- README.md | 44 +- Radiation/API/RadiationAPI.cs | 79 ++++ .../Commands/Radiation/DisableCommand.cs | 33 ++ Radiation/Commands/Radiation/EnableCommand.cs | 33 ++ Radiation/Commands/Radiation/StartCommand.cs | 33 ++ Radiation/Commands/Radiation/StopCommand.cs | 33 ++ Radiation/Commands/RadiationCommand.cs | 54 +++ Radiation/Config.cs | 77 ++++ Radiation/Events/ServerEvents.cs | 44 ++ Radiation/Methods.cs | 92 ++++ Radiation/Plugin.cs | 59 +++ Radiation/Properties/AssemblyInfo.cs | 36 ++ Radiation/Radiation.csproj | 85 ++++ VERSION.md | 5 + example.config.yml | 61 +++ 17 files changed, 1166 insertions(+), 2 deletions(-) create mode 100644 .gitignore rename LICENSE => LICENSE.md (97%) create mode 100644 Radiation/API/RadiationAPI.cs create mode 100644 Radiation/Commands/Radiation/DisableCommand.cs create mode 100644 Radiation/Commands/Radiation/EnableCommand.cs create mode 100644 Radiation/Commands/Radiation/StartCommand.cs create mode 100644 Radiation/Commands/Radiation/StopCommand.cs create mode 100644 Radiation/Commands/RadiationCommand.cs create mode 100644 Radiation/Config.cs create mode 100644 Radiation/Events/ServerEvents.cs create mode 100644 Radiation/Methods.cs create mode 100644 Radiation/Plugin.cs create mode 100644 Radiation/Properties/AssemblyInfo.cs create mode 100644 Radiation/Radiation.csproj create mode 100644 VERSION.md create mode 100644 example.config.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8dd4607 --- /dev/null +++ b/.gitignore @@ -0,0 +1,398 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml \ No newline at end of file diff --git a/LICENSE b/LICENSE.md similarity index 97% rename from LICENSE rename to LICENSE.md index 3002cd1..b153dc1 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 ragge +Copyright (c) 2023 raggebatman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 93b3275..9eeabcc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,44 @@ # Radiation -SCP:SL Plugin using Northwood's API + +Radiation is a plugin that's made to stop people from +extending rounds too much. +It works by ticking away players' health, starting at a configurable time +after the Alpha Warhead has detonated. +You can choose which roles will take damage and you can choose how that +damage is applied. +View the config file for details. + +## Commands + +Radiation is managed using the `radiation` command. + +- `radiation start` +- `radiation stop` +- `radiation enable` +- `radiation disable` + +Start/Stop is used to manage whether or not the radiation is ticking damage. + +Enable/Disable is used to manage whether or not the radiation will begin. +Useful if you want to disable the plugin temporarily for some reason. + +With the config key `enable_radiation_on_round_start` you can make sure +that radiation always is enabled, no matter if a moderator disabled it +on the previous round. + +## Permissions + +Each command has its own permission. + +- `radiation.start` +- `radiation.stop` +- `radiation.enable` +- `radiation.disable` + +## Details + +License: MIT + +Framework: NwPluginApi + +Requires: NWAPIPermissionSystem \ No newline at end of file diff --git a/Radiation/API/RadiationAPI.cs b/Radiation/API/RadiationAPI.cs new file mode 100644 index 0000000..138419e --- /dev/null +++ b/Radiation/API/RadiationAPI.cs @@ -0,0 +1,79 @@ +using PluginAPI.Core; +using PlayerStatsSystem; + +namespace Radiation.API +{ + public static class RadiationAPI + { + private static readonly Config _config = Plugin.Singleton.Config; + + public static bool ShowHint() + { + if (!_config.HintEnable) return false; + + var players = Player.GetPlayers(); + + if (players.IsEmpty()) return false; + + foreach (Player player in players) + { + var id = player.RoleBase.RoleTypeId; + + if (_config.TakesAbsoluteDamage.Contains(id) || _config.TakesRelativeDamage.Contains(id)) + { + player.ReceiveHint(_config.HintText, _config.HintDuration); + } + } + + return true; + } + + public static bool ShowBroadcast() + { + if (!_config.BroadcastEnable) return false; + + Server.SendBroadcast(_config.BroadcastText, _config.BroadcastDuration); + + return true; + } + + public static void DealDamage() + { + var players = Player.GetPlayers(); + + foreach (Player player in players) + { + if (!player.IsAlive) continue; + + var health = player.GetStatModule(); + + var id = player.RoleBase.RoleTypeId; + + float damage; + + if (_config.TakesAbsoluteDamage.Contains(id)) + { + damage = _config.TickDamageAbsolute; + } + else + if (_config.TakesRelativeDamage.Contains(id)) + { + damage = (health.MaxValue / 100) * _config.TickDamagePercent; + } + else + { + continue; + } + + if (health.CurValue - damage > 0f) + { + player.Damage(damage, _config.DeathReason); + } + else + { + player.Kill(_config.DeathReason); + } + } + } + } +} diff --git a/Radiation/Commands/Radiation/DisableCommand.cs b/Radiation/Commands/Radiation/DisableCommand.cs new file mode 100644 index 0000000..2977379 --- /dev/null +++ b/Radiation/Commands/Radiation/DisableCommand.cs @@ -0,0 +1,33 @@ +using System; +using CommandSystem; +using NWAPIPermissionSystem; + +namespace Radiation.Commands +{ + public class DisableCommand : ICommand + { + public string Command { get; } = "disable"; + public string Description { get; } = "Disable radiation, will not do damage after warhead detonates"; + public string[] Aliases { get; } + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + if (!sender.CheckPermission("radiation.disable")) + { + response = "You do not have the required permission (radiation.disable) to execute this command"; + return false; + } + + if (Plugin.Singleton.DisableRadiation()) + { + response = "Radiation has been disabled."; + return true; + } + else + { + response = "Radiation is already disabled."; + return false; + } + } + } +} diff --git a/Radiation/Commands/Radiation/EnableCommand.cs b/Radiation/Commands/Radiation/EnableCommand.cs new file mode 100644 index 0000000..92630f4 --- /dev/null +++ b/Radiation/Commands/Radiation/EnableCommand.cs @@ -0,0 +1,33 @@ +using System; +using CommandSystem; +using NWAPIPermissionSystem; + +namespace Radiation.Commands +{ + public class EnableCommand : ICommand + { + public string Command { get; } = "enable"; + public string Description { get; } = "Enable radiation, will start doing damage after warhead detonates"; + public string[] Aliases { get; } + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + if (!sender.CheckPermission("radiation.enable")) + { + response = "You do not have the required permission (radiation.enable) to execute this command"; + return false; + } + + if (Plugin.Singleton.EnableRadiation()) + { + response = "Radiation has been enabled."; + return true; + } + else + { + response = "Radiation is already enabled."; + return false; + } + } + } +} diff --git a/Radiation/Commands/Radiation/StartCommand.cs b/Radiation/Commands/Radiation/StartCommand.cs new file mode 100644 index 0000000..ad592db --- /dev/null +++ b/Radiation/Commands/Radiation/StartCommand.cs @@ -0,0 +1,33 @@ +using System; +using CommandSystem; +using NWAPIPermissionSystem; + +namespace Radiation.Commands +{ + public class StartCommand : ICommand + { + public string Command { get; } = "start"; + public string Description { get; } = "Start doing tick damage"; + public string[] Aliases { get; } + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + if (!sender.CheckPermission("radiation.start")) + { + response = "You do not have the required permission (radiation.start) to execute this command"; + return false; + } + + if (Plugin.Singleton.StartRadiation()) + { + response = "Radiation has been started."; + return true; + } + else + { + response = "Radiation has already started."; + return false; + } + } + } +} diff --git a/Radiation/Commands/Radiation/StopCommand.cs b/Radiation/Commands/Radiation/StopCommand.cs new file mode 100644 index 0000000..4820162 --- /dev/null +++ b/Radiation/Commands/Radiation/StopCommand.cs @@ -0,0 +1,33 @@ +using System; +using CommandSystem; +using NWAPIPermissionSystem; + +namespace Radiation.Commands +{ + public class StopCommand : ICommand + { + public string Command { get; } = "stop"; + public string Description { get; } = "Stop doing tick damage"; + public string[] Aliases { get; } + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + if (!sender.CheckPermission("radiation.stop")) + { + response = "You do not have the required permission (radiation.stop) to execute this command"; + return false; + } + + if (Plugin.Singleton.StopRadiation()) + { + response = "Radiation has been stopped."; + return true; + } + else + { + response = "Radiation has already stopped."; + return false; + } + } + } +} diff --git a/Radiation/Commands/RadiationCommand.cs b/Radiation/Commands/RadiationCommand.cs new file mode 100644 index 0000000..9b7da26 --- /dev/null +++ b/Radiation/Commands/RadiationCommand.cs @@ -0,0 +1,54 @@ +using System; +using System.Text; +using CommandSystem; +using NorthwoodLib.Pools; + +using PluginAPI.Core; +using Radiation.Commands; + +namespace Radiation +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class RadiationCommand : ParentCommand + { + public override string Command => "radiation"; + public override string Description => "Manage facility radiation"; + public override string[] Aliases => new string[] { }; + + public override void LoadGeneratedCommands() + { + try + { + RegisterCommand(new StartCommand()); + RegisterCommand(new StopCommand()); + RegisterCommand(new EnableCommand()); + RegisterCommand(new DisableCommand()); + } + catch (Exception e) + { + Log.Warning("Caught an exception while registering commands."); + Log.Debug($"{e}"); + } + finally + { + Log.Info("Registered commands"); + } + } + + public RadiationCommand() => this.LoadGeneratedCommands(); + + protected override bool ExecuteParent(ArraySegment arguments, ICommandSender sender, out string response) + { + StringBuilder stringBuilder = StringBuilderPool.Shared.Rent(); + + stringBuilder.AppendLine("Available commands: "); + stringBuilder.AppendLine("- radiation start - Start doing tick damage"); + stringBuilder.AppendLine("- radiation stop - Stop doing tick damage"); + stringBuilder.AppendLine("- radiation enable - Enable tick damage, will start tick damage if warhead is detonated"); + stringBuilder.AppendLine("- radiation disable - Disable tick damage, will not start tick damage if warhead detonates"); + + response = StringBuilderPool.Shared.ToStringReturn(stringBuilder); + return false; + } + } +} \ No newline at end of file diff --git a/Radiation/Config.cs b/Radiation/Config.cs new file mode 100644 index 0000000..b546573 --- /dev/null +++ b/Radiation/Config.cs @@ -0,0 +1,77 @@ +using System.Collections.Generic; +using System.ComponentModel; +using PlayerRoles; + +namespace Radiation +{ + public class Config + { + [Description("Whether or not to enable radiation at the start of the round.\n# If false, radiation will not start after warhead detonation if it had been disabled the round prior.\n# Type: float")] + public bool EnableRadiationOnRoundStart { get; set; } = true; + + [Description("The delay in seconds after warhead detonation before radiation damage is dealt.\n# Type: float")] + public float RadiationDelay { get; set; } = 300.0f; + + [Description("The death reason that the player will see due to this plugin.\n# Type: string")] + public string DeathReason { get; set; } = "Died to alpha warhead radiation."; + + + [Description("The timeframe between each damage tick specified in seconds.\n# Type: float")] + public float TickInterval { get; set; } = 2.0f; + + [Description("The damage that is dealt to the player as an absolute value.\n# Type: float")] + public float TickDamageAbsolute { get; set; } = 10.0f; + + [Description("The damage that is dealt to the player as a percentage of their max health.\n# Type: float")] + public float TickDamagePercent { get; set; } = 5.0f; + + + [Description("Enable or disable a broadcast to show when radiation has started.\n# Type: bool")] + public bool BroadcastEnable { get; set; } = true; + + [Description("The text that is shown in the broadcast.\n# Type: string")] + public string BroadcastText { get; set; } = "Warhead radiation has reached the surface!"; + + [Description("The duration in seconds of the broadcast.\n# Type: ushort")] + public ushort BroadcastDuration { get; set; } = 10; + + + [Description("Enable or disable a hint to show players that radiation has started.\n# Type: bool")] + public bool HintEnable { get; set; } = false; + + [Description("The text that is shown in the hint.\n# Type: string")] + public string HintText { get; set; } = "Radiation Poisoning"; + + [Description("The duration in seconds of the hint.\n# Type: ushort")] + public ushort HintDuration { get; set; } = 10; + + + [Description("Select which roles will take absolute damage from radiation.\n# Type: List")] + public List TakesAbsoluteDamage { get; set; } = new List() + { + RoleTypeId.ChaosConscript, + RoleTypeId.ChaosMarauder, + RoleTypeId.ChaosRepressor, + RoleTypeId.ChaosRifleman, + RoleTypeId.ClassD, + RoleTypeId.FacilityGuard, + RoleTypeId.NtfCaptain, + RoleTypeId.NtfPrivate, + RoleTypeId.NtfSergeant, + RoleTypeId.NtfSpecialist, + RoleTypeId.Scientist, + RoleTypeId.Tutorial + }; + + [Description("Select which roles will take percentage damage from radiation.\n# Type: List")] + public List TakesRelativeDamage { get; set; } = new List() + { + RoleTypeId.Scp049, + RoleTypeId.Scp0492, + RoleTypeId.Scp096, + RoleTypeId.Scp106, + RoleTypeId.Scp173, + RoleTypeId.Scp939 + }; + } +} diff --git a/Radiation/Events/ServerEvents.cs b/Radiation/Events/ServerEvents.cs new file mode 100644 index 0000000..df7788b --- /dev/null +++ b/Radiation/Events/ServerEvents.cs @@ -0,0 +1,44 @@ +using PluginAPI.Core.Attributes; +using PluginAPI.Enums; +using PluginAPI.Events; + +namespace Radiation.Events +{ + public class ServerEvents + { + private readonly Config _config; + + public ServerEvents() + { + _config = Plugin.Singleton.Config; + } + + [PluginEvent(ServerEventType.RoundStart)] + private void OnRoundStart(RoundStartEvent @event) + { + Plugin.Singleton.StopRadiation(); + + if (!_config.EnableRadiationOnRoundStart) return; + + Plugin.Singleton.EnableRadiation(); + } + + [PluginEvent(ServerEventType.RoundEnd)] + private void OnRoundEnd(RoundEndEvent @event) + { + Plugin.Singleton.StopRadiation(); + } + + [PluginEvent(ServerEventType.RoundRestart)] + private void OnRoundRestart(RoundRestartEvent @event) + { + Plugin.Singleton.StopRadiation(); + } + + [PluginEvent(ServerEventType.WarheadDetonation)] + private void OnWarheadDetonation(WarheadDetonationEvent @event) + { + Plugin.Singleton.StartDelay(); + } + } +} diff --git a/Radiation/Methods.cs b/Radiation/Methods.cs new file mode 100644 index 0000000..655928d --- /dev/null +++ b/Radiation/Methods.cs @@ -0,0 +1,92 @@ +using PluginAPI.Core; +using MEC; + +using Radiation.API; +using System.Collections.Generic; + +namespace Radiation +{ + public partial class Plugin + { + private bool radiationEnabled { get; set; } = false; + private bool radiationStarted { get; set; } = false; + + public bool StartDelay() + { + if (radiationStarted || !radiationEnabled) return false; + + Timing.RunCoroutine(DelayCoroutine(), "radiation_delay"); + + return true; + } + + public bool StartRadiation() + { + if (radiationStarted || !radiationEnabled) return false; + + Timing.RunCoroutine(TickCoroutine(), "radiation_tick"); + + RadiationAPI.ShowHint(); + + RadiationAPI.ShowBroadcast(); + + radiationStarted = true; + + return true; + } + + public bool StopRadiation() + { + if (!radiationStarted) return false; + + Timing.KillCoroutines("radiation_delay"); + + Timing.KillCoroutines("radiation_tick"); + + radiationStarted = false; + + return true; + } + + public bool DisableRadiation() + { + if (!radiationEnabled) return false; + + radiationEnabled = false; + + StopRadiation(); + + Log.Info("Disabled radiation"); + + return true; + } + + public bool EnableRadiation() + { + if (radiationEnabled) return false; + + radiationEnabled = true; + + if (Warhead.IsDetonated) StartRadiation(); + + Log.Info("Enabled radiation"); + + return true; + } + + private IEnumerator DelayCoroutine() + { + yield return Timing.WaitForSeconds(Config.RadiationDelay); + StartRadiation(); + } + + private IEnumerator TickCoroutine() + { + while (true) + { + yield return Timing.WaitForSeconds(Config.TickInterval); + RadiationAPI.DealDamage(); + } + } + } +} \ No newline at end of file diff --git a/Radiation/Plugin.cs b/Radiation/Plugin.cs new file mode 100644 index 0000000..9c128d7 --- /dev/null +++ b/Radiation/Plugin.cs @@ -0,0 +1,59 @@ +using PluginAPI.Core; +using PluginAPI.Core.Attributes; +using PluginAPI.Events; + +using Radiation.Events; +using System; +using PluginAPI.Enums; + +namespace Radiation +{ + partial class Plugin + { + public static Plugin Singleton { get; set; } + + [PluginConfig] + public Config Config; + + [PluginPriority(LoadPriority.Low)] + [PluginEntryPoint("radiation", "1.0.0", "Warhead radiation to hinder prolonged rounds.", "raggebatman")] + void LoadPlugin() + { + try + { + Singleton = this; + + EventManager.RegisterEvents(Singleton); + + Log.Info("Registered events"); + + Singleton.EnableRadiation(); + } + catch (Exception e) + { + Log.Warning("Caught an exception while loading plugin."); + Log.Debug($"{e}"); + } + } + + [PluginUnload] + public void UnloadPlugin() + { + try + { + Singleton.DisableRadiation(); + + EventManager.UnregisterEvents(Singleton); + + Log.Info("Unregistered events"); + + Singleton = null; + } + catch (Exception e) + { + Log.Warning("Caught an exception while unloading plugin."); + Log.Debug($"{e}"); + } +} + } +} diff --git a/Radiation/Properties/AssemblyInfo.cs b/Radiation/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..afee4fe --- /dev/null +++ b/Radiation/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Radiation")] +[assembly: AssemblyDescription("SCP:SL Plugin using Northwood's API")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("N/A")] +[assembly: AssemblyProduct("Radiation")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("N/A")] +[assembly: AssemblyCulture("neutral")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4d97c189-5eb8-4f85-b40b-332c1d5878ed")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.*")] +[assembly: AssemblyFileVersion("1.0.0.*")] diff --git a/Radiation/Radiation.csproj b/Radiation/Radiation.csproj new file mode 100644 index 0000000..1f528e4 --- /dev/null +++ b/Radiation/Radiation.csproj @@ -0,0 +1,85 @@ + + + + + Debug + AnyCPU + {4D97C189-5EB8-4F85-B40B-332C1D5878ED} + Library + Properties + Radiation + Radiation + v4.8 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + .\Assembly-CSharp.dll + + + .\Assembly-CSharp-firstpass.dll + + + .\CommandSystem.Core.dll + + + .\Mirror.dll + + + .\NorthwoodLib.dll + + + .\NWAPIPermissionSystem.dll + + + .\PluginAPI.dll + + + .\Pooling.dll + + + + + + + + + + + .\UnityEngine.dll + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/VERSION.md b/VERSION.md new file mode 100644 index 0000000..4b50bdf --- /dev/null +++ b/VERSION.md @@ -0,0 +1,5 @@ +# History + +## 1.0.0 - 2023-09-24 + +Initial release. \ No newline at end of file diff --git a/example.config.yml b/example.config.yml new file mode 100644 index 0000000..c0aa291 --- /dev/null +++ b/example.config.yml @@ -0,0 +1,61 @@ +# Whether or not to enable radiation at the start of the round. +# If false, radiation will not start after warhead detonation if it had been disabled the round prior. +# Type: float +enable_radiation_on_round_start: true +# The delay in seconds after warhead detonation before radiation damage is dealt. +# Type: float +radiation_delay: 300 +# The death reason that the player will see due to this plugin. +# Type: string +death_reason: Died to alpha warhead radiation. +# The timeframe between each damage tick specified in seconds. +# Type: float +tick_interval: 2 +# The damage that is dealt to the player as an absolute value. +# Type: float +tick_damage_absolute: 10 +# The damage that is dealt to the player as a percentage of their max health. +# Type: float +tick_damage_percent: 5 +# Enable or disable a broadcast to show when radiation has started. +# Type: bool +broadcast_enable: true +# The text that is shown in the broadcast. +# Type: string +broadcast_text: Warhead radiation has reached the surface! +# The duration in seconds of the broadcast. +# Type: ushort +broadcast_duration: 10 +# Enable or disable a hint to show players that radiation has started. +# Type: bool +hint_enable: false +# The text that is shown in the hint. +# Type: string +hint_text: Radiation Poisoning +# The duration in seconds of the hint. +# Type: ushort +hint_duration: 10 +# Select which roles will take absolute damage from radiation. +# Type: List +takes_absolute_damage: +- ChaosConscript +- ChaosMarauder +- ChaosRepressor +- ChaosRifleman +- ClassD +- FacilityGuard +- NtfCaptain +- NtfPrivate +- NtfSergeant +- NtfSpecialist +- Scientist +- Tutorial +# Select which roles will take percentage damage from radiation. +# Type: List +takes_relative_damage: +- Scp049 +- Scp0492 +- Scp096 +- Scp106 +- Scp173 +- Scp939