Skip to content

Commit

Permalink
Add rebel / st color overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 28, 2024
1 parent 08312e8 commit c76daad
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
25 changes: 3 additions & 22 deletions mod/Jailbreak.Rebel/RebelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void Start(BasePlugin basePlugin) {
basePlugin.RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);
basePlugin.RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
basePlugin.RegisterEventHandler<EventRoundStart>(OnRoundStart);
basePlugin.RegisterListener<Listeners.OnTick>(OnTick);

basePlugin.AddTimer(1f, () => {
foreach (var player in GetActiveRebels()) {
Expand All @@ -45,7 +44,6 @@ public void Start(BasePlugin basePlugin) {
}

applyRebelColor(player);
sendTimeLeft(player);
}
}, TimerFlags.REPEAT);
}
Expand Down Expand Up @@ -90,16 +88,6 @@ public void UnmarkRebel(CCSPlayerController player) {

public void DisableRebelForRound() { enabled = false; }

private void OnTick() {
foreach (var player in GetActiveRebels()) {
if (!player.IsReal()) continue;

if (GetRebelTimeLeft(player) <= 0) continue;

sendTimeLeft(player);
}
}

private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) {
enabled = true;
rebelTimes.Clear();
Expand Down Expand Up @@ -151,16 +139,9 @@ private void applyRebelColor(CCSPlayerController player) {
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 {formattedColor}<b>rebelling</b></font>");
player.ColorScreen(
Color.FromArgb(8 + (int)Math.Round(getRebelTimePercentage(player) * 32),
Color.Red), 1f, 1.5f, PlayerExtensions.FadeFlags.FADE_OUT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views.Warden;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Generic;
using Jailbreak.Public.Mod.Rebel;
using Jailbreak.Public.Mod.Warden;
Expand All @@ -28,6 +29,8 @@ public void Grant(CCSPlayerController player) {

if (rebel.IsRebel(player)) rebel.UnmarkRebel(player);
setSpecialColor(player, true);
player.ColorScreen(Color.FromArgb(16, 0, 255, 0), 999999, 0.2f,
PlayerExtensions.FadeFlags.FADE_OUT);

notifications.Granted.ToChat(player).ToCenter(player);

Expand All @@ -41,6 +44,7 @@ public void Revoke(CCSPlayerController player) {
sts.Get(player).HasSpecialTreatment = false;

setSpecialColor(player, false);
player.ColorScreen(Color.FromArgb(16, 0, 255, 0), 0f, 1.5f);

notifications.Revoked.ToChat(player).ToCenter(player);

Expand Down
28 changes: 28 additions & 0 deletions public/Jailbreak.Public/Extensions/PlayerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.UserMessages;
using CounterStrikeSharp.API.Modules.Utils;

namespace Jailbreak.Public.Extensions;
Expand Down Expand Up @@ -149,4 +150,31 @@ public static void SetColor(this CCSPlayerController player, Color color) {
.FirstOrDefault(w => w.Value?.DesignerName == designerName)
?.Value;
}

public enum FadeFlags {
FADE_IN, FADE_OUT, FADE_STAYOUT
}

public static void ColorScreen(this CCSPlayerController player, Color color,
float hold = 0.1f, float fade = 0.2f, FadeFlags flags = FadeFlags.FADE_IN,
bool withPurge = true) {
var fadeMsg = UserMessage.FromId(106);

fadeMsg.SetInt("duration", Convert.ToInt32(fade * 512));
fadeMsg.SetInt("hold_time", Convert.ToInt32(hold * 512));

var flag = flags switch {
FadeFlags.FADE_IN => 0x0001,
FadeFlags.FADE_OUT => 0x0002,
FadeFlags.FADE_STAYOUT => 0x0008,
_ => 0x0001
};

if (withPurge) flag |= 0x0010;

fadeMsg.SetInt("flags", flag);
fadeMsg.SetInt("color",
color.R | color.G << 8 | color.B << 16 | color.A << 24);
fadeMsg.Send(player);
}
}
2 changes: 1 addition & 1 deletion public/Jailbreak.Public/Jailbreak.Public.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.233"/>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.260"/>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0"/>
<PackageReference Include="System.Text.Json" Version="8.0.4"/>
<ProjectReference Include="..\Jailbreak.Tag\Jailbreak.Tag.csproj"/>
Expand Down

0 comments on commit c76daad

Please sign in to comment.