diff --git a/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs b/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs index 217c94d6..af0a2229 100644 --- a/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs +++ b/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs @@ -1,3 +1,5 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Logistics; using Jailbreak.Formatting.Views.Warden; @@ -16,10 +18,19 @@ public IView CannotOpenYet(int seconds) { } public IView AlreadyOpened - => new SimpleView { WardenLocale.PREFIX, "You already opened cells." }; + => new SimpleView { WardenLocale.PREFIX, "Cells are already opened." }; + + public IView CellsOpenedBy(CCSPlayerController? player) { + return player == null ? + new SimpleView { + WardenLocale.PREFIX, + $"{ChatColors.Blue}The warden {ChatColors.Default}opened the cells." + } : + new SimpleView { WardenLocale.PREFIX, player, "opened the cells." }; + } public IView CellsOpened - => new SimpleView { WardenLocale.PREFIX, "The warden opened cells." }; + => new SimpleView { WardenLocale.PREFIX, "Cells were auto-opened." }; public IView OpeningFailed => new SimpleView { WardenLocale.PREFIX, "Failed to open the cells." }; diff --git a/mod/Jailbreak.Warden/Commands/OpenCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/WardenOpenCommandsBehavior.cs similarity index 69% rename from mod/Jailbreak.Warden/Commands/OpenCommandsBehavior.cs rename to mod/Jailbreak.Warden/Commands/WardenOpenCommandsBehavior.cs index c7867fe8..5d9b050c 100644 --- a/mod/Jailbreak.Warden/Commands/OpenCommandsBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/WardenOpenCommandsBehavior.cs @@ -4,6 +4,7 @@ using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Cvars.Validators; +using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; @@ -13,19 +14,19 @@ namespace Jailbreak.Warden.Commands; -public class OpenCommandsBehavior(IWardenService warden, IWardenLocale msg, - IWardenCmdOpenLocale wardenCmdOpenMsg, IZoneManager zoneManager) - : IPluginBehavior { +public class WardenOpenCommandsBehavior(IWardenService warden, + IWardenLocale msg, IWardenCmdOpenLocale wardenCmdOpenMsg, + IZoneManager zoneManager) : IPluginBehavior, IWardenOpenCommand { public static readonly FakeConVar CvOpenCommandCooldown = new( "css_jb_warden_open_cooldown", "Minimum seconds warden must wait before being able to open the cells.", 30, customValidators: new RangeValidator(0, 300)); - private bool openedCells; + public bool OpenedCells { get; set; } [GameEventHandler] public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { - openedCells = false; + OpenedCells = false; return HookResult.Continue; } @@ -45,15 +46,21 @@ public void Command_Open(CCSPlayerController? executor, CommandInfo info) { return; } - if (openedCells) { + if (OpenedCells) { wardenCmdOpenMsg.AlreadyOpened.ToChat(executor); return; } } - openedCells = true; - var result = MapUtil.OpenCells(zoneManager); - (result ? wardenCmdOpenMsg.CellsOpened : wardenCmdOpenMsg.OpeningFailed) - .ToAllChat(); + OpenedCells = true; + var result = MapUtil.OpenCells(zoneManager); + IView message; + if (result) { + if (executor != null && !warden.IsWarden(executor)) { + message = wardenCmdOpenMsg.CellsOpenedBy(executor); + } else { message = wardenCmdOpenMsg.CellsOpenedBy(null); } + } else { message = wardenCmdOpenMsg.OpeningFailed; } + + message.ToAllChat(); } } \ No newline at end of file diff --git a/mod/Jailbreak.Warden/Global/WardenBehavior.cs b/mod/Jailbreak.Warden/Global/WardenBehavior.cs index 2c9053cf..bc19e38f 100644 --- a/mod/Jailbreak.Warden/Global/WardenBehavior.cs +++ b/mod/Jailbreak.Warden/Global/WardenBehavior.cs @@ -14,6 +14,9 @@ using Jailbreak.Public.Mod.Mute; using Jailbreak.Public.Mod.Rebel; using Jailbreak.Public.Mod.Warden; +using Jailbreak.Public.Mod.Zones; +using Jailbreak.Public.Utils; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using MStatsShared; using Timer = CounterStrikeSharp.API.Modules.Timers.Timer; @@ -21,7 +24,7 @@ namespace Jailbreak.Warden.Global; // By making it a struct we ensure values from the CCSPlayerPawn are passed by VALUE. -internal struct PreWardenStats(int armorValue, int health, int maxHealth, +public struct PreWardenStats(int armorValue, int health, int maxHealth, bool headHealthShot, bool hadHelmetArmor) { public readonly int ArmorValue = armorValue; public readonly int Health = health; @@ -33,7 +36,8 @@ internal struct PreWardenStats(int armorValue, int health, int maxHealth, public class WardenBehavior(ILogger logger, IWardenLocale locale, IRichLogService logs, ISpecialTreatmentService specialTreatment, IRebelService rebels, - WardenConfig config, IMuteService mute) : IPluginBehavior, IWardenService { + WardenConfig config, IMuteService mute, IServiceProvider provider) + : IPluginBehavior, IWardenService { private readonly ISet bluePrisoners = new HashSet(); @@ -61,13 +65,17 @@ public class WardenBehavior(ILogger logger, "Max HP for the warden", 100, ConVarFlags.FCVAR_NONE, new RangeValidator(1, 200)); + public readonly FakeConVar CvWardenAutoOpenCells = + new("css_jb_warden_opencells_delay", + "Delay in seconds to auto-open cells at, -1 to disable", 60); + private bool firstWarden; private string? oldTag; private char? oldTagColor; - private BasePlugin? parent; + private BasePlugin parent = null!; private PreWardenStats? preWardenStats; - private Timer? unblueTimer; + private Timer? unblueTimer, openCellsTimer; public void Start(BasePlugin basePlugin) { parent = basePlugin; } @@ -386,6 +394,7 @@ private bool playerHasHealthshot(CCSPlayerController player, public HookResult OnRoundEnd(EventRoundEnd ev, GameEventInfo info) { TryRemoveWarden(); mute.UnPeaceMute(); + openCellsTimer?.Kill(); return HookResult.Continue; } @@ -394,6 +403,23 @@ public HookResult OnRoundStart(EventRoundStart ev, GameEventInfo info) { firstWarden = true; preWardenStats = null; + if (CvWardenAutoOpenCells.Value < 0 || RoundUtil.IsWarmup()) + return HookResult.Continue; + var openCmd = provider.GetService(); + if (openCmd == null) return HookResult.Continue; + var cmdLocale = provider.GetRequiredService(); + + openCellsTimer?.Kill(); + openCellsTimer = parent.AddTimer(CvWardenAutoOpenCells.Value, () => { + if (openCmd.OpenedCells) return; + var zone = provider.GetService(); + if (zone != null) + MapUtil.OpenCells(zone); + else + MapUtil.OpenCells(); + cmdLocale.CellsOpened.ToAllChat(); + }); + return HookResult.Continue; } diff --git a/mod/Jailbreak.Warden/WardenServiceExtension.cs b/mod/Jailbreak.Warden/WardenServiceExtension.cs index ebcc0397..5f6fb1ff 100644 --- a/mod/Jailbreak.Warden/WardenServiceExtension.cs +++ b/mod/Jailbreak.Warden/WardenServiceExtension.cs @@ -19,12 +19,12 @@ public static void AddJailbreakWarden( .AddPluginBehavior(); serviceCollection .AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); - serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); diff --git a/mod/Jailbreak.Zones/RandomZoneGenerator.cs b/mod/Jailbreak.Zones/RandomZoneGenerator.cs index 03bdb1d9..32232753 100644 --- a/mod/Jailbreak.Zones/RandomZoneGenerator.cs +++ b/mod/Jailbreak.Zones/RandomZoneGenerator.cs @@ -3,14 +3,16 @@ using CounterStrikeSharp.API.Modules.Timers; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.Zones; using Jailbreak.Public.Utils; +using Microsoft.Extensions.DependencyInjection; using Timer = CounterStrikeSharp.API.Modules.Timers.Timer; namespace Jailbreak.Zones; -public class RandomZoneGenerator(IZoneManager zoneManager, IZoneFactory factory) - : IPluginBehavior { +public class RandomZoneGenerator(IZoneManager zoneManager, IZoneFactory factory, + IServiceProvider provider) : IPluginBehavior { private IZone? cells; private string? currentMap; private IList? manualSpawnPoints; @@ -44,13 +46,17 @@ private void reload() { private void tick() { if (currentMap != Server.MapName) reload(); currentMap = Server.MapName; + + var sdManager = provider.GetService(); + if (sdManager is { IsSDRunning: true }) return; + foreach (var player in PlayerUtil.GetAlive()) tick(player); } private void tick(CCSPlayerController player) { var pawn = player.PlayerPawn.Value; if (pawn == null) return; - if (!pawn.OnGroundLastTick) return; + if (!pawn.OnGroundLastTick || !pawn.TakesDamage) return; var pos = pawn.AbsOrigin; if (pos == null) return; pos = pos.Clone(); diff --git a/public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs b/public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs index 140ba008..07ff0a6b 100644 --- a/public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs +++ b/public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs @@ -1,9 +1,22 @@ +using CounterStrikeSharp.API.Core; using Jailbreak.Formatting.Base; namespace Jailbreak.Formatting.Views.Warden; public interface IWardenCmdOpenLocale { + /// + /// The cells were auto-opened. + /// public IView CellsOpened { get; } + + /// + /// The cells were opened by the specified player. + /// If the player is null, the cells were opened by the warden. + /// + /// + /// + public IView CellsOpenedBy(CCSPlayerController? player); + public IView OpeningFailed { get; } public IView AlreadyOpened { get; } public IView CannotOpenYet(int seconds); diff --git a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs index 671587dc..18dcb513 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs @@ -8,6 +8,7 @@ using Jailbreak.Public.Mod.LastRequest; using Jailbreak.Public.Mod.Rebel; using Jailbreak.Public.Mod.SpecialDay.Enums; +using Jailbreak.Public.Mod.Warden; using Jailbreak.Public.Mod.Zones; using Jailbreak.Public.Utils; using Microsoft.Extensions.DependencyInjection; @@ -94,6 +95,8 @@ public virtual void Setup() { MapUtil.OpenCells(); else MapUtil.OpenCells(zones); + var openCmd = Provider.GetService(); + if (openCmd != null) openCmd.OpenedCells = true; } doTeleports(); @@ -252,6 +255,7 @@ protected object GetConvarValue(ConVar? cvar) { } protected void SetConvarValue(ConVar? cvar, object value) { + var previous = GetConvarValue(cvar); if (cvar == null) return; try { switch (cvar.Type) { @@ -288,13 +292,12 @@ protected void SetConvarValue(ConVar? cvar, object value) { or "mp_death_drop_gun") { // These convars require a frame to take effect, otherwise client-side // stuff is not properly updated - var opposite = !(bool)value; - Server.ExecuteCommand($"{cvar.Name} {opposite}"); + Server.ExecuteCommand($"{cvar.Name} {previous}"); Server.NextFrame(() => Server.ExecuteCommand($"{cvar.Name} {value}")); } else { Server.ExecuteCommand(cvar.Name + " " + value); } } catch (Exception e) { Server.PrintToChatAll( - $"There was an error setting {cvar.Name} ({cvar.Type}) to {value}"); + $"There was an error setting {cvar.Name} ({cvar.Type}) to {value} ({value.GetType()}"); Server.PrintToConsole(e.Message); Server.PrintToConsole(e.StackTrace ?? ""); } diff --git a/public/Jailbreak.Public/Mod/Warden/IWardenOpenCommand.cs b/public/Jailbreak.Public/Mod/Warden/IWardenOpenCommand.cs new file mode 100644 index 00000000..0615c6e8 --- /dev/null +++ b/public/Jailbreak.Public/Mod/Warden/IWardenOpenCommand.cs @@ -0,0 +1,5 @@ +namespace Jailbreak.Public.Mod.Warden; + +public interface IWardenOpenCommand { + bool OpenedCells { get; set; } +} \ No newline at end of file