Skip to content

Commit

Permalink
Add rebel notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Feb 5, 2024
1 parent 1cf0cc5 commit 282bc68
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions mod/Jailbreak.Rebel/RebelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public RebelManager(IRebelNotifications notifs, ILogService logs)
public void Start(BasePlugin parent)
{
parent.RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);
parent.RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
parent.RegisterEventHandler<EventRoundStart>(OnRoundStart);

parent.AddTimer(1f, () =>
Expand All @@ -43,6 +44,7 @@ public void Start(BasePlugin parent)
}

ApplyRebelColor(player);
SendTimeLeft(player);
}
}, TimerFlags.REPEAT);
}
Expand Down Expand Up @@ -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<CCSPlayerController> GetActiveRebels()
{
return rebelTimes.Keys.ToHashSet();
Expand Down Expand Up @@ -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);
Expand All @@ -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 = $"<font color=\"#{color.R:X2}{color.G:X2}{color.B:X2}\">";

player.PrintToCenterHtml($"You are a rebel for {formattedColor}{formattedTime}</font> more seconds.");
}
}

0 comments on commit 282bc68

Please sign in to comment.