Refactor skill lookup logic and vote system, update language files
Refactored command handling to improve player and skill lookup logic, replaced some list operations with direct queries, and updated method signatures for clarity and null safety. The vote system was reworked to support more robust vote tracking, cooldowns, and localized chat messages. Language files were updated to add new vote-related translations. Various code style and nullability improvements were made throughout the plugin.
This commit is contained in:
parent
54b265d43d
commit
e33975fe8b
117 changed files with 1532 additions and 1674 deletions
|
|
@ -1,6 +1,8 @@
|
|||
using System.Collections.Immutable;
|
||||
using System.Drawing;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using jRandomSkills.src.player;
|
||||
using jRandomSkills.src.utils;
|
||||
|
|
@ -13,48 +15,23 @@ namespace jRandomSkills
|
|||
{
|
||||
private const Skills skillName = Skills.Ghost;
|
||||
private static bool roundEnd = false;
|
||||
private static string[] disabledWeapons =
|
||||
{
|
||||
"weapon_deagle",
|
||||
"weapon_revolver",
|
||||
"weapon_glock",
|
||||
"weapon_usp_silencer",
|
||||
"weapon_cz75a",
|
||||
"weapon_fiveseven",
|
||||
"weapon_p250",
|
||||
"weapon_tec9",
|
||||
"weapon_elite",
|
||||
"weapon_hkp2000",
|
||||
"weapon_ak47",
|
||||
"weapon_m4a1",
|
||||
"weapon_m4a4",
|
||||
"weapon_m4a1_silencer",
|
||||
"weapon_famas",
|
||||
"weapon_galilar",
|
||||
"weapon_aug",
|
||||
"weapon_sg553",
|
||||
"weapon_mp9",
|
||||
"weapon_mac10",
|
||||
"weapon_bizon",
|
||||
"weapon_mp7",
|
||||
"weapon_ump45",
|
||||
"weapon_p90",
|
||||
"weapon_mp5sd",
|
||||
"weapon_ssg08",
|
||||
"weapon_awp",
|
||||
"weapon_scar20",
|
||||
"weapon_g3sg1",
|
||||
"weapon_nova",
|
||||
"weapon_xm1014",
|
||||
"weapon_mag7",
|
||||
"weapon_sawedoff",
|
||||
"weapon_m249",
|
||||
"weapon_negev"
|
||||
};
|
||||
private static readonly string[] disabledWeapons =
|
||||
[
|
||||
"weapon_deagle", "weapon_revolver", "weapon_glock", "weapon_usp_silencer",
|
||||
"weapon_cz75a", "weapon_fiveseven", "weapon_p250", "weapon_tec9",
|
||||
"weapon_elite", "weapon_hkp2000", "weapon_ak47", "weapon_m4a1",
|
||||
"weapon_m4a4", "weapon_m4a1_silencer", "weapon_famas", "weapon_galilar",
|
||||
"weapon_aug", "weapon_sg553", "weapon_mp9", "weapon_mac10",
|
||||
"weapon_bizon", "weapon_mp7", "weapon_ump45", "weapon_p90",
|
||||
"weapon_mp5sd", "weapon_ssg08", "weapon_awp", "weapon_scar20",
|
||||
"weapon_g3sg1", "weapon_nova", "weapon_xm1014", "weapon_mag7",
|
||||
"weapon_sawedoff", "weapon_m249", "weapon_negev"
|
||||
];
|
||||
private static readonly HashSet<uint> invisibleEntities = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
if (Config.config.SkillsInfo.FirstOrDefault(s => s.Name == skillName.ToString())?.Active != true)
|
||||
if (Config.LoadedConfig.SkillsInfo.FirstOrDefault(s => s.Name == skillName.ToString())?.Active != true)
|
||||
return;
|
||||
|
||||
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"));
|
||||
|
|
@ -67,7 +44,7 @@ namespace jRandomSkills
|
|||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) continue;
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill == skillName)
|
||||
EnableSkill(player);
|
||||
}
|
||||
|
|
@ -81,7 +58,7 @@ namespace jRandomSkills
|
|||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) continue;
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill == skillName)
|
||||
DisableSkill(player);
|
||||
}
|
||||
|
|
@ -92,9 +69,9 @@ namespace jRandomSkills
|
|||
Instance.RegisterEventHandler<EventPlayerDeath>((@event, info) =>
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (!player.IsValid || player.PlayerPawn.Value == null) return HookResult.Continue;
|
||||
if (player == null || !player.IsValid || player.PlayerPawn.Value == null) return HookResult.Continue;
|
||||
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill == skillName)
|
||||
DisableSkill(player);
|
||||
|
||||
|
|
@ -105,11 +82,12 @@ namespace jRandomSkills
|
|||
{
|
||||
var player = @event.Userid;
|
||||
if (!Instance.IsPlayerValid(player)) return HookResult.Continue;
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player?.SteamID);
|
||||
|
||||
if (playerInfo?.Skill != skillName) return HookResult.Continue;
|
||||
SetWeaponVisibility(player, false);
|
||||
SetWeaponAttack(player, true);
|
||||
SetWeaponVisibility(player!, false);
|
||||
SetWearablesVisibility(player!, false);
|
||||
SetWeaponAttack(player!, true);
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
|
|
@ -121,12 +99,24 @@ namespace jRandomSkills
|
|||
});
|
||||
|
||||
Instance.RegisterListener<OnTick>(OnTick);
|
||||
Instance.RegisterListener<CheckTransmit>(CheckTransmit);
|
||||
}
|
||||
|
||||
public static void CheckTransmit([CastFrom(typeof(nint))] CCheckTransmitInfoList infoList)
|
||||
{
|
||||
foreach (var (info, player) in infoList)
|
||||
{
|
||||
if (player == null) continue;
|
||||
foreach (var entity in invisibleEntities)
|
||||
info.TransmitEntities.Remove((int)entity);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
SetPlayerVisibility(player, false);
|
||||
SetWeaponVisibility(player, false);
|
||||
SetWearablesVisibility(player, false);
|
||||
SetWeaponAttack(player, true);
|
||||
}
|
||||
|
||||
|
|
@ -134,6 +124,7 @@ namespace jRandomSkills
|
|||
{
|
||||
SetPlayerVisibility(player, true);
|
||||
SetWeaponVisibility(player, true);
|
||||
SetWearablesVisibility(player, true);
|
||||
SetWeaponAttack(player, false);
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +132,7 @@ namespace jRandomSkills
|
|||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill == skillName)
|
||||
UpdateHUD(player);
|
||||
}
|
||||
|
|
@ -161,15 +152,36 @@ namespace jRandomSkills
|
|||
}
|
||||
}
|
||||
|
||||
private static void SetWeaponVisibility(CCSPlayerController player, bool visible)
|
||||
private static void SetWearablesVisibility(CCSPlayerController player, bool visible)
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
var playerPawn = player.PlayerPawn.Value!;
|
||||
|
||||
var color = visible ? Color.FromArgb(255, 255, 255, 255) : Color.FromArgb(0, 255, 255, 255);
|
||||
var shadowStrength = visible ? 1.0f : 0.0f;
|
||||
|
||||
foreach (var weapon in playerPawn.WeaponServices?.MyWeapons)
|
||||
foreach (var item in playerPawn.MyWearables)
|
||||
{
|
||||
if (item != null && item.IsValid && item.Value != null && item.Value.IsValid)
|
||||
{
|
||||
Server.PrintToChatAll($"NAME: {item.Value.DesignerName}");
|
||||
item.Value.Render = color;
|
||||
item.Value.ShadowStrength = shadowStrength;
|
||||
Utilities.SetStateChanged(item.Value, "CBaseModelEntity", "m_clrRender");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetWeaponVisibility(CCSPlayerController player, bool visible)
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value!;
|
||||
if (playerPawn.WeaponServices == null) return;
|
||||
|
||||
var color = visible ? Color.FromArgb(255, 255, 255, 255) : Color.FromArgb(0, 255, 255, 255);
|
||||
var shadowStrength = visible ? 1.0f : 0.0f;
|
||||
|
||||
foreach (var weapon in playerPawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
|
|
@ -184,11 +196,11 @@ namespace jRandomSkills
|
|||
{
|
||||
if (roundEnd || player == null || !player.IsValid) return;
|
||||
var pawn = player?.PlayerPawn?.Value;
|
||||
if (pawn == null || !pawn.IsValid) return;
|
||||
if (pawn == null || !pawn.IsValid || pawn.WeaponServices == null) return;
|
||||
|
||||
foreach (var weapon in pawn?.WeaponServices?.MyWeapons)
|
||||
foreach (var weapon in pawn.WeaponServices.MyWeapons)
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
if (disabledWeapons.Contains(weapon?.Value?.DesignerName))
|
||||
if (disabledWeapons.Contains(weapon.Value.DesignerName))
|
||||
{
|
||||
weapon.Value.NextPrimaryAttackTick = disableWeapon ? int.MaxValue : Server.TickCount;
|
||||
weapon.Value.NextSecondaryAttackTick = disableWeapon ? int.MaxValue : Server.TickCount;
|
||||
|
|
@ -200,11 +212,15 @@ namespace jRandomSkills
|
|||
|
||||
private static void UpdateHUD(CCSPlayerController player)
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid || pawn.WeaponServices == null) return;
|
||||
|
||||
var skillData = SkillData.Skills.FirstOrDefault(s => s.Skill == skillName);
|
||||
if (skillData == null) return;
|
||||
|
||||
var weapon = player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value;
|
||||
if (weapon == null || !disabledWeapons.Contains(weapon.DesignerName)) return;
|
||||
var weapon = pawn.WeaponServices.ActiveWeapon.Value;
|
||||
if (weapon == null || !weapon.IsValid || !disabledWeapons.Contains(weapon.DesignerName)) return;
|
||||
|
||||
string infoLine = $"<font class='fontSize-l' class='fontWeight-Bold' color='#FFFFFF'>{Localization.GetTranslation("your_skill")}:</font> <br>";
|
||||
string skillLine = $"<font class='fontSize-l' class='fontWeight-Bold' color='{skillData.Color}'>{skillData.Name}</font> <br>";
|
||||
|
|
@ -214,11 +230,8 @@ namespace jRandomSkills
|
|||
player.PrintToCenterHtml(hudContent);
|
||||
}
|
||||
|
||||
public class SkillConfig : Config.DefaultSkillInfo
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#FFFFFF", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#FFFFFF", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : base(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue