Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS authored Feb 3, 2024
2 parents 612482c + 07c221f commit c02e210
Show file tree
Hide file tree
Showing 36 changed files with 222 additions and 244 deletions.
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: [ "https://edgm.rs/donate", "https://msws.xyz/donate" ] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
4 changes: 2 additions & 2 deletions mod/Jailbreak.Teams/Queue/QueueBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public bool TryPop(int count)
{
_logger.LogInformation("[Queue] Popping player {@Name}", queue[i].PlayerName);

ForceGuard( queue[i] );
ForceGuard(queue[i]);
}

return true;
Expand All @@ -96,7 +96,7 @@ public bool TryPush(int count)
.ToList();
_logger.LogInformation("[Queue] Push requested {@Count} out of {@GuardCount}", count, players.Count);

for (int i = 0; i < Math.Min(count, players.Count); i++)
for (var i = 0; i < Math.Min(count, players.Count); i++)
{
var toSwap = players[i];
_logger.LogInformation("[Queue] Pushing {@Name}", toSwap.PlayerName);
Expand Down
11 changes: 3 additions & 8 deletions mod/Jailbreak.Teams/Queue/QueueState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

public class QueueState
{

public QueueState()
{
}

/// <summary>
/// The counter value when the player entered the queue
/// Lower = join CT sooner
/// The counter value when the player entered the queue
/// Lower = join CT sooner
/// </summary>
public int Position { get; set; }

Expand All @@ -23,4 +18,4 @@ public QueueState()
/// If this is false, they will be swapped back to prisoner.
/// </summary>
public bool IsGuard { get; set; }
}
}
47 changes: 23 additions & 24 deletions mod/Jailbreak.Teams/Ratio/RatioBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Public.Behaviors;
Expand All @@ -13,33 +12,25 @@

using Serilog;

using Microsoft.Extensions.Logging;

Check warning on line 15 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The using directive for 'Microsoft.Extensions.Logging' appeared previously in this namespace

Check warning on line 15 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The using directive for 'Microsoft.Extensions.Logging' appeared previously in this namespace

namespace Jailbreak.Teams.Ratio;

public class RatioBehavior : IPluginBehavior
{
private IGuardQueue _guardQueue;
private ILogger<RatioBehavior> _logger;

public enum RatioActionType
{
Add,
Remove,
None,
}

public struct RatioAction
{
public RatioActionType Type { get; init; }
public int Count { get; init; }

public RatioAction(int count = 0, RatioActionType type = RatioActionType.None)
{
Count = count;
Type = type;
}
None
}

private RatioConfig _config;
private readonly RatioConfig _config;
private readonly IGuardQueue _guardQueue;

Check failure on line 32 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'RatioBehavior' already contains a definition for '_guardQueue'

Check failure on line 32 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'RatioBehavior' already contains a definition for '_guardQueue'

Check failure on line 32 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'RatioBehavior' already contains a definition for '_guardQueue'

Check failure on line 32 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'RatioBehavior' already contains a definition for '_guardQueue'
private readonly ILogger<RatioBehavior> _logger;

Check failure on line 33 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'RatioBehavior' already contains a definition for '_logger'

Check failure on line 33 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'RatioBehavior' already contains a definition for '_logger'

Check failure on line 33 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'RatioBehavior' already contains a definition for '_logger'

Check failure on line 33 in mod/Jailbreak.Teams/Ratio/RatioBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type 'RatioBehavior' already contains a definition for '_logger'

public RatioBehavior(RatioConfig config, IGuardQueue guardQueue, ILogger<RatioBehavior> logger)
{
Expand All @@ -49,7 +40,7 @@ public RatioBehavior(RatioConfig config, IGuardQueue guardQueue, ILogger<RatioBe
}

/// <summary>
/// Evaluate whether the provided CT/T ratio needs
/// Evaluate whether the provided CT/T ratio needs
/// </summary>
/// <param name="ct"></param>
/// <param name="t"></param>
Expand All @@ -59,9 +50,9 @@ public RatioAction Evaluate(int ct, int t)
// No divide by zero errors today...
// Make value 0.01 so the decision will always be to add Ts
// 1 / 0.01 = 100, etc...
var normalized_ct = (ct == 0 ? 0.01 : (double)ct);
double ts_per_ct = t / (double)normalized_ct;
int target = (int)( (ct + t) / _config.Target ) + 1;
var normalized_ct = ct == 0 ? 0.01 : ct;
var ts_per_ct = t / normalized_ct;
var target = (int)((ct + t) / _config.Target) + 1;

_logger.LogTrace("[Ratio] Evaluating ratio of {@Ct}ct to {@T}t: {@TsPerCt}t/ct ratio, {@Target} target.", ct ,t ,ts_per_ct, target);

Expand All @@ -82,11 +73,11 @@ public RatioAction Evaluate(int ct, int t)

_logger.LogTrace("[Ratio] Decision: Goldilocks: {@Maximum} (max) <= {@TsPerCt} (t/ct) <= {@Minimum} (min)", _config.Maximum, ts_per_ct, _config.Minimum);
// Take no action
return new();
return new RatioAction();
}

/// <summary>
/// When a round starts, balance out the teams
/// When a round starts, balance out the teams
/// </summary>
[GameEventHandler(HookMode.Pre)]
public HookResult OnRoundStart(EventRoundStart ev, GameEventInfo info)
Expand All @@ -113,8 +104,16 @@ public HookResult OnRoundStart(EventRoundStart ev, GameEventInfo info)
return HookResult.Continue;
}

public void Dispose()
public struct RatioAction
{
public RatioActionType Type { get; init; }

public int Count { get; init; }

public RatioAction(int count = 0, RatioActionType type = RatioActionType.None)
{
Count = count;
Type = type;
}
}
}
}
14 changes: 7 additions & 7 deletions mod/Jailbreak.Teams/Ratio/RatioConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
public class RatioConfig
{
/// <summary>
/// The minimum amount of Ts per every CT.
/// When this is passed, CTs will be added until Target is reached.
/// The minimum amount of Ts per every CT.
/// When this is passed, CTs will be added until Target is reached.
/// </summary>
public double Minimum { get; set; } = 2.5;

/// <summary>
/// The maximum amount of Ts per every CT.
/// When this is passed, CTs will be removed until Target is reached.
/// The maximum amount of Ts per every CT.
/// When this is passed, CTs will be removed until Target is reached.
/// </summary>
public double Maximum { get; set; } = 4;

/// <summary>
/// When the ratio is autobalanced, the amount of guards
/// should be total_players / target.
/// When the ratio is autobalanced, the amount of guards
/// should be total_players / target.
/// </summary>
public double Target { get; set; } = 4;
}
}
2 changes: 1 addition & 1 deletion mod/Jailbreak.Teams/TeamsServiceExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public static void AddJailbreakTeams(this IServiceCollection collection)
collection.AddPluginBehavior<IGuardQueue, QueueBehavior>();
collection.AddPluginBehavior<RatioBehavior>();
}
}
}
5 changes: 0 additions & 5 deletions mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public WardenCommandsBehavior(IWardenSelectionService queue, IWardenService ward
_notifications = notifications;
}


[ConsoleCommand("css_pass", "Pass warden onto another player")]
[ConsoleCommand("css_uw", "Pass warden onto another player")]
[CommandHelper(0, "", CommandUsage.CLIENT_ONLY)]
Expand Down Expand Up @@ -82,8 +81,4 @@ public void Command_Warden(CCSPlayerController? player, CommandInfo command)

_notifications.CURRENT_WARDEN(_warden.Warden).ToPlayerChat(player);
}

public void Dispose()
{
}
}
28 changes: 15 additions & 13 deletions mod/Jailbreak.Warden/Global/WardenBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

using Serilog;

using Microsoft.Extensions.Logging;

Check warning on line 20 in mod/Jailbreak.Warden/Global/WardenBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The using directive for 'Microsoft.Extensions.Logging' appeared previously in this namespace

Check warning on line 20 in mod/Jailbreak.Warden/Global/WardenBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The using directive for 'Microsoft.Extensions.Logging' appeared previously in this namespace

Check warning on line 20 in mod/Jailbreak.Warden/Global/WardenBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The using directive for 'Microsoft.Extensions.Logging' appeared previously in this namespace

Check warning on line 20 in mod/Jailbreak.Warden/Global/WardenBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The using directive for 'Microsoft.Extensions.Logging' appeared previously in this namespace

namespace Jailbreak.Warden.Global;

public class WardenBehavior : IPluginBehavior, IWardenService
Expand All @@ -35,18 +37,18 @@ public WardenBehavior(ILogger<WardenBehavior> logger, IWardenNotifications notif
}

/// <summary>
/// Get the current warden, if there is one.
/// Get the current warden, if there is one.
/// </summary>
public CCSPlayerController? Warden => _warden;
public CCSPlayerController? Warden { get; private set; }

/// <summary>
/// Whether or not a warden is currently assigned
/// Whether or not a warden is currently assigned
/// </summary>
public bool HasWarden => _hasWarden;
public bool HasWarden { get; private set; }

public bool TrySetWarden(CCSPlayerController controller)
{
if (_hasWarden)
if (HasWarden)
return false;

// Verify player is a CT
Expand All @@ -55,8 +57,8 @@ public bool TrySetWarden(CCSPlayerController controller)
if (!controller.PawnIsAlive)
return false;

_hasWarden = true;
_warden = controller;
HasWarden = true;
Warden = controller;

if (_warden.Pawn.Value != null)
{
Expand All @@ -73,7 +75,7 @@ public bool TrySetWarden(CCSPlayerController controller)

public bool TryRemoveWarden()
{
if (!_hasWarden)
if (!HasWarden)
return false;

_hasWarden = false;
Expand All @@ -89,10 +91,10 @@ public bool TryRemoveWarden()
[GameEventHandler]
public HookResult OnDeath(EventPlayerDeath ev, GameEventInfo info)
{
if (!_hasWarden)
if (!HasWarden)
return HookResult.Continue;

if (ev.Userid.UserId == _warden.UserId)
if (ev.Userid.UserId == Warden.UserId)
{
if (!this.TryRemoveWarden())
_logger.LogWarning("[Warden] BUG: Problem removing current warden :^(");
Expand All @@ -111,18 +113,18 @@ public HookResult OnDeath(EventPlayerDeath ev, GameEventInfo info)
[GameEventHandler]
public HookResult OnRoundEnd(EventRoundEnd ev, GameEventInfo info)
{
this.TryRemoveWarden();
TryRemoveWarden();

return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect ev, GameEventInfo info)
{
if (!_hasWarden)
if (!HasWarden)
return HookResult.Continue;

if (ev.Userid.UserId == _warden.UserId)
if (ev.Userid.UserId == Warden.UserId)
{
if (!this.TryRemoveWarden())
_logger.LogWarning("[Warden] BUG: Problem removing current warden :^(");
Expand Down
4 changes: 1 addition & 3 deletions mod/Jailbreak.Warden/Selection/QueueFavorState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public class QueueFavorState
{

public const int BASE_TICKETS = 2;

public int RoundsWithoutWarden { get; set; } = 0;
Expand All @@ -15,5 +14,4 @@ public int GetTickets()
+ Favor
+ RoundsWithoutWarden;
}

}
}
6 changes: 2 additions & 4 deletions mod/Jailbreak.Warden/Selection/QueueState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

public class QueueState
{

/// <summary>
/// Whether or not this player is currently in the queue
/// Whether or not this player is currently in the queue
/// </summary>
public bool InQueue { get; set; } = false;

}
}
Loading

0 comments on commit c02e210

Please sign in to comment.