diff --git a/lang/Jailbreak.English/SpecialDay/GunDayLocale.cs b/lang/Jailbreak.English/SpecialDay/GunDayLocale.cs index 0359f306..3b3ed110 100644 --- a/lang/Jailbreak.English/SpecialDay/GunDayLocale.cs +++ b/lang/Jailbreak.English/SpecialDay/GunDayLocale.cs @@ -1,8 +1,8 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Base; -using Jailbreak.Formatting.Objects; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; namespace Jailbreak.English.SpecialDay; @@ -21,27 +21,28 @@ public IView PromotedTo(string weapon, int weaponsLeft) { if (weaponsLeft == 1) return new SimpleView { PREFIX, - $"You were promoted to", + "You were promoted to", weapon + ".", ChatColors.Green + "LAST WEAPON!" }; return new SimpleView { PREFIX, - $"You were promoted to", + "You were promoted to", weapon + ".", weaponsLeft, "weapons left." }; } - public IView PlayerOnLastPromotion(CCSPlayerController player) - => new SimpleView { + public IView PlayerOnLastPromotion(CCSPlayerController player) { + return new SimpleView { PREFIX, player, "is on their last weapon!", ChatColors.LightRed + "Watch out!" }; + } public IView PlayerWon(CCSPlayerController player) { var view = new SimpleView { PREFIX, player, "won the game!" }; diff --git a/lang/Jailbreak.English/SpecialDay/SDLocale.cs b/lang/Jailbreak.English/SpecialDay/SDLocale.cs index 14e9a271..fc471098 100644 --- a/lang/Jailbreak.English/SpecialDay/SDLocale.cs +++ b/lang/Jailbreak.English/SpecialDay/SDLocale.cs @@ -4,6 +4,7 @@ using Jailbreak.Formatting.Logistics; using Jailbreak.Formatting.Objects; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; namespace Jailbreak.English.SpecialDay; diff --git a/lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs b/lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs index fdcc0f0a..23b785ff 100644 --- a/lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs +++ b/lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs @@ -1,5 +1,6 @@ using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Utils; namespace Jailbreak.English.SpecialDay; diff --git a/lang/Jailbreak.English/SpecialDay/SpeedrunDayLocale.cs b/lang/Jailbreak.English/SpecialDay/SpeedrunDayLocale.cs index b15ed2e8..3e43777c 100644 --- a/lang/Jailbreak.English/SpecialDay/SpeedrunDayLocale.cs +++ b/lang/Jailbreak.English/SpecialDay/SpeedrunDayLocale.cs @@ -2,6 +2,7 @@ using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; namespace Jailbreak.English.SpecialDay; diff --git a/lang/Jailbreak.English/SpecialDay/TeamDayLocale.cs b/lang/Jailbreak.English/SpecialDay/TeamDayLocale.cs index d1b88e7d..d4c31aeb 100644 --- a/lang/Jailbreak.English/SpecialDay/TeamDayLocale.cs +++ b/lang/Jailbreak.English/SpecialDay/TeamDayLocale.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Utils; namespace Jailbreak.English.SpecialDay; diff --git a/mod/Jailbreak.Debug/Subcommands/DebugCenterHud.cs b/mod/Jailbreak.Debug/Subcommands/DebugCenterHud.cs index a2d4d980..2e9eb67a 100644 --- a/mod/Jailbreak.Debug/Subcommands/DebugCenterHud.cs +++ b/mod/Jailbreak.Debug/Subcommands/DebugCenterHud.cs @@ -7,12 +7,16 @@ public class DebugCenterHud(IServiceProvider services) : AbstractCommand(services) { public override void OnCommand(CCSPlayerController? executor, WrappedInfo info) { - ServerExtensions.GetGameRules().GameRestart = - !ServerExtensions.GetGameRules().GameRestart; + var rules = ServerExtensions.GetGameRules(); + if (rules == null) { + info.ReplyToCommand("Failed to get GameRules."); + return; + } + + rules.GameRestart = !rules.GameRestart; if (info.ArgCount == 1) - info.ReplyToCommand( - $"Set Center HUD to {ServerExtensions.GetGameRules().GameRestart}"); + info.ReplyToCommand($"Set Center HUD to {rules.GameRestart}"); executor?.PrintToCenterHtml("This is a test message", 100); } diff --git a/mod/Jailbreak.Debug/Subcommands/DebugZone.cs b/mod/Jailbreak.Debug/Subcommands/DebugZone.cs index 30bd31df..0718065d 100644 --- a/mod/Jailbreak.Debug/Subcommands/DebugZone.cs +++ b/mod/Jailbreak.Debug/Subcommands/DebugZone.cs @@ -178,12 +178,10 @@ await zoneManager.PushZoneWithID(innerZone, innerPair.Value.Item2, .GetResult(); var toRemove = new List(); - foreach (var spawn in spawns) { + foreach (var spawn in spawns) if (doNotTeleport.Any(d - => d.IsInsideZone(spawn.CalculateCenterPoint()))) { + => d.IsInsideZone(spawn.CalculateCenterPoint()))) toRemove.Add(spawn); - } - } info.ReplyToCommand("Removing " + toRemove.Count + " auto-generated zones"); diff --git a/mod/Jailbreak.LastGuard/LastGuard.cs b/mod/Jailbreak.LastGuard/LastGuard.cs index eb99329d..f9d45ad3 100644 --- a/mod/Jailbreak.LastGuard/LastGuard.cs +++ b/mod/Jailbreak.LastGuard/LastGuard.cs @@ -61,18 +61,6 @@ public class LastGuard(ILGLocale notifications, ILastRequestManager lrManager) private bool isLastGuard; private List lastGuardPrisoners = []; - public int CalculateHealth() { - var aliveTerrorists = Utilities.GetPlayers() - .Where(plr => plr is { PawnIsAlive: true, Team: CsTeam.Terrorist }) - .ToList(); - - return (int)Math.Floor(aliveTerrorists - .Select(player => player.PlayerPawn.Value?.Health ?? 0) - .Select(playerHealth - => Math.Min(playerHealth, CvMaxTHealthContribution.Value)) - .Sum() * CvGuardHealthRatio.Value); - } - public void StartLastGuard(CCSPlayerController lastGuard) { var guardPlayerPawn = lastGuard.PlayerPawn.Value; @@ -121,6 +109,18 @@ public void StartLastGuard(CCSPlayerController lastGuard) { public void DisableLastGuardForRound() { canStart = false; } + public int CalculateHealth() { + var aliveTerrorists = Utilities.GetPlayers() + .Where(plr => plr is { PawnIsAlive: true, Team: CsTeam.Terrorist }) + .ToList(); + + return (int)Math.Floor(aliveTerrorists + .Select(player => player.PlayerPawn.Value?.Health ?? 0) + .Select(playerHealth + => Math.Min(playerHealth, CvMaxTHealthContribution.Value)) + .Sum() * CvGuardHealthRatio.Value); + } + [GameEventHandler] public HookResult OnPlayerDeathEvent(EventPlayerDeath @event, GameEventInfo info) { diff --git a/mod/Jailbreak.LastRequest/LastRequestManager.cs b/mod/Jailbreak.LastRequest/LastRequestManager.cs index 689f5285..f7f0c9a9 100644 --- a/mod/Jailbreak.LastRequest/LastRequestManager.cs +++ b/mod/Jailbreak.LastRequest/LastRequestManager.cs @@ -187,7 +187,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { if (!IsLREnabledForRound) return HookResult.Continue; - if (player.GetTeam() != CsTeam.Terrorist) return HookResult.Continue; + if (player.Team != CsTeam.Terrorist) return HookResult.Continue; if (countAlivePrisoners() - 1 > CvPrisonerToLR.Value) return HookResult.Continue; @@ -221,7 +221,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, if (!IsLREnabledForRound) return HookResult.Continue; - if (player.GetTeam() != CsTeam.Terrorist) return HookResult.Continue; + if (player.Team != CsTeam.Terrorist) return HookResult.Continue; if (countAlivePrisoners() > CvPrisonerToLR.Value) return HookResult.Continue; @@ -236,6 +236,6 @@ private int countAlivePrisoners() { private bool prisonerCountsToLR(CCSPlayerController player) { if (!player.IsReal()) return false; if (!player.PawnIsAlive) return false; - return player.GetTeam() == CsTeam.Terrorist; + return player.Team == CsTeam.Terrorist; } } \ No newline at end of file diff --git a/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs b/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs index bfbf31a5..d6c6888e 100644 --- a/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs +++ b/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs @@ -17,10 +17,6 @@ public class BulletForBullet : TeleportingRequest { "weapon_nova" ]; - private static readonly string[] GUN_NAMES = [ - "Desert Eagle", "USPS", "Tec9", "Scout", "Nova" - ]; - private readonly ChatMenu chatMenu; private readonly bool magForMag; private readonly ILRB4BLocale msg; @@ -43,7 +39,7 @@ public BulletForBullet(BasePlugin plugin, IServiceProvider provider, public override LRType Type => magForMag ? LRType.MAG_FOR_MAG : LRType.SHOT_FOR_SHOT; - private void OnSelect(CCSPlayerController player, ChatMenuOption option, + private void OnSelect(CCSPlayerController player, ChatMenuOption _, string designer) { if (player.Slot != Prisoner.Slot) return; designerName = designer; diff --git a/mod/Jailbreak.Logs/Tags/PlayerTagHelper.cs b/mod/Jailbreak.Logs/Tags/PlayerTagHelper.cs index 82afcc2e..a2e0167a 100644 --- a/mod/Jailbreak.Logs/Tags/PlayerTagHelper.cs +++ b/mod/Jailbreak.Logs/Tags/PlayerTagHelper.cs @@ -3,7 +3,6 @@ using Jailbreak.Formatting.Core; using Jailbreak.Formatting.Objects; using Jailbreak.Formatting.Views.Logging; -using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Rebel; using Jailbreak.Public.Mod.Warden; using Microsoft.Extensions.DependencyInjection; @@ -25,7 +24,7 @@ public class PlayerTagHelper(IServiceProvider provider) : IRichPlayerTag { public FormatObject Rich(CCSPlayerController player) { if (wardenService.Value != null && wardenService.Value.IsWarden(player)) return new StringFormatObject("(WARDEN)", ChatColors.DarkBlue); - if (player.GetTeam() == CsTeam.CounterTerrorist) + if (player.Team == CsTeam.CounterTerrorist) return new StringFormatObject("(CT)", ChatColors.BlueGrey); if (rebelService.Value != null && rebelService.Value.IsRebel(player)) return new StringFormatObject("(REBEL)", ChatColors.DarkRed); diff --git a/mod/Jailbreak.Rebel/RebelListener.cs b/mod/Jailbreak.Rebel/RebelListener.cs index 2bedd3ab..f3b6326b 100644 --- a/mod/Jailbreak.Rebel/RebelListener.cs +++ b/mod/Jailbreak.Rebel/RebelListener.cs @@ -14,12 +14,12 @@ public class RebelListener(IRebelService rebelService, public HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) { var player = @event.Userid; if (player == null || !player.IsReal()) return HookResult.Continue; - if (player.GetTeam() != CsTeam.CounterTerrorist) return HookResult.Continue; + if (player.Team != CsTeam.CounterTerrorist) return HookResult.Continue; var attacker = @event.Attacker; if (attacker == null || !attacker.IsReal()) return HookResult.Continue; - if (attacker.GetTeam() != CsTeam.Terrorist) return HookResult.Continue; + if (attacker.Team != CsTeam.Terrorist) return HookResult.Continue; if (lastRequestManager.IsInLR(attacker)) return HookResult.Continue; diff --git a/mod/Jailbreak.SpecialDay/SpecialDayCommand.cs b/mod/Jailbreak.SpecialDay/SpecialDayCommand.cs index 8b576523..c57acc7d 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDayCommand.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDayCommand.cs @@ -7,6 +7,7 @@ using CounterStrikeSharp.API.Modules.Menu; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.SpecialDay; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/CustomDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/CustomDay.cs index 1fea9ac4..85f7e8a5 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/CustomDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/CustomDay.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API.Core; using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/FFADay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/FFADay.cs index b5f06b79..f2024996 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/FFADay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/FFADay.cs @@ -2,6 +2,7 @@ using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs index badce20f..2ff928db 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs @@ -1,59 +1,58 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +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 Microsoft.VisualBasic.CompilerServices; namespace Jailbreak.SpecialDay.SpecialDays; public class GunGameDay(BasePlugin plugin, IServiceProvider provider) : AbstractSpecialDay(plugin, provider), ISpecialDayMessageProvider { - private readonly IList weaponProgression = []; + private readonly IList BAD = [ + "weapon_deagle", "weapon_elite", "weapon_fiveseven", "weapon_glock", + "weapon_hkp2000", "weapon_p250", "weapon_usp_silencer", "weapon_tec9", + "weapon_cz75a", "weapon_revolver" + ]; private readonly IList BEST = [ "weapon_awp", "weapon_scar20", "weapon_g3sg1" ]; - private readonly IList GREAT = [ - "weapon_ak47", "weapon_m4a1", "weapon_m4a1_silencer", - ]; - private readonly IList GOOD = [ "weapon_bizon", "weapon_mac10", "weapon_mp5sd", "weapon_mp7", "weapon_mp9", "weapon_p90", "weapon_ump45", "weapon_negev" ]; + private readonly IList GREAT = [ + "weapon_ak47", "weapon_m4a1", "weapon_m4a1_silencer" + ]; + + private readonly IList LAST = ["weapon_knife", "weapon_taser"]; + private readonly IList OKAY = [ "weapon_mag7", "weapon_nova", "weapon_sawedoff", "weapon_xm1014", "weapon_ssg08" ]; - private readonly IList BAD = [ - "weapon_deagle", "weapon_elite", "weapon_fiveseven", "weapon_glock", - "weapon_hkp2000", "weapon_p250", "weapon_usp_silencer", "weapon_tec9", - "weapon_cz75a", "weapon_revolver" - ]; - - private readonly IList LAST = ["weapon_knife", "weapon_taser"]; - private readonly IDictionary progressions = new Dictionary(); - private ShuffleBag? spawns; + private readonly IList weaponProgression = []; - public ISDInstanceLocale Locale => new GunDayLocale(); + private ShuffleBag? spawns; public override SDType Type => SDType.GUNGAME; public override SpecialDaySettings Settings => new GunGameSettings(); private IGunDayLocale msg => (IGunDayLocale)Locale; + public ISDInstanceLocale Locale => new GunDayLocale(); + public override void Setup() { Timers[5] += () => Locale.BeginsIn(5).ToAllChat(); Timers[10] += Execute; @@ -100,8 +99,10 @@ private HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) { if (player == null || !player.IsValid) return HookResult.Continue; if (!progressions.TryGetValue(player.Slot, out var index)) index = 0; Plugin.AddTimer(0.1f, () => { + if (!player.IsValid || player.Pawn.Value == null || !player.Pawn.IsValid) + return; player.GiveNamedItem(weaponProgression[index]); - if (spawns != null) player.Teleport(spawns.GetNext()); + if (spawns != null) player.Pawn.Value.Teleport(spawns.GetNext()); }); return HookResult.Continue; } @@ -115,11 +116,10 @@ private HookResult OnDeath(EventPlayerDeath @event, GameEventInfo info) { if (!progressions.TryGetValue(player.Slot, out playerIndex)) playerIndex = 0; if (attacker == null || !attacker.IsValid) { - if (playerIndex > 0) { - playerIndex--; - msg.DemotedDueToSuicide.ToChat(player); - progressions[player.Slot] = playerIndex; - } + if (playerIndex <= 0) return HookResult.Continue; + playerIndex--; + msg.DemotedDueToSuicide.ToChat(player); + progressions[player.Slot] = playerIndex; return HookResult.Continue; } @@ -137,6 +137,7 @@ private HookResult OnDeath(EventPlayerDeath @event, GameEventInfo info) { p.RemoveWeapons(); } + attacker.SetSpeed(2f); attacker.RemoveWeapons(); attacker.GiveNamedItem("weapon_negev"); attacker.GiveNamedItem("weapon_knife"); @@ -145,22 +146,22 @@ private HookResult OnDeath(EventPlayerDeath @event, GameEventInfo info) { Server.ExecuteCommand("mp_respawn_on_death_t 0"); Server.ExecuteCommand("mp_respawn_on_death_ct 0"); + RoundUtil.SetTimeRemaining(Math.Min(RoundUtil.GetTimeRemaining(), 30)); + Plugin.DeregisterEventHandler(OnDeath, HookMode.Pre); return HookResult.Continue; } - + attackerProgress += 1; if (@event.Weapon.Contains("knife")) { - progressions[attacker.Slot] = Math.Min(attackerProgress + 2, - weaponProgression.Count - 1); - msg.DemotedDueToSuicide.ToChat(player); + attackerProgress += 1; + msg.DemotedDueToKnife.ToChat(player); progressions[player.Slot] = Math.Max(playerIndex - 1, 0); - } else { - progressions[attacker.Slot] = Math.Min(attackerProgress + 1, - weaponProgression.Count - 1); } - attackerProgress = attackerProgress + 1; + attackerProgress = Math.Min(attackerProgress, weaponProgression.Count - 1); + + progressions[attacker.Slot] = attackerProgress; if (attackerProgress == weaponProgression.Count - 1) msg.PlayerOnLastPromotion(attacker).ToAllChat(); diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/HideAndSeekDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/HideAndSeekDay.cs index 2a21ae4f..df392521 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/HideAndSeekDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/HideAndSeekDay.cs @@ -4,6 +4,7 @@ using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; @@ -66,11 +67,11 @@ public HNSSettings() { } public override int InitialHealth(CCSPlayerController player) { - return player.GetTeam() == CsTeam.Terrorist ? 250 : 50; + return player.Team == CsTeam.Terrorist ? 250 : 50; } public override int InitialArmor(CCSPlayerController player) { - if (player.GetTeam() != CsTeam.Terrorist) return -1; + if (player.Team != CsTeam.Terrorist) return -1; return 500; } diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/ISpecialDayMessageProvider.cs b/mod/Jailbreak.SpecialDay/SpecialDays/ISpecialDayMessageProvider.cs index 10f8ec4b..4f9fde51 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/ISpecialDayMessageProvider.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/ISpecialDayMessageProvider.cs @@ -1,4 +1,5 @@ using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; namespace Jailbreak.SpecialDay.SpecialDays; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs index 3fd9887c..d95287ec 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs @@ -5,6 +5,7 @@ using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs index 4232abde..490900a6 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs @@ -2,6 +2,7 @@ using CounterStrikeSharp.API.Core; using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs index e1fd6d80..cdc79960 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API.Core; using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs index d24bf85a..c311963b 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs @@ -1,7 +1,4 @@ -using System.Collections; -using System.Diagnostics; using System.Drawing; -using System.Runtime.InteropServices.Marshalling; using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Cvars; @@ -11,6 +8,7 @@ using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Draw; using Jailbreak.Public.Mod.SpecialDay; @@ -92,14 +90,14 @@ private readonly Dictionary> /// private readonly HashSet finishedPlayers = new(); - private LinkedList<(int, float)> finishTimestampList = new(); - private readonly Random rng = new(); private float? bestTime; private int? bestTimePlayerSlot; private AbstractTrail? bestTrail; + private LinkedList<(int, float)> finishTimestampList = new(); + private IGenericCmdLocale generics = null!; private int round, playersAliveAtStart; private Timer? roundEndTimer; @@ -381,8 +379,9 @@ private void sendDistances(LinkedList<(int, float)> unfinished) { return; } - ServerExtensions.GetGameRules().GameRestart = - ServerExtensions.GetGameRules().RestartRoundTime < Server.CurrentTime; + var rules = ServerExtensions.GetGameRules(); + if (rules != null) + rules.GameRestart = rules.RestartRoundTime < Server.CurrentTime; var originalCompletions = new LinkedList<(int, float)>(finishTimestampList); @@ -416,7 +415,7 @@ private void sendDistances(LinkedList<(int, float)> unfinished) { playerLine = playerLine.Previous; var p = Utilities.GetPlayerFromSlot(slot); if (p == null) continue; - lines = generateHTMLLine(p, pos - (d++), dist) + (d == 1 ? "" : "
") + lines = generateHTMLLine(p, pos - d++, dist) + (d == 1 ? "" : "
") + lines; display++; } @@ -430,7 +429,7 @@ private void sendDistances(LinkedList<(int, float)> unfinished) { playerLine = playerLine.Next; var p = Utilities.GetPlayerFromSlot(slot); if (p == null) continue; - lines += "
" + generateHTMLLine(p, pos + (++d), dist); + lines += "
" + generateHTMLLine(p, pos + ++d, dist); display++; } @@ -454,7 +453,7 @@ private string generateHTMLLine(CCSPlayerController player, int position, var isSafe = position < eliminations && distance < 0; var isInDanger = position > playersAliveAtStart - eliminations; - var text = $"{position} {player.PlayerName}"; + var text = $"{position} {player.PlayerName}"; if (isSafe) { color = "00FF00"; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs index 393c13ca..15c5a900 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API.Core; using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/WardayDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/WardayDay.cs index 76799bf8..5a0701d5 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/WardayDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/WardayDay.cs @@ -3,6 +3,7 @@ using Jailbreak.English.SpecialDay; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; @@ -45,7 +46,7 @@ public WardaySettings() { } public override float FreezeTime(CCSPlayerController player) { - return player.GetTeam() == CsTeam.CounterTerrorist ? 3 : 5; + return player.Team == CsTeam.CounterTerrorist ? 3 : 5; } } } \ No newline at end of file diff --git a/mod/Jailbreak.Warden/Global/WardenBehavior.cs b/mod/Jailbreak.Warden/Global/WardenBehavior.cs index 845bd4d7..1df179a9 100644 --- a/mod/Jailbreak.Warden/Global/WardenBehavior.cs +++ b/mod/Jailbreak.Warden/Global/WardenBehavior.cs @@ -85,7 +85,7 @@ public bool TrySetWarden(CCSPlayerController controller) { if (HasWarden) return false; // Verify player is a CT - if (controller.GetTeam() != CsTeam.CounterTerrorist) return false; + if (controller.Team != CsTeam.CounterTerrorist) return false; if (!controller.PawnIsAlive) return false; mute.UnPeaceMute(); diff --git a/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs b/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs index 2e3cc87e..d3556b12 100644 --- a/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs +++ b/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs @@ -6,7 +6,6 @@ using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; -using Jailbreak.Public.Extensions; using Jailbreak.Public.Generic; using Jailbreak.Public.Mod.Warden; using Microsoft.Extensions.Logging; diff --git a/public/Jailbreak.Formatting/Views/ILogLocale.cs b/public/Jailbreak.Formatting/Views/ILogLocale.cs index f1483cd4..95bb741b 100644 --- a/public/Jailbreak.Formatting/Views/ILogLocale.cs +++ b/public/Jailbreak.Formatting/Views/ILogLocale.cs @@ -1,9 +1,8 @@ -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Modules.Utils; +using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Core; using Jailbreak.Formatting.Objects; -using Jailbreak.Public.Extensions; +using Jailbreak.Public.Utils; namespace Jailbreak.Formatting.Views; @@ -13,13 +12,10 @@ public interface ILogLocale { public IView EndJailbreakLogs { get; } public FormatObject Time() { - var gamerules = ServerExtensions.GetGameRules(); - var start = gamerules.RoundStartTime; - var current = Server.CurrentTime; - var elapsed = current - start; + var elapsed = RoundUtil.GetTimeElapsed(); var minutes = Math.Floor(elapsed / 60f).ToString("00"); - var seconds = Math.Floor(elapsed % 60).ToString("00"); + var seconds = (elapsed % 60).ToString("00"); return new StringFormatObject($"[{minutes}:{seconds}]", ChatColors.Gold); } diff --git a/public/Jailbreak.Formatting/Views/SpecialDay/IGunDayLocale.cs b/public/Jailbreak.Formatting/Views/SpecialDay/IGunDayLocale.cs index 9413365d..7fe9ebf1 100644 --- a/public/Jailbreak.Formatting/Views/SpecialDay/IGunDayLocale.cs +++ b/public/Jailbreak.Formatting/Views/SpecialDay/IGunDayLocale.cs @@ -1,7 +1,7 @@ using CounterStrikeSharp.API.Core; using Jailbreak.Formatting.Base; -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.SpecialDay; public interface IGunDayLocale : ISDInstanceLocale { IView DemotedDueToSuicide { get; } diff --git a/public/Jailbreak.Formatting/Views/SpecialDay/ISDInstanceLocale.cs b/public/Jailbreak.Formatting/Views/SpecialDay/ISDInstanceLocale.cs index ef28b39f..8023509b 100644 --- a/public/Jailbreak.Formatting/Views/SpecialDay/ISDInstanceLocale.cs +++ b/public/Jailbreak.Formatting/Views/SpecialDay/ISDInstanceLocale.cs @@ -1,6 +1,6 @@ using Jailbreak.Formatting.Base; -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.SpecialDay; public interface ISDInstanceLocale : ISDLocale { public string Name { get; } diff --git a/public/Jailbreak.Formatting/Views/SpecialDay/ISDLocale.cs b/public/Jailbreak.Formatting/Views/SpecialDay/ISDLocale.cs index 87cc6a40..6e61d872 100644 --- a/public/Jailbreak.Formatting/Views/SpecialDay/ISDLocale.cs +++ b/public/Jailbreak.Formatting/Views/SpecialDay/ISDLocale.cs @@ -1,6 +1,6 @@ using Jailbreak.Formatting.Base; -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.SpecialDay; public interface ISDLocale { public IView SpecialDayRunning(string name); diff --git a/public/Jailbreak.Formatting/Views/SpecialDay/ISpeedDayLocale.cs b/public/Jailbreak.Formatting/Views/SpecialDay/ISpeedDayLocale.cs index 21996443..e3f60803 100644 --- a/public/Jailbreak.Formatting/Views/SpecialDay/ISpeedDayLocale.cs +++ b/public/Jailbreak.Formatting/Views/SpecialDay/ISpeedDayLocale.cs @@ -2,7 +2,7 @@ using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Base; -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.SpecialDay; public interface ISpeedDayLocale : ISDInstanceLocale { public IView NoneEliminated { get; } diff --git a/public/Jailbreak.Public/Extensions/ServerExtensions.cs b/public/Jailbreak.Public/Extensions/ServerExtensions.cs index eaec511a..3c79aa48 100644 --- a/public/Jailbreak.Public/Extensions/ServerExtensions.cs +++ b/public/Jailbreak.Public/Extensions/ServerExtensions.cs @@ -1,7 +1,5 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Memory; -using CounterStrikeSharp.API.Modules.Utils; namespace Jailbreak.Public.Extensions; diff --git a/public/Jailbreak.Public/Extensions/StringExtensions.cs b/public/Jailbreak.Public/Extensions/StringExtensions.cs index 075db104..192e6271 100644 --- a/public/Jailbreak.Public/Extensions/StringExtensions.cs +++ b/public/Jailbreak.Public/Extensions/StringExtensions.cs @@ -9,7 +9,7 @@ public static string Sanitize(this string unknown) { public static string Repeat(this string stringToRepeat, int repeat) { var builder = new StringBuilder(repeat * stringToRepeat.Length); - for (int i = 0; i < repeat; i++) { builder.Append(stringToRepeat); } + for (var i = 0; i < repeat; i++) builder.Append(stringToRepeat); return builder.ToString(); } diff --git a/public/Jailbreak.Public/Extensions/VectorExtensions.cs b/public/Jailbreak.Public/Extensions/VectorExtensions.cs index fc9821c2..c943547f 100644 --- a/public/Jailbreak.Public/Extensions/VectorExtensions.cs +++ b/public/Jailbreak.Public/Extensions/VectorExtensions.cs @@ -8,8 +8,8 @@ public static Vector Clone(this Vector vector) { } /// - /// Calculates the (Euclidean) distance between the two vectors - /// Where possible, use DistanceSquared instead for performance reasons + /// Calculates the (Euclidean) distance between the two vectors + /// Where possible, use DistanceSquared instead for performance reasons /// /// /// @@ -19,7 +19,7 @@ public static float Distance(this Vector vector, Vector other) { } /// - /// Calculates the squared (Euclidean) distance between the two vectors + /// Calculates the squared (Euclidean) distance between the two vectors /// /// /// @@ -30,8 +30,8 @@ public static float DistanceSquared(this Vector vector, Vector other) { } /// - /// Calculates the horizontal distance between the two vectors - /// Where possible, use HorizontalDistanceSquared instead for performance reasons + /// Calculates the horizontal distance between the two vectors + /// Where possible, use HorizontalDistanceSquared instead for performance reasons /// /// /// @@ -41,7 +41,7 @@ public static float HorizontalDistance(this Vector vector, Vector other) { } /// - /// Calculates the squared horizontal distance between the two vectors + /// Calculates the squared horizontal distance between the two vectors /// /// /// diff --git a/public/Jailbreak.Public/Mod/Damage/IDamageBlocker.cs b/public/Jailbreak.Public/Mod/Damage/IDamageBlocker.cs index d551e6de..ab704fdf 100644 --- a/public/Jailbreak.Public/Mod/Damage/IDamageBlocker.cs +++ b/public/Jailbreak.Public/Mod/Damage/IDamageBlocker.cs @@ -4,8 +4,8 @@ namespace Jailbreak.Public.Mod.Damage; /// -/// Wrapper for managing a player's health and preventing a player from -/// taking damage. +/// Wrapper for managing a player's health and preventing a player from +/// taking damage. /// public interface IDamageBlocker { HookResult BlockUserDamage(EventPlayerHurt @event, GameEventInfo _) { diff --git a/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs b/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs index 5b376899..26260d60 100644 --- a/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs +++ b/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs @@ -4,7 +4,7 @@ namespace Jailbreak.Public.Mod.Draw; /// -/// An implementation of BeamedShape that allows for drawing a circle +/// An implementation of BeamedShape that allows for drawing a circle /// public class BeamCircle : BeamedShape { private readonly BeamLine?[] lines; diff --git a/public/Jailbreak.Public/Mod/Draw/BeamLine.cs b/public/Jailbreak.Public/Mod/Draw/BeamLine.cs index 2301dc44..d804f8d3 100644 --- a/public/Jailbreak.Public/Mod/Draw/BeamLine.cs +++ b/public/Jailbreak.Public/Mod/Draw/BeamLine.cs @@ -8,7 +8,7 @@ namespace Jailbreak.Public.Mod.Draw; /// -/// An implementation of DrawableShape that uses a CEnvBeam to draw a line +/// An implementation of DrawableShape that uses a CEnvBeam to draw a line /// /// /// diff --git a/public/Jailbreak.Public/Mod/Draw/DrawableShape.cs b/public/Jailbreak.Public/Mod/Draw/DrawableShape.cs index 4e856ba5..6c586534 100644 --- a/public/Jailbreak.Public/Mod/Draw/DrawableShape.cs +++ b/public/Jailbreak.Public/Mod/Draw/DrawableShape.cs @@ -10,10 +10,11 @@ namespace Jailbreak.Public.Mod.Draw; /// Represents a drawable shape /// public abstract class DrawableShape(BasePlugin plugin, Vector position) { + protected readonly BasePlugin Plugin = plugin; + protected Timer? KillTimer; // Internal timer used to remove the shape after a certain amount of time - protected readonly BasePlugin Plugin = plugin; private Vector position = position.Clone(); // Note that this can mean different things for different shapes @@ -32,7 +33,7 @@ public virtual void Update() { } /// - /// Tells the shape to draw itself and then remove itself after a certain amount of time + /// Tells the shape to draw itself and then remove itself after a certain amount of time /// /// Time in seconds the shape should be shown public void Draw(float lifetime) { diff --git a/public/Jailbreak.Public/Mod/Mute/MuteReason.cs b/public/Jailbreak.Public/Mod/Mute/MuteReason.cs index d577546f..667de35e 100644 --- a/public/Jailbreak.Public/Mod/Mute/MuteReason.cs +++ b/public/Jailbreak.Public/Mod/Mute/MuteReason.cs @@ -2,22 +2,22 @@ public enum MuteReason { /// - /// An admin invoked the peace + /// An admin invoked the peace /// ADMIN, /// - /// The warden invoked the peace + /// The warden invoked the peace /// WARDEN_INVOKED, /// - /// The first warden of the round has been assigned + /// The first warden of the round has been assigned /// INITIAL_WARDEN, /// - /// A new warden has been assigned + /// A new warden has been assigned /// WARDEN_TAKEN } \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs index 75d17b01..a4fa7547 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs @@ -15,8 +15,8 @@ namespace Jailbreak.Public.Mod.SpecialDay; /// -/// Represents a special day that will last for the entire round and affect -/// all players. +/// Represents a special day that will last for the entire round and affect +/// all players. /// /// /// @@ -25,8 +25,8 @@ public abstract class AbstractSpecialDay(BasePlugin plugin, protected readonly BasePlugin Plugin = plugin; /// - /// Responsible for tracking what convars we've changed to be able - /// to change them back to their original values once the day ends. + /// Responsible for tracking what convars we've changed to be able + /// to change them back to their original values once the day ends. /// private readonly Dictionary previousConvarValues = new(); @@ -89,7 +89,7 @@ public virtual void Setup() { Provider.GetService()?.DisableRebelForRound(); if (Settings.OpenCells) { - var zones = provider.GetService(); + var zones = Provider.GetService(); if (zones == null) MapUtil.OpenCells(); else diff --git a/public/Jailbreak.Public/Utils/RoundUtil.cs b/public/Jailbreak.Public/Utils/RoundUtil.cs index e6f4ffa5..931906ff 100644 --- a/public/Jailbreak.Public/Utils/RoundUtil.cs +++ b/public/Jailbreak.Public/Utils/RoundUtil.cs @@ -5,33 +5,39 @@ namespace Jailbreak.Public.Utils; public static class RoundUtil { public static int GetTimeElapsed() { - var gamerules = ServerExtensions.GetGameRules(); + var gamerules = ServerExtensions.GetGameRules(); + if (gamerules == null) return 0; var freezeTime = gamerules.FreezeTime; return (int)(Server.CurrentTime - gamerules.RoundStartTime - freezeTime); } public static int GetTimeRemaining() { var gamerules = ServerExtensions.GetGameRules(); + if (gamerules == null) return 0; return gamerules.RoundTime - GetTimeElapsed(); } public static void SetTimeRemaining(int seconds) { var gamerules = ServerExtensions.GetGameRules(); + if (gamerules == null) return; gamerules.RoundTime = GetTimeElapsed() + seconds; - - Utilities.SetStateChanged(ServerExtensions.GetGameRulesProxy(), - "CCSGameRulesProxy", "m_pGameRules"); + var proxy = ServerExtensions.GetGameRulesProxy(); + if (proxy == null) return; + Utilities.SetStateChanged(proxy, "CCSGameRulesProxy", "m_pGameRules"); } public static void AddTimeRemaining(int time) { var gamerules = ServerExtensions.GetGameRules(); + if (gamerules == null) return; gamerules.RoundTime += time; - Utilities.SetStateChanged(ServerExtensions.GetGameRulesProxy(), - "CCSGameRulesProxy", "m_pGameRules"); + var proxy = ServerExtensions.GetGameRulesProxy(); + if (proxy == null) return; + Utilities.SetStateChanged(proxy, "CCSGameRulesProxy", "m_pGameRules"); } public static bool IsWarmup() { - return ServerExtensions.GetGameRules().WarmupPeriod; + var rules = ServerExtensions.GetGameRules(); + return rules == null || rules.WarmupPeriod; } } \ No newline at end of file diff --git a/public/Jailbreak.Validator/WeaponValidator.cs b/public/Jailbreak.Validator/WeaponValidator.cs index 293f28d4..4bc90916 100644 --- a/public/Jailbreak.Validator/WeaponValidator.cs +++ b/public/Jailbreak.Validator/WeaponValidator.cs @@ -45,7 +45,7 @@ public bool Validate(string value, out string? errorMessage) { WeaponType.SHOTGUNS => Tag.SHOTGUNS.Contains(weapon), WeaponType.SMGS => Tag.SMGS.Contains(weapon), WeaponType.HEAVY => Tag.HEAVY.Contains(weapon), - _ => throw new ArgumentOutOfRangeException("weapon") + _ => throw new ArgumentOutOfRangeException(nameof(weapon)) }; if (!result) return false; } diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 38cf874f..c7811e1c 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -11,6 +11,7 @@ using Jailbreak.English.Warden; using Jailbreak.Formatting.Views; using Jailbreak.Formatting.Views.LastRequest; +using Jailbreak.Formatting.Views.SpecialDay; using Jailbreak.Formatting.Views.Warden; using Jailbreak.Generic; using Jailbreak.LastGuard;