diff --git a/lang/Jailbreak.English/Mute/WardenPeaceLocale.cs b/lang/Jailbreak.English/Mute/WardenPeaceLocale.cs index da428ae9..7827257f 100644 --- a/lang/Jailbreak.English/Mute/WardenPeaceLocale.cs +++ b/lang/Jailbreak.English/Mute/WardenPeaceLocale.cs @@ -4,7 +4,6 @@ using Jailbreak.Formatting.Logistics; using Jailbreak.Formatting.Objects; using Jailbreak.Formatting.Views.Warden; -using Microsoft.Extensions.Primitives; namespace Jailbreak.English.Mute; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs index 9b5e567e..cf5f5a6b 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs @@ -133,9 +133,8 @@ override protected HookResult public class InfectionSettings : SpecialDaySettings { public InfectionSettings() { - CtTeleport = TeleportType.ARMORY; - TTeleport = TeleportType.RANDOM; - RestrictWeapons = true; + CtTeleport = TeleportType.ARMORY; + TTeleport = TeleportType.RANDOM; WithRespawns(CsTeam.CounterTerrorist); } diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs index 0f1f34da..69e6d3f2 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs @@ -60,10 +60,12 @@ public override void Execute() { player.GiveNamedItem(weapon); } + Plugin.RegisterListener(OnTick); + base.Execute(); } - override protected void OnTick() { + protected void OnTick() { foreach (var player in PlayerUtil.GetAlive()) disableScope(player); } @@ -83,11 +85,17 @@ private void disableScope(CCSPlayerController player) { activeWeapon.NextPrimaryAttackTick = Server.TickCount + 500; } + override protected HookResult + OnEnd(EventRoundEnd @event, GameEventInfo info) { + var result = base.OnEnd(@event, info); + Plugin.RemoveListener(OnTick); + return result; + } + private class NoScopeSettings : FFASettings { public NoScopeSettings() { - CtTeleport = TeleportType.RANDOM; - TTeleport = TeleportType.RANDOM; - RestrictWeapons = true; + CtTeleport = TeleportType.RANDOM; + TTeleport = TeleportType.RANDOM; ConVarValues["sv_gravity"] = CV_GRAVITY.Value; ConVarValues["sv_infinite_ammo"] = 2; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs index 682ef3ab..610a28da 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs @@ -30,6 +30,8 @@ public override ISDInstanceLocale Locale "Additional (non-ammo restricted) weapons to give for the day", "weapon_knife", ConVarFlags.FCVAR_NONE, new ItemValidator()); + private bool started; + public override void Setup() { base.Setup(); Plugin.RegisterEventHandler(OnPlayerDamage); @@ -48,12 +50,28 @@ public override void Execute() { player.GetWeaponBase(CV_WEAPON.Value)?.SetAmmo(1, 0); } } + + started = true; + } + + override protected HookResult OnPickup(EventItemPickup @event, + GameEventInfo info) { + var result = base.OnPickup(@event, info); + if (!started) return result; + + var player = @event.Userid; + if (player == null || !player.IsValid) return result; + player.RemoveWeapons(); + player.SetHealth(1); + return result; } private HookResult OnPlayerDamage(EventPlayerHurt @event, GameEventInfo info) { if (@event.Userid == null || !@event.Userid.IsValid) return HookResult.Continue; + if (@event.Attacker == null || !@event.Attacker.IsValid) + return HookResult.Continue; @event.Userid?.SetHealth(0); return HookResult.Changed; } @@ -74,9 +92,8 @@ override protected HookResult public class OitcSettings : SpecialDaySettings { public OitcSettings() { - CtTeleport = TeleportType.RANDOM; - TTeleport = TeleportType.RANDOM; - RestrictWeapons = true; + CtTeleport = TeleportType.RANDOM; + TTeleport = TeleportType.RANDOM; WithFriendlyFire(); ConVarValues["mp_death_drop_gun"] = 0; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs index a1dc59bf..0b6164dc 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs @@ -821,7 +821,6 @@ public SpeedrunSettings() { CtTeleport = TeleportType.RANDOM_STACKED; TTeleport = TeleportType.RANDOM_STACKED; StripToKnife = true; - RestrictWeapons = true; ConVarValues["mp_ignore_round_win_conditions"] = true; if (new Random().Next(5) == 0) WithAutoBhop(); WithFriendlyFire(); diff --git a/mod/Jailbreak.Warden/Global/WardenBehavior.cs b/mod/Jailbreak.Warden/Global/WardenBehavior.cs index 2b3b3a74..c7788dd2 100644 --- a/mod/Jailbreak.Warden/Global/WardenBehavior.cs +++ b/mod/Jailbreak.Warden/Global/WardenBehavior.cs @@ -152,7 +152,7 @@ public bool TrySetWarden(CCSPlayerController controller) { logs.Append(logs.Player(Warden), "is now the warden."); - unblueTimer = parent!.AddTimer(3, unmarkPrisonersBlue); + unblueTimer = parent.AddTimer(3, unmarkPrisonersBlue); mute.PeaceMute(firstWarden ? MuteReason.INITIAL_WARDEN : MuteReason.WARDEN_TAKEN); diff --git a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs index 49926d8f..8597765b 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs @@ -50,6 +50,7 @@ public abstract class AbstractSpecialDay(BasePlugin plugin, public virtual void Setup() { Plugin.RegisterFakeConVars(this); Plugin.RegisterEventHandler(OnEnd); + Plugin.RegisterEventHandler(OnPickup); foreach (var entry in Settings.ConVarValues) { var cv = ConVar.Find(entry.Key); @@ -307,33 +308,7 @@ protected void SetConvarValue(ConVar? cvar, object value) { /// /// Called when the actual action begins for the special day. /// - public virtual void Execute() { - EnableDamage(); - if (Settings.RestrictWeapons) - Plugin.RegisterListener(OnTick); - } - - virtual protected void OnTick() { - foreach (var player in PlayerUtil.GetAlive()) { - var weapons = Settings.AllowedWeapons(player); - if (weapons == null) continue; - disableWeapon(player, weapons); - } - } - - private void disableWeapon(CCSPlayerController player, - ICollection allowed) { - if (!player.IsReal()) return; - var pawn = player.PlayerPawn.Value; - if (pawn == null || !pawn.IsValid) return; - var weaponServices = pawn.WeaponServices; - if (weaponServices == null) return; - var activeWeapon = weaponServices.ActiveWeapon.Value; - if (activeWeapon == null || !activeWeapon.IsValid) return; - if (allowed.Contains(activeWeapon.DesignerName)) return; - activeWeapon.NextSecondaryAttackTick = Server.TickCount + 500; - activeWeapon.NextPrimaryAttackTick = Server.TickCount + 500; - } + public virtual void Execute() { EnableDamage(); } virtual protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) { foreach (var entry in previousConvarValues) { @@ -344,13 +319,26 @@ virtual protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) { previousConvarValues.Clear(); - if (Settings.RestrictWeapons) - Plugin.RemoveListener(OnTick); - Plugin.DeregisterEventHandler(OnEnd); + Plugin.DeregisterEventHandler(OnPickup); return HookResult.Continue; } + virtual protected HookResult OnPickup(EventItemPickup @event, + GameEventInfo info) { + var player = @event.Userid; + if (player == null || !player.IsValid) return HookResult.Continue; + var allowed = Settings.AllowedWeapons(player); + var weapon = "weapon_" + @event.Item; + if (allowed == null || allowed.Contains(@event.Item)) + return HookResult.Continue; + player.RemoveItemByDesignerName(weapon, true); + return HookResult.Continue; + } + + [Obsolete("No longer used, you must manually register/unregister this")] + virtual protected void OnTick() { } + protected void DisableDamage() { foreach (var player in PlayerUtil.GetAlive()) DisableDamage(player); } diff --git a/public/Jailbreak.Public/Mod/SpecialDay/SpecialDaySettings.cs b/public/Jailbreak.Public/Mod/SpecialDay/SpecialDaySettings.cs index fdfa72b8..dbadcae0 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/SpecialDaySettings.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/SpecialDaySettings.cs @@ -56,6 +56,8 @@ public enum TeleportType { /// /// Used to avoid registring a costly OnTick listener if false /// + [Obsolete( + "With the new optimization, we now remove weapons if disallowed, making this obsolete.")] public bool RestrictWeapons = false; ///