Skip to content

Commit

Permalink
Feat/count cmd (#312)
Browse files Browse the repository at this point in the history
* Unmute everyone on round start regardless of peace status

* Dont enable LR if already enabled

* Fix warden breaking after guaranteed warden rtd

* Add count command

* Cleanup
  • Loading branch information
MSWS authored Oct 12, 2024
1 parent d2521b1 commit cb4155d
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 38 deletions.
31 changes: 31 additions & 0 deletions lang/Jailbreak.English/Warden/WardenCmdCountLocale.cs
Original file line number Diff line number Diff line change
@@ -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<Formatting.Languages.English> {
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." };
}
2 changes: 1 addition & 1 deletion mod/Gangs.Boostrap/Gangs.Boostrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<ProjectReference Include="..\Gangs.BombIconPerk\Gangs.BombIconPerk.csproj"/>
<ProjectReference Include="..\Gangs.SpecialDayColorPerk\Gangs.SpecialDayColorPerk.csproj" />
<ProjectReference Include="..\Gangs.SpecialDayColorPerk\Gangs.SpecialDayColorPerk.csproj"/>
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions mod/Gangs.SpecialDayColorPerk/Gangs.SpecialDayColorPerk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.260" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.260"/>
</ItemGroup>

<ItemGroup>
<Reference Include="GangsAPI">
<HintPath>..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll</HintPath>
</Reference>
<Reference Include="GangsAPI">
<HintPath>..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Gangs.BaseImpl\Gangs.BaseImpl.csproj" />
<ProjectReference Include="..\Gangs.BombIconPerk\Gangs.BombIconPerk.csproj" />
<ProjectReference Include="..\Gangs.BaseImpl\Gangs.BaseImpl.csproj"/>
<ProjectReference Include="..\Gangs.BombIconPerk\Gangs.BombIconPerk.csproj"/>
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions mod/Gangs.SpecialDayColorPerk/SDColorPerk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ namespace Gangs.SpecialDayColorPerk;

public class SDColorPerk(IServiceProvider provider)
: BasePerk<SDColorData>(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<IGangStatManager>();

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<int?> GetCost(IGangPlayer player) {
return Task.FromResult<int?>(null);
}
Expand All @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions mod/Jailbreak.LastRequest/LastRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions mod/Jailbreak.RTD/Rewards/WeaponReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.SpecialDay/Jailbreak.SpecialDay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<ProjectReference Include="..\..\lang\Jailbreak.English\Jailbreak.English.csproj"/>
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj"/>
<ProjectReference Include="..\..\public\Jailbreak.Validator\Jailbreak.Validator.csproj"/>
<ProjectReference Include="..\Gangs.SpecialDayColorPerk\Gangs.SpecialDayColorPerk.csproj" />
<ProjectReference Include="..\Gangs.SpecialDayColorPerk\Gangs.SpecialDayColorPerk.csproj"/>
<ProjectReference Include="..\Jailbreak.Trail\Jailbreak.Trail.csproj"/>
<ProjectReference Include="..\Jailbreak.Zones\Jailbreak.Zones.csproj"/>
</ItemGroup>

<ItemGroup>
<Reference Include="GangsAPI">
<HintPath>..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll</HintPath>
<HintPath>..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll</HintPath>
</Reference>
<Reference Include="MStatsShared">
<HintPath>..\..\public\Jailbreak.Public\Mixin\MStatsShared.dll</HintPath>
Expand Down
5 changes: 1 addition & 4 deletions mod/Jailbreak.SpecialDay/SpecialDayManager.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
45 changes: 45 additions & 0 deletions mod/Jailbreak.Warden/Commands/CountCommandsBehavior.cs
Original file line number Diff line number Diff line change
@@ -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<int> 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<int>(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);
}
}
21 changes: 13 additions & 8 deletions mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> CV_MAX_RADIUS = new(
"css_jb_warden_marker_max_radius", "Maximum radius for warden marker", 360);

Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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}"));
Expand Down
3 changes: 1 addition & 2 deletions mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void ScheduleChooseWarden(float time = 7.0f) {
/// </summary>
protected void OnChooseWarden() {
guaranteedWarden.Clear();
queueInactive = true;
if (warden.HasWarden) return;
var eligible = Utilities.GetPlayers()
.Where(player => player.PawnIsAlive)
Expand All @@ -124,7 +125,6 @@ protected void OnChooseWarden() {

if (eligible.Count == 0) {
locale.NoWardens.ToAllChat();
queueInactive = true;

return;
}
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion mod/Jailbreak.Warden/WardenServiceExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ public static void AddJailbreakWarden(
serviceCollection
.AddPluginBehavior<IWardenOpenCommand, WardenOpenCommandsBehavior>();


serviceCollection.AddPluginBehavior<SpecialTreatmentCommandsBehavior>();
serviceCollection.AddPluginBehavior<PeaceCommandsBehavior>();
serviceCollection.AddPluginBehavior<WardenCommandsBehavior>();
serviceCollection.AddPluginBehavior<RollCommandBehavior>();
serviceCollection.AddPluginBehavior<ChickenCommandBehavior>();
serviceCollection.AddPluginBehavior<SoccerCommandBehavior>();

serviceCollection.AddPluginBehavior<WardenMarkerBehavior>();
serviceCollection.AddPluginBehavior<IMarkerService, WardenMarkerBehavior>();
serviceCollection.AddPluginBehavior<WardenPaintBehavior>();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
22 changes: 22 additions & 0 deletions public/Jailbreak.Public/Mod/Warden/IMarkerService.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit cb4155d

Please sign in to comment.