Skip to content

Commit

Permalink
Add team switch listener, fix log assignment (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS authored Feb 10, 2024
1 parent 0b40f00 commit 757748c
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions mod/Jailbreak.Warden/Global/WardenBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Jailbreak.Warden.Global;
public class WardenBehavior : IPluginBehavior, IWardenService
{
private ILogger<WardenBehavior> _logger;
private IRichLogService logs;
private IRichLogService _logs;

private IWardenNotifications _notifications;

Expand All @@ -27,7 +27,7 @@ public WardenBehavior(ILogger<WardenBehavior> logger, IWardenNotifications notif
{
_logger = logger;
_notifications = notifications;
logs = logs;
_logs = logs;
}

/// <summary>
Expand Down Expand Up @@ -65,7 +65,7 @@ public bool TrySetWarden(CCSPlayerController controller)
.ToAllChat()
.ToAllCenter();

logs.Append( logs.Player(_warden), "is now the warden.");
_logs.Append( _logs.Player(_warden), "is now the warden.");
return true;
}

Expand All @@ -81,7 +81,7 @@ public bool TryRemoveWarden()
_warden.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor;
_warden.Pawn.Value.Render = Color.FromArgb(254, 255, 255, 255);
Utilities.SetStateChanged(_warden.Pawn.Value, "CBaseModelEntity", "m_clrRender");
logs.Append( logs.Player(_warden), "is no longer the warden.");
_logs.Append( _logs.Player(_warden), "is no longer the warden.");
}

_warden = null;
Expand All @@ -92,23 +92,35 @@ public bool TryRemoveWarden()
[GameEventHandler]
public HookResult OnDeath(EventPlayerDeath ev, GameEventInfo info)
{
if (!_hasWarden)
if(!((IWardenService)this).IsWarden(ev.Userid))
return HookResult.Continue;

ProcessWardenDeath();
return HookResult.Continue;
}

if (ev.Userid.UserId == _warden.UserId)
{
if (!this.TryRemoveWarden())
_logger.LogWarning("[Warden] BUG: Problem removing current warden :^(");
[GameEventHandler]
public HookResult OnChangeTeam(EventPlayerTeam @event, GameEventInfo info)
{
var player = @event.Userid;
if (!((IWardenService)this).IsWarden(player))
return HookResult.Continue;

ProcessWardenDeath();
return HookResult.Continue;
}

// Warden died!
_notifications.WARDEN_DIED
.ToAllChat()
.ToAllCenter();
private void ProcessWardenDeath()
{
if (!this.TryRemoveWarden())
_logger.LogWarning("[Warden] BUG: Problem removing current warden :^(");

_notifications.BECOME_NEXT_WARDEN.ToAllChat();
}
// Warden died!
_notifications.WARDEN_DIED
.ToAllChat()
.ToAllCenter();

return HookResult.Continue;
_notifications.BECOME_NEXT_WARDEN.ToAllChat();
}

[GameEventHandler]
Expand All @@ -122,21 +134,18 @@ public HookResult OnRoundEnd(EventRoundEnd ev, GameEventInfo info)
[GameEventHandler]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect ev, GameEventInfo info)
{
if (!_hasWarden)
if(!((IWardenService) this).IsWarden(ev.Userid))
return HookResult.Continue;

if (ev.Userid.UserId == _warden.UserId)
{
if (!this.TryRemoveWarden())
_logger.LogWarning("[Warden] BUG: Problem removing current warden :^(");

if (!this.TryRemoveWarden())
_logger.LogWarning("[Warden] BUG: Problem removing current warden :^(");


_notifications.WARDEN_LEFT
.ToAllChat()
.ToAllCenter();
_notifications.WARDEN_LEFT
.ToAllChat()
.ToAllCenter();

_notifications.BECOME_NEXT_WARDEN.ToAllChat();
}
_notifications.BECOME_NEXT_WARDEN.ToAllChat();

return HookResult.Continue;
}
Expand Down

0 comments on commit 757748c

Please sign in to comment.