diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/AbstractZoneRestrictedDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/AbstractZoneRestrictedDay.cs index 57d7ef03..b1592968 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/AbstractZoneRestrictedDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/AbstractZoneRestrictedDay.cs @@ -49,8 +49,8 @@ public override void Execute() { } override protected HookResult - OnEnd(EventRoundEnd @event, GameEventInfo info) { - var result = base.OnEnd(@event, info); + onEnd(EventRoundEnd @event, GameEventInfo info) { + var result = base.onEnd(@event, info); foreach (var restrictor in Restrictors) restrictor.Kill(); Restrictors.Clear(); return result; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs index 7d07443c..4a3034ce 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs @@ -177,8 +177,8 @@ private HookResult OnDeath(EventPlayerDeath @event, GameEventInfo info) { } override protected HookResult - OnEnd(EventRoundEnd @event, GameEventInfo info) { - var result = base.OnEnd(@event, info); + onEnd(EventRoundEnd @event, GameEventInfo info) { + var result = base.onEnd(@event, info); Plugin.DeregisterEventHandler(OnDeath, HookMode.Pre); Plugin.DeregisterEventHandler(OnRespawn); diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs index 65714458..2201033a 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs @@ -12,13 +12,11 @@ namespace Jailbreak.SpecialDay.SpecialDays; -public class InfectionDay : AbstractArmoryRestrictedDay, - ISpecialDayMessageProvider { +public class InfectionDay(BasePlugin plugin, IServiceProvider provider) + : AbstractArmoryRestrictedDay(plugin, provider, CsTeam.CounterTerrorist), + ISpecialDayMessageProvider { private readonly ICollection swappedPrisoners = new HashSet(); - public InfectionDay(BasePlugin Plugin, IServiceProvider provider) : base( - Plugin, provider, CsTeam.CounterTerrorist) { } - public override SDType Type => SDType.INFECTION; public override SpecialDaySettings Settings => new InfectionSettings(); @@ -40,12 +38,12 @@ public override void Setup() { foreach (var ct in PlayerUtil.FromTeam(CsTeam.CounterTerrorist)) ct.SetColor(Color.LimeGreen); - Plugin.RegisterEventHandler(OnPlayerDeath); - Plugin.RegisterEventHandler(OnRespawn); + Plugin.RegisterEventHandler(onPlayerDeath); + Plugin.RegisterEventHandler(onRespawn); } private HookResult - OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { + onPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { var player = @event.Userid; if (player == null || !player.IsValid) return HookResult.Continue; if (player.Team != CsTeam.Terrorist) return HookResult.Continue; @@ -101,7 +99,7 @@ private HookResult return HookResult.Continue; } - public HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) { + private HookResult onRespawn(EventPlayerSpawn @event, GameEventInfo info) { var player = @event.Userid; if (player == null || !player.IsValid) return HookResult.Continue; if (player.Team != CsTeam.CounterTerrorist) return HookResult.Continue; @@ -117,15 +115,15 @@ public HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) { } override protected HookResult - OnEnd(EventRoundEnd @event, GameEventInfo info) { - var result = base.OnEnd(@event, info); - Plugin.DeregisterEventHandler(OnPlayerDeath); - Plugin.DeregisterEventHandler(OnRespawn); + onEnd(EventRoundEnd @event, GameEventInfo info) { + var result = base.onEnd(@event, info); + Plugin.DeregisterEventHandler(onPlayerDeath); + Plugin.DeregisterEventHandler(onRespawn); Plugin.AddTimer(0.1f, () => { foreach (var index in swappedPrisoners) { var player = Utilities.GetPlayerFromSlot(index); - if (player == null) continue; + if (player == null || !player.IsValid) continue; player.SwitchTeam(CsTeam.Terrorist); } }); diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs index 484290e7..8cfa4297 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs @@ -1,11 +1,14 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Modules.Cvars.Validators; using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; using Jailbreak.Public.Utils; +using Jailbreak.Validator; namespace Jailbreak.SpecialDay.SpecialDays; @@ -17,20 +20,42 @@ public override ISDInstanceLocale Locale => new SoloDayLocale("No Scope", "Your scope broke! Fight against everyone else. No camping!"); - public override SpecialDaySettings Settings => new NoScopeSettings(); + public override SpecialDaySettings Settings => new NoScopeSettings(this); + + public readonly FakeConVar CvWeapon = new("jb_sd_noscope_weapon", + "Weapon to give to all players, recommended it be a weapon with a scope (duh)", + "weapon_ssg08", ConVarFlags.FCVAR_NONE, + new ItemValidator(allowMultiple: true)); + + public readonly FakeConVar CvWeaponWhitelist = new( + "jb_sd_noscope_allowedweapons", + "Weapons to allow players to use, empty for no restrictions", + string.Join(",", + Tag.UTILITY.Union(new[] { "weapon_ssg08", "weapon_knife" }.ToHashSet())), + ConVarFlags.FCVAR_NONE, new ItemValidator(allowMultiple: true)); + + public readonly FakeConVar CvKnifeDelay = new( + "jb_sd_noscope_knife_delay", + "Time delay in seconds to give knives at, 0 to disable", 120, + ConVarFlags.FCVAR_NONE, new RangeValidator(0, 500)); + + public readonly FakeConVar CvGravity = new("jb_sd_noscope_gravity", + "Gravity to set during the special day, default is 800", 200f); public override void Setup() { - Timers[120] += () => { - foreach (var player in PlayerUtil.GetAlive()) - player.GiveNamedItem("weapon_knife"); - }; + if (CvKnifeDelay.Value > 0) + Timers[CvKnifeDelay.Value] += () => { + foreach (var player in PlayerUtil.GetAlive()) + player.GiveNamedItem("weapon_knife"); + }; base.Setup(); } public override void Execute() { foreach (var player in PlayerUtil.GetAlive()) { player.RemoveWeapons(); - player.GiveNamedItem("weapon_ssg08"); + foreach (var weapon in CvWeapon.Value.Split(",")) + player.GiveNamedItem(weapon); } base.Execute(); @@ -50,18 +75,22 @@ private void disableScope(CCSPlayerController player) { if (activeWeapon == null || !activeWeapon.IsValid) return; activeWeapon.NextSecondaryAttackTick = Server.TickCount + 500; - if (activeWeapon.DesignerName is "weapon_ssg08" or "weapon_knife") return; - if (Tag.UTILITY.Contains(activeWeapon.DesignerName)) return; + if (CvWeaponWhitelist.Value.Contains(activeWeapon.DesignerName, + StringComparison.CurrentCultureIgnoreCase)) + return; activeWeapon.NextPrimaryAttackTick = Server.TickCount + 500; } private class NoScopeSettings : FFASettings { - public NoScopeSettings() { + private readonly NoScopeDay day; + + public NoScopeSettings(NoScopeDay day) { + this.day = day; CtTeleport = TeleportType.RANDOM; TTeleport = TeleportType.RANDOM; RestrictWeapons = true; - ConVarValues["sv_gravity"] = (float)200; + ConVarValues["sv_gravity"] = day.CvGravity.Value; ConVarValues["sv_infinite_ammo"] = 2; } diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs index 897a6a63..9511fb06 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs @@ -51,10 +51,10 @@ private HookResult } override protected HookResult - OnEnd(EventRoundEnd @event, GameEventInfo info) { + onEnd(EventRoundEnd @event, GameEventInfo info) { Plugin.DeregisterEventHandler(OnPlayerDamage); Plugin.DeregisterEventHandler(OnPlayerDeath); - return base.OnEnd(@event, info); + return base.onEnd(@event, info); } } diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs index 3a56627d..845e70fe 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs @@ -799,8 +799,8 @@ private void announceTimes() { } override protected HookResult - OnEnd(EventRoundEnd @event, GameEventInfo info) { - var result = base.OnEnd(@event, info); + onEnd(EventRoundEnd @event, GameEventInfo info) { + var result = base.onEnd(@event, info); Plugin.RemoveListener(checkFinishers); bestTrail?.Kill(); diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs index ff1a410b..5aef815b 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs @@ -40,9 +40,9 @@ private HookResult onDamage(EventPlayerHurt @event, GameEventInfo info) { } override protected HookResult - OnEnd(EventRoundEnd @event, GameEventInfo info) { + onEnd(EventRoundEnd @event, GameEventInfo info) { Plugin.DeregisterEventHandler(onDamage); - return base.OnEnd(@event, info); + return base.onEnd(@event, info); } public class TeleportSettings : SpecialDaySettings { diff --git a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs index 49926d8f..a73457f3 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs @@ -49,7 +49,7 @@ public abstract class AbstractSpecialDay(BasePlugin plugin, /// public virtual void Setup() { Plugin.RegisterFakeConVars(this); - Plugin.RegisterEventHandler(OnEnd); + Plugin.RegisterEventHandler(onEnd); foreach (var entry in Settings.ConVarValues) { var cv = ConVar.Find(entry.Key); @@ -335,7 +335,7 @@ private void disableWeapon(CCSPlayerController player, activeWeapon.NextPrimaryAttackTick = Server.TickCount + 500; } - virtual protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) { + virtual protected HookResult onEnd(EventRoundEnd @event, GameEventInfo info) { foreach (var entry in previousConvarValues) { var cv = ConVar.Find(entry.Key); if (cv == null || entry.Value == null) continue; @@ -347,7 +347,7 @@ virtual protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) { if (Settings.RestrictWeapons) Plugin.RemoveListener(OnTick); - Plugin.DeregisterEventHandler(OnEnd); + Plugin.DeregisterEventHandler(onEnd); return HookResult.Continue; }