jRandomSkills/jRandomSkills - SRC Files/src/player/skills/JetKick.cs
ByDexter dfa68db18b v1.2.4.b2
# v1.2.4.b2

#### Crashes
* **Ninja, Ghost, C4 Camouflage** - a client could crash with `CopyExistingEntity: missing client entity` when a hidden player died nearby. Hidden players are now revealed in the `player_death` pre-hook, inside the same tick as the death, so the client always holds the entity. Cleanup previously ran on a 2-tick timer and left a gap.

#### Skills
* **Falcon Eye** - weapons stayed locked into the next round if the camera was active when the round ended. Restoring the default view no longer depends on the camera entity still existing.
* **Jump Ban** - the target could still jump. Upward velocity is now zeroed on the jump input, the downward pull was raised, and the block lasts longer.
* **Jump Ban** - the "you can jump again" message never arrived. It was gated behind a freeze-time check that is always true when skills are cleared.
* **Blast Shot** - grenades could be thrown during freeze time.
* **Sound Maker** - phantom screams came from world origin `0 0 0`, and the sound was sent to the emitter's own team. Only living enemies now receive it.
* **Careful Bullets, Darkness, Deaf, Expensive Ammo, Giant, Glitch, Jammer, Jet Kick, Jump Curse, Magnifier, Nightmare, Poison, Primary Ban, Wild Throw** - the message telling the target the effect had ended never arrived, for the same freeze-time reason.

#### Freeze time
* **DisableOnFreezeTime** - the setting only applied to actively triggered skills; passive damage handlers ignored it entirely. Cypher, Exploding Barrel, Explosive Shot, Fortnite, Iana, Illusionist and Replicator now honour it.

#### Reliability
* **Skill distribution** - a round could start with nobody receiving a skill. A permission lookup for a player who was disconnecting threw and aborted the whole selection loop; those lookups are now isolated, and a failure on one player no longer stops the rest.
* **Skill distribution** - if a round still ends with no skills assigned while players are connected, distribution retries up to 6 times at 0.5s intervals and writes the reason to the debug log.
2026-09-17 10:20:16 +03:00

183 lines
7.9 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 JetKick : ISkill
{
private const Skills skillName = Skills.JetKick;
private static readonly ConcurrentDictionary<uint, byte> targetedPlayers = [];
private static readonly ConcurrentDictionary<uint, uint> playersToTarget = [];
private static readonly object setLock = new();
public static void LoadSkill()
{
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
}
public static void NewRound()
{
lock (setLock)
{
foreach (var player in PlayerManager.GetTickPlayers())
{
DisableSkill(player);
SkillUtils.CloseMenu(player);
}
targetedPlayers.Clear();
playersToTarget.Clear();
}
}
public static void PlayerDisconnect(uint playerIndex)
{
lock (setLock)
{
targetedPlayers.TryRemove(playerIndex, out _);
if (playersToTarget.TryRemove(playerIndex, out uint targetIndex))
targetedPlayers.TryRemove(targetIndex, out _);
foreach (var kvp in playersToTarget)
if (kvp.Value == playerIndex)
playersToTarget.TryRemove(kvp.Key, out _);
}
}
public static void OnTick()
{
if (Server.TickCount % 32 != 0) return;
foreach (var player in PlayerManager.GetTickPlayers())
{
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
if (playerInfo == null || playerInfo.Skill != skillName) continue;
if (!SkillUtils.HasMenu(player)) continue;
var enemies = PlayerManager.GetTickPlayers().Where(p => p != null && p.IsValid).Select(p => PlayerManager.GetPlayerEvent(p)).Where(p => p != null && p.IsValid && p.Team != player.Team && p.PlayerPawn?.Value != null && p.PlayerPawn.Value.IsValid && p.PlayerPawn.Value.Health > 0 && !p.IsHLTV && p.Team != CsTeam.Spectator && p.Team != CsTeam.None).OfType<CCSPlayerController>().ToArray();
ConcurrentBag<(string, string)> menuItems = new(enemies.Select(e => (e.PlayerName, e.Index.ToString())));
SkillUtils.UpdateMenu(player, menuItems);
}
}
public static void TypeSkill(CCSPlayerController player, string[] commands)
{
if (player == null || !player.IsValid || player.LifeState != (byte)LifeState_t.LIFE_ALIVE) return;
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
if (playerInfo?.Skill != skillName) return;
var playerEvent = PlayerManager.GetPlayerFromEvent(player);
if (playerEvent == null || !playerEvent.IsValid) return;
if (playerInfo.SkillUsed)
{
playerEvent.PrintToChat($" {ChatColors.Red}{playerEvent.GetTranslation("areareaper_used_info")}");
return;
}
string enemyId = commands[0];
if (!uint.TryParse(enemyId, out uint enemyIndex))
{
playerEvent.PrintToChat($" {ChatColors.Red}" + playerEvent.GetTranslation("selectplayerskill_incorrect_enemy_index"));
return;
}
var enemy = Utilities.GetPlayerFromIndex((int)enemyIndex);
if (enemy == null || !enemy.IsValid || enemy.Team == player.Team)
{
playerEvent.PrintToChat($" {ChatColors.Red}" + playerEvent.GetTranslation("selectplayerskill_incorrect_enemy_index"));
return;
}
targetedPlayers.TryAdd(enemy.Index, 0);
playersToTarget[player.Index] = enemy.Index;
var enemyEvent = PlayerManager.GetPlayerFromEvent(enemy);
if (enemyEvent == null || !enemyEvent.IsValid) return;
playerInfo.SkillUsed = true;
playerEvent.PrintToChat($" {ChatColors.Green}" + playerEvent.GetTranslation("jetkick_player_info", enemy.PlayerName));
enemyEvent.PrintToChat($" {ChatColors.Red}" + enemyEvent.GetTranslation("jetkick_enemy_info"));
}
public static void EnableSkill(CCSPlayerController player)
{
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
if (playerInfo == null) return;
playerInfo.SkillUsed = false;
var playerEvent = PlayerManager.GetPlayerFromEvent(player);
if (playerEvent == null || !playerEvent.IsValid) return;
var enemies = PlayerManager.GetTickPlayers().Where(p => p != null && p.IsValid).Select(p => PlayerManager.GetPlayerEvent(p)).Where(p => p != null && p.IsValid && p.Team != player.Team && p.PlayerPawn?.Value != null && p.PlayerPawn.Value.IsValid && p.PlayerPawn.Value.Health > 0 && !p.IsHLTV && p.Team != CsTeam.Spectator && p.Team != CsTeam.None).OfType<CCSPlayerController>().ToArray();
if (enemies.Length > 0)
{
ConcurrentBag<(string, string)> menuItems = new(enemies.Select(e => (e.PlayerName, e.Index.ToString())));
SkillUtils.CreateMenu(player, menuItems);
}
else
playerEvent.PrintToChat($" {ChatColors.Red}{playerEvent.GetTranslation("selectplayerskill_incorrect_enemy_index")}");
}
public static void DisableSkill(CCSPlayerController player)
{
if (playersToTarget.TryRemove(player.Index, out uint targetIndex))
{
var target = PlayerManager.GetPlayerFromEvent(Utilities.GetPlayerFromIndex((int)targetIndex));
if (target != null && target.IsValid)
{
if (target.PawnIsAlive)
target.PrintToChat($" {ChatColors.Green}" + target.GetTranslation("jetkick_disable_info"));
}
targetedPlayers.TryRemove(targetIndex, out _);
}
SkillUtils.CloseMenu(player);
}
public static void PlayerDeath(EventPlayerDeath @event)
{
var player = @event.Userid;
if (player == null || !player.IsValid) return;
targetedPlayers.TryRemove(player.Index, out _);
SkillUtils.CloseMenu(player);
}
public static void WeaponFire(EventWeaponFire @event)
{
var player = PlayerManager.GetPlayerEvent(@event.Userid);
if (player == null || !player.IsValid) return;
if (!targetedPlayers.ContainsKey(player.Index)) return;
if (!SkillUtils.FiresBullets(@event.Weapon)) return;
PushPlayer(player);
}
private static void PushPlayer(CCSPlayerController player)
{
if (Heavyweight.Resists(player)) return;
var playerPawn = player.PlayerPawn.Value;
if (playerPawn == null || !playerPawn.IsValid || playerPawn.Health <= 0) return;
Vector newVelocity = -SkillUtils.GetForwardVector(playerPawn.V_angle) * SkillsInfo.GetValue<float>(skillName, "pushVelocity");
playerPawn.Teleport(null, null, newVelocity);
}
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#5a4fd1", 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, float pushVelocity = 400f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, hudDuration, descriptionHudDuration, maxPerServer, rarity)
{
public float PushVelocity { get; set; } = pushVelocity;
}
}
}