diff --git a/lang/Jailbreak.English/Warden/WardenCmdCountLocale.cs b/lang/Jailbreak.English/Warden/WardenCmdCountLocale.cs new file mode 100644 index 00000000..8a3885f2 --- /dev/null +++ b/lang/Jailbreak.English/Warden/WardenCmdCountLocale.cs @@ -0,0 +1,31 @@ +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Formatting.Base; +using Jailbreak.Formatting.Logistics; +using Jailbreak.Formatting.Views.Warden; + +namespace Jailbreak.English.Warden; + +public class WardenCmdCountLocale : IWardenCmdCountLocale, + ILanguage { + public IView PrisonersInMarker(int prisoners) { + return new SimpleView { + WardenLocale.PREFIX, + ChatColors.Grey + "There " + (prisoners == 1 ? "is" : " are"), + prisoners, + ChatColors.Grey + "prisoner" + (prisoners == 1 ? "" : "s") + + " in the marker." + }; + } + + public IView CannotCountYet(int seconds) { + return new SimpleView { + WardenLocale.PREFIX, + "You must wait", + seconds, + "seconds before counting prisoners." + }; + } + + public IView NoMarkerSet + => new SimpleView { WardenLocale.PREFIX, "No marker set." }; +} \ No newline at end of file diff --git a/mod/Gangs.Boostrap/Gangs.Boostrap.csproj b/mod/Gangs.Boostrap/Gangs.Boostrap.csproj index d38ef7b3..c9c1b0f6 100644 --- a/mod/Gangs.Boostrap/Gangs.Boostrap.csproj +++ b/mod/Gangs.Boostrap/Gangs.Boostrap.csproj @@ -8,7 +8,7 @@ - + diff --git a/mod/Gangs.SpecialDayColorPerk/Gangs.SpecialDayColorPerk.csproj b/mod/Gangs.SpecialDayColorPerk/Gangs.SpecialDayColorPerk.csproj index 00f19816..3502e553 100644 --- a/mod/Gangs.SpecialDayColorPerk/Gangs.SpecialDayColorPerk.csproj +++ b/mod/Gangs.SpecialDayColorPerk/Gangs.SpecialDayColorPerk.csproj @@ -7,18 +7,18 @@ - + - - ..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll - + + ..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll + - - + + diff --git a/mod/Gangs.SpecialDayColorPerk/SDColorPerk.cs b/mod/Gangs.SpecialDayColorPerk/SDColorPerk.cs index 274f5f33..7d6b56fb 100644 --- a/mod/Gangs.SpecialDayColorPerk/SDColorPerk.cs +++ b/mod/Gangs.SpecialDayColorPerk/SDColorPerk.cs @@ -10,16 +10,19 @@ namespace Gangs.SpecialDayColorPerk; public class SDColorPerk(IServiceProvider provider) : BasePerk(provider) { - public override string StatId => STAT_ID; - public override string Name => "Special Day Color"; public const string STAT_ID = "jb_sd_color"; private readonly IGangStatManager gangStats = provider.GetRequiredService(); + public override string StatId => STAT_ID; + public override string Name => "Special Day Color"; + public override string? Description => "Change the color of your gang during special days!"; + public override SDColorData Value { get; set; } = new(); + public override Task GetCost(IGangPlayer player) { return Task.FromResult(null); } @@ -35,8 +38,6 @@ public override string? Description public override Task OnPurchase(IGangPlayer player) { return Task.CompletedTask; } - - public override SDColorData Value { get; set; } = new(); } public class SDColorData { diff --git a/mod/Jailbreak.LastRequest/LastRequestManager.cs b/mod/Jailbreak.LastRequest/LastRequestManager.cs index a248e9ed..ce638cbc 100644 --- a/mod/Jailbreak.LastRequest/LastRequestManager.cs +++ b/mod/Jailbreak.LastRequest/LastRequestManager.cs @@ -91,11 +91,6 @@ public void DisableLRForRound() { IsLREnabledForRound = false; } - private static bool shouldGrantCredits() { - if (API.Gangs == null) return false; - return Utilities.GetPlayers().Count >= CV_MIN_PLAYERS_FOR_CREDITS.Value; - } - public void EnableLR(CCSPlayerController? died = null) { messages.LastRequestEnabled().ToAllChat(); IsLREnabled = true; @@ -183,6 +178,11 @@ public bool EndLastRequest(AbstractLastRequest lr, LRResult result) { return true; } + private static bool shouldGrantCredits() { + if (API.Gangs == null) return false; + return Utilities.GetPlayers().Count >= CV_MIN_PLAYERS_FOR_CREDITS.Value; + } + [GameEventHandler(HookMode.Pre)] public HookResult OnTakeDamage(EventPlayerHurt @event, GameEventInfo info) { IDamageBlocker damageBlockerHandler = this; @@ -262,6 +262,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, private void checkLR() { Server.RunOnTick(Server.TickCount + 32, () => { + if (IsLREnabled) return; if (Utilities.GetPlayers().All(p => p.Team != CsTeam.CounterTerrorist)) return; if (countAlivePrisoners() > CV_PRISONER_TO_LR.Value) return; diff --git a/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs b/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs index 9e587ca7..4931cac6 100644 --- a/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs +++ b/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs @@ -12,6 +12,7 @@ namespace Jailbreak.LastRequest.LastRequests; public class BulletForBullet : TeleportingRequest { + private const string weaponName = "weapon_deagle"; private readonly ChatMenu chatMenu; private readonly bool magForMag; private readonly ILRB4BLocale msg; @@ -41,8 +42,6 @@ public override void Setup() { Execute(); } - private const string weaponName = "weapon_deagle"; - public override void Execute() { State = LRState.PENDING; MenuManager.OpenChatMenu(Prisoner, chatMenu); diff --git a/mod/Jailbreak.RTD/Rewards/WeaponReward.cs b/mod/Jailbreak.RTD/Rewards/WeaponReward.cs index 23d459d2..cef94276 100644 --- a/mod/Jailbreak.RTD/Rewards/WeaponReward.cs +++ b/mod/Jailbreak.RTD/Rewards/WeaponReward.cs @@ -20,9 +20,8 @@ public WeaponReward(string weapon, CsTeam? requiredTeam = CsTeam.Terrorist) { public virtual string Name => weapon.GetFriendlyWeaponName(); public virtual string Description - => "You won a" - + (weapon.GetFriendlyWeaponName()[0].IsVowel() ? "n" : "") + " " - + weapon.GetFriendlyWeaponName() + " next round."; + => "You won a" + (weapon.GetFriendlyWeaponName()[0].IsVowel() ? "n" : "") + + " " + weapon.GetFriendlyWeaponName() + " next round."; public bool CanGrantReward(CCSPlayerController player) { if (requiredTeam == null) return true; diff --git a/mod/Jailbreak.SpecialDay/Jailbreak.SpecialDay.csproj b/mod/Jailbreak.SpecialDay/Jailbreak.SpecialDay.csproj index 78f28541..6d20f6ef 100644 --- a/mod/Jailbreak.SpecialDay/Jailbreak.SpecialDay.csproj +++ b/mod/Jailbreak.SpecialDay/Jailbreak.SpecialDay.csproj @@ -10,14 +10,14 @@ - + - ..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll + ..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll ..\..\public\Jailbreak.Public\Mixin\MStatsShared.dll diff --git a/mod/Jailbreak.SpecialDay/SpecialDayManager.cs b/mod/Jailbreak.SpecialDay/SpecialDayManager.cs index dc85cb93..3b83278c 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDayManager.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDayManager.cs @@ -1,12 +1,9 @@ -using System.Drawing; -using System.Net; -using CounterStrikeSharp.API; +using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Utils; using Gangs.SpecialDayColorPerk; using GangsAPI.Data; -using GangsAPI.Perks; using GangsAPI.Services.Gang; using GangsAPI.Services.Player; using Jailbreak.Formatting.Extensions; diff --git a/mod/Jailbreak.Warden/Commands/CountCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/CountCommandsBehavior.cs new file mode 100644 index 00000000..964bb157 --- /dev/null +++ b/mod/Jailbreak.Warden/Commands/CountCommandsBehavior.cs @@ -0,0 +1,45 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Modules.Cvars.Validators; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Formatting.Extensions; +using Jailbreak.Formatting.Views.Warden; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Warden; +using Jailbreak.Public.Utils; + +namespace Jailbreak.Warden.Commands; + +public class CountCommandsBehavior(IWardenService warden, IWardenLocale msg, + IWardenCmdCountLocale locale, IMarkerService markers) : IPluginBehavior { + public static readonly FakeConVar CV_COUNT_COMMAND_COOLDOWN = new( + "css_jb_warden_count_cooldown", + "Minimum seconds warden must wait before being able to count perisoners in marker.", + 30, customValidators: new RangeValidator(0, 300)); + + [ConsoleCommand("css_count", "Counts the prisoners in marker")] + public void Command_Count(CCSPlayerController? executor, CommandInfo info) { + if (executor == null) return; + if (!warden.IsWarden(executor)) { + msg.NotWarden.ToChat(executor); + return; + } + + if (RoundUtil.GetTimeElapsed() < CV_COUNT_COMMAND_COOLDOWN.Value) { + locale.CannotCountYet(CV_COUNT_COMMAND_COOLDOWN.Value).ToChat(executor); + return; + } + + if (markers.MarkerPosition == null) { + locale.NoMarkerSet.ToChat(executor); + return; + } + + var prisoners = PlayerUtil.FromTeam(CsTeam.Terrorist) + .Count(markers.InMarker); + + locale.PrisonersInMarker(prisoners); + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs b/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs index 3880eb1d..3063243d 100644 --- a/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs +++ b/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs @@ -12,7 +12,8 @@ namespace Jailbreak.Warden.Markers; -public class WardenMarkerBehavior(IWardenService warden) : IPluginBehavior { +public class WardenMarkerBehavior(IWardenService warden) + : IPluginBehavior, IMarkerService { public static readonly FakeConVar CV_MAX_RADIUS = new( "css_jb_warden_marker_max_radius", "Maximum radius for warden marker", 360); @@ -23,11 +24,15 @@ public class WardenMarkerBehavior(IWardenService warden) : IPluginBehavior { "css_jb_warden_resize_time", "Milliseconds to wait for resizing marker", 800); - private Vector? currentPos; + // private Vector? MarkerPosition; private BeamCircle? marker; private long placementTime; - private float radius; + + public Vector? MarkerPosition { get; private set; } + + public float radius { get; private set; } + // private float radius; public void Start(BasePlugin basePlugin) { marker = new BeamCircle(basePlugin, new Vector(), CV_MIN_RADIUS.Value, @@ -42,8 +47,8 @@ public HookResult OnPing(EventPlayerPing @event, GameEventInfo info) { if (!warden.IsWarden(player)) return HookResult.Handled; var vec = new Vector(@event.X, @event.Y, @event.Z); - if (currentPos != null) { - var distance = currentPos.Distance(vec); + if (MarkerPosition != null) { + var distance = MarkerPosition.Distance(vec); var timeElapsed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - placementTime; if (timeElapsed < CV_RESIZE_TIME.Value) { @@ -61,9 +66,9 @@ public HookResult OnPing(EventPlayerPing @event, GameEventInfo info) { } } - radius = CV_MIN_RADIUS.Value; - currentPos = vec; - placementTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + radius = CV_MIN_RADIUS.Value; + MarkerPosition = vec; + placementTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); API.Stats?.PushStat(new ServerStat("JB_MARKER", $"{vec.X:F2} {vec.Y:F2} {vec.Z:F2}")); diff --git a/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs b/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs index a2a70ce2..dbbe15ff 100644 --- a/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs +++ b/mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs @@ -112,6 +112,7 @@ public void ScheduleChooseWarden(float time = 7.0f) { /// protected void OnChooseWarden() { guaranteedWarden.Clear(); + queueInactive = true; if (warden.HasWarden) return; var eligible = Utilities.GetPlayers() .Where(player => player.PawnIsAlive) @@ -124,7 +125,6 @@ protected void OnChooseWarden() { if (eligible.Count == 0) { locale.NoWardens.ToAllChat(); - queueInactive = true; return; } @@ -154,7 +154,6 @@ protected void OnChooseWarden() { // Disable the warden raffle for future wardens // (eg in the event of warden death) - queueInactive = true; } private bool canEnterQueue(CCSPlayerController player) { diff --git a/mod/Jailbreak.Warden/WardenServiceExtension.cs b/mod/Jailbreak.Warden/WardenServiceExtension.cs index 78165ffa..51442958 100644 --- a/mod/Jailbreak.Warden/WardenServiceExtension.cs +++ b/mod/Jailbreak.Warden/WardenServiceExtension.cs @@ -21,6 +21,7 @@ public static void AddJailbreakWarden( serviceCollection .AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); @@ -28,7 +29,7 @@ public static void AddJailbreakWarden( serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); - serviceCollection.AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); } } \ No newline at end of file diff --git a/public/Jailbreak.Formatting/Views/Warden/IWardenCmdCountLocale.cs b/public/Jailbreak.Formatting/Views/Warden/IWardenCmdCountLocale.cs new file mode 100644 index 00000000..bde4b7c4 --- /dev/null +++ b/public/Jailbreak.Formatting/Views/Warden/IWardenCmdCountLocale.cs @@ -0,0 +1,9 @@ +using Jailbreak.Formatting.Base; + +namespace Jailbreak.Formatting.Views.Warden; + +public interface IWardenCmdCountLocale { + public IView NoMarkerSet { get; } + public IView PrisonersInMarker(int prisoners); + public IView CannotCountYet(int seconds); +} \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/Warden/IMarkerService.cs b/public/Jailbreak.Public/Mod/Warden/IMarkerService.cs new file mode 100644 index 00000000..024ae232 --- /dev/null +++ b/public/Jailbreak.Public/Mod/Warden/IMarkerService.cs @@ -0,0 +1,22 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Extensions; + +namespace Jailbreak.Public.Mod.Warden; + +public interface IMarkerService { + Vector? MarkerPosition { get; } + float radius { get; } + + public bool InMarker(Vector pos) { + if (MarkerPosition == null) return false; + var widenedRadius = radius + 32; + return MarkerPosition.DistanceSquared(pos) <= widenedRadius * widenedRadius; + } + + public bool InMarker(CCSPlayerController player) { + if (MarkerPosition == null) return false; + var pos = player.PlayerPawn.Value?.AbsOrigin; + return pos != null && InMarker(pos); + } +} \ No newline at end of file