This commit is contained in:
Juzlus 2025-09-23 04:53:25 +02:00
parent a36fdbf92d
commit 04a4fdce0d
143 changed files with 3565 additions and 2344 deletions

View file

@ -2,36 +2,45 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using jRandomSkills.src.player;
using jRandomSkills.src.utils;
using System.Collections.Concurrent;
namespace jRandomSkills
{
public class Distancer : ISkill
{
private const Skills skillName = Skills.Distancer;
private static readonly HashSet<CCSPlayerController> distancerPlayers = [];
private static readonly ConcurrentDictionary<CCSPlayerController, byte> distancerPlayers = [];
private static readonly object setLock = new();
public static void LoadSkill()
{
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"));
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
}
public static void NewRound()
{
distancerPlayers.Clear();
lock (setLock)
distancerPlayers.Clear();
}
public static void OnTick()
{
foreach (var player in distancerPlayers)
if (SkillUtils.IsFreezeTime()) return;
foreach (var player in distancerPlayers.Keys)
{
var playerInfo = jRandomSkills.Instance.SkillPlayer.FirstOrDefault(s => s.SteamID == player?.SteamID);
if (playerInfo == null) return;
if (playerInfo.SkillDescriptionHudExpired >= DateTime.Now)
{
playerInfo.PrintHTML = null;
return;
}
var playerPawn = player.PlayerPawn.Value;
if (playerPawn == null || !playerPawn.IsValid) return;
if (playerPawn.LifeState != (byte)LifeState_t.LIFE_ALIVE) return;
var skillData = SkillData.Skills.FirstOrDefault(s => s.Skill == skillName);
if (skillData == null) return;
string closetEnemy = "Bot";
double closetDistance = double.MaxValue;
@ -47,27 +56,22 @@ namespace jRandomSkills
}
string distanceColor = closetDistance > 1500 ? "#00FF00" : closetDistance > 600 ? "#FFFF00" : "#FF0000";
string infoLine = $"<font class='fontSize-l' class='fontWeight-Bold' color='#FFFFFF'>{player.GetTranslation("your_skill")}:</font> <br>";
string skillLine = $"<font class='fontSize-l' class='fontWeight-Bold' color='{skillData.Color}'>{player.GetSkillName(skillData.Skill)}</font> <br>";
string remainingLine = $"<font class='fontSize-m' color='#FFFFFF'>{closetEnemy}: <font color='{distanceColor}'>{closetDistance}</font></font> <br>";
var hudContent = infoLine + skillLine + remainingLine;
player.PrintToCenterHtml(hudContent);
playerInfo.PrintHTML = $"{closetEnemy}: <font color='{distanceColor}'>{closetDistance}</font>";
}
}
public static void EnableSkill(CCSPlayerController player)
{
distancerPlayers.Add(player);
distancerPlayers.TryAdd(player, 0);
}
public static void DisableSkill(CCSPlayerController player)
{
distancerPlayers.Remove(player);
distancerPlayers.TryRemove(player, out _);
SkillUtils.ResetPrintHTML(player);
}
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#00f2ff", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#00f2ff", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates)
{
}
}