Introduce optional `HudDuration` and `DescriptionHudDuration` fields in skill config metadata and propagate them through all skill config constructors and `skillsInfo.json`.
75 lines
No EOL
3.3 KiB
C#
75 lines
No EOL
3.3 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using src.utils;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace src.player.skills
|
|
{
|
|
public class Distancer : ISkill
|
|
{
|
|
private const Skills skillName = Skills.Distancer;
|
|
private static readonly ConcurrentDictionary<uint, byte> distancerPlayers = [];
|
|
private static readonly object setLock = new();
|
|
|
|
public static void LoadSkill()
|
|
{
|
|
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
|
}
|
|
|
|
public static void NewRound()
|
|
{
|
|
lock (setLock)
|
|
distancerPlayers.Clear();
|
|
}
|
|
|
|
public static void OnTick()
|
|
{
|
|
if (SkillUtils.IsFreezeTime()) return;
|
|
foreach (var playerIndex in distancerPlayers.Keys)
|
|
{
|
|
var player = Utilities.GetPlayerFromIndex((int)playerIndex);
|
|
if (player == null || !player.IsValid) continue;
|
|
|
|
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
|
if (playerInfo == null) continue;
|
|
|
|
var playerPawn = player.PlayerPawn.Value;
|
|
if (playerPawn == null || !playerPawn.IsValid) continue;
|
|
if (playerPawn.LifeState != (byte)LifeState_t.LIFE_ALIVE) continue;
|
|
|
|
string closetEnemy = "Bot";
|
|
double closetDistance = double.MaxValue;
|
|
|
|
foreach (var enemy in Utilities.GetPlayers().Where(p => p.Team != player.Team))
|
|
{
|
|
var enemyPawn = enemy.PlayerPawn.Value;
|
|
if (enemyPawn == null || !enemyPawn.IsValid) continue;
|
|
if (enemyPawn.LifeState != (byte)LifeState_t.LIFE_ALIVE || playerPawn.AbsOrigin == null || enemyPawn.AbsOrigin == null) continue;
|
|
double distance = (int)SkillUtils.GetDistance(playerPawn.AbsOrigin, enemyPawn.AbsOrigin);
|
|
if (distance >= closetDistance) continue;
|
|
closetDistance = distance;
|
|
closetEnemy = enemy.PlayerName;
|
|
}
|
|
|
|
string distanceColor = closetDistance > 1500 ? "#00FF00" : closetDistance > 600 ? "#FFFF00" : "#FF0000";
|
|
playerInfo.PrintHTML = $"{System.Net.WebUtility.HtmlEncode(closetEnemy)}: <font color='{distanceColor}'>{(closetDistance > 3000 ? "3000+" : closetDistance)}</font>";
|
|
}
|
|
}
|
|
|
|
public static void EnableSkill(CCSPlayerController player)
|
|
{
|
|
distancerPlayers.TryAdd(player.Index, 0);
|
|
}
|
|
|
|
public static void DisableSkill(CCSPlayerController player)
|
|
{
|
|
distancerPlayers.TryRemove(player.Index, out _);
|
|
SkillUtils.ResetPrintHTML(player);
|
|
}
|
|
|
|
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#00f2ff", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", float? hudDuration = null, float? descriptionHudDuration = null, int maxPerServer = -1, Rarity rarity = Rarity.Common) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, hudDuration, descriptionHudDuration, maxPerServer, rarity)
|
|
{
|
|
}
|
|
}
|
|
} |