diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 426976d2..9fadd81f 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -27,6 +27,7 @@ public RebelManager(IRebelNotifications notifs, ILogService logs) public void Start(BasePlugin parent) { parent.RegisterEventHandler(OnPlayerDisconnect); + parent.RegisterEventHandler(OnPlayerDeath); parent.RegisterEventHandler(OnRoundStart); parent.AddTimer(1f, () => @@ -43,6 +44,7 @@ public void Start(BasePlugin parent) } ApplyRebelColor(player); + SendTimeLeft(player); } }, TimerFlags.REPEAT); } @@ -70,6 +72,15 @@ HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) return HookResult.Continue; } + HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) + { + var player = @event.Userid; + if (!player.IsReal()) + return HookResult.Continue; + rebelTimes.Remove(player); + return HookResult.Continue; + } + public ISet GetActiveRebels() { return rebelTimes.Keys.ToHashSet(); @@ -116,11 +127,9 @@ private float GetRebelTimePercentage(CCSPlayerController player) return 0; return (float)(100 - (120 - x) * (Math.Sqrt(120 - x)) / 13f) / 100; } - - private void ApplyRebelColor(CCSPlayerController player) + + private Color GetRebelColor(CCSPlayerController player) { - if (!player.IsReal() || player.Pawn.Value == null) - return; var percent = GetRebelTimePercentage(player); var percentRGB = 255 - (int)Math.Round(percent * 255.0); var color = Color.FromArgb(254, 255, percentRGB, percentRGB); @@ -129,8 +138,27 @@ private void ApplyRebelColor(CCSPlayerController player) color = Color.FromArgb(254, 255, 255, 255); } + return color; + } + + private void ApplyRebelColor(CCSPlayerController player) + { + if (!player.IsReal() || player.Pawn.Value == null) + return; + var color = GetRebelColor(player); + player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; player.Pawn.Value.Render = color; Utilities.SetStateChanged(player.Pawn.Value, "CBaseModelEntity", "m_clrRender"); } + + private void SendTimeLeft(CCSPlayerController player) + { + var timeLeft = GetRebelTimeLeft(player); + var formattedTime = TimeSpan.FromSeconds(timeLeft).ToString(@"mm\:ss"); + var color = GetRebelColor(player); + var formattedColor = $""; + + player.PrintToCenterHtml($"You are a rebel for {formattedColor}{formattedTime} more seconds."); + } } \ No newline at end of file