v.1.1.7
This commit is contained in:
parent
a36fdbf92d
commit
04a4fdce0d
143 changed files with 3565 additions and 2344 deletions
|
|
@ -4,24 +4,25 @@ 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 Noclip : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.Noclip;
|
||||
private static readonly float timerCooldown = Config.GetValue<float>(skillName, "cooldown");
|
||||
private static readonly float duration = Config.GetValue<float>(skillName, "duration");
|
||||
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 OnTick()
|
||||
|
|
@ -37,17 +38,20 @@ namespace jRandomSkills
|
|||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
SkillPlayerInfo[player.SteamID] = new PlayerSkillInfo
|
||||
SkillPlayerInfo.TryAdd(player.SteamID, new PlayerSkillInfo
|
||||
{
|
||||
SteamID = player.SteamID,
|
||||
CanUse = true,
|
||||
IsFlying = false,
|
||||
Cooldown = DateTime.MinValue,
|
||||
};
|
||||
LastPosition = null,
|
||||
});
|
||||
}
|
||||
|
||||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
SkillPlayerInfo.Remove(player.SteamID);
|
||||
SkillPlayerInfo.TryRemove(player.SteamID, out _);
|
||||
SkillUtils.ResetPrintHTML(player);
|
||||
}
|
||||
|
||||
private static void UpdateHUD(CCSPlayerController player, PlayerSkillInfo skillInfo)
|
||||
|
|
@ -56,35 +60,35 @@ namespace jRandomSkills
|
|||
float flying = 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);
|
||||
|
||||
float flyingTime = (int)(skillInfo.Cooldown.AddSeconds(duration) - DateTime.Now).TotalMilliseconds;
|
||||
float flyingTime = (int)(skillInfo.Cooldown.AddSeconds(SkillsInfo.GetValue<float>(skillName, "duration")) - DateTime.Now).TotalMilliseconds;
|
||||
flying = Math.Max(flyingTime, 0);
|
||||
|
||||
if (cooldown == 0 && skillInfo?.CanUse == false)
|
||||
skillInfo.CanUse = true;
|
||||
}
|
||||
|
||||
var skillData = SkillData.Skills.FirstOrDefault(s => s.Skill == skillName);
|
||||
if (skillData == null) return;
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(s => s.SteamID == player?.SteamID);
|
||||
if (playerInfo == null) 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
|
||||
? (
|
||||
flying != 0
|
||||
? $"<font class='fontSize-m' color='#FFFFFF'>{player.GetTranslation("active_hud_info", $"<font color='#00FF00'>{Math.Round(flying / 100, 2)}</font>")}</font> <br>"
|
||||
: $"<font class='fontSize-m' color='#FFFFFF'>{player.GetTranslation("hud_info", $"<font color='#FF0000'>{cooldown}</font>")}</font> <br>"
|
||||
) : "";
|
||||
if (cooldown == 0)
|
||||
{
|
||||
playerInfo.PrintHTML = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var hudContent = infoLine + skillLine + remainingLine;
|
||||
player.PrintToCenterHtml(hudContent);
|
||||
playerInfo.PrintHTML =
|
||||
skillInfo?.IsFlying == true
|
||||
? $"{player.GetTranslation("active_hud_info", $"<font color='#00FF00'>{Math.Round(flying / 100, 2)}</font>")}"
|
||||
: $"{player.GetTranslation("hud_info", $"<font color='#FF0000'>{cooldown}</font>")}";
|
||||
}
|
||||
|
||||
public static void UseSkill(CCSPlayerController player)
|
||||
{
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
var duration = SkillsInfo.GetValue<float>(skillName, "duration");
|
||||
if (playerPawn?.CBodyComponent == null) return;
|
||||
|
||||
if (SkillPlayerInfo.TryGetValue(player.SteamID, out var skillInfo))
|
||||
|
|
@ -93,10 +97,39 @@ namespace jRandomSkills
|
|||
if (skillInfo.CanUse)
|
||||
{
|
||||
skillInfo.CanUse = false;
|
||||
skillInfo.IsFlying = true;
|
||||
skillInfo.Cooldown = DateTime.Now;
|
||||
skillInfo.LastPosition = playerPawn.AbsOrigin == null ? null : new Vector(playerPawn.AbsOrigin.X, playerPawn.AbsOrigin.Y, playerPawn.AbsOrigin.Z);
|
||||
|
||||
playerPawn.ActualMoveType = MoveType_t.MOVETYPE_NOCLIP;
|
||||
Instance.AddTimer(duration, () => playerPawn.ActualMoveType = MoveType_t.MOVETYPE_WALK);
|
||||
Instance.AddTimer(duration, () => {
|
||||
if (playerPawn == null || !playerPawn.IsValid || !skillInfo.IsFlying) return;
|
||||
skillInfo.IsFlying = false;
|
||||
playerPawn.ActualMoveType = MoveType_t.MOVETYPE_WALK;
|
||||
});
|
||||
|
||||
Instance.AddTimer(duration + 4, () => {
|
||||
if (playerPawn == null || !playerPawn.IsValid || !player.PawnIsAlive || skillInfo.IsFlying) return;
|
||||
if (skillInfo.LastPosition == null || playerPawn.AbsOrigin == null) return;
|
||||
skillInfo.IsFlying = false;
|
||||
var diff = Math.Abs(playerPawn.AbsOrigin.Z - skillInfo.LastPosition.Z);
|
||||
if (diff > 3000 && playerPawn.AbsOrigin.Z < skillInfo.LastPosition.Z)
|
||||
playerPawn.Teleport(skillInfo.LastPosition, null, new Vector(0,0,0));
|
||||
});
|
||||
}
|
||||
else if (skillInfo.IsFlying)
|
||||
{
|
||||
skillInfo.IsFlying = false;
|
||||
playerPawn.ActualMoveType = MoveType_t.MOVETYPE_WALK;
|
||||
|
||||
Instance.AddTimer(4, () => {
|
||||
if (playerPawn == null || !playerPawn.IsValid || !player.PawnIsAlive || skillInfo.IsFlying) return;
|
||||
if (skillInfo.LastPosition == null || playerPawn.AbsOrigin == null) return;
|
||||
skillInfo.IsFlying = false;
|
||||
var diff = Math.Abs(playerPawn.AbsOrigin.Z - skillInfo.LastPosition.Z);
|
||||
if (diff > 3000 && playerPawn.AbsOrigin.Z < skillInfo.LastPosition.Z)
|
||||
playerPawn.Teleport(skillInfo.LastPosition, null, new Vector(0, 0, 0));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -105,10 +138,12 @@ namespace jRandomSkills
|
|||
{
|
||||
public ulong SteamID { get; set; }
|
||||
public bool CanUse { get; set; }
|
||||
public bool IsFlying { get; set; }
|
||||
public DateTime Cooldown { get; set; }
|
||||
public Vector? LastPosition { get; set; }
|
||||
}
|
||||
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#44ebd4", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float cooldown = 30f, float duration = 2f) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#44ebd4", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = true, bool needsTeammates = false, float cooldown = 30f, float duration = 2f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates)
|
||||
{
|
||||
public float Cooldown { get; set; } = cooldown;
|
||||
public float Duration { get; set; } = duration;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue