Skip to content

Commit

Permalink
Mark prisoners blue when warden dies (#83)
Browse files Browse the repository at this point in the history
* Mark prisoners blue when warden dies

* Move rebel before warden
  • Loading branch information
MSWS authored Mar 24, 2024
1 parent 1919b57 commit 4fbe210
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
67 changes: 64 additions & 3 deletions mod/Jailbreak.Warden/Global/WardenBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.Logs;
using Jailbreak.Public.Mod.Rebel;
using Jailbreak.Public.Mod.Warden;
using Microsoft.Extensions.Logging;

Expand All @@ -17,17 +18,28 @@ public class WardenBehavior : IPluginBehavior, IWardenService
{
private ILogger<WardenBehavior> _logger;
private IRichLogService _logs;

private IWardenNotifications _notifications;
private ISpecialTreatmentService _specialTreatment;
private IRebelService _rebels;
private ISet<CCSPlayerController> _bluePrisoners = new HashSet<CCSPlayerController>();
private BasePlugin _parent;

private bool _hasWarden;
private CCSPlayerController? _warden;

public WardenBehavior(ILogger<WardenBehavior> logger, IWardenNotifications notifications, IRichLogService logs)
public WardenBehavior(ILogger<WardenBehavior> logger, IWardenNotifications notifications, IRichLogService logs,

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

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_parent' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
ISpecialTreatmentService specialTreatment, IRebelService rebels)
{
_logger = logger;
_notifications = notifications;
_logs = logs;
_specialTreatment = specialTreatment;
_rebels = rebels;
}

public void Start(BasePlugin parent)
{
_parent = parent;
}

/// <summary>
Expand Down Expand Up @@ -57,7 +69,7 @@ public bool TrySetWarden(CCSPlayerController controller)
if (_warden.Pawn.Value != null)
{
_warden.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor;
_warden.Pawn.Value.Render = Color.Blue;
_warden.Pawn.Value.Render = Color.FromArgb(254, 0, 0, 255);
Utilities.SetStateChanged(_warden.Pawn.Value, "CBaseModelEntity", "m_clrRender");
}

Expand All @@ -66,6 +78,8 @@ public bool TrySetWarden(CCSPlayerController controller)
.ToAllCenter();

_logs.Append( _logs.Player(_warden), "is now the warden.");

_parent.AddTimer(3, UnmarkPrisonersBlue);
return true;
}

Expand Down Expand Up @@ -121,6 +135,53 @@ private void ProcessWardenDeath()
.ToAllCenter();

_notifications.BECOME_NEXT_WARDEN.ToAllChat();

MarkPrisonersBlue();
}

private void UnmarkPrisonersBlue()
{
foreach (var player in _bluePrisoners)
{
var pawn = player.Pawn.Value;
if (pawn == null)
continue;
if(IgnoreColor(player))
continue;
pawn.RenderMode = RenderMode_t.kRenderNormal;
pawn.Render = Color.FromArgb(254, 255, 255, 255);
Utilities.SetStateChanged(pawn, "CBaseModelEntity", "m_clrRender");
}
_bluePrisoners.Clear();
}

private void MarkPrisonersBlue()
{
foreach(CCSPlayerController player in Utilities.GetPlayers())
{
if(!player.IsReal() || player.Team != CsTeam.Terrorist)
continue;
if(IgnoreColor(player))
continue;

var pawn = player.Pawn.Value;
if(pawn == null)
continue;
pawn.RenderMode = RenderMode_t.kRenderTransColor;
pawn.Render = Color.FromArgb(254, 0, 0, 255);
Utilities.SetStateChanged(pawn, "CBaseModelEntity", "m_clrRender");

_bluePrisoners.Add(player);
}
}

private bool IgnoreColor(CCSPlayerController player)
{
if (_specialTreatment.IsSpecialTreatment(player))
return true;
if (_rebels.IsRebel(player))
return true;
return false;
}

[GameEventHandler]
Expand Down
2 changes: 1 addition & 1 deletion src/Jailbreak/JailbreakServiceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public void ConfigureServices(IServiceCollection serviceCollection)

serviceCollection.AddJailbreakGeneric();
serviceCollection.AddJailbreakLogs();
serviceCollection.AddJailbreakRebel();
serviceCollection.AddJailbreakWarden();
serviceCollection.AddJailbreakTeams();
serviceCollection.AddJailbreakRebel();
serviceCollection.AddJailbreakDebug();
serviceCollection.AddJailbreakLastRequest();

Expand Down

0 comments on commit 4fbe210

Please sign in to comment.