diff --git a/Jailbreak.sln b/Jailbreak.sln index ac8dc8c3..2bb8cfe3 100644 --- a/Jailbreak.sln +++ b/Jailbreak.sln @@ -30,7 +30,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.LastRequest", "mo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Mute", "mod\Jailbreak.Mute\Jailbreak.Mute.csproj", "{C9F050A5-5B08-4F48-98F5-B5792A217DB0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.SpecialDay", "mod\Jailbreak.SpecialDay\Jailbreak.SpecialDay.csproj", "{CF21BE72-5A51-4F5D-B65D-4936FEAA806C}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.LastGuard", "mod\Jailbreak.LastGuard\Jailbreak.LastGuard.csproj", "{B77E4011-E07F-4BDA-A34F-99DADF0BD276}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -82,10 +82,10 @@ Global {C9F050A5-5B08-4F48-98F5-B5792A217DB0}.Debug|Any CPU.Build.0 = Debug|Any CPU {C9F050A5-5B08-4F48-98F5-B5792A217DB0}.Release|Any CPU.ActiveCfg = Release|Any CPU {C9F050A5-5B08-4F48-98F5-B5792A217DB0}.Release|Any CPU.Build.0 = Release|Any CPU - {CF21BE72-5A51-4F5D-B65D-4936FEAA806C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CF21BE72-5A51-4F5D-B65D-4936FEAA806C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CF21BE72-5A51-4F5D-B65D-4936FEAA806C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CF21BE72-5A51-4F5D-B65D-4936FEAA806C}.Release|Any CPU.Build.0 = Release|Any CPU + {B77E4011-E07F-4BDA-A34F-99DADF0BD276}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B77E4011-E07F-4BDA-A34F-99DADF0BD276}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B77E4011-E07F-4BDA-A34F-99DADF0BD276}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B77E4011-E07F-4BDA-A34F-99DADF0BD276}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581} @@ -99,6 +99,6 @@ Global {4F10E2B5-E8BB-4253-9BE6-9187575ADB13} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} {D8952626-7B8D-4ABB-A3AE-FC81C688787B} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} {C9F050A5-5B08-4F48-98F5-B5792A217DB0} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} - {CF21BE72-5A51-4F5D-B65D-4936FEAA806C} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} + {B77E4011-E07F-4BDA-A34F-99DADF0BD276} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} EndGlobalSection EndGlobal diff --git a/README.md b/README.md index 5dc62406..1ef4c4b9 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ The classic Jail gamemode, ported to Counter-Strike 2. Our **Stable** builds run on EdgeGamers' own Jailbreak servers. Our **Nightly** builds are used exclusively for development and staging, and are likely to have problems. +## Versioning +Our release tags starting from 'v1.2.0' follow the [Semantic Versioning 2.0.0](https://semver.org/) standard, +where `MAJOR.MINOR.PATCH` are incremented based on the following: +- `MAJOR` when we make incompatible API changes, +- `MINOR` when we add functionality in a backwards-compatible manner, **or** modify gameplay behavior +- `PATCH` when we make backwards-compatible bug fixes, **or** modify non-gameplay (cosmetic) behavior + ## Status - **⚙️ Server** diff --git a/lang/Jailbreak.English/Generic/GenericCommandNotifications.cs b/lang/Jailbreak.English/Generic/GenericCommandNotifications.cs index 75cb92b6..cce6e2cf 100644 --- a/lang/Jailbreak.English/Generic/GenericCommandNotifications.cs +++ b/lang/Jailbreak.English/Generic/GenericCommandNotifications.cs @@ -51,4 +51,13 @@ public IView InvalidParameter(string parameter, string expected) $"{ChatColors.Red}Invalid parameter '{ChatColors.LightBlue}{parameter}{ChatColors.Red}', expected a(n) {ChatColors.White}{expected}{ChatColors.Red}." }; } + + public IView NoPermissionMessage(string permission) + { + return new SimpleView + { + PREFIX, + $"{ChatColors.Red}You do not have permission to use this command. Required permission: {ChatColors.White}{permission}{ChatColors.Red}." + }; + } } \ No newline at end of file diff --git a/lang/Jailbreak.English/LastGuard/LastGuardNotifications.cs b/lang/Jailbreak.English/LastGuard/LastGuardNotifications.cs new file mode 100644 index 00000000..12b35a27 --- /dev/null +++ b/lang/Jailbreak.English/LastGuard/LastGuardNotifications.cs @@ -0,0 +1,28 @@ +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Formatting.Base; +using Jailbreak.Formatting.Logistics; +using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Core; +using Jailbreak.Formatting.Objects; + +namespace Jailbreak.English.LastGuard; + +public class LastGuardNotifications : ILastGuardNotifications, ILanguage +{ + public static FormatObject PREFIX = + new HiddenFormatObject($" {ChatColors.Blue}[{ChatColors.LightBlue}Last Guard{ChatColors.Blue}]") + { + // Hide in panorama and center text + Plain = false, + Panorama = false, + Chat = true + }; + + public IView LG_STARTED(int ctHealth, int tHealth) + { + return new SimpleView() + { + PREFIX, + $"{ChatColors.Red}Last Guard has been activated! Last guard has", ctHealth, $"{ChatColors.Red}health and T's have", tHealth, $"{ChatColors.Red}health." }; + } +} diff --git a/lang/Jailbreak.English/SpecialDay/SpecialDayNotifications.cs b/lang/Jailbreak.English/SpecialDay/SpecialDayNotifications.cs deleted file mode 100644 index 158a3096..00000000 --- a/lang/Jailbreak.English/SpecialDay/SpecialDayNotifications.cs +++ /dev/null @@ -1,49 +0,0 @@ -using CounterStrikeSharp.API.Modules.Utils; -using Jailbreak.Formatting.Base; -using Jailbreak.Formatting.Logistics; -using Jailbreak.Formatting.Views; -using Jailbreak.Formatting.Core; -using Jailbreak.Formatting.Objects; - -namespace Jailbreak.English.SpecialDay; - -public class SpecialDayNotifications : ISpecialDayNotifications, ILanguage -{ - public static FormatObject PREFIX = - new HiddenFormatObject($" {ChatColors.Blue}[{ChatColors.LightBlue}Special Days{ChatColors.Blue}]") - { - // Hide in panorama and center text - Plain = false, - Panorama = false, - Chat = true - }; - - public IView SD_WARDAY_STARTED => new SimpleView - { - { - PREFIX, - $"Today is a {ChatColors.DarkRed}Warday{ChatColors.White}! CTs versus Ts. CTs pick a location on the map, and Ts must actively pursue!" - }, - { PREFIX, "Last team standing wins!" } - }; - - public IView SD_FREEDAY_STARTED => new SimpleView - { - PREFIX, - $"Today is a {ChatColors.Green}Freeday{ChatColors.White}! Do whatever you want!" - }; - - public IView SD_FFA_STARTED => new SimpleView - { PREFIX, $"Today is a {ChatColors.LightRed}Free for All{ChatColors.White}! Everyone for themselves." }; - - public IView SD_FFA_STARTING => new SimpleView { PREFIX, "Free for all starts in 30 seconds!" }; - - public IView SD_CUSTOM_STARTED => new SimpleView - { - PREFIX, - $"Today is a {ChatColors.Yellow}Custom Day{ChatColors.White}, listen carefully to the Warden's instructions." - }; - - public IView SD_NOT_WARDEN => new SimpleView { PREFIX, "You are not the warden." }; - public IView SD_CANT_START => new SimpleView { PREFIX, "Unable to do special days this round." }; -} \ No newline at end of file diff --git a/lang/Jailbreak.English/Warden/WardenNotifications.cs b/lang/Jailbreak.English/Warden/WardenNotifications.cs index 7917ef4f..f90ac8ba 100644 --- a/lang/Jailbreak.English/Warden/WardenNotifications.cs +++ b/lang/Jailbreak.English/Warden/WardenNotifications.cs @@ -52,13 +52,23 @@ public class WardenNotifications : IWardenNotifications, ILanguage - new SimpleView { PREFIX, "The fire command has failed to work for some unknown reason..." }; + new SimpleView { PREFIX, "The fire command has failed to work for some unknown reason..." }; public IView PASS_WARDEN(CCSPlayerController player) { return new SimpleView { PREFIX, player, "has resigned from being warden." }; } + public IView FIRE_WARDEN(CCSPlayerController player) + { + return new SimpleView { PREFIX, player, "was fired from being warden." }; + } + + public IView FIRE_WARDEN(CCSPlayerController player, CCSPlayerController admin) + { + return new SimpleView { PREFIX, admin, "has fired", player, "from being warden." }; + } + public IView NEW_WARDEN(CCSPlayerController player) { return new SimpleView { PREFIX, player, "is now the warden!" }; @@ -76,5 +86,4 @@ public IView FIRE_COMMAND_SUCCESS(CCSPlayerController player) { return new SimpleView { PREFIX, player, "has been fired and is no longer the warden." }; } - } \ No newline at end of file diff --git a/mod/Jailbreak.SpecialDay/Jailbreak.SpecialDay.csproj b/mod/Jailbreak.LastGuard/Jailbreak.LastGuard.csproj similarity index 98% rename from mod/Jailbreak.SpecialDay/Jailbreak.SpecialDay.csproj rename to mod/Jailbreak.LastGuard/Jailbreak.LastGuard.csproj index 935e5bbd..f430fd60 100644 --- a/mod/Jailbreak.SpecialDay/Jailbreak.SpecialDay.csproj +++ b/mod/Jailbreak.LastGuard/Jailbreak.LastGuard.csproj @@ -10,5 +10,5 @@ - + diff --git a/mod/Jailbreak.LastGuard/LastGuard.cs b/mod/Jailbreak.LastGuard/LastGuard.cs new file mode 100644 index 00000000..ed5dedaf --- /dev/null +++ b/mod/Jailbreak.LastGuard/LastGuard.cs @@ -0,0 +1,101 @@ +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Formatting.Extensions; +using Jailbreak.Formatting.Views; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.LastGuard; +using Jailbreak.Public.Mod.LastRequest; + +namespace Jailbreak.LastGuard; + +public class LastGuard : ILastGuardService, IPluginBehavior +{ + + private readonly LastGuardConfig _config; + private readonly ILastGuardNotifications _notifications; + private readonly ILastRequestManager _lrManager; + private bool _canStart = false; + + public LastGuard(LastGuardConfig config, ILastGuardNotifications notifications, ILastRequestManager lrManager) + { + _config = config; + _notifications = notifications; + _lrManager = lrManager; + } + + public void Start(BasePlugin plugin) + { + + } + + [GameEventHandler] + public HookResult OnPlayerDeathEvent(EventPlayerDeath @event, GameEventInfo info) + { + var target = @event.Userid; + if (target == null) return HookResult.Continue; + if (target.Team != CsTeam.CounterTerrorist) return HookResult.Continue; + var aliveCts = Utilities.GetPlayers() + .Count(plr => plr.IsReal() && plr is { PawnIsAlive: true, Team: CsTeam.CounterTerrorist }) - 1; + + if (aliveCts == 1 && !_lrManager.IsLREnabled) + { + var lastGuard = Utilities.GetPlayers().First(plr => plr.IsReal() && plr != target && plr is { PawnIsAlive: true, Team: CsTeam.CounterTerrorist }); + + StartLastGuard(lastGuard); + } + return HookResult.Continue; + } + + [GameEventHandler] + public HookResult OnRoundStartEvent(EventRoundStart @event, GameEventInfo info) + { + _canStart = Utilities.GetPlayers().Count(plr => plr.IsReal() && plr is { PawnIsAlive: true, Team: CsTeam.CounterTerrorist}) >= _config.MinimumCTs; + return HookResult.Continue; + } + + public int CalculateHealth() + { + var aliveTerrorists = Utilities.GetPlayers() + .Where(plr => plr.IsReal() && plr is { PawnIsAlive: true, Team: CsTeam.Terrorist }); + + foreach (var terrorist in aliveTerrorists) + { + if (terrorist.PlayerPawn.Value?.Health > 100) terrorist.PlayerPawn.Value.Health = 100; + } + + return aliveTerrorists.Select(player => player.PlayerPawn.Value.Health).Select(playerHealth => (int)(playerHealth * 0.45)).Sum(); + } + + public void StartLastGuard(CCSPlayerController lastGuard) + { + if (!_canStart) return; + + var ctPlayerPawn = lastGuard.PlayerPawn.Value; + + if (!ctPlayerPawn.IsValid) return; + + var ctHealth = ctPlayerPawn.Health; + var ctCalcHealth = CalculateHealth(); + + ctPlayerPawn.Health = ctHealth > ctCalcHealth ? 125 : ctCalcHealth; + + Utilities.SetStateChanged(ctPlayerPawn, "CBaseEntity", "m_iHealth"); + + var aliveTerrorists = Utilities.GetPlayers() + .Where(plr => plr.IsReal() && plr is { PawnIsAlive: true, Team: CsTeam.Terrorist }); + + + _notifications.LG_STARTED(lastGuard.PlayerPawn.Value.Health, aliveTerrorists.Select(plr => plr.PlayerPawn.Value.Health).Sum()).ToAllCenter().ToAllChat(); + + if (string.IsNullOrEmpty(_config.LastGuardWeapon)) return; + + foreach (var player in aliveTerrorists) + { + player.GiveNamedItem(_config.LastGuardWeapon); + } + + } +} diff --git a/mod/Jailbreak.LastGuard/LastGuardConfig.cs b/mod/Jailbreak.LastGuard/LastGuardConfig.cs new file mode 100644 index 00000000..534d7b4f --- /dev/null +++ b/mod/Jailbreak.LastGuard/LastGuardConfig.cs @@ -0,0 +1,7 @@ +namespace Jailbreak.LastGuard; + +public class LastGuardConfig +{ + public string? LastGuardWeapon { get; } = "weapon_glock"; + public int MinimumCTs { get; } = 4; +} \ No newline at end of file diff --git a/mod/Jailbreak.LastGuard/LastGuardServiceExtension.cs b/mod/Jailbreak.LastGuard/LastGuardServiceExtension.cs new file mode 100644 index 00000000..00c1e040 --- /dev/null +++ b/mod/Jailbreak.LastGuard/LastGuardServiceExtension.cs @@ -0,0 +1,14 @@ +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.LastGuard; +using Microsoft.Extensions.DependencyInjection; + +namespace Jailbreak.LastGuard; + +public static class RebelServiceExtension +{ + public static void AddJailbreakLastGuard(this IServiceCollection collection) + { + collection.AddConfig("lastguard"); + collection.AddPluginBehavior(); + } +} \ No newline at end of file diff --git a/mod/Jailbreak.LastRequest/LastRequestCommand.cs b/mod/Jailbreak.LastRequest/LastRequestCommand.cs index 27c0a1d4..96aebda0 100644 --- a/mod/Jailbreak.LastRequest/LastRequestCommand.cs +++ b/mod/Jailbreak.LastRequest/LastRequestCommand.cs @@ -10,14 +10,12 @@ using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.LastRequest; using Jailbreak.Public.Mod.LastRequest.Enums; -using Jailbreak.Public.Mod.SpecialDays; using Microsoft.Extensions.DependencyModel; namespace Jailbreak.LastRequest; public class LastRequestCommand( ILastRequestManager manager, - ISpecialDayHandler sdHandler, ILastRequestMessages messages, IGenericCommandNotifications generic, ILastRequestFactory factory) @@ -25,14 +23,12 @@ public class LastRequestCommand( { private LastRequestMenuSelector _menuSelector; private LastRequestPlayerSelector _playerSelector; - private ISpecialDayHandler _sdHandler; private BasePlugin _plugin; // css_lr public void Start(BasePlugin plugin) { _plugin = plugin; - _sdHandler = sdHandler; _playerSelector = new LastRequestPlayerSelector(manager); _menuSelector = new LastRequestMenuSelector(factory); } @@ -49,11 +45,6 @@ public void Command_LastRequest(CCSPlayerController? executor, CommandInfo info) return; } - if (_sdHandler.IsSpecialDayActive()) - { - info.ReplyToCommand("You cannot LR during a special day!"); - } - if (!executor.PawnIsAlive) { info.ReplyToCommand("You must be alive to LR."); diff --git a/mod/Jailbreak.LastRequest/LastRequestManager.cs b/mod/Jailbreak.LastRequest/LastRequestManager.cs index e99f80ff..8e04d383 100644 --- a/mod/Jailbreak.LastRequest/LastRequestManager.cs +++ b/mod/Jailbreak.LastRequest/LastRequestManager.cs @@ -10,7 +10,6 @@ using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; -using Jailbreak.Public.Mod.SpecialDays; using Jailbreak.Public.Mod.LastRequest; using Jailbreak.Public.Mod.LastRequest.Enums; using Jailbreak.Public.Mod.Damage; @@ -21,12 +20,10 @@ namespace Jailbreak.LastRequest; public class LastRequestManager( LastRequestConfig _config, ILastRequestMessages _messages, - IServiceProvider _provider, - ISpecialDayHandler sdHandler + IServiceProvider _provider ) : ILastRequestManager, IBlockUserDamage { - private ISpecialDayHandler _sdHandler; private BasePlugin _parent; private ILastRequestFactory _factory; @@ -37,7 +34,6 @@ public void Start(BasePlugin parent) { _factory = _provider.GetRequiredService(); _parent = parent; - _sdHandler = sdHandler; } [GameEventHandler(HookMode.Pre)] @@ -153,11 +149,23 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) { var player = @event.Userid; + + if (player == null) return HookResult.Continue; + if (!player.IsReal() || ServerExtensions.GetGameRules().WarmupPeriod) return HookResult.Continue; + if (IsLREnabled) return HookResult.Continue; + var activeLr = ((ILastRequestManager)this).GetActiveLR(player); + + if (activeLr != null && activeLr.state != LRState.Active) + { + EndLastRequest(activeLr, player.Team == CsTeam.Terrorist ? LRResult.GuardWin : LRResult.PrisonerWin); + return HookResult.Continue; + } + if (player.GetTeam() != CsTeam.Terrorist) return HookResult.Continue; if (CountAlivePrisoners() > _config.PrisonersToActiveLR) @@ -175,7 +183,6 @@ public void DisableLR() public void EnableLR() { - if (_sdHandler.IsSpecialDayActive()) return; IsLREnabled = true; SetRoundTime(60); @@ -276,4 +283,4 @@ public bool EndLastRequest(AbstractLastRequest lr, LRResult result) ActiveLRs.Remove(lr); return true; } -} \ No newline at end of file +} diff --git a/mod/Jailbreak.Mute/MuteSystem.cs b/mod/Jailbreak.Mute/MuteSystem.cs index 2bea9036..28b9968b 100644 --- a/mod/Jailbreak.Mute/MuteSystem.cs +++ b/mod/Jailbreak.Mute/MuteSystem.cs @@ -1,5 +1,6 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; @@ -22,8 +23,6 @@ public class MuteSystem(IServiceProvider provider) : IPluginBehavior, IMuteServi private IPeaceMessages messages; private IWardenService warden; - private Queue ctScheduledMutes = new(); - private Queue tScheduledMutes = new(); private Timer? prisonerTimer, guardTimer; @@ -31,85 +30,36 @@ public void Start(BasePlugin parent) { this.parent = parent; - messages = provider.GetRequiredService(); - warden = provider.GetRequiredService(); - - parent.RegisterListener(OnPlayerSpeak); + this.messages = provider.GetRequiredService(); + this.warden = provider.GetRequiredService(); } - public void Dispose() + [GameEventHandler] + public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { - parent.RemoveListener("OnClientVoice", OnPlayerSpeak); + UnPeaceMute(); + return HookResult.Continue; } - private void TickTerroristMutes() + [GameEventHandler] + public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) { - if (tScheduledMutes.Count == 0) - return; - - var muteDuration = tScheduledMutes.Dequeue(); - - prisonerTimer = parent.AddTimer(muteDuration, () => - { - if (tScheduledMutes.Count != 0) - { - TickTerroristMutes(); - return; - } - - foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal() && player.Team == CsTeam.Terrorist)) - { - UnMute(player); - } - - prisonerTimer?.Kill(); - prisonerTimer = null; - }); + UnPeaceMute(); + return HookResult.Continue; } - private void TickCounterTerroristMutes() + public void Dispose() { - if (ctScheduledMutes.Count == 0) - return; - - var muteDuration = ctScheduledMutes.Dequeue(); - - guardTimer = parent.AddTimer(muteDuration, () => - { - if (ctScheduledMutes.Count != 0) - { - TickCounterTerroristMutes(); - return; - } - - foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal() && player.Team == CsTeam.CounterTerrorist)) - { - UnMute(player); - } - - - guardTimer?.Kill(); - guardTimer = null; - }); + parent.RemoveListener(OnPlayerSpeak); } public void PeaceMute(MuteReason reason) { var duration = GetPeaceDuration(reason); var ctDuration = Math.Min(10, duration); - - if (IsPeaceEnabled()) - { - foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal() && (player.VoiceFlags & VoiceFlags.Muted) != 0)) - UnMute(player); - } - foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal())) if (!warden.IsWarden(player)) - Mute(player); + mute(player); switch (reason) { @@ -127,40 +77,47 @@ public void PeaceMute(MuteReason reason) break; } - this.peaceEnd = DateTime.Now.AddSeconds(duration); - this.ctPeaceEnd = DateTime.Now.AddSeconds(ctDuration); - this.lastPeace = DateTime.Now; + peaceEnd = DateTime.Now.AddSeconds(duration); + ctPeaceEnd = DateTime.Now.AddSeconds(ctDuration); + lastPeace = DateTime.Now; guardTimer?.Kill(); prisonerTimer?.Kill(); - ctScheduledMutes.Enqueue(ctDuration); - tScheduledMutes.Enqueue(duration); - - if (tScheduledMutes.Count == 1 || prisonerTimer == null) TickTerroristMutes(); - if (ctScheduledMutes.Count == 1 || guardTimer == null) TickCounterTerroristMutes(); + guardTimer = parent.AddTimer(ctDuration, unmuteGuards); + prisonerTimer = parent.AddTimer(duration, unmutePrisoners); } - public void UnPeaceMute() + private void unmuteGuards() { foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal() && player.Team == CsTeam.Terrorist)) - { - UnMute(player); - } + .Where(player => + player.IsReal() && player is { Team: CsTeam.CounterTerrorist, PawnIsAlive: true })) + unmute(player); + + messages.UNMUTED_GUARDS.ToAllChat(); + guardTimer = null; + } + private void unmutePrisoners() + { foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal() && player.Team == CsTeam.CounterTerrorist)) - { - UnMute(player); - } + .Where(player => + player.IsReal() && player is { Team: CsTeam.Terrorist, PawnIsAlive: true })) + unmute(player); - prisonerTimer?.Kill(); + messages.UNMUTED_PRISONERS.ToAllChat(); prisonerTimer = null; - guardTimer?.Kill(); - guardTimer = null; } + public void UnPeaceMute() + { + if (guardTimer != null) + unmuteGuards(); + + if (prisonerTimer != null) + unmutePrisoners(); + } private int GetPeaceDuration(MuteReason reason) { @@ -173,20 +130,20 @@ private int GetPeaceDuration(MuteReason reason) { MuteReason.ADMIN => baseTime, MuteReason.WARDEN_TAKEN => baseTime / 5, - MuteReason.INITIAL_WARDEN => (int) Math.Ceiling(baseTime / 2.0), + MuteReason.INITIAL_WARDEN => 2 * baseTime / 3, MuteReason.WARDEN_INVOKED => baseTime / 2, _ => baseTime }; } - private void Mute(CCSPlayerController player) + private void mute(CCSPlayerController player) { - if (BypassMute(player)) + if (bypassMute(player)) return; player.VoiceFlags |= VoiceFlags.Muted; } - private void UnMute(CCSPlayerController player) + private void unmute(CCSPlayerController player) { player.VoiceFlags &= ~VoiceFlags.Muted; } @@ -210,48 +167,49 @@ private void OnPlayerSpeak(int playerSlot) if (warden.IsWarden(player)) { // Always let the warden speak - UnMute(player); + unmute(player); return; } - if (!player.PawnIsAlive && !BypassMute(player)) + if (!player.PawnIsAlive && !bypassMute(player)) { // Normal players can't speak when dead messages.DEAD_REMINDER.ToPlayerCenter(player); - Mute(player); + mute(player); return; } - if (IsMuted(player)) + if (isMuted(player)) { // Remind any muted players they're muted messages.MUTE_REMINDER.ToPlayerCenter(player); return; } - if (!BypassMute(player)) return; - - // Warn admins if they're not muted - if (IsPeaceEnabled()) + if (bypassMute(player)) { - if (player.Team == CsTeam.CounterTerrorist && DateTime.Now >= ctPeaceEnd) - return; - messages.PEACE_REMINDER.ToPlayerCenter(player); - } + // Warn admins if they're not muted + if (IsPeaceEnabled()) + { + if (player.Team == CsTeam.CounterTerrorist && DateTime.Now >= ctPeaceEnd) + return; + messages.PEACE_REMINDER.ToPlayerCenter(player); + } - if (!player.PawnIsAlive) - messages.ADMIN_DEAD_REMINDER.ToPlayerCenter(player); + if (!player.PawnIsAlive) + messages.ADMIN_DEAD_REMINDER.ToPlayerCenter(player); + } } - private bool IsMuted(CCSPlayerController player) + private bool isMuted(CCSPlayerController player) { if (!player.IsReal()) return false; return (player.VoiceFlags & VoiceFlags.Muted) != 0; } - private bool BypassMute(CCSPlayerController player) + private bool bypassMute(CCSPlayerController player) { return player.IsReal() && AdminManager.PlayerHasPermissions(player, "@css/chat"); } -} +} \ No newline at end of file diff --git a/mod/Jailbreak.Rebel/JihadC4/JihadC4Behavior.cs b/mod/Jailbreak.Rebel/JihadC4/JihadC4Behavior.cs index be743229..bdf26f8d 100644 --- a/mod/Jailbreak.Rebel/JihadC4/JihadC4Behavior.cs +++ b/mod/Jailbreak.Rebel/JihadC4/JihadC4Behavior.cs @@ -9,7 +9,6 @@ using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Rebel; using Microsoft.Extensions.Logging; -using Jailbreak.Public.Mod.SpecialDays; namespace Jailbreak.Rebel.JihadC4; diff --git a/mod/Jailbreak.SpecialDay/Commands/SpecialDayCommandsBehavior.cs b/mod/Jailbreak.SpecialDay/Commands/SpecialDayCommandsBehavior.cs deleted file mode 100644 index 5b1ce9de..00000000 --- a/mod/Jailbreak.SpecialDay/Commands/SpecialDayCommandsBehavior.cs +++ /dev/null @@ -1,52 +0,0 @@ -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Core.Attributes.Registration; -using CounterStrikeSharp.API.Modules.Commands; -using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; -using Jailbreak.Public.Behaviors; -using Jailbreak.Public.Mod.SpecialDays; -using Jailbreak.Public.Mod.Warden; - -namespace Jailbreak.SpecialDay.Commands; - -public class SpecialDayCommandsBehavior() : IPluginBehavior -{ - private IWardenService _warden; - - private ISpecialDayMenu _menu; - - private ISpecialDayNotifications _specialDayNotifications; - - private SpecialDayHandler _handler; - - public SpecialDayCommandsBehavior(IWardenService warden, ISpecialDayMenu menu, ISpecialDayNotifications notifications, SpecialDayHandler handler) : this() - { - _warden = warden; - _menu = menu; - _specialDayNotifications = notifications; - _handler = handler; - } - - [ConsoleCommand("css_specialday", "Open the special day menu")] - [ConsoleCommand("css_sd", "Open the special day menu")] - [CommandHelper(0, "", CommandUsage.CLIENT_ONLY)] - public void Command_Toggle(CCSPlayerController? player, CommandInfo command) - { - if (player == null) - return; - - if (!_handler.CanStartSpecialDay()) - { - _specialDayNotifications.SD_CANT_START.ToPlayerChat(player); - return; - } - - if (!_warden.IsWarden(player)) - { - _specialDayNotifications.SD_NOT_WARDEN.ToPlayerChat(player); - return; - } - - _menu.OpenMenu(player); - } -} diff --git a/mod/Jailbreak.SpecialDay/SpecialDayConfig.cs b/mod/Jailbreak.SpecialDay/SpecialDayConfig.cs deleted file mode 100644 index 0d88b8ff..00000000 --- a/mod/Jailbreak.SpecialDay/SpecialDayConfig.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Jailbreak.SpecialDay; - -public class SpecialDayConfig -{ - public int MinRoundsBeforeSpecialDay { get; } = 4; - public int MaxRoundSecondsBeforeSpecialDay { get; } = 30; -} diff --git a/mod/Jailbreak.SpecialDay/SpecialDayHandler.cs b/mod/Jailbreak.SpecialDay/SpecialDayHandler.cs deleted file mode 100644 index fffeb482..00000000 --- a/mod/Jailbreak.SpecialDay/SpecialDayHandler.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System.Reflection; -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Core.Attributes.Registration; -using Jailbreak.Formatting.Views; -using Jailbreak.Public.Behaviors; -using Jailbreak.Public.Extensions; -using Jailbreak.Public.Mod.Damage; -using Jailbreak.Public.Mod.Rebel; -using Jailbreak.Public.Mod.SpecialDays; - -namespace Jailbreak.SpecialDay; - -public class SpecialDayHandler(SpecialDayConfig config, IJihadC4Service jihadC4Service) : ISpecialDayHandler, IPluginBehavior -{ - private int _roundsSinceLastSpecialDay = 0; - private bool _isSpecialDayActive = false; - private int _roundStartTime = 0; - private ISpecialDay? _currentSpecialDay = null; - private BasePlugin _plugin; - - public void Start(BasePlugin plugin) - { - plugin.RegisterEventHandler(OnRoundEnd); - plugin.RegisterEventHandler(OnRoundStart); - plugin.RegisterEventHandler(DamageHandler); - _plugin = plugin; - } - - [GameEventHandler] - private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) - { - if (!_isSpecialDayActive && _currentSpecialDay == null) return HookResult.Continue; - - _isSpecialDayActive = false; - _currentSpecialDay?.OnEnd(); - - _currentSpecialDay = null; - _roundsSinceLastSpecialDay = 0; - - return HookResult.Continue; - } - - [GameEventHandler(HookMode.Pre)] - private HookResult DamageHandler(EventPlayerHurt @event, GameEventInfo info) - { - if (_currentSpecialDay == null) - { - return HookResult.Continue; - } - if (_currentSpecialDay is IBlockUserDamage damageHandler) - { - return damageHandler.BlockUserDamage(@event, info); - } - return HookResult.Continue; - } - - [GameEventHandler] - private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) - { - _roundStartTime = (int)Math.Round(Server.CurrentTime); - if (ServerExtensions.GetGameRules().WarmupPeriod) - return HookResult.Continue; - _roundsSinceLastSpecialDay++; - return HookResult.Continue; - } - - public int RoundsSinceLastSpecialDay() - { - return _roundsSinceLastSpecialDay; - } - - public bool CanStartSpecialDay() - { - return RoundsSinceLastSpecialDay() >= config.MinRoundsBeforeSpecialDay && ((int)Math.Round(Server.CurrentTime - _roundStartTime)) <= config.MaxRoundSecondsBeforeSpecialDay; - } - - public bool IsSpecialDayActive() - { - return _isSpecialDayActive; - } - - public bool StartSpecialDay(string name, ISpecialDayNotifications _notifications) - { - if (_isSpecialDayActive || !CanStartSpecialDay()) return false; - - var fullName = "Jailbreak.SpecialDay.SpecialDays"; - var q = from t in Assembly.GetExecutingAssembly().GetTypes() - where t.IsClass && t.Namespace == fullName && t.GetInterface("ISpecialDay") != null - select t; - - foreach (var type in q) - { - if (type == null) continue; - var item = (ISpecialDay)Activator.CreateInstance(type, _plugin, _notifications); - if (item == null) continue; - if (item.Name != name) continue; - - if (!item.ShouldJihadC4BeEnabled) - { - jihadC4Service.ClearActiveC4s(); - } - - _currentSpecialDay = item; - _isSpecialDayActive = true; - _currentSpecialDay.OnStart(); - break; - } - - //Server.NextFrame(() => Server.PrintToChatAll($"{_currentSpecialDay?.Name} has started - {_currentSpecialDay?.Description}")); - return true; - } -} \ No newline at end of file diff --git a/mod/Jailbreak.SpecialDay/SpecialDayMenu.cs b/mod/Jailbreak.SpecialDay/SpecialDayMenu.cs deleted file mode 100644 index 19186d53..00000000 --- a/mod/Jailbreak.SpecialDay/SpecialDayMenu.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Reflection; -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Menu; -using Jailbreak.Formatting.Views; -using Jailbreak.Public.Behaviors; -using Jailbreak.Public.Mod.SpecialDays; - -namespace Jailbreak.SpecialDay; - -public class SpecialDayMenu : ISpecialDayMenu, IPluginBehavior -{ - private BaseMenu _menu; - private readonly ISpecialDayHandler _handler; - private BasePlugin _plugin; - private readonly ISpecialDayNotifications _notifications; - - public SpecialDayMenu(ISpecialDayHandler handler, ISpecialDayNotifications notifications) - { - _notifications = notifications; - _handler = handler; - } - - public void Start(BasePlugin plugin) { - _menu = new CenterHtmlMenu("Special Days", plugin); - _plugin = plugin; - AddSpecialDays(); - } - private void AddSpecialDays() - { - var fullName = "Jailbreak.SpecialDay.SpecialDays"; - var types = from type in Assembly.GetExecutingAssembly().GetTypes() - where type.IsClass && type.Namespace == fullName && type.GetInterface("ISpecialDay") != null - select type; - - foreach (var type in types) - { - if (type == null) return; - var item = (ISpecialDay?) Activator.CreateInstance(type, _plugin, _notifications); - if (item == null) return; - AddSpecialDay(item); - } - } - - private void AddSpecialDay(ISpecialDay specialDay) - { - _menu.AddMenuOption(specialDay.Name, (player, _menu) => - { - _handler.StartSpecialDay(specialDay.Name, _notifications); - MenuManager.CloseActiveMenu(player); - }); - } - - public void OpenMenu(CCSPlayerController player) - { - _menu.Open(player); - } -} \ No newline at end of file diff --git a/mod/Jailbreak.SpecialDay/SpecialDayServiceExtension.cs b/mod/Jailbreak.SpecialDay/SpecialDayServiceExtension.cs deleted file mode 100644 index 34e03b95..00000000 --- a/mod/Jailbreak.SpecialDay/SpecialDayServiceExtension.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Jailbreak.Public.Extensions; -using Jailbreak.Public.Mod.SpecialDays; -using Jailbreak.Public.Mod.Warden; -using Microsoft.Extensions.DependencyInjection; -using Jailbreak.SpecialDay.Commands; - -namespace Jailbreak.SpecialDay; - -public static class SpecialDayServiceExtension -{ - public static void AddSpecialDays(this IServiceCollection serviceCollection) - { - serviceCollection.AddConfig("SpecialDay"); - serviceCollection.AddPluginBehavior(); - serviceCollection.AddPluginBehavior(); - serviceCollection.AddPluginBehavior(); - } -} diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/CustomDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/CustomDay.cs deleted file mode 100644 index 8876930c..00000000 --- a/mod/Jailbreak.SpecialDay/SpecialDays/CustomDay.cs +++ /dev/null @@ -1,43 +0,0 @@ -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Utils; -using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; -using Jailbreak.Public.Extensions; -using Jailbreak.Public.Mod.SpecialDays; -using Jailbreak.Public.Utils; - -namespace Jailbreak.SpecialDay.SpecialDays; - -public class CustomDay : ISpecialDay -{ - - public string Name => "Freeday"; - public string Description => "All prisoners and guards are allowed to roam freely."; - public bool ShouldJihadC4BeEnabled => true; - - private readonly ISpecialDayNotifications _notifications; - - public CustomDay(BasePlugin plugin, ISpecialDayNotifications notifications) - { - _notifications = notifications; - } - - public void OnStart() - { - _notifications.SD_CUSTOM_STARTED - .ToAllChat() - .ToAllCenter(); - - foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal())) - { - if (player.Team == CsTeam.Terrorist) FreezeManager.FreezePlayer(player, 10); - } - } - - - public void OnEnd() - { - //do nothing for now - } -} \ No newline at end of file diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/FreeForAllDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/FreeForAllDay.cs deleted file mode 100644 index a1207592..00000000 --- a/mod/Jailbreak.SpecialDay/SpecialDays/FreeForAllDay.cs +++ /dev/null @@ -1,116 +0,0 @@ -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Cvars; -using CounterStrikeSharp.API.Modules.Timers; -using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; -using Jailbreak.Public.Extensions; -using Jailbreak.Public.Mod.Damage; -using Jailbreak.Public.Mod.SpecialDays; -using Jailbreak.Public.Utils; -using Timer = CounterStrikeSharp.API.Modules.Timers.Timer; - -namespace Jailbreak.SpecialDay.SpecialDays; - -public class FreeForAllDay : ISpecialDay, IBlockUserDamage -{ - public string Name => "Free For All"; - public string Description => "Everyone for themselves. Your goal is to be the last man standing!"; - public bool ShouldJihadC4BeEnabled => false; - - private int timer = 0; - private Timer? timer1; - private BasePlugin _plugin; - private bool _hasStarted = true; - private readonly ISpecialDayNotifications _notifications; - - public FreeForAllDay(BasePlugin plugin, ISpecialDayNotifications notifications) - { - _notifications = notifications; - _plugin = plugin; - } - - public bool ShouldBlockDamage(CCSPlayerController player, CCSPlayerController? attacker, EventPlayerHurt @event) - { - if (_hasStarted) - { - return false; - } - return true; - } - - public void OnStart() - { - _notifications.SD_FFA_STARTING - .ToAllChat() - .ToAllCenter(); - var spawn = Utilities.FindAllEntitiesByDesignerName("info_player_counterterrorist").ToList(); - - foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal())) - { - var max = spawn.Count; - - var index = new Random().Next(0, max); - - player.PlayerPawn.Value!.Teleport(spawn[index].AbsOrigin); - FreezeManager.FreezePlayer(player, 3); - } - - var friendlyFire = ConVar.Find("mp_friendlyfire"); - var teammates = ConVar.Find("mp_teammates_are_enemies"); - - if (friendlyFire == null) return; - - var friendlyFireValue = friendlyFire.GetPrimitiveValue(); //assume false in this example, use GetNativeValue for vectors, Qangles, etc - - if (!friendlyFireValue) - { - friendlyFire.SetValue(true); - } - - if (teammates == null) return; - - teammates.SetValue(true); - - _hasStarted = false; - AddTimers(); - } - - private void AddTimers() - { - timer1 = _plugin.AddTimer(1f, () => - { - timer++; - - if (timer != 30) return; - - _notifications.SD_FFA_STARTED - .ToAllChat() - .ToAllCenter(); - _hasStarted = true; - timer1.Kill(); - }, TimerFlags.REPEAT); - - } - - public void OnEnd() - { - - var friendlyFire = ConVar.Find("mp_friendlyfire"); - var teammates = ConVar.Find("mp_teammates_are_enemies"); - - if (friendlyFire == null) return; - - var friendlyFireValue = friendlyFire.GetPrimitiveValue(); //assume false in this example, use GetNativeValue for vectors, Qangles, etc - - if (friendlyFireValue) - { - friendlyFire?.SetValue(false); - } - - teammates?.SetValue(false); - - } - -} diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/Freeday.cs b/mod/Jailbreak.SpecialDay/SpecialDays/Freeday.cs deleted file mode 100644 index bf64e26f..00000000 --- a/mod/Jailbreak.SpecialDay/SpecialDays/Freeday.cs +++ /dev/null @@ -1,52 +0,0 @@ -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Core; -using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; -using Jailbreak.Public.Mod.SpecialDays; - -namespace Jailbreak.SpecialDay.SpecialDays; - -public class Freeday : ISpecialDay -{ - public string Name => "Freeday"; - public string Description => "All prisoners and guards are allowed to roam freely."; - public bool ShouldJihadC4BeEnabled => true; - private readonly ISpecialDayNotifications _notifications; - - public Freeday(BasePlugin plugin, ISpecialDayNotifications notifications) - { - _notifications = notifications; - } - - public void OnStart() - { - _notifications.SD_FREEDAY_STARTED - .ToAllChat() - .ToAllCenter(); - - ForceEntInput("func_door","Open"); - ForceEntInput("func_door_rotating","Open"); - ForceEntInput("prop_door_rotating","Open"); - } - - private static void ForceEntInput(String name, String input) - { - // search for door entitys and open all of them! - var target = Utilities.FindAllEntitiesByDesignerName(name); - - foreach(var ent in target) - { - if(!ent.IsValid) - { - continue; - } - - ent.AcceptInput(input); - } - } - - public void OnEnd() - { - //do nothing for now - } -} \ No newline at end of file diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/Warday.cs b/mod/Jailbreak.SpecialDay/SpecialDays/Warday.cs deleted file mode 100644 index a15e352d..00000000 --- a/mod/Jailbreak.SpecialDay/SpecialDays/Warday.cs +++ /dev/null @@ -1,76 +0,0 @@ -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Timers; -using CounterStrikeSharp.API.Modules.Utils; -using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; -using Jailbreak.Public.Extensions; -using Jailbreak.Public.Mod.Damage; -using Jailbreak.Public.Mod.SpecialDays; -using Jailbreak.Public.Utils; -using Timer = CounterStrikeSharp.API.Modules.Timers.Timer; - -namespace Jailbreak.SpecialDay.SpecialDays; - -public class Warday : ISpecialDay, IBlockUserDamage -{ - public string Name => "Warday"; - public string Description => $" {ChatColors.Red}[Warday] {ChatColors.Blue} Guards versus Prisoners. Your goal is to ensure that your team is last team standing!"; - public bool ShouldJihadC4BeEnabled => false; - private int timer = 0; - private Timer timer1; - private BasePlugin _plugin; - private bool _hasStarted = true; - private readonly ISpecialDayNotifications _notifications; - - public Warday(BasePlugin plugin, ISpecialDayNotifications notifications) - { - _notifications = notifications; - _plugin = plugin; - } - - public bool ShouldBlockDamage(CCSPlayerController player, CCSPlayerController? attacker, EventPlayerHurt @event) - { - if (_hasStarted) - { - return false; - } - return true; - } - - public void OnStart() - { - _notifications.SD_WARDAY_STARTED - .ToAllChat() - .ToAllCenter(); - var spawn = Utilities.FindAllEntitiesByDesignerName("info_player_counterterrorist").First(); - - foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal())) - { - player.PlayerPawn.Value!.Teleport(spawn.AbsOrigin); - if (player.Team == CsTeam.Terrorist) FreezeManager.FreezePlayer(player, 30); - } - _hasStarted = false; - AddTimers(); - } - - private void AddTimers() - { - timer1 = _plugin.AddTimer(1f, () => - { - timer++; - - if (timer != 30) return; - _hasStarted = true; - timer1.Kill(); - }, TimerFlags.REPEAT); - - } - - public void OnEnd() - { - //do nothing for now - } - -} \ No newline at end of file diff --git a/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs index 72a44641..064d0847 100644 --- a/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs @@ -2,11 +2,13 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Warden; using Microsoft.Extensions.DependencyInjection; @@ -59,6 +61,48 @@ public void Command_Pass(CCSPlayerController? player, CommandInfo command) _lastPassCommand[player] = DateTime.Now; } + [ConsoleCommand("css_fire", "Force the warden to pass")] + [CommandHelper(0, "", CommandUsage.CLIENT_ONLY)] + public void Command_Fire(CCSPlayerController? player, CommandInfo command) + { + if (player == null) + return; + + if (!_warden.HasWarden || _warden.Warden == null) + { + _notifications.CURRENT_WARDEN(null).ToPlayerChat(player); + return; + } + + if (!AdminManager.PlayerHasPermissions(player, "@css/ban")) + { + _generics.NoPermissionMessage("@css/ban").ToPlayerChat(player); + return; + } + + foreach (var client in Utilities.GetPlayers().Where(p => p.IsReal())) + { + if (AdminManager.PlayerHasPermissions(client, "@css/chat")) + { + _notifications.FIRE_WARDEN(_warden.Warden, player).ToPlayerChat(client); + } + else + { + _notifications.FIRE_WARDEN(_warden.Warden).ToPlayerChat(client); + } + + client.ExecuteClientCommand( + $"play sounds/{_config.WardenPassedSoundName}"); + } + + _notifications.BECOME_NEXT_WARDEN.ToAllChat(); + + _lastPassCommand[_warden.Warden] = DateTime.Now; + + if (!_warden.TryRemoveWarden(true)) + Server.PrintToChatAll("[BUG] Couldn't remove warden :^("); + } + [ConsoleCommand("css_warden", "Become a warden, Join the warden queue, or see information about the current warden.")] [ConsoleCommand("css_w", "Become a warden, Join the warden queue, or see information about the current warden.")] diff --git a/mod/Jailbreak.Warden/WardenServiceExtension.cs b/mod/Jailbreak.Warden/WardenServiceExtension.cs index af619dc8..e78d67ad 100644 --- a/mod/Jailbreak.Warden/WardenServiceExtension.cs +++ b/mod/Jailbreak.Warden/WardenServiceExtension.cs @@ -25,7 +25,6 @@ public static void AddJailbreakWarden(this IServiceCollection serviceCollection) serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); - serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); } diff --git a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs index 811b92e4..a12c066c 100644 --- a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs +++ b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs @@ -62,4 +62,8 @@ public void WithMute() public void WithRaceLR() where TRaceLR : class, ILanguage, IRaceLRMessages => _collection.AddSingleton(); + + public void WithLastGuard() + where TLastGuard : class, ILanguage, ILastGuardNotifications + => _collection.AddSingleton(); } diff --git a/public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs b/public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs index a91532dc..08b4670f 100644 --- a/public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs +++ b/public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs @@ -8,4 +8,5 @@ public interface IGenericCommandNotifications public IView PlayerFoundMultiple(string query); public IView CommandOnCooldown(DateTime cooldownEndsAt); public IView InvalidParameter(string parameter, string expected); + public IView NoPermissionMessage(string permission); } \ No newline at end of file diff --git a/public/Jailbreak.Formatting/Views/ILastGuardNotifications.cs b/public/Jailbreak.Formatting/Views/ILastGuardNotifications.cs new file mode 100644 index 00000000..c58b45ee --- /dev/null +++ b/public/Jailbreak.Formatting/Views/ILastGuardNotifications.cs @@ -0,0 +1,9 @@ +using Jailbreak.Formatting.Base; + +namespace Jailbreak.Formatting.Views; + +public interface ILastGuardNotifications +{ + public IView LG_STARTED(int ctHealth, int tHealth); + +} \ No newline at end of file diff --git a/public/Jailbreak.Formatting/Views/IWardenNotifications.cs b/public/Jailbreak.Formatting/Views/IWardenNotifications.cs index 0b837890..55d5224e 100644 --- a/public/Jailbreak.Formatting/Views/IWardenNotifications.cs +++ b/public/Jailbreak.Formatting/Views/IWardenNotifications.cs @@ -38,4 +38,7 @@ public interface IWardenNotifications /// public IView CURRENT_WARDEN(CCSPlayerController? player); public IView FIRE_COMMAND_SUCCESS(CCSPlayerController player); + + public IView FIRE_WARDEN(CCSPlayerController player); + public IView FIRE_WARDEN(CCSPlayerController player, CCSPlayerController admin); } diff --git a/public/Jailbreak.Public/Mod/LastGuard/ILastGuardService.cs b/public/Jailbreak.Public/Mod/LastGuard/ILastGuardService.cs new file mode 100644 index 00000000..746155db --- /dev/null +++ b/public/Jailbreak.Public/Mod/LastGuard/ILastGuardService.cs @@ -0,0 +1,9 @@ +using CounterStrikeSharp.API.Core; + +namespace Jailbreak.Public.Mod.LastGuard; + +public interface ILastGuardService +{ + int CalculateHealth(); + void StartLastGuard(CCSPlayerController lastGuard); +} \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDay.cs b/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDay.cs deleted file mode 100644 index 10e0122e..00000000 --- a/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDay.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Jailbreak.Public.Mod.SpecialDays; - -public interface ISpecialDay -{ - string Name { get; } - string Description { get; } - void OnStart(); - void OnEnd(); - bool ShouldJihadC4BeEnabled { get; } -} \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDayHandler.cs b/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDayHandler.cs deleted file mode 100644 index 291cf4ab..00000000 --- a/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDayHandler.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Jailbreak.Public.Mod.SpecialDays; - -public interface ISpecialDayHandler -{ - int RoundsSinceLastSpecialDay(); - bool CanStartSpecialDay(); - bool IsSpecialDayActive(); - bool StartSpecialDay(string name,T a); -} \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDayMenu.cs b/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDayMenu.cs deleted file mode 100644 index e68fb299..00000000 --- a/public/Jailbreak.Public/Mod/SpecialDays/ISpecialDayMenu.cs +++ /dev/null @@ -1,8 +0,0 @@ -using CounterStrikeSharp.API.Core; - -namespace Jailbreak.Public.Mod.SpecialDays; - -public interface ISpecialDayMenu -{ - void OpenMenu(CCSPlayerController warden); -} \ No newline at end of file diff --git a/src/Jailbreak/Jailbreak.csproj b/src/Jailbreak/Jailbreak.csproj index 09630742..37a221bf 100644 --- a/src/Jailbreak/Jailbreak.csproj +++ b/src/Jailbreak/Jailbreak.csproj @@ -60,8 +60,8 @@ - - + + diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 979d5abc..5f7ebbbe 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -4,20 +4,20 @@ using Jailbreak.Config; using Jailbreak.Debug; using Jailbreak.English.Generic; +using Jailbreak.English.LastGuard; using Jailbreak.English.LastRequest; using Jailbreak.English.Logs; using Jailbreak.English.Mute; using Jailbreak.English.Rebel; -using Jailbreak.English.SpecialDay; using Jailbreak.English.Warden; using Jailbreak.Formatting.Logistics; using Jailbreak.Generic; +using Jailbreak.LastGuard; using Jailbreak.LastRequest; using Jailbreak.Logs; using Jailbreak.Mute; using Jailbreak.Public.Configuration; using Jailbreak.Rebel; -using Jailbreak.SpecialDay; using Jailbreak.Warden; using Microsoft.Extensions.DependencyInjection; @@ -34,7 +34,6 @@ public void ConfigureServices(IServiceCollection serviceCollection) // Do we want to make this scoped? // Not sure how this will behave with multiple rounds and whatnot. serviceCollection.AddTransient(); - serviceCollection.AddSpecialDays(); serviceCollection.AddJailbreakGeneric(); serviceCollection.AddJailbreakLogs(); serviceCollection.AddJailbreakRebel(); @@ -42,6 +41,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) serviceCollection.AddJailbreakWarden(); serviceCollection.AddJailbreakDebug(); serviceCollection.AddJailbreakLastRequest(); + serviceCollection.AddJailbreakLastGuard(); // Add in english localization serviceCollection.AddLanguage(config => @@ -52,11 +52,11 @@ public void ConfigureServices(IServiceCollection serviceCollection) config.WithLogging(); config.WithRollCommand(); config.WithJihadC4(); - config.WithSpecialDay(); config.WithLastRequest(); config.WithSpecialTreatment(); config.WithMute(); config.WithRaceLR(); + config.WithLastGuard(); }); } }