Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add team switch listener, fix log assignment #40

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading