jRandomSkills/jRandomSkills - SRC Files/src/player/skills/Jester.cs
ByDexter b2d2c5bf9a v1.2.3.b6
New skills (9)
- Bounty: put a cash price on an enemy's head, the killer collects it.
- EmpGrenade: grenade victims lose radar and crosshair for a while.
- GravityDecoy: the decoy alters gravity for everyone in its radius.
- Heavyweight: immune to push and slow effects from other skills.
- Nemesis: the marked player takes extra damage from everyone.
- Punisher: banks part of the damage you take and releases it on your next hit.
- Rewind: drop a marker and teleport back to it shortly after.
- TrueArmor: armor absorbs part of incoming damage instead of health.
- Voodoo: the marked enemy shares the damage you take.

Shared systems
- DecoyRing: reusable ground ring so decoy skills show their real area of effect. Adopted by FireRain, FrozenDecoy, GravityDecoy and MagneticDecoy.
- WeaponPool: single cached weapon classification (rifle/pistol/grenade) with a normalizing lookup, backed by the new config Weapons section. Replaces the duplicated hardcoded arrays in Assassin, Chicken, Ghost, NoNades, PrimaryBan, RandomWeapon, SniperElite and WeaponsSwap. [because of compatibility with WeaponRestrict]
- HUD suppression registry in SkillUtils: crosshair and radar hiding is now refcounted per owner, so overlapping skills (Glitch, Jammer, EmpGrenade) cannot restore each other's state early.
- SkillUtils.ResolveHiddenPawns: shared invisible-pawn resolution for C4Camouflage, Ghost and Ninja.
- Config gained a Weapons section with automatic migration for existing installs, plus a per-skill DisableOnPistolRound switch honoured by both the round draw and css_setskill.

Sound
- Volume rebalance
- Add SkillUtils.EmitSoundToPlayer with a private RecipientFilter. A null filter had been broadcasting every skill sound to all clients. Migrated 16 call sites: Poison, DemonEye, ToxicSmoke, CarefulBullets, Thorns, HotBomb, LastGasp, LongKnife, Nightmare, Jester, Tripwire, Medic, HealingSmoke, Rewind, Watchmaker.
- New effects: LongKnife knife-hit feedback (Weapon_Knife.Hit.Heavy/Light), Grapple hook impact, Fortnite barricade placement, Ricochet bounce, Nightmare cursed tone, Replicator/Illusionist spawn, PsychicDefusing defuse cue, TakeAmmo pickup, Tripwire and Jammer trigger tones.
- 29 skills gained a configurable SoundVolume, LongKnife also HitSoundVolume.
- Grapple: emit the hook impact at the hook entity instead of at the owner so the enemy team can locate it.
- PawelJumper: the engine already plays the first jump, only extra jumps emit.

Models and visuals
- Grapple: real hook model with configurable hookScale and hookEmbed so the hook sits in the surface it hit.
- Pilot: glowing exhaust trail parented to the pawn, active only while airborne.

Performance
- SkillsInfo.GetValue now resolves through a ConcurrentDictionary cache instead of reflecting on every call; invalidated on config reload.
- HUD render cache keyed on player, config, description flag and the three source lines; identical frames skip the rebuild.
- Glaz.CheckTransmit: hoist smoke index resolution out of the per-viewer loop and build the pawn-owner map lazily.
- playersSkills switched from ConcurrentBag to HashSet<Skills>, turning the NoRepeat filter from an O(n) scan into a set lookup.

Fixes
- NoRepeat could hand a player two or three skills in one round because the history bag was never deduplicated; the HashSet rewrite closes it.
- SniperElite: restore the saved weapon after the halftime team swap instead of dropping it on the pistol round.
- Illiterate: the holder alert now reaches chat and is exempt from its own scrambler via PrintToChat(ignoreIlliterate).
- EntityManager.DestroyBeam: zero out width and render colour before the kill so beams cannot linger visibly, with a next-frame Remove fallback.
- Ricochet: drop all 18 diagnostic Trace calls and the Trace helper; the skill measured stable over 48h and the tracing dominated the debug log.

Debug
- Tag round start, round end and freeze-time-end lines with [WARMUP] so warmup load is separable from live rounds.
2026-08-09 00:37:02 +03:00

286 lines
No EOL
10 KiB
C#

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using src.utils;
using System.Collections.Concurrent;
using System.Drawing;
using static src.jRandomSkills;
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;
namespace src.player.skills
{
public class Jester : ISkill
{
private const Skills skillName = Skills.Jester;
private const string toggleSound = "Weapon_Taser.ChargeReady";
private static readonly ConcurrentDictionary<uint, JesterInfo> jesters = [];
public static void LoadSkill()
{
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
}
public static void PlayerDisconnect(uint playerIndex)
{
if (!jesters.TryRemove(playerIndex, out var jester)) return;
jester.Generation++;
jester.Active = false;
jester.Timer?.Kill();
jester.Timer = null;
}
public static void NewRound()
{
Server.NextWorldUpdate(() =>
{
foreach (var jester in jesters.Values)
{
if (jester.Timer != null)
{
jester.Timer?.Kill();
jester.Timer = null;
}
var player = Utilities.GetPlayerFromIndex((int)jester.PlayerIndex);
if (player != null && player.IsValid)
{
SkillUtils.ResetPrintHTML(player);
var pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid || player.LifeState != (byte)LifeState_t.LIFE_ALIVE) continue;
var color = Color.FromArgb(255, 255, 255, 255);
pawn.Render = color;
Utilities.SetStateChanged(pawn, "CBaseModelEntity", "m_clrRender");
}
}
jesters.Clear();
});
}
public static void DisableSkill(CCSPlayerController player)
{
var jester = GetJesterInfo(player.Index);
if (jester == null) return;
jester.Generation++;
jester.Active = false;
jester.Timer = null;
jesters.TryRemove(player.Index, out _);
Server.NextWorldUpdate(() =>
{
SkillUtils.ResetPrintHTML(player);
SetPlayerColor(player, true);
});
}
public static void BombBegindefuse(EventBombBegindefuse @event)
{
var player = PlayerManager.GetPlayerEvent(@event.Userid);
if (player == null || !player.IsValid) return;
uint playerIndex = player.Index;
var jester = GetJesterInfo(playerIndex);
if (jester == null) return;
if (jester.Timer != null)
{
jester.Timer?.Kill();
jester.Timer = null;
}
jester.Timer = Instance.AddTimer(1, () =>
{
ChangeMode(playerIndex, false);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
public static void BombBeginplant(EventBombBeginplant @event)
{
var player = PlayerManager.GetPlayerEvent(@event.Userid);
if (player == null || !player.IsValid) return;
uint playerIndex = player.Index;
var jester = GetJesterInfo(playerIndex);
if (jester == null) return;
if (jester.Timer != null)
{
jester.Timer?.Kill();
jester.Timer = null;
}
jester.Timer = Instance.AddTimer(1, () =>
{
if (player != null && player.IsValid)
ChangeMode(playerIndex, false);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
public static bool PlayerHurtPre(EventPlayerHurt @event)
{
var victim = PlayerManager.GetPlayerEvent(@event.Userid);
if (!Instance.IsPlayerValid(victim)) return false;
if (!IsActiveJester(victim!.Index))
{
var attacker = PlayerManager.GetPlayerEvent(@event.Attacker);
if (!Instance.IsPlayerValid(attacker) || !IsActiveJester(attacker!.Index)) return false;
}
SkillUtils.RestoreHealth(victim);
return true;
}
public static bool IsActiveJester(uint playerIndex)
{
if (GetJesterInfo(playerIndex)?.Active != true) return false;
return PlayerManager.GetPlayerByIndex(playerIndex)?.Skill == skillName;
}
public static void EnableSkill(CCSPlayerController player)
{
var minTime = SkillsInfo.GetValue<float>(skillName, "minTime");
var maxTime = SkillsInfo.GetValue<float>(skillName, "maxTime");
float wait = (float)Instance.Random.NextDouble() * (maxTime - minTime) + minTime;
uint playerIndex = player.Index;
if (!jesters.TryGetValue(playerIndex, out var jester))
{
jester = new JesterInfo
{
PlayerIndex = playerIndex,
Active = false,
Generation = 0
};
jesters[playerIndex] = jester;
}
jester.Generation++;
int generation = jester.Generation;
jester.Timer = Instance.AddTimer(wait, () =>
{
if (!jesters.TryGetValue(playerIndex, out var info))
return;
if (info.Generation != generation)
return;
ChangeMode(playerIndex);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
private static void ChangeMode(uint playerIndex, bool? forceActive = null)
{
if (!jesters.TryGetValue(playerIndex, out var jester)) return;
var player = Utilities.GetPlayerFromIndex((int)playerIndex);
if (player == null || !player.IsValid || player.LifeState != (byte)LifeState_t.LIFE_ALIVE)
{
jesters.TryRemove(playerIndex, out _);
return;
}
bool previousState = jester.Active;
jester.Active = forceActive ?? !jester.Active;
if (jester.Active != previousState)
{
SetPlayerColor(player);
var playerEvent = PlayerManager.GetPlayerFromEvent(player);
if (playerEvent != null && playerEvent.IsValid)
SkillUtils.EmitSoundToPlayer(playerEvent, toggleSound, SkillsInfo.GetValue<float>(skillName, "soundVolume"));
}
var minTime = SkillsInfo.GetValue<float>(skillName, "minTime");
var maxTime = SkillsInfo.GetValue<float>(skillName, "maxTime");
float wait = (float)Instance.Random.NextDouble() * (maxTime - minTime) + minTime;
jester.Generation++;
int generation = jester.Generation;
jester.Timer = Instance.AddTimer(wait, () =>
{
if (!jesters.TryGetValue(playerIndex, out var info))
return;
if (info.Generation != generation)
return;
ChangeMode(playerIndex);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
private static void SetPlayerColor(CCSPlayerController? player, bool forceDisable = false)
{
if (player == null || !player.IsValid) return;
var pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid) return;
var jester = GetJesterInfo(player.Index);
if (!forceDisable && jester == null) return;
var color = jester?.Active == true && !forceDisable ? Color.FromArgb(255, 128, 0, 128) : Color.FromArgb(255, 255, 255, 255);
pawn.Render = color;
Utilities.SetStateChanged(pawn, "CBaseModelEntity", "m_clrRender");
}
public static void OnTick()
{
if (!SkillUtils.IsHudFrame()) return;
if (SkillUtils.IsFreezeTime()) return;
foreach (var player in PlayerManager.GetTickPlayers())
{
var playeEvent = PlayerManager.GetPlayerEvent(player);
if (playeEvent == null || !playeEvent.IsValid || playeEvent.PlayerPawn.Value == null || !playeEvent.PlayerPawn.Value.IsValid) continue;
var playerInfo = PlayerManager.GetPlayerByIndex(playeEvent.Index);
if (playerInfo?.Skill == skillName)
UpdateHUD(playeEvent);
}
}
private static void UpdateHUD(CCSPlayerController player)
{
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
if (playerInfo == null) return;
var jester = GetJesterInfo(player.Index);
if (jester == null) return;
playerInfo.PrintHTML = $"{player.GetTranslation("jester_mode")}: <font color='{(jester.Active ? "#00ff00" : "#ff0000")}'>{player.GetTranslation(jester.Active ? "jester_on" : "jester_off")}</font>";
}
public static JesterInfo? GetJesterInfo(uint playerIndex)
{
if (jesters.TryGetValue(playerIndex, value: out var info))
return info;
return null;
}
public class JesterInfo()
{
public required uint PlayerIndex { get; set; }
public bool Active { get; set; } = false;
public int Generation { get; set; } = 0;
public Timer? Timer { get; set; } = null;
}
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#8f108f", 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 minTime = 10f, float maxTime = 25f, float soundVolume = .5f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, hudDuration, descriptionHudDuration, maxPerServer, rarity)
{
public float SoundVolume { get; set; } = soundVolume;
public float MinTime { get; set; } = minTime;
public float MaxTime { get; set; } = maxTime;
}
}
}