forked from itsAudioo/SpawnProtection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
108 lines (90 loc) · 2.88 KB
/
Utils.cs
File metadata and controls
108 lines (90 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
namespace SpawnProtection
{
using System.Drawing;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Timers;
public sealed partial class SpawnProt
{
public enum ProtectionState
{
None,
Protected
}
private string GenerateProgressBar(float progress)
{
int totalBars = Math.Max(1, int.Parse(Localizer["progressbar.total_bars"].Value));
var filledBars = Math.Max(0, Math.Min(totalBars, (int)(totalBars * progress)));
var emptyBars = Math.Max(0, totalBars - filledBars);
string filledPart = new string(Localizer["progressbar.filled_part"].Value[0], filledBars);
string emptyPart = new string(Localizer["progressbar.empty_part"].Value[0], emptyBars);
return $"<font color='{GetColorBasedOnProgress(progress, 1.0f)}' class='fontSize-l'>{filledPart}</font>" +
$"<font color='{GetColorBasedOnProgress(progress, 0.6f)}' class='fontSize-l'>{emptyPart}</font>";
}
private string GetColorBasedOnProgress(float progress, float brightness = 1.0f)
{
progress = Math.Clamp(progress, 0, 1);
brightness = Math.Clamp(brightness, 0, 1);
int red, green, blue = 0;
if (progress < 0.5f)
{
red = (int)(255 * brightness);
green = (int)(255 * (progress * 2) * brightness);
}
else
{
red = (int)(255 * (2 * (1 - progress)) * brightness);
green = (int)(255 * brightness);
}
return $"#{red:X2}{green:X2}{blue:X2}";
}
private void HandleTransparentModel(CCSPlayerController player, bool isTransparent = false)
{
if (!Config.TransparentModel)
return;
if (player.IsBot() || !player.IsAlive() || player.PlayerPawn is null or { IsValid: false } || player.PlayerPawn.Value is null)
return;
if (isTransparent)
{
player.PlayerPawn!.Value!.Render = Color.FromArgb(255, 255, 255, 255);
}
else
{
player.PlayerPawn.Value.Render = Color.FromArgb(185, 0, 255, 0);
}
Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender");
}
private void CreateProtectionTimer(CCSPlayerController player, PlayerState state)
{
state.SpawnTimer?.Kill();
state.SpawnTimer = AddTimer(0.1f, () =>
{
if (state.ProtectionTimer <= 0.1f)
{
StopSpawnProtection(player, state);
return;
}
state.ProtectionTimer -= 0.1f;
}, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
}
void GetGameRules() => gameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules!;
public bool IsWarmup
{
get
{
if (gameRules is null)
GetGameRules();
return gameRules is not null && gameRules.WarmupPeriod;
}
}
public bool IsFreezeTime
{
get
{
if (gameRules is null)
GetGameRules();
return gameRules is not null && gameRules.FreezePeriod;
}
}
}
}