## 📋 Changelog - #### General: - ###### Updated Chinese language translation by [by: [@Ericzzrbb](hhttps://github.com/Ericzzrbb)]. - ###### Fixed a bug where a player could be given multiple skills at once while the HUD displayed only one (the player list was never cleared on map change and had no duplicate protection on join). [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Fixed skill names and descriptions showing the raw translation key on Turkish servers (culture-sensitive lowercasing) - affected skills starting with "I" (e.g. Illiterate, Impostor, InfiniteAmmo, Iana). [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### RayTrace-based skills and the skill-use button no longer throw when the RayTrace module is not installed - they now degrade gracefully instead of crashing. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Fixed the skill-use button (when bound to Use/E) blocking option selection inside WSAD target menus. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Performance: cached reflection lookups in `SkillAction` and `SkillsInfo.GetValue`, and de-duplicated the repeated event-dispatch logic on hot paths (OnTick, OnTakeDamage, etc.). [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Stability: removed dead methods that threw `NotImplementedException`, hardened team-score handling, and reset all skill state on round start / map change. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Build: post-build copy paths now follow the active `$(Configuration)` and `$(TargetFramework)`. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Added new Turkish translation strings for the skill notifications listed below. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Fixed bot-related messages so they now display correctly in the chat of the controlling player. - ###### When a player takes control of a bot, all active skill effects affecting that bot are now correctly transferred to the controlling player. - ###### Prevented bots from automatically using skills while being controlled by a player. - #### Skill improvements: - ###### Wallhack: - ###### Fixed enemy outlines briefly flashing for everyone when the skill holder dies. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Area Reaper: - ###### Teammates (CT) are now notified which bombsite (A/B) was sealed. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Wild Throw: - ###### Now notifies the targeted player, consistent with other targeted skills. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Careful Bullets / Darkness / Deaf / Glitch / Jammer / Jump Ban / Magnifier / Poison / Primary Ban / Wild Throw: - ###### The targeted player is now notified when the effect ends after the skill holder dies. [by: [@ByDexterTR](https://github.com/ByDexterTR)] - ###### Careful Bullets: - ###### Added damage-taken sound effects when missing a shot - ###### C4 Camouflage / Ninja: - ###### Fixed a bug where dying with invisibility active and taking control of a bot would grant invisibility to the bot as well. - ###### Poison: - ###### Added damage-taken sound effects. - ###### Primary Ban: - ###### Changed mechanic to directly block shooting weapons instead of forcing a weapon switch to the knife. - ###### Hot Bomb: - ###### Replaced the bomb-burning sound effects. - ###### Added a notification when the burning effect ends and the bomb returns to its normal color.
214 lines
No EOL
8.9 KiB
C#
214 lines
No EOL
8.9 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Timers;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using src.utils;
|
|
using System.Collections.Concurrent;
|
|
using static src.jRandomSkills;
|
|
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;
|
|
|
|
namespace src.player.skills
|
|
{
|
|
public class Darkness : ISkill
|
|
{
|
|
private const Skills skillName = Skills.Darkness;
|
|
private static readonly ConcurrentDictionary<uint, byte> playersInDark = [];
|
|
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 Utilities.GetPlayers())
|
|
{
|
|
if (playersInDark.ContainsKey(player.Index))
|
|
DisableSkill(player);
|
|
SkillUtils.CloseMenu(player);
|
|
}
|
|
playersInDark.Clear();
|
|
playersToTarget.Clear();
|
|
}
|
|
}
|
|
|
|
public static void OnTick()
|
|
{
|
|
if (Server.TickCount % 32 != 0) return;
|
|
foreach (var player in Utilities.GetPlayers())
|
|
{
|
|
if (!SkillUtils.HasMenu(player)) continue;
|
|
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
|
|
|
if (playerInfo == null || playerInfo.Skill != skillName) continue;
|
|
var enemies = Utilities.GetPlayers().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).ToArray();
|
|
|
|
ConcurrentBag<(string, string)> menuItems = [.. 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)
|
|
{
|
|
playerEvent.PrintToChat($" {ChatColors.Red}" + playerEvent.GetTranslation("selectplayerskill_incorrect_enemy_index"));
|
|
return;
|
|
}
|
|
|
|
SetUpPostProcessing(enemy);
|
|
playersToTarget[player.Index] = enemy.Index;
|
|
playerInfo.SkillUsed = true;
|
|
|
|
var enemyEvent = PlayerManager.GetPlayerFromEvent(enemy);
|
|
if (enemyEvent == null || !enemyEvent.IsValid) return;
|
|
|
|
playerEvent.PrintToChat($" {ChatColors.Green}" + playerEvent.GetTranslation("darkness_player_info", enemy.PlayerName));
|
|
enemyEvent.PrintToChat($" {ChatColors.Red}" + enemyEvent.GetTranslation("darkness_enemy_info"));
|
|
}
|
|
|
|
public static void BotTakeover(EventBotTakeover @event)
|
|
{
|
|
var bot = @event.Botid;
|
|
if (bot == null || !bot.IsValid) return;
|
|
|
|
var player = @event.Userid;
|
|
if (player == null || !player.IsValid) return;
|
|
|
|
if (!playersInDark.ContainsKey(bot.Index)) return;
|
|
|
|
ApplyColor(player);
|
|
}
|
|
|
|
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 = Utilities.GetPlayers().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).ToArray();
|
|
if (enemies.Length > 0)
|
|
{
|
|
ConcurrentBag<(string, string)> menuItems = [.. 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)
|
|
{
|
|
lock (setLock)
|
|
{
|
|
if (playersToTarget.TryRemove(player.Index, out uint targetIndex))
|
|
{
|
|
var target = PlayerManager.GetPlayerFromEvent(Utilities.GetPlayerFromIndex((int)targetIndex));
|
|
if (target != null && target.IsValid)
|
|
SetUpPostProcessing(target, true);
|
|
playersInDark.TryRemove(targetIndex, out _);
|
|
}
|
|
|
|
SkillUtils.CloseMenu(player);
|
|
}
|
|
}
|
|
|
|
public static void PlayerDeath(EventPlayerDeath @event)
|
|
{
|
|
var player = @event.Userid;
|
|
if (player == null || !player.IsValid) return;
|
|
|
|
SetUpPostProcessing(player, true);
|
|
playersInDark.TryRemove(player.Index, out _);
|
|
SkillUtils.CloseMenu(player);
|
|
}
|
|
|
|
private static void SetUpPostProcessing(CCSPlayerController? player, bool turnOff = false)
|
|
{
|
|
if (player == null || !player.IsValid) return;
|
|
|
|
uint playerIndex = player.Index;
|
|
player = PlayerManager.GetPlayerFromEvent(player);
|
|
|
|
lock (setLock)
|
|
{
|
|
if (!turnOff)
|
|
{
|
|
playersInDark.TryAdd(playerIndex, 0);
|
|
ApplyColor(player);
|
|
|
|
Timer? darkTimer = null;
|
|
darkTimer = Instance.AddTimer(5f, () => {
|
|
if (!playersInDark.ContainsKey(playerIndex))
|
|
{
|
|
darkTimer?.Kill();
|
|
return;
|
|
}
|
|
|
|
var target = PlayerManager.GetPlayerFromEvent(Utilities.GetPlayerFromIndex((int)playerIndex));
|
|
if (target == null || !target.IsValid)
|
|
{
|
|
darkTimer?.Kill();
|
|
return;
|
|
}
|
|
|
|
if (target.PawnIsAlive)
|
|
ApplyColor(target);
|
|
}, TimerFlags.STOP_ON_MAPCHANGE | TimerFlags.REPEAT);
|
|
}
|
|
else
|
|
{
|
|
SkillUtils.ApplyScreenColor(player, r: 0, g: 0, b: 0, a: 0, duration: 200, holdTime: 0);
|
|
playersInDark.TryRemove(playerIndex, out _);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ApplyColor(CCSPlayerController? player)
|
|
{
|
|
SkillUtils.ApplyScreenColor(player,
|
|
r: SkillsInfo.GetValue<int>(skillName, "R"),
|
|
g: SkillsInfo.GetValue<int>(skillName, "G"),
|
|
b: SkillsInfo.GetValue<int>(skillName, "B"),
|
|
a: SkillsInfo.GetValue<int>(skillName, "A"),
|
|
duration: 100,
|
|
holdTime: 3000);
|
|
}
|
|
|
|
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#383838", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", int maxPerServer = -1, Rarity rarity = Rarity.Rare, int r = 0, int g = 0, int b = 0, int a = 230) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, maxPerServer, rarity)
|
|
{
|
|
public int R { get; set; } = r;
|
|
public int G { get; set; } = g;
|
|
public int B { get; set; } = b;
|
|
public int A { get; set; } = a;
|
|
}
|
|
}
|
|
} |