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

@ -4,42 +4,41 @@ using CounterStrikeSharp.API.Modules.Utils;
using jRandomSkills.src.player;
using jRandomSkills.src.utils;
using static jRandomSkills.jRandomSkills;
using System.Collections.Concurrent;
namespace jRandomSkills
{
public class Earthquake : ISkill
{
private const Skills skillName = Skills.Earthquake;
private static readonly float timerCooldown = Config.GetValue<float>(skillName, "cooldown");
private static readonly float amplitude = Config.GetValue<float>(skillName, "amplitude");
private static readonly float frequency = Config.GetValue<float>(skillName, "frequency");
private static readonly float duration = Config.GetValue<float>(skillName, "duration");
private static readonly float radius = Config.GetValue<float>(skillName, "radius");
private static readonly Dictionary<ulong, PlayerSkillInfo> SkillPlayerInfo = [];
private static readonly ConcurrentDictionary<ulong, PlayerSkillInfo> SkillPlayerInfo = [];
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()
{
SkillPlayerInfo.Clear();
lock (setLock)
SkillPlayerInfo.Clear();
}
public static void EnableSkill(CCSPlayerController player)
{
SkillPlayerInfo[player.SteamID] = new PlayerSkillInfo
SkillPlayerInfo.TryAdd(player.SteamID, new PlayerSkillInfo
{
SteamID = player.SteamID,
CanUse = true,
Cooldown = DateTime.MinValue,
};
});
}
public static void DisableSkill(CCSPlayerController player)
{
SkillPlayerInfo.Remove(player.SteamID);
SkillPlayerInfo.TryRemove(player.SteamID, out _);
SkillUtils.ResetPrintHTML(player);
}
public static void PlayerDeath(EventPlayerDeath @event)
@ -48,7 +47,7 @@ namespace jRandomSkills
if (player == null || !player.IsValid) return;
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
if (playerInfo?.Skill == skillName)
SkillPlayerInfo.Remove(player.SteamID);
SkillPlayerInfo.TryRemove(player.SteamID, out _);
}
public static void OnTick()
@ -67,22 +66,20 @@ namespace jRandomSkills
float cooldown = 0;
if (skillInfo != null)
{
float time = (int)(skillInfo.Cooldown.AddSeconds(timerCooldown) - DateTime.Now).TotalSeconds;
float time = (int)Math.Ceiling((skillInfo.Cooldown.AddSeconds(SkillsInfo.GetValue<float>(skillName, "cooldown")) - DateTime.Now).TotalSeconds);
cooldown = Math.Max(time, 0);
if (cooldown == 0 && skillInfo?.CanUse == false)
skillInfo.CanUse = true;
}
var skillData = SkillData.Skills.FirstOrDefault(s => s.Skill == skillName);
if (skillData == null) return;
if (cooldown == 0)
return;
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 = cooldown != 0 ? $"<font class='fontSize-m' color='#FFFFFF'>{player.GetTranslation("hud_info", $"<font color='#FF0000'>{cooldown}</font>")}</font> <br>" : "";
var playerInfo = Instance.SkillPlayer.FirstOrDefault(s => s.SteamID == player?.SteamID);
if (playerInfo == null) return;
var hudContent = infoLine + skillLine + remainingLine;
player.PrintToCenterHtml(hudContent);
string remainingLine = $"{player.GetTranslation("hud_info", $"<font color='#FF0000'>{cooldown}</font>")}";
}
public static void UseSkill(CCSPlayerController player)
@ -119,10 +116,10 @@ namespace jRandomSkills
shake.DispatchSpawn();
if (!shake.IsValid) return;
shake.Amplitude = amplitude;
shake.Frequency = frequency;
shake.Duration = duration;
shake.Radius = radius;
shake.Amplitude = SkillsInfo.GetValue<float>(skillName, "amplitude");
shake.Frequency = SkillsInfo.GetValue<float>(skillName, "frequency");
shake.Duration = SkillsInfo.GetValue<float>(skillName, "duration");
shake.Radius = SkillsInfo.GetValue<float>(skillName, "radius");
shake.Teleport(new Vector(pawn.AbsOrigin.X, pawn.AbsOrigin.Y, pawn.AbsOrigin.Z + pawn.ViewOffset.Z));
shake.AcceptInput("SetParent", pawn, pawn, "!activator");
@ -136,7 +133,7 @@ namespace jRandomSkills
public DateTime Cooldown { get; set; }
}
public class SkillConfig(Skills skill = skillName, bool active = false, string color = "#42f59b", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float cooldown = 16f, float amplitude = 15f, float frequency = 500f, float duration = 8f, float radius = 50f) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
public class SkillConfig(Skills skill = skillName, bool active = false, string color = "#42f59b", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, float cooldown = 16f, float amplitude = 15f, float frequency = 500f, float duration = 8f, float radius = 50f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates)
{
public float Cooldown { get; set; } = cooldown;
public float Amplitude { get; set; } = amplitude;