diff --git a/lang/Jailbreak.English/LastRequest/LastRequestLocale.cs b/lang/Jailbreak.English/LastRequest/LastRequestLocale.cs index e03fb0a9..3a2f2425 100644 --- a/lang/Jailbreak.English/LastRequest/LastRequestLocale.cs +++ b/lang/Jailbreak.English/LastRequest/LastRequestLocale.cs @@ -4,7 +4,7 @@ using Jailbreak.Formatting.Core; using Jailbreak.Formatting.Logistics; using Jailbreak.Formatting.Objects; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.LastRequest; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.LastRequest; using Jailbreak.Public.Mod.LastRequest.Enums; diff --git a/lang/Jailbreak.English/Mute/WardenPeaceLocale.cs b/lang/Jailbreak.English/Mute/WardenPeaceLocale.cs index e74879d1..bb5e9116 100644 --- a/lang/Jailbreak.English/Mute/WardenPeaceLocale.cs +++ b/lang/Jailbreak.English/Mute/WardenPeaceLocale.cs @@ -3,7 +3,7 @@ using Jailbreak.Formatting.Core; using Jailbreak.Formatting.Logistics; using Jailbreak.Formatting.Objects; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; namespace Jailbreak.English.Mute; diff --git a/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs b/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs index c3dcbc44..217c94d6 100644 --- a/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs +++ b/lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs @@ -1,6 +1,6 @@ using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Logistics; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; namespace Jailbreak.English.Warden; @@ -15,6 +15,9 @@ public IView CannotOpenYet(int seconds) { }; } + public IView AlreadyOpened + => new SimpleView { WardenLocale.PREFIX, "You already opened cells." }; + public IView CellsOpened => new SimpleView { WardenLocale.PREFIX, "The warden opened cells." }; diff --git a/lang/Jailbreak.English/Warden/WardenCmdRollLocale.cs b/lang/Jailbreak.English/Warden/WardenCmdRollLocale.cs index a29bce92..a53e2854 100644 --- a/lang/Jailbreak.English/Warden/WardenCmdRollLocale.cs +++ b/lang/Jailbreak.English/Warden/WardenCmdRollLocale.cs @@ -1,6 +1,6 @@ using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Logistics; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; namespace Jailbreak.English.Warden; diff --git a/lang/Jailbreak.English/Warden/WardenLocale.cs b/lang/Jailbreak.English/Warden/WardenLocale.cs index 84544953..ba461a5d 100644 --- a/lang/Jailbreak.English/Warden/WardenLocale.cs +++ b/lang/Jailbreak.English/Warden/WardenLocale.cs @@ -4,7 +4,7 @@ using Jailbreak.Formatting.Core; using Jailbreak.Formatting.Logistics; using Jailbreak.Formatting.Objects; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; namespace Jailbreak.English.Warden; diff --git a/mod/Jailbreak.Debug/DebugCommand.cs b/mod/Jailbreak.Debug/DebugCommand.cs index c251d5b0..18b6a1c2 100644 --- a/mod/Jailbreak.Debug/DebugCommand.cs +++ b/mod/Jailbreak.Debug/DebugCommand.cs @@ -24,7 +24,7 @@ public void Start(BasePlugin basePlugin) { commands.Add("lg", new LastGuard(serviceProvider)); commands.Add("zone", new Zone(serviceProvider, basePlugin)); commands.Add("endround", new EndRound(serviceProvider)); - commands.Add("opencells", new OpenCells(serviceProvider)); + commands.Add("testnearopen", new TestNearOpen(serviceProvider)); } [RequiresPermissions("@css/root")] diff --git a/mod/Jailbreak.Debug/Subcommands/LastRequest.cs b/mod/Jailbreak.Debug/Subcommands/LastRequest.cs index 904b6680..94c2f44b 100644 --- a/mod/Jailbreak.Debug/Subcommands/LastRequest.cs +++ b/mod/Jailbreak.Debug/Subcommands/LastRequest.cs @@ -2,7 +2,7 @@ using CounterStrikeSharp.API.Modules.Menu; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.LastRequest; using Jailbreak.LastRequest; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.LastRequest; diff --git a/mod/Jailbreak.Debug/Subcommands/OpenCells.cs b/mod/Jailbreak.Debug/Subcommands/OpenCells.cs deleted file mode 100644 index d4e84282..00000000 --- a/mod/Jailbreak.Debug/Subcommands/OpenCells.cs +++ /dev/null @@ -1,13 +0,0 @@ -using CounterStrikeSharp.API.Core; -using Jailbreak.Public.Mod.Zones; -using Jailbreak.Public.Utils; -using Microsoft.Extensions.DependencyInjection; - -namespace Jailbreak.Debug.Subcommands; - -public class OpenCells(IServiceProvider services) : AbstractCommand(services) { - public override void OnCommand(CCSPlayerController? executor, - WrappedInfo info) { - MapUtil.OpenCells(Services.GetRequiredService()); - } -} \ No newline at end of file diff --git a/mod/Jailbreak.Debug/Subcommands/TestNearOpen.cs b/mod/Jailbreak.Debug/Subcommands/TestNearOpen.cs new file mode 100644 index 00000000..dea70522 --- /dev/null +++ b/mod/Jailbreak.Debug/Subcommands/TestNearOpen.cs @@ -0,0 +1,17 @@ +using CounterStrikeSharp.API.Core; +using Jailbreak.Public.Utils; + +namespace Jailbreak.Debug.Subcommands; + +public class TestNearOpen(IServiceProvider services) + : AbstractCommand(services) { + public override void OnCommand(CCSPlayerController? executor, + WrappedInfo info) { + if (executor == null) return; + var pos = executor.Pawn.Value?.AbsOrigin; + if (pos == null) return; + MapUtil.OpenCells(Sensitivity.ANY, pos); + info.ReplyToCommand( + "Attempted to open cells using the button nearest to you."); + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Debug/Subcommands/Zone.cs b/mod/Jailbreak.Debug/Subcommands/Zone.cs index b453ed0d..9ed78d82 100644 --- a/mod/Jailbreak.Debug/Subcommands/Zone.cs +++ b/mod/Jailbreak.Debug/Subcommands/Zone.cs @@ -1,6 +1,6 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Zones; using Microsoft.Extensions.DependencyInjection; @@ -160,7 +160,6 @@ await zoneManager.PushZoneWithID(innerZone, innerPair.Value.Item2, foreach (var listZone in toList) info.ReplyToCommand( $"Points: {listZone.GetBorderPoints().Count()}/{listZone.GetAllPoints().Count()}Center: {listZone.CalculateCenterPoint()} Area: {listZone.GetArea()}"); - return; } @@ -176,12 +175,19 @@ await zoneManager.PushZoneWithID(innerZone, innerPair.Value.Item2, attemptBeginCreation(executor, specifiedType.Value); return; case "set": - foreach (var zone in zoneManager.GetZones(specifiedType.Value) + var zones = zoneManager.GetZones(specifiedType.Value) .GetAwaiter() - .GetResult()) - zoneManager.DeleteZone(zone.Id); + .GetResult(); + + Server.NextFrameAsync(async () => { + var copy = zones.ToList(); + + foreach (var zone in copy) await zoneManager.DeleteZone(zone.Id); + + Server.NextFrame(() + => attemptBeginCreation(executor, specifiedType.Value)); + }); - attemptBeginCreation(executor, specifiedType.Value); return; case "tpto": case "tp": @@ -207,6 +213,26 @@ await zoneManager.PushZoneWithID(innerZone, innerPair.Value.Item2, info.ReplyToCommand("Teleported to zone #" + tpDestinations.First().Id); return; + case "generate": + if (specifiedType != ZoneType.ARMORY + && specifiedType != ZoneType.CELL) { + info.ReplyToCommand("Invalid zone type"); + return; + } + + var entName = specifiedType == ZoneType.CELL ? + "info_player_terrorist" : + "info_player_counterterrorist"; + + var spawns = Utilities + .FindAllEntitiesByDesignerName(entName) + .Where(s => s.AbsOrigin != null) + .Select(s => s.AbsOrigin!); + + var generated = factory.CreateZone(spawns); + generated.Draw(plugin, specifiedType.Value.GetColor(), 120); + info.ReplyToCommand($"Drawing auto-generated {specifiedType} zone"); + return; } } @@ -219,7 +245,8 @@ private void if (type.IsSinglePoint()) { if (executor.PlayerPawn.Value?.AbsOrigin != null) { - var zone = factory.CreateZone([executor.PlayerPawn.Value.AbsOrigin!]); + var zone = + factory.CreateZone([executor.PlayerPawn.Value.AbsOrigin!.Clone()]); zone.Draw(plugin, type.GetColor(), 1f); Server.NextFrameAsync(async () => { await zoneManager.PushZone(zone, type); @@ -275,26 +302,21 @@ private void return null; } - var validZones = value.Where(zone - => zone.IsInsideZone(player.PlayerPawn.Value!.AbsOrigin!)) - .ToList(); + var validZones = value.MinBy(z + => z.GetMinDistanceSquared(player.PlayerPawn.Value!.AbsOrigin!)); - switch (validZones.Count) { - case 0: - if (print) player.PrintToChat("No zones found"); - return null; - case > 1: - if (print) player.PrintToChat("Multiple zones found."); - return null; - default: - return (validZones.First(), type.Value); + if (validZones == null) { + if (print) player.PrintToChat("No zones found"); + return null; } + + return (validZones, type.Value); } private void sendUsage(CCSPlayerController player) { player.PrintToChat("Usage: css_zone [add/set/remove/tp] [type]"); - player.PrintToChat(ChatColors.Default - + " css_zone [addinner/show/list] "); - player.PrintToChat(ChatColors.Default + " css_zone [finish/reload]"); + player.PrintToChat("css_zone [addinner/show/list] "); + player.PrintToChat("css_zone [finish/reload]"); + player.PrintToChat("css_zone generate [cell/armory]"); } } \ No newline at end of file diff --git a/mod/Jailbreak.LastRequest/LastRequestCommand.cs b/mod/Jailbreak.LastRequest/LastRequestCommand.cs index 56e802c5..b0b71e67 100644 --- a/mod/Jailbreak.LastRequest/LastRequestCommand.cs +++ b/mod/Jailbreak.LastRequest/LastRequestCommand.cs @@ -5,6 +5,7 @@ using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.LastRequest; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.LastRequest; diff --git a/mod/Jailbreak.LastRequest/LastRequestManager.cs b/mod/Jailbreak.LastRequest/LastRequestManager.cs index a17010c2..fd708a55 100644 --- a/mod/Jailbreak.LastRequest/LastRequestManager.cs +++ b/mod/Jailbreak.LastRequest/LastRequestManager.cs @@ -6,7 +6,7 @@ using CounterStrikeSharp.API.Modules.Menu; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.LastRequest; using Jailbreak.Public; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Damage; @@ -51,7 +51,7 @@ public bool ShouldBlockDamage(CCSPlayerController player, if (playerLR == null != (attackerLR == null)) { // One of them is in an LR - messages.DamageBlockedInsideLastRequest.ToPlayerCenter(attacker); + messages.DamageBlockedInsideLastRequest.ToCenter(attacker); return true; } @@ -62,7 +62,7 @@ public bool ShouldBlockDamage(CCSPlayerController player, // Same LR, allow damage return false; - messages.DamageBlockedNotInSameLR.ToPlayerCenter(attacker); + messages.DamageBlockedNotInSameLR.ToCenter(attacker); return true; } diff --git a/mod/Jailbreak.LastRequest/LastRequests/RockPaperScissors.cs b/mod/Jailbreak.LastRequest/LastRequests/RockPaperScissors.cs index 85e68dfa..a6759bec 100644 --- a/mod/Jailbreak.LastRequest/LastRequests/RockPaperScissors.cs +++ b/mod/Jailbreak.LastRequest/LastRequests/RockPaperScissors.cs @@ -72,7 +72,7 @@ public override void Execute() { MenuManager.OpenChatMenu(Prisoner, chatMenu); MenuManager.OpenChatMenu(Guard, chatMenu); - Plugin.AddTimer(RoundUtil.GetTimeRemaining() - 1, timeout, + Plugin.AddTimer(Math.Min(RoundUtil.GetTimeRemaining() - 1, 25), timeout, TimerFlags.STOP_ON_MAPCHANGE); } diff --git a/mod/Jailbreak.LastRequest/LastRequests/WeaponizedRequest.cs b/mod/Jailbreak.LastRequest/LastRequests/WeaponizedRequest.cs index ceca316a..f96f2146 100644 --- a/mod/Jailbreak.LastRequest/LastRequests/WeaponizedRequest.cs +++ b/mod/Jailbreak.LastRequest/LastRequests/WeaponizedRequest.cs @@ -1,6 +1,6 @@ using CounterStrikeSharp.API.Core; using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.LastRequest; using Jailbreak.Public.Mod.LastRequest; using Jailbreak.Public.Mod.LastRequest.Enums; using Microsoft.Extensions.DependencyInjection; diff --git a/mod/Jailbreak.Mute/MuteSystem.cs b/mod/Jailbreak.Mute/MuteSystem.cs index a5064fdd..89eb9de3 100644 --- a/mod/Jailbreak.Mute/MuteSystem.cs +++ b/mod/Jailbreak.Mute/MuteSystem.cs @@ -4,7 +4,7 @@ using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Mute; @@ -150,14 +150,14 @@ private void OnPlayerSpeak(int playerSlot) { if (!player.PawnIsAlive && !bypassMute(player)) { // Normal players can't speak when dead - messages!.DeadReminder.ToPlayerCenter(player); + messages!.DeadReminder.ToCenter(player); mute(player); return; } if (isMuted(player)) { // Remind any muted players they're muted - messages!.MuteReminder.ToPlayerCenter(player); + messages!.MuteReminder.ToCenter(player); return; } @@ -167,10 +167,10 @@ private void OnPlayerSpeak(int playerSlot) { if (IsPeaceEnabled()) { if (player.Team == CsTeam.CounterTerrorist && DateTime.Now >= ctPeaceEnd) return; - messages!.PeaceReminder.ToPlayerCenter(player); + messages!.PeaceReminder.ToCenter(player); } - if (!player.PawnIsAlive) messages!.AdminDeadReminder.ToPlayerCenter(player); + if (!player.PawnIsAlive) messages!.AdminDeadReminder.ToCenter(player); } private bool isMuted(CCSPlayerController player) { diff --git a/mod/Jailbreak.SpecialDay/SpecialDayCommand.cs b/mod/Jailbreak.SpecialDay/SpecialDayCommand.cs index 45a88748..49b8c832 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.Warden; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.SpecialDay; using Jailbreak.Public.Mod.SpecialDay.Enums; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/AbstractArmoryRestrictedDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/AbstractArmoryRestrictedDay.cs index 8a73dd98..2ed92344 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/AbstractArmoryRestrictedDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/AbstractArmoryRestrictedDay.cs @@ -9,9 +9,16 @@ namespace Jailbreak.SpecialDay.SpecialDays; -public abstract class AbstractArmoryRestrictedDay(BasePlugin plugin, - IServiceProvider provider, CsTeam restrictedTeam = CsTeam.Terrorist) - : AbstractZoneRestrictedDay(plugin, provider, restrictedTeam) { +public abstract class AbstractArmoryRestrictedDay : AbstractZoneRestrictedDay { + private readonly IServiceProvider provider1; + + protected AbstractArmoryRestrictedDay(BasePlugin plugin, + IServiceProvider provider, + CsTeam restrictedTeam = CsTeam.Terrorist) : base(plugin, provider, + restrictedTeam) { + provider1 = provider; + } + public override IView ZoneReminder => ArmoryReminder; public virtual IView ArmoryReminder @@ -23,7 +30,7 @@ public virtual IView ArmoryReminder override protected IZone GetZone() { - var manager = provider.GetRequiredService(); + var manager = provider1.GetRequiredService(); var zones = manager.GetZones(ZoneType.ARMORY).GetAwaiter().GetResult(); if (zones.Count > 0) return new MultiZoneWrapper(zones); diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/AbstractCellRestrictedDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/AbstractCellRestrictedDay.cs index 52810fcf..c906f390 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/AbstractCellRestrictedDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/AbstractCellRestrictedDay.cs @@ -9,9 +9,16 @@ namespace Jailbreak.SpecialDay.SpecialDays; -public abstract class AbstractCellRestrictedDay(BasePlugin plugin, - IServiceProvider provider, CsTeam restrictedTeam = CsTeam.Terrorist) - : AbstractZoneRestrictedDay(plugin, provider, restrictedTeam) { +public abstract class AbstractCellRestrictedDay : AbstractZoneRestrictedDay { + private readonly IServiceProvider provider1; + + protected AbstractCellRestrictedDay(BasePlugin plugin, + IServiceProvider provider, + CsTeam restrictedTeam = CsTeam.Terrorist) : base(plugin, provider, + restrictedTeam) { + provider1 = provider; + } + public override IView ZoneReminder => CellReminder; public virtual IView CellReminder @@ -22,7 +29,7 @@ public virtual IView CellReminder new SimpleView { IsdLocale.PREFIX, "Stay in cells!" }; override protected IZone GetZone() { - var manager = provider.GetRequiredService(); + var manager = provider1.GetRequiredService(); var zones = manager.GetZones(ZoneType.CELL).GetAwaiter().GetResult(); if (zones.Count > 0) return new MultiZoneWrapper(zones); diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/AbstractZoneRestrictedDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/AbstractZoneRestrictedDay.cs index b46cf2e4..0b11d323 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/AbstractZoneRestrictedDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/AbstractZoneRestrictedDay.cs @@ -10,12 +10,18 @@ namespace Jailbreak.SpecialDay.SpecialDays; -public abstract class AbstractZoneRestrictedDay(BasePlugin plugin, - IServiceProvider provider, CsTeam restrictedTeam = CsTeam.Terrorist) - : AbstractSpecialDay(plugin, provider) { +public abstract class AbstractZoneRestrictedDay : AbstractSpecialDay { + protected readonly CsTeam RestrictedTeam; + protected readonly IList Restrictors = new List(); + protected AbstractZoneRestrictedDay(BasePlugin plugin, + IServiceProvider provider, + CsTeam restrictedTeam = CsTeam.Terrorist) : base(plugin, provider) { + RestrictedTeam = restrictedTeam; + } + public abstract IView ZoneReminder { get; } abstract protected IZone GetZone(); @@ -23,11 +29,11 @@ public abstract class AbstractZoneRestrictedDay(BasePlugin plugin, public override void Setup() { base.Setup(); - ZoneReminder.ToTeamChat(restrictedTeam); - GetZone().Draw(plugin, Color.Firebrick, 55); + ZoneReminder.ToTeamChat(RestrictedTeam); + GetZone().Draw(Plugin, Color.Firebrick, 55); - foreach (var t in PlayerUtil.FromTeam(restrictedTeam)) { - var zoneRestrictor = new ZoneMovementRestrictor(plugin, t, GetZone(), + foreach (var t in PlayerUtil.FromTeam(RestrictedTeam)) { + var zoneRestrictor = new ZoneMovementRestrictor(Plugin, t, GetZone(), DistanceZone.WIDTH_CELL, () => ZoneReminder.ToChat(t)); Restrictors.Add(zoneRestrictor); } diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs index 01b490d3..1f704c80 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs @@ -12,10 +12,13 @@ namespace Jailbreak.SpecialDay.SpecialDays; -public class InfectionDay(BasePlugin plugin, IServiceProvider provider) - : AbstractArmoryRestrictedDay(plugin, provider, CsTeam.CounterTerrorist), - ISpecialDayMessageProvider { +public class InfectionDay : AbstractArmoryRestrictedDay, + ISpecialDayMessageProvider { private readonly ICollection swappedPrisoners = new HashSet(); + + public InfectionDay(BasePlugin Plugin, IServiceProvider provider) : base( + Plugin, provider, CsTeam.CounterTerrorist) { } + public override SDType Type => SDType.INFECTION; public override SpecialDaySettings Settings => new InfectionSettings(); @@ -37,8 +40,8 @@ public override void Setup() { foreach (var ct in PlayerUtil.FromTeam(CsTeam.CounterTerrorist)) ct.SetColor(Color.LimeGreen); - plugin.RegisterEventHandler(OnPlayerDeath); - plugin.RegisterEventHandler(OnRespawn); + Plugin.RegisterEventHandler(OnPlayerDeath); + Plugin.RegisterEventHandler(OnRespawn); } private HookResult @@ -81,12 +84,12 @@ private HookResult @event.Attacker : null) .ToChat(player); - plugin.AddTimer(0.1f, () => { + Plugin.AddTimer(0.1f, () => { player.SwitchTeam(CsTeam.CounterTerrorist); player.Respawn(); - plugin.AddTimer(0.1f, () => { + Plugin.AddTimer(0.1f, () => { player.RemoveWeapons(); - plugin.AddTimer(3, () => { player.GiveNamedItem("weapon_knife"); }); + Plugin.AddTimer(3, () => { player.GiveNamedItem("weapon_knife"); }); }); if (nearest.Count == 0 || target == null) { player.PlayerPawn.Value!.Teleport(pos); @@ -104,7 +107,7 @@ public HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) { if (player.Team != CsTeam.CounterTerrorist) return HookResult.Continue; var hp = Settings.InitialHealth(player); - if (hp != -1) plugin.AddTimer(0.1f, () => { player.SetHealth(hp); }); + if (hp != -1) Plugin.AddTimer(0.1f, () => { player.SetHealth(hp); }); var color = swappedPrisoners.Contains(player.Slot) ? Color.DarkOliveGreen : @@ -116,8 +119,8 @@ public HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) { override protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) { var result = base.OnEnd(@event, info); - plugin.DeregisterEventHandler(OnPlayerDeath); - plugin.DeregisterEventHandler(OnRespawn); + Plugin.DeregisterEventHandler(OnPlayerDeath); + Plugin.DeregisterEventHandler(OnRespawn); foreach (var index in swappedPrisoners) { var player = Utilities.GetPlayerFromSlot(index); diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs index 41f4f611..c91a2528 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs @@ -20,8 +20,8 @@ public override ISDInstanceLocale Locale public override void Setup() { base.Setup(); - plugin.RegisterEventHandler(OnPlayerDamage); - plugin.RegisterEventHandler(OnPlayerDeath); + Plugin.RegisterEventHandler(OnPlayerDamage); + Plugin.RegisterEventHandler(OnPlayerDeath); } public override void Execute() { @@ -52,8 +52,8 @@ private HookResult override protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) { - plugin.DeregisterEventHandler(OnPlayerDamage); - plugin.DeregisterEventHandler(OnPlayerDeath); + Plugin.DeregisterEventHandler(OnPlayerDamage); + Plugin.DeregisterEventHandler(OnPlayerDeath); return base.OnEnd(@event, info); } } @@ -68,7 +68,7 @@ public OitcSettings() { ConVarValues["mp_death_drop_gun"] = 0; } - public override ISet? AllowedWeapons(CCSPlayerController player) { + public override ISet AllowedWeapons(CCSPlayerController player) { return new HashSet { "weapon_deagle", "weapon_knife" }; } } \ No newline at end of file diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs index 5ad6a030..d7cc3c15 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs @@ -34,16 +34,15 @@ public class SpeedrunDay(BasePlugin plugin, IServiceProvider provider) "Duration in seconds to give players time to read the rules of speedrun", 8); - private readonly IDictionary> - activeTrails = new Dictionary>(); + private readonly Dictionary> + activeTrails = new(); /// /// Negative values represent players who finished. /// Positive values represent players who are still alive, and the value /// being the distance they are from the target. /// - private readonly IDictionary finishTimestamps = - new SortedDictionary(); + private readonly SortedDictionary finishTimestamps = new(); private readonly Random rng = new(); private float? bestTime; @@ -60,6 +59,7 @@ private readonly IDictionary> private Vector? start; private Vector? target; private BeamCircle? targetCircle; + public override SDType Type => SDType.SPEEDRUN; private SpeedrunDayLocale msg => (SpeedrunDayLocale)Locale; @@ -68,7 +68,7 @@ private readonly IDictionary> public ISDInstanceLocale Locale => new SpeedrunDayLocale(); public override void Setup() { - generics = provider.GetRequiredService(); + generics = Provider.GetRequiredService(); foreach (var player in Utilities.GetPlayers().Where(p => !p.PawnIsAlive)) player.Respawn(); @@ -98,7 +98,7 @@ public override void Setup() { Timers[FIRST_ROUND_FREEZE] += () => { start = speedrunner.PlayerPawn.Value!.AbsOrigin!.Clone(); speedrunner.UnFreeze(); - bestTrail = new ActivePulsatingBeamPlayerTrail(plugin, speedrunner, 0f, + bestTrail = new ActivePulsatingBeamPlayerTrail(Plugin, speedrunner, 0f, MAX_POINTS, 0.15f); }; @@ -108,7 +108,7 @@ public override void Setup() { => msg.RuntimeLeft(10).ToChat(speedrunner); Timers[FIRST_SPEEDRUNNER_TIME + FIRST_ROUND_FREEZE] += () => { target = speedrunner.PlayerPawn.Value?.AbsOrigin!.Clone(); - targetCircle = new BeamCircle(plugin, target!, 10, 16); + targetCircle = new BeamCircle(Plugin, target!, 10, 16); targetCircle.SetColor(Color.Green); targetCircle.Draw(); @@ -243,8 +243,8 @@ private void resetTrails() { if (bestTime == null || time <= bestTime) { bestTrail?.Kill(); activeTrails[bestPlayer].StopTracking(); - // bestTrail = BeamTrail.FromTrail(plugin, activeTrails[bestPlayer]); - bestTrail = PulsatingBeamTrail.FromTrail(plugin, + // bestTrail = BeamTrail.FromTrail(Plugin, activeTrails[bestPlayer]); + bestTrail = PulsatingBeamTrail.FromTrail(Plugin, activeTrails[bestPlayer]); } } @@ -256,7 +256,7 @@ private void resetTrails() { foreach (var player in PlayerUtil.GetAlive()) activeTrails[player.Slot] = - new ActiveInvisiblePlayerTrail(plugin, player, 0f, MAX_POINTS); + new ActiveInvisiblePlayerTrail(Plugin, player, 0f, MAX_POINTS); } // https://www.desmos.com/calculator/e1qwgpmtmz @@ -294,7 +294,7 @@ private void endRound() { if (aliveCount > 1) if (ctMade != tMade && round == 1) { - var random = PlayerUtil.GetRandomFromTeam(rng.Next(2) == 0 ? + var random = PlayerUtil.GetRandomFromTeam(tMade ? CsTeam.CounterTerrorist : CsTeam.Terrorist); @@ -305,8 +305,7 @@ private void endRound() { bestTrail?.Kill(); randomTrail.StopTracking(); - // bestTrail = BeamTrail.FromTrail(plugin, activeTrails[bestPlayer]); - bestTrail = PulsatingBeamTrail.FromTrail(plugin, randomTrail); + bestTrail = PulsatingBeamTrail.FromTrail(Plugin, randomTrail); target = bestTrail!.GetEndSegment()!.GetEnd(); } @@ -361,7 +360,7 @@ private void endRound() { winner.GiveNamedItem("weapon_knife"); winner.GiveNamedItem("weapon_negev"); - plugin.RemoveListener(OnTick); + Plugin.RemoveListener(OnTick); RoundUtil.SetTimeRemaining(30); Server.ExecuteCommand("mp_ignore_round_win_conditions 0"); @@ -443,7 +442,7 @@ private void announceTimes() { var player = Utilities.GetPlayerFromSlot(slot); if (player == null) continue; if (time > 0) - msg.PlayerTime(player, times.Length - i - 1, time).ToChat(player); + msg.PlayerTime(player, times.Length - i, time).ToChat(player); } } @@ -456,7 +455,6 @@ public static IEnumerable> override protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) { - var id = 0; var result = base.OnEnd(@event, info); finishCheckTimer?.Kill(); @@ -483,7 +481,7 @@ public SpeedrunSettings() { public override Func RoundTime => () => FIRST_SPEEDRUNNER_TIME + FIRST_ROUND_FREEZE; - public override ISet? AllowedWeapons(CCSPlayerController player) { + public override ISet AllowedWeapons(CCSPlayerController player) { // Return empty set to allow no weapons return new HashSet(); } diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs index ad1d2b9b..393c13ca 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs @@ -8,7 +8,7 @@ namespace Jailbreak.SpecialDay.SpecialDays; public class TeleportDay(BasePlugin plugin, IServiceProvider provider) - : FFADay(plugin, provider), ISpecialDayMessageProvider { + : FFADay(plugin, provider) { public override SDType Type => SDType.FFA; public override SpecialDaySettings Settings => new TeleportSettings(); diff --git a/mod/Jailbreak.Trail/ActiveBeamPlayerTrail.cs b/mod/Jailbreak.Trail/ActiveBeamPlayerTrail.cs index bb1fb4f8..0f02aa9b 100644 --- a/mod/Jailbreak.Trail/ActiveBeamPlayerTrail.cs +++ b/mod/Jailbreak.Trail/ActiveBeamPlayerTrail.cs @@ -10,7 +10,7 @@ public class ActiveBeamPlayerTrail(BasePlugin plugin, : ActivePlayerTrail(plugin, player, lifetime, maxPoints, updateRate) { public override BeamTrailSegment CreateSegment(Vector start, Vector end) { - var beam = new BeamLine(plugin, start, end); + var beam = new BeamLine(Plugin, start, end); return new BeamTrailSegment(beam); } } \ No newline at end of file diff --git a/mod/Jailbreak.Trail/ActivePlayerTrail.cs b/mod/Jailbreak.Trail/ActivePlayerTrail.cs index 42b543ba..6bc14c57 100644 --- a/mod/Jailbreak.Trail/ActivePlayerTrail.cs +++ b/mod/Jailbreak.Trail/ActivePlayerTrail.cs @@ -8,11 +8,13 @@ namespace Jailbreak.Trail; public abstract class ActivePlayerTrail : AbstractTrail where T : ITrailSegment { + protected readonly BasePlugin Plugin; protected readonly Timer Timer; public ActivePlayerTrail(BasePlugin plugin, CCSPlayerController player, float lifetime = 20, int maxPoints = 100, float updateRate = 0.5f) : base( lifetime, maxPoints) { + Plugin = plugin; Player = player; Timer = plugin.AddTimer(updateRate, Tick, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE); diff --git a/mod/Jailbreak.Trail/ActivePulsatingBeamPlayerTrail.cs b/mod/Jailbreak.Trail/ActivePulsatingBeamPlayerTrail.cs index e70de8f8..bffe08d3 100644 --- a/mod/Jailbreak.Trail/ActivePulsatingBeamPlayerTrail.cs +++ b/mod/Jailbreak.Trail/ActivePulsatingBeamPlayerTrail.cs @@ -5,8 +5,7 @@ namespace Jailbreak.Trail; public class ActivePulsatingBeamPlayerTrail(BasePlugin plugin, CCSPlayerController player, float lifetime = 20, int maxPoints = 100, - float updateRate = 0.5f, float pulseRate = 0.5f, float pulseMin = 0.5f, - float pulseMax = 2.5f) + float updateRate = 0.5f) : ActivePlayerTrail(plugin, player, lifetime, maxPoints, updateRate) { private readonly PulsatingBeamTrail trail = new(plugin, lifetime, maxPoints, diff --git a/mod/Jailbreak.Trail/BeamTrail.cs b/mod/Jailbreak.Trail/BeamTrail.cs index 50d38519..e0c6c087 100644 --- a/mod/Jailbreak.Trail/BeamTrail.cs +++ b/mod/Jailbreak.Trail/BeamTrail.cs @@ -7,7 +7,7 @@ namespace Jailbreak.Trail; public class BeamTrail(BasePlugin plugin, float lifetime = 20, int maxPoints = 100) : AbstractTrail(lifetime, maxPoints) { - public static BeamTrail? FromTrail(BasePlugin plugin, + public static BeamTrail FromTrail(BasePlugin plugin, AbstractTrail trail) where T : ITrailSegment { var beamTrail = new BeamTrail(plugin, trail.Lifetime, trail.MaxPoints); foreach (var segment in trail) diff --git a/mod/Jailbreak.Trail/PulsatingBeamTrail.cs b/mod/Jailbreak.Trail/PulsatingBeamTrail.cs index eafeb386..5c2eeced 100644 --- a/mod/Jailbreak.Trail/PulsatingBeamTrail.cs +++ b/mod/Jailbreak.Trail/PulsatingBeamTrail.cs @@ -14,8 +14,7 @@ public class PulsatingBeamTrail : AbstractTrail { private readonly Timer timer; public PulsatingBeamTrail(BasePlugin plugin, float lifetime = 20, - int maxPoints = 100, float updateRate = 0.25f, - Func? transform = null) : base(lifetime, maxPoints) { + int maxPoints = 100, float updateRate = 0.25f) : base(lifetime, maxPoints) { this.plugin = plugin; timer = plugin.AddTimer(updateRate, Update, @@ -43,11 +42,11 @@ public override void Kill() { timer.Kill(); } - public static PulsatingBeamTrail? FromTrail(BasePlugin plugin, + public static PulsatingBeamTrail FromTrail(BasePlugin plugin, AbstractTrail trail, float updateRate = 0.25f, Func? transform = null) where T : ITrailSegment { var beamTrail = new PulsatingBeamTrail(plugin, trail.Lifetime, - trail.MaxPoints, updateRate, transform); + trail.MaxPoints, updateRate); foreach (var segment in trail) beamTrail.Segments.Add( beamTrail.CreateSegment(segment.GetStart(), segment.GetEnd())); diff --git a/mod/Jailbreak.Trail/TrailManager.cs b/mod/Jailbreak.Trail/TrailManager.cs index 0a4dec43..7b2a1cba 100644 --- a/mod/Jailbreak.Trail/TrailManager.cs +++ b/mod/Jailbreak.Trail/TrailManager.cs @@ -16,7 +16,7 @@ public bool RemovePlayerTrail(CCSPlayerController player) { throw new NotImplementedException(); } - public BeamTrailSegment? GetPlayerTrail(CCSPlayerController player) { + public BeamTrailSegment GetPlayerTrail(CCSPlayerController player) { throw new NotImplementedException(); } } \ No newline at end of file diff --git a/mod/Jailbreak.Warden/Commands/OpenCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/OpenCommandsBehavior.cs index ce348bca..c7867fe8 100644 --- a/mod/Jailbreak.Warden/Commands/OpenCommandsBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/OpenCommandsBehavior.cs @@ -5,7 +5,7 @@ using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Cvars.Validators; using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Warden; using Jailbreak.Public.Mod.Zones; @@ -21,21 +21,37 @@ public class OpenCommandsBehavior(IWardenService warden, IWardenLocale msg, "Minimum seconds warden must wait before being able to open the cells.", 30, customValidators: new RangeValidator(0, 300)); + private bool openedCells; + + [GameEventHandler] + public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { + openedCells = false; + return HookResult.Continue; + } + [ConsoleCommand("css_open", "Opens the cell doors")] [ConsoleCommand("css_o", "Opens the cell doors")] public void Command_Open(CCSPlayerController? executor, CommandInfo info) { if (executor != null - && !AdminManager.PlayerHasPermissions(executor, "@css/cheat")) + && !AdminManager.PlayerHasPermissions(executor, "@css/cheat")) { if (!warden.IsWarden(executor)) { msg.NotWarden.ToChat(executor); return; } - if (RoundUtil.GetTimeElapsed() < CvOpenCommandCooldown.Value) { - wardenCmdOpenMsg.CannotOpenYet(CvOpenCommandCooldown.Value); - return; + if (RoundUtil.GetTimeElapsed() < CvOpenCommandCooldown.Value) { + wardenCmdOpenMsg.CannotOpenYet(CvOpenCommandCooldown.Value) + .ToChat(executor); + return; + } + + if (openedCells) { + wardenCmdOpenMsg.AlreadyOpened.ToChat(executor); + return; + } } + openedCells = true; var result = MapUtil.OpenCells(zoneManager); (result ? wardenCmdOpenMsg.CellsOpened : wardenCmdOpenMsg.OpeningFailed) .ToAllChat(); diff --git a/mod/Jailbreak.Warden/Commands/PeaceCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/PeaceCommandsBehavior.cs index 8ac180e3..673b30a3 100644 --- a/mod/Jailbreak.Warden/Commands/PeaceCommandsBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/PeaceCommandsBehavior.cs @@ -4,6 +4,7 @@ using CounterStrikeSharp.API.Modules.Commands; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Mute; using Jailbreak.Public.Mod.Warden; diff --git a/mod/Jailbreak.Warden/Commands/RollCommandBehavior.cs b/mod/Jailbreak.Warden/Commands/RollCommandBehavior.cs index cd0d573e..740f7980 100644 --- a/mod/Jailbreak.Warden/Commands/RollCommandBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/RollCommandBehavior.cs @@ -3,6 +3,7 @@ using CounterStrikeSharp.API.Modules.Commands; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Warden; diff --git a/mod/Jailbreak.Warden/Commands/SpecialTreatmentCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/SpecialTreatmentCommandsBehavior.cs index 4c26d4f2..fd51ec8c 100644 --- a/mod/Jailbreak.Warden/Commands/SpecialTreatmentCommandsBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/SpecialTreatmentCommandsBehavior.cs @@ -4,6 +4,7 @@ using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Warden; diff --git a/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs index 8d8437c5..b0abd2de 100644 --- a/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs @@ -6,6 +6,7 @@ using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Warden; using Jailbreak.Public.Utils; diff --git a/mod/Jailbreak.Warden/Global/WardenBehavior.cs b/mod/Jailbreak.Warden/Global/WardenBehavior.cs index eedfe1d4..845bd4d7 100644 --- a/mod/Jailbreak.Warden/Global/WardenBehavior.cs +++ b/mod/Jailbreak.Warden/Global/WardenBehavior.cs @@ -6,8 +6,8 @@ using CounterStrikeSharp.API.Modules.Cvars.Validators; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; using Jailbreak.Formatting.Views.Logging; +using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; diff --git a/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs b/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs index 71576a8f..7c778f87 100644 --- a/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs +++ b/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs @@ -4,7 +4,7 @@ using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; -using Jailbreak.Formatting.Views; +using Jailbreak.Formatting.Views.Warden; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; using Jailbreak.Public.Generic; diff --git a/mod/Jailbreak.Warden/SpecialTreatment/SpecialTreatmentBehavior.cs b/mod/Jailbreak.Warden/SpecialTreatment/SpecialTreatmentBehavior.cs index a9c76b9d..9cf2e9a8 100644 --- a/mod/Jailbreak.Warden/SpecialTreatment/SpecialTreatmentBehavior.cs +++ b/mod/Jailbreak.Warden/SpecialTreatment/SpecialTreatmentBehavior.cs @@ -29,7 +29,7 @@ public void Grant(CCSPlayerController player) { if (rebel.IsRebel(player)) rebel.UnmarkRebel(player); setSpecialColor(player, true); - notifications.Granted.ToChat(player).ToPlayerCenter(player); + notifications.Granted.ToChat(player).ToCenter(player); notifications.GrantedTo(player).ToAllChat(); } @@ -42,7 +42,7 @@ public void Revoke(CCSPlayerController player) { setSpecialColor(player, false); - notifications.Revoked.ToChat(player).ToPlayerCenter(player); + notifications.Revoked.ToChat(player).ToCenter(player); notifications.RevokedFrom(player).ToAllChat(); } diff --git a/mod/Jailbreak.Zones/MultiZoneWrapper.cs b/mod/Jailbreak.Zones/MultiZoneWrapper.cs index aeccf157..5b2430b4 100644 --- a/mod/Jailbreak.Zones/MultiZoneWrapper.cs +++ b/mod/Jailbreak.Zones/MultiZoneWrapper.cs @@ -4,6 +4,7 @@ using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Zones; +using JetBrains.Annotations; namespace Jailbreak.Zones; @@ -17,7 +18,10 @@ public class MultiZoneWrapper(IEnumerable? zones = null) : IZone, IEnumerable { private readonly IEnumerable zones = zones ?? []; + [MustDisposeResource] public IEnumerator GetEnumerator() { return zones.GetEnumerator(); } + + [MustDisposeResource] IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public int Id { get; set; } diff --git a/mod/Jailbreak.Zones/RandomZoneGenerator.cs b/mod/Jailbreak.Zones/RandomZoneGenerator.cs index 72cf6a80..10a5c538 100644 --- a/mod/Jailbreak.Zones/RandomZoneGenerator.cs +++ b/mod/Jailbreak.Zones/RandomZoneGenerator.cs @@ -11,12 +11,12 @@ namespace Jailbreak.Zones; public class RandomZoneGenerator(IZoneManager zoneManager, IZoneFactory factory) : IPluginBehavior { - private BasePlugin plugin = null!; private IZone? cells; + private string? currentMap; private IList? manualSpawnPoints; + private BasePlugin plugin = null!; private IList? restrictedAreas; private Timer? timer; - private string? currentMap; public void Start(BasePlugin basePlugin, bool hotreload) { plugin = basePlugin; @@ -28,7 +28,7 @@ public void Start(BasePlugin basePlugin, bool hotreload) { private void startTimer() { timer?.Kill(); - timer = plugin.AddTimer(1f, tick, TimerFlags.REPEAT); + timer = plugin.AddTimer(63f, tick, TimerFlags.REPEAT); } private void reload() { @@ -72,15 +72,15 @@ private void tick(CCSPlayerController player) { var autoSpawnPoints = getAutoSpawnPoints(); - var allSpawnPoints = (manualSpawnPoints ?? []).Concat(autoSpawnPoints ?? []) + var allSpawnPoints = (manualSpawnPoints ?? []).Concat(autoSpawnPoints) .ToList(); if (allSpawnPoints.Count > 0) { dist = allSpawnPoints.Min(a => a.GetMinDistanceSquared(pos)); - if (dist <= DistanceZone.WIDTH_CELL * 2) return; + if (dist <= DistanceZone.WIDTH_MEDIUM_ROOM) return; } - if (allSpawnPoints.Count > Server.MaxPlayers && autoSpawnPoints != null) { + if (allSpawnPoints.Count > Server.MaxPlayers) { var nearestPoint = autoSpawnPoints .OrderBy(z => z.GetMinDistanceSquared(pos)) .First(); @@ -92,9 +92,6 @@ private void tick(CCSPlayerController player) { var newScore = zoneScore(newPoints); - Server.PrintToChatAll( - $"Attempting to replace spawnpoint, old: {currentScore}, new: {newScore}"); - if (newScore <= currentScore) return; var map = Server.MapName; @@ -107,11 +104,8 @@ private void tick(CCSPlayerController player) { return; } - Server.PrintToChatAll( - $"Creating new spawn point, not yet reached population limit. {allSpawnPoints.Count}/{Server.MaxPlayers}"); - var spawn = factory.CreateZone([pos]); - autoSpawnPoints?.Add(spawn); + autoSpawnPoints.Add(spawn); Server.NextFrameAsync(async () => { await zoneManager.PushZone(spawn, ZoneType.SPAWN_AUTO, currentMap!); }); @@ -132,19 +126,19 @@ private float zoneScore(IList? zones) { return total; } - private IList? getManualSpawnPoints() { + private IList getManualSpawnPoints() { var zones = zoneManager.GetZones(ZoneType.SPAWN).GetAwaiter().GetResult(); return zones; } - private IList? getAutoSpawnPoints() { + private IList getAutoSpawnPoints() { var zones = zoneManager.GetZones(ZoneType.SPAWN_AUTO) .GetAwaiter() .GetResult(); return zones; } - private IZone? getCells() { + private IZone getCells() { var result = zoneManager.GetZones(ZoneType.CELL).GetAwaiter().GetResult(); if (result.Count > 0) return new MultiZoneWrapper(result); @@ -163,14 +157,15 @@ private IZone getArmory() { var bounds = new DistanceZone( Utilities - .FindAllEntitiesByDesignerName("info_player_terrorist") + .FindAllEntitiesByDesignerName< + SpawnPoint>("info_player_counterterrorist") .Where(s => s.AbsOrigin != null) .Select(s => s.AbsOrigin!) .ToList(), DistanceZone.WIDTH_CELL); return bounds; } - private IList? getRestrictedAreas() { + private IList getRestrictedAreas() { List result = []; var tZones = zoneManager.GetZones(ZoneType.ZONE_LIMIT_T) .GetAwaiter() diff --git a/mod/Jailbreak.Zones/SqlZoneManager.cs b/mod/Jailbreak.Zones/SqlZoneManager.cs index f3dc44a5..4115f58c 100644 --- a/mod/Jailbreak.Zones/SqlZoneManager.cs +++ b/mod/Jailbreak.Zones/SqlZoneManager.cs @@ -8,26 +8,29 @@ namespace Jailbreak.Zones; public class SqlZoneManager(IZoneFactory factory) : IZoneManager { - public static FakeConVar CvSqlTable = new("css_jb_zonetable", + public static readonly FakeConVar CvSqlTable = new("css_jb_zonetable", "The table name for the zones", "cs2_jb_zones"); - public static FakeConVar CvSqlConnectionString = + public static readonly FakeConVar CvSqlConnectionString = new("css_jb_sqlconnection", "The connection string for the database", "", ConVarFlags.FCVAR_PROTECTED); - private readonly IDictionary> zones = - new Dictionary>(); + private readonly Dictionary> zones = new(); private BasePlugin plugin = null!; public void Start(BasePlugin basePlugin) { plugin = basePlugin; + CvSqlConnectionString.ValueChanged += async (_, _) => { + await LoadZones(Server.MapName); + }; + basePlugin.RegisterListener(OnMapStart); basePlugin.RegisterListener(OnMapEnd); } - public void Dispose() { + void IDisposable.Dispose() { plugin.RemoveListener(OnMapStart); plugin.RemoveListener(OnMapEnd); } @@ -35,10 +38,9 @@ public void Dispose() { public async Task DeleteZone(int zoneId, string map) { foreach (var list in zones.Values) { var zone = list.FirstOrDefault(z => z.Id == zoneId); - if (zone != null) { - list.Remove(zone); - break; - } + if (zone == null) continue; + list.Remove(zone); + break; } foreach (var list in zones.Values) { @@ -48,11 +50,11 @@ public async Task DeleteZone(int zoneId, string map) { break; } + await using var conn = createConnection(); + if (conn == null) return; try { - var conn = createConnection(); - if (conn == null) return; await conn.OpenAsync(); - var cmd = conn.CreateCommand(); + await using var cmd = conn.CreateCommand(); cmd.CommandText = $""" DELETE FROM {CvSqlTable.Value.Trim('"')} WHERE zoneid = @zoneid @@ -62,9 +64,9 @@ public async Task DeleteZone(int zoneId, string map) { cmd.Parameters.AddWithValue("@zoneid", zoneId); cmd.Parameters.AddWithValue("@map", map); await cmd.ExecuteNonQueryAsync(); - + } catch (MySqlException e) { Console.WriteLine(e); } finally { await conn.CloseAsync(); - } catch (MySqlException e) { Console.WriteLine(e); } + } } public async Task PushZoneWithID(IZone zone, ZoneType type, string map) { @@ -83,9 +85,9 @@ public async Task PushZoneWithID(IZone zone, ZoneType type, string map) { list.Add(zone); + await using var conn = createConnection(); + if (conn == null) return; try { - var conn = createConnection(); - if (conn == null) return; await conn.OpenAsync(); var insertPointCommand = $""" @@ -95,9 +97,7 @@ public async Task PushZoneWithID(IZone zone, ZoneType type, string map) { var pointId = 0; foreach (var point in zone.GetAllPoints()) { - var cmd = conn.CreateCommand(); - cmd.CommandText = insertPointCommand; - + await using var cmd = new MySqlCommand(insertPointCommand, conn); cmd.Parameters.AddWithValue("@map", map); cmd.Parameters.AddWithValue("@type", type.ToString()); @@ -108,9 +108,9 @@ public async Task PushZoneWithID(IZone zone, ZoneType type, string map) { cmd.Parameters.AddWithValue("@pointid", pointId++); await cmd.ExecuteNonQueryAsync(); } - + } catch (MySqlException e) { Console.WriteLine(e); } finally { await conn.CloseAsync(); - } catch (MySqlException e) { Console.WriteLine(e); } + } } public Task> GetZones(string map, ZoneType type) { @@ -125,9 +125,9 @@ public async Task PushZone(IZone zone, ZoneType type, string map) { zones[type] = list; } - list.Add(zone); - - var nextId = zones.SelectMany(s => s.Value).Max(z => z.Id) + 1; + var nextId = zones.Count == 0 ? + 0 : + zones.SelectMany(s => s.Value).Max(z => z.Id) + 1; zone.Id = nextId; await PushZoneWithID(zone, type, map); } @@ -138,7 +138,7 @@ public async Task UpdateZone(IZone zone, ZoneType type, int id) { await PushZoneWithID(zone, type, Server.MapName); } - public Task>> GetAllZones() { + public Task>> GetAllZones() { return Task.FromResult(zones); } @@ -154,9 +154,9 @@ public async Task LoadZones(string map) { private void OnMapEnd() { zones.Clear(); } private async Task createTable() { + await using var conn = createConnection(); + if (conn == null) return; try { - var conn = createConnection(); - if (conn == null) return; await conn.OpenAsync(); var cmdText = $""" @@ -171,10 +171,11 @@ type VARCHAR(32) NOT NULL, PRIMARY KEY(map, zoneid, pointid)) """; - var cmd = new MySqlCommand(cmdText, conn); + await using var cmd = new MySqlCommand(cmdText, conn); await cmd.ExecuteNonQueryAsync(); + } catch (MySqlException e) { Console.WriteLine(e); } finally { await conn.CloseAsync(); - } catch (MySqlException e) { Console.WriteLine(e); } + } } private void OnMapStart(string mapname) { @@ -184,62 +185,60 @@ private void OnMapStart(string mapname) { }); } - private MySqlCommand queryAllZones(string map, ZoneType type) { + private MySqlCommand queryAllZones(MySqlConnection conn, string map, + ZoneType type) { var cmdText = $""" SELECT * FROM {CvSqlTable.Value.Trim('"')} WHERE map = '{map}' AND type = '{type}' ORDER BY zoneid, pointid DESC """; - return new MySqlCommand(cmdText); + return new MySqlCommand(cmdText, conn); } public async Task LoadZones(string map, ZoneType type) { - var conn = createConnection(); + // var conn = createConnection(); + await using var conn = createConnection(); if (conn == null) return; - var cmd = queryAllZones(map, type); - try { await conn.OpenAsync(); - cmd.Connection = conn; - - var reader = await cmd.ExecuteReaderAsync(); - - var currentZone = -1; - var pointId = -1; - var zoneCreator = new BasicZoneCreator(); + await using var cmd = queryAllZones(conn, map, type); + await using var reader = await cmd.ExecuteReaderAsync(); + var currentZone = -1; + var pointId = -1; + var zoneCreator = new BasicZoneCreator(); zoneCreator.BeginCreation(); - Server.NextFrame(() => { - while (reader.Read()) { - var point = new Vector(reader.GetFloat("X"), reader.GetFloat("Y"), - reader.GetFloat("Z")); + while (await reader.ReadAsync()) { + var x = reader.GetFloat("X"); + var y = reader.GetFloat("Y"); + var z = reader.GetFloat("Z"); + var zoneId = reader.GetInt32("zoneid"); + var pid = reader.GetInt32("pointid"); + Server.NextFrame(() => { + var point = new Vector(x, y, z); zoneCreator.AddPoint(point); - var zoneId = reader.GetInt32("zoneid"); - pointId = reader.GetInt32("pointid"); - // We just started reading zones if (currentZone == -1) currentZone = zoneId; - if (pointId == 0 || zoneId != currentZone) { - if (zoneId != currentZone) - printNotClosedWarning(map, zoneId, pointId, currentZone); - // Assume the zone is closed and allow the new zone to be created - var zone = zoneCreator.Build(factory); - if (!zones.ContainsKey(type)) zones[type] = new List(); - zone.Id = zoneId; - zones[type].Add(zone); - pointId = -1; - currentZone = -1; - zoneCreator.BeginCreation(); - } - } - - reader.Close(); - - if (pointId > 0) printNotClosedWarning(map, -1, pointId, currentZone); - }); - } catch (MySqlException e) { Console.WriteLine(e); } + if (pid != 0 && zoneId == currentZone) return; + if (zoneId != currentZone) + printNotClosedWarning(map, zoneId, pid, currentZone); + // Assume the zone is closed and allow the new zone to be created + var zone = zoneCreator.Build(factory); + if (!zones.ContainsKey(type)) zones[type] = new List(); + zone.Id = zoneId; + zones[type].Add(zone); + pointId = -1; + currentZone = -1; + zoneCreator.BeginCreation(); + }); + } + + if (pointId > 0) printNotClosedWarning(map, -1, pointId, currentZone); + } catch (MySqlException e) { Console.WriteLine(e); } finally { + await conn.CloseAsync(); + } await Task.Delay((int)Math.Ceiling(Server.TickInterval / 1000) * 5); } diff --git a/public/Jailbreak.Formatting/Extensions/ViewExtensions.cs b/public/Jailbreak.Formatting/Extensions/ViewExtensions.cs index 559e5b2e..067798b9 100644 --- a/public/Jailbreak.Formatting/Extensions/ViewExtensions.cs +++ b/public/Jailbreak.Formatting/Extensions/ViewExtensions.cs @@ -6,6 +6,8 @@ using Jailbreak.Public.Extensions; using Jailbreak.Public.Utils; +#pragma warning disable CS0618 // Type or member is obsolete + namespace Jailbreak.Formatting.Extensions; public static class ViewExtensions { diff --git a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs index df057de7..304cdbfa 100644 --- a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs +++ b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs @@ -2,13 +2,8 @@ namespace Jailbreak.Formatting.Logistics; -public class LanguageConfig where TDialect : IDialect { - private readonly IServiceCollection collection; - - public LanguageConfig(IServiceCollection collection) { - this.collection = collection; - } - +public class LanguageConfig(IServiceCollection collection) + where TDialect : IDialect { public void Configure(Dictionary serviceMap) { foreach (var (service, implementation) in serviceMap) { var method = typeof(IServiceCollection).GetMethod("AddSingleton") diff --git a/public/Jailbreak.Formatting/Views/LastRequest/ILRLocale.cs b/public/Jailbreak.Formatting/Views/LastRequest/ILRLocale.cs index 484d0cc1..91aea8de 100644 --- a/public/Jailbreak.Formatting/Views/LastRequest/ILRLocale.cs +++ b/public/Jailbreak.Formatting/Views/LastRequest/ILRLocale.cs @@ -3,7 +3,7 @@ using Jailbreak.Public.Mod.LastRequest; using Jailbreak.Public.Mod.LastRequest.Enums; -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.LastRequest; /// /// Last Request Locale diff --git a/public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs b/public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs index fa00b58a..140ba008 100644 --- a/public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs +++ b/public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs @@ -1,9 +1,10 @@ using Jailbreak.Formatting.Base; -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.Warden; public interface IWardenCmdOpenLocale { public IView CellsOpened { get; } public IView OpeningFailed { get; } + public IView AlreadyOpened { get; } public IView CannotOpenYet(int seconds); } \ No newline at end of file diff --git a/public/Jailbreak.Formatting/Views/Warden/IWardenCmdRollLocale.cs b/public/Jailbreak.Formatting/Views/Warden/IWardenCmdRollLocale.cs index 6c43959a..9dda48a5 100644 --- a/public/Jailbreak.Formatting/Views/Warden/IWardenCmdRollLocale.cs +++ b/public/Jailbreak.Formatting/Views/Warden/IWardenCmdRollLocale.cs @@ -1,6 +1,6 @@ using Jailbreak.Formatting.Base; -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.Warden; public interface IWardenCmdRollLocale { IView Roll(int roll); diff --git a/public/Jailbreak.Formatting/Views/Warden/IWardenLocale.cs b/public/Jailbreak.Formatting/Views/Warden/IWardenLocale.cs index 2d3c82f6..177eaeb5 100644 --- a/public/Jailbreak.Formatting/Views/Warden/IWardenLocale.cs +++ b/public/Jailbreak.Formatting/Views/Warden/IWardenLocale.cs @@ -3,7 +3,7 @@ // ReSharper disable InconsistentNaming -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.Warden; public interface IWardenLocale { public IView PickingShortly { get; } diff --git a/public/Jailbreak.Formatting/Views/Warden/IWardenPeaceLocale.cs b/public/Jailbreak.Formatting/Views/Warden/IWardenPeaceLocale.cs index ee1f6324..fc0e6dbb 100644 --- a/public/Jailbreak.Formatting/Views/Warden/IWardenPeaceLocale.cs +++ b/public/Jailbreak.Formatting/Views/Warden/IWardenPeaceLocale.cs @@ -1,6 +1,6 @@ using Jailbreak.Formatting.Base; -namespace Jailbreak.Formatting.Views; +namespace Jailbreak.Formatting.Views.Warden; public interface IWardenPeaceLocale { public IView UnmutedGuards { get; } diff --git a/public/Jailbreak.Public/Behaviors/IPluginBehavior.cs b/public/Jailbreak.Public/Behaviors/IPluginBehavior.cs index 8a14d42d..6baed579 100644 --- a/public/Jailbreak.Public/Behaviors/IPluginBehavior.cs +++ b/public/Jailbreak.Public/Behaviors/IPluginBehavior.cs @@ -13,7 +13,5 @@ void IDisposable.Dispose() { } /// void Start(BasePlugin basePlugin) { } - void Start(BasePlugin basePlugin, bool hotreload) { - Start(basePlugin); - } + void Start(BasePlugin basePlugin, bool hotreload) { Start(basePlugin); } } \ No newline at end of file diff --git a/public/Jailbreak.Public/Extensions/CollectionExtensions.cs b/public/Jailbreak.Public/Extensions/CollectionExtensions.cs index e2f24e0c..5b78e4b9 100644 --- a/public/Jailbreak.Public/Extensions/CollectionExtensions.cs +++ b/public/Jailbreak.Public/Extensions/CollectionExtensions.cs @@ -11,4 +11,9 @@ public static void Shuffle(this IList list) { (list[k], list[n]) = (list[n], list[k]); } } + + public static void Shuffle(this IEnumerable enumerable) { + var list = enumerable.ToList(); + list.Shuffle(); + } } \ No newline at end of file diff --git a/public/Jailbreak.Public/Extensions/WeaponExtensions.cs b/public/Jailbreak.Public/Extensions/WeaponExtensions.cs index 59db0fee..4501fc5d 100644 --- a/public/Jailbreak.Public/Extensions/WeaponExtensions.cs +++ b/public/Jailbreak.Public/Extensions/WeaponExtensions.cs @@ -133,6 +133,7 @@ public static string GetFriendlyWeaponName(this string designerName) { public static void AddBulletsToMagazine(this CBasePlayerWeapon? weapon, int bullets) { + if (weapon == null) return; if (weapon.Clip1 + bullets > weapon.VData!.MaxClip1) { var overflowBullets = weapon.Clip1 + bullets - weapon.VData!.MaxClip1; weapon.Clip1 = weapon.VData!.MaxClip1; diff --git a/public/Jailbreak.Public/Jailbreak.Public.csproj b/public/Jailbreak.Public/Jailbreak.Public.csproj index 7351b823..029c9835 100644 --- a/public/Jailbreak.Public/Jailbreak.Public.csproj +++ b/public/Jailbreak.Public/Jailbreak.Public.csproj @@ -8,6 +8,7 @@ + diff --git a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs index e25c9d10..6d55fc7e 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs @@ -16,8 +16,9 @@ namespace Jailbreak.Public.Mod.SpecialDay; public abstract class AbstractSpecialDay(BasePlugin plugin, IServiceProvider provider) { + protected readonly BasePlugin Plugin = plugin; private readonly Dictionary previousConvarValues = new(); - protected BasePlugin Plugin = plugin; + protected readonly IServiceProvider Provider = provider; protected IDictionary Timers = new DefaultableDictionary(new Dictionary(), @@ -70,15 +71,15 @@ public virtual void Setup() { if (Settings.StartInvulnerable) DisableDamage(); if (!Settings.AllowLastRequests) - provider.GetRequiredService().DisableLRForRound(); + Provider.GetRequiredService().DisableLRForRound(); if (!Settings.AllowLastGuard) - provider.GetRequiredService() + Provider.GetRequiredService() .DisableLastGuardForRound(); if (!Settings.AllowRebels) - provider.GetRequiredService().DisableRebelForRound(); + Provider.GetRequiredService().DisableRebelForRound(); if (Settings.OpenCells) - MapUtil.OpenCells(provider.GetRequiredService()); + MapUtil.OpenCells(Provider.GetRequiredService()); doTeleports(); @@ -91,7 +92,7 @@ public virtual void Setup() { foreach (var entry in Timers) Plugin.AddTimer(entry.Key, () => { - if (provider.GetRequiredService().CurrentSD != this) + if (Provider.GetRequiredService().CurrentSD != this) return; entry.Value.Invoke(); }, TimerFlags.STOP_ON_MAPCHANGE); @@ -122,35 +123,30 @@ private void doTeleports(SpecialDaySettings.TeleportType type, .FindAllEntitiesByDesignerName("info_player_counterterrorist") .Where(s => s.AbsOrigin != null) .Select(s => s.AbsOrigin!); + var enumerable = tSpawns as Vector[] ?? tSpawns.ToArray(); + enumerable.Shuffle(); + var positions = ctSpawns as Vector[] ?? ctSpawns.ToArray(); + positions.Shuffle(); + IEnumerable spawnPositions; switch (type) { case SpecialDaySettings.TeleportType.CELL: - spawnPositions = tSpawns; + spawnPositions = enumerable; break; case SpecialDaySettings.TeleportType.CELL_STACKED: - spawnPositions = [tSpawns.First()]; + spawnPositions = [enumerable.First()]; break; case SpecialDaySettings.TeleportType.ARMORY: - spawnPositions = ctSpawns; + spawnPositions = positions; break; case SpecialDaySettings.TeleportType.ARMORY_STACKED: - spawnPositions = [ctSpawns.First()]; + spawnPositions = [positions.First()]; break; case SpecialDaySettings.TeleportType.RANDOM: - spawnPositions = getRandomSpawns(false, false).ToList(); - // If we don't have enough manually specified spawns, - // gradually pull from the other spawn types - if (spawnPositions.Count() < PlayerUtil.GetAlive().Count()) - spawnPositions = getRandomSpawns(false).ToList(); - if (spawnPositions.Count() < PlayerUtil.GetAlive().Count()) - spawnPositions = getRandomSpawns().ToList(); + spawnPositions = getAtLeastRandom(PlayerUtil.GetAlive().Count()); break; case SpecialDaySettings.TeleportType.RANDOM_STACKED: - spawnPositions = getRandomSpawns(false, false).Take(1).ToList(); - if (!spawnPositions.Any()) - spawnPositions = getRandomSpawns(false).Take(1).ToList(); - if (!spawnPositions.Any()) - spawnPositions = getRandomSpawns().Take(1).ToList(); + spawnPositions = getAtLeastRandom(1); break; default: return; @@ -161,8 +157,17 @@ private void doTeleports(SpecialDaySettings.TeleportType type, player.PlayerPawn.Value?.Teleport(baggedSpawns.GetNext()); } + private List getAtLeastRandom(int count) { + // Progressively get more lax with our "randomness quality" + var result = getRandomSpawns(false, false, false); + if (result.Count < count) result = getRandomSpawns(false, false); + if (result.Count < count) result = getRandomSpawns(false); + if (result.Count < count) result = getRandomSpawns(); + return result; + } + private List getRandomSpawns(bool includeSpawns = true, - bool includeTps = true) { + bool includeTps = true, bool includeAuto = true) { var result = new List(); if (includeTps) { @@ -188,7 +193,13 @@ private List getRandomSpawns(bool includeSpawns = true, result.AddRange(ctSpawns); } - var zoneManager = provider.GetRequiredService(); + var zoneManager = Provider.GetRequiredService(); + if (includeAuto) + result.AddRange(zoneManager.GetZones(ZoneType.SPAWN_AUTO) + .GetAwaiter() + .GetResult() + .Select(z => z.GetCenterPoint())); + var zones = zoneManager.GetZones(ZoneType.SPAWN).GetAwaiter().GetResult(); result.AddRange(zones.Select(z => z.GetCenterPoint())); diff --git a/public/Jailbreak.Public/Mod/SpecialDay/DefaultDictionary.cs b/public/Jailbreak.Public/Mod/SpecialDay/DefaultDictionary.cs index 489a86cd..a4bc1280 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/DefaultDictionary.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/DefaultDictionary.cs @@ -1,4 +1,5 @@ using System.Collections; +using JetBrains.Annotations; namespace Jailbreak.Public.Mod.SpecialDay; @@ -12,10 +13,12 @@ public DefaultableDictionary(IDictionary dictionary, this.defaultValue = defaultValue; } + [MustDisposeResource] public IEnumerator> GetEnumerator() { return dictionary.GetEnumerator(); } + [MustDisposeResource] IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Add(KeyValuePair item) { dictionary.Add(item); } diff --git a/public/Jailbreak.Public/Mod/SpecialDay/ShuffleBag.cs b/public/Jailbreak.Public/Mod/SpecialDay/ShuffleBag.cs index 90144205..bc873ad5 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/ShuffleBag.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/ShuffleBag.cs @@ -23,7 +23,9 @@ public ShuffleBag(IEnumerable items) { public IEnumerator GetEnumerator() { while (true) yield return GetNext(); + // ReSharper disable IteratorNeverReturns } + // ReSharper restore IteratorNeverReturns IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } diff --git a/public/Jailbreak.Public/Mod/Trail/AbstractTrail.cs b/public/Jailbreak.Public/Mod/Trail/AbstractTrail.cs index f4eaefab..9fddff66 100644 --- a/public/Jailbreak.Public/Mod/Trail/AbstractTrail.cs +++ b/public/Jailbreak.Public/Mod/Trail/AbstractTrail.cs @@ -1,6 +1,7 @@ using System.Collections; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Public.Extensions; +using JetBrains.Annotations; namespace Jailbreak.Public.Mod.Trail; @@ -19,8 +20,10 @@ public virtual int MaxPoints { set => maxPoints = value; } + [MustDisposeResource] public IEnumerator GetEnumerator() { return Segments.GetEnumerator(); } + [MustDisposeResource] IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public virtual T? GetStartSegment() { return Segments.LastOrDefault(); } diff --git a/public/Jailbreak.Public/Mod/Zones/IZoneManager.cs b/public/Jailbreak.Public/Mod/Zones/IZoneManager.cs index 166d4d0c..f18b4666 100644 --- a/public/Jailbreak.Public/Mod/Zones/IZoneManager.cs +++ b/public/Jailbreak.Public/Mod/Zones/IZoneManager.cs @@ -23,5 +23,5 @@ Task PushZone(IZone zone, ZoneType type) { Task UpdateZone(IZone zone, ZoneType type, int id); - Task>> GetAllZones(); + Task>> GetAllZones(); } \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/Zones/ZoneType.cs b/public/Jailbreak.Public/Mod/Zones/ZoneType.cs index a33eb2d8..da48b01e 100644 --- a/public/Jailbreak.Public/Mod/Zones/ZoneType.cs +++ b/public/Jailbreak.Public/Mod/Zones/ZoneType.cs @@ -46,7 +46,7 @@ public enum ZoneType { /// /// Similar to SPAWN, but this spawn location was automatically - /// generated + /// generated /// SPAWN_AUTO, @@ -80,7 +80,8 @@ public static Color GetColor(this ZoneType type) { ZoneType.ZONE_LIMIT_T => Color.OrangeRed, ZoneType.ZONE_LIMIT_CT => Color.LightBlue, ZoneType.SPAWN_AUTO => Color.Gray, - _ => Color.Black + ZoneType.CELL_BUTTON => Color.DarkRed, + _ => Color.Magenta }; } diff --git a/public/Jailbreak.Public/Utils/MapUtil.cs b/public/Jailbreak.Public/Utils/MapUtil.cs index 6bc740bb..fc45aa0c 100644 --- a/public/Jailbreak.Public/Utils/MapUtil.cs +++ b/public/Jailbreak.Public/Utils/MapUtil.cs @@ -23,12 +23,17 @@ public static bool OpenCells(IZoneManager zoneManager) { .GetAwaiter() .GetResult(); - if (zones.Count == 0) return OpenCells() <= Sensitivity.TARGET_CELL; + Server.PrintToChatAll("Attempting to open cells..."); - return OpenCells(Sensitivity.ANY, zones[0].GetCenterPoint()) != null; + if (zones == null || zones.Count == 0) { + Server.PrintToChatAll("No cell buttons found."); + return OpenCells() <= Sensitivity.TARGET_CELL; + } + + return OpenCells(Sensitivity.ANY, zones.First().GetCenterPoint()) != null; } - private static Sensitivity? OpenCells( + public static Sensitivity? OpenCells( Sensitivity sensitivity = Sensitivity.NAME_CELL_DOOR, Vector? source = null) { if (source == null) source = getCtSpawn(); @@ -80,8 +85,12 @@ public static bool OpenCells(IZoneManager zoneManager) { } private static void PressButton(CBaseEntity entity) { - entity.AcceptInput("Unlock"); - entity.AcceptInput("Press"); + Server.PrintToChatAll( + $"Pressing button {entity.Globalname} {entity.Target}"); + entity.AcceptInput("Unlock", + PlayerUtil.FromTeam(CsTeam.CounterTerrorist).FirstOrDefault()); + entity.AcceptInput("Press", + PlayerUtil.FromTeam(CsTeam.CounterTerrorist).FirstOrDefault()); } private static bool IsCellButton(CBaseEntity ent, Sensitivity sen) { diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index d72e3156..f4306f70 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -9,7 +9,6 @@ using Jailbreak.English.Rebel; using Jailbreak.English.SpecialDay; using Jailbreak.English.Warden; -using Jailbreak.Formatting.Logistics; using Jailbreak.Formatting.Views; using Jailbreak.Formatting.Views.LastRequest; using Jailbreak.Formatting.Views.Warden;