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
|
|
@ -11,10 +11,10 @@ namespace jRandomSkills
|
|||
public class Ninja : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.Ninja;
|
||||
private static float idlePercentInvisibility = Config.GetValue<float>(skillName, "idlePercentInvisibility");
|
||||
private static float duckPercentInvisibility = Config.GetValue<float>(skillName, "duckPercentInvisibility");
|
||||
private static float knifePercentInvisibility = Config.GetValue<float>(skillName, "knifePercentInvisibility");
|
||||
private static Dictionary<nint, float> invisibilityChanged = new Dictionary<nint, float>();
|
||||
private static readonly float idlePercentInvisibility = Config.GetValue<float>(skillName, "idlePercentInvisibility");
|
||||
private static readonly float duckPercentInvisibility = Config.GetValue<float>(skillName, "duckPercentInvisibility");
|
||||
private static readonly float knifePercentInvisibility = Config.GetValue<float>(skillName, "knifePercentInvisibility");
|
||||
private static readonly Dictionary<nint, float> invisibilityChanged = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
|
|
@ -31,9 +31,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);
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ 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;
|
||||
UpdateNinja(player);
|
||||
|
|
@ -58,7 +58,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)
|
||||
UpdateNinja(player);
|
||||
}
|
||||
|
|
@ -70,16 +70,24 @@ namespace jRandomSkills
|
|||
SetWeaponVisibility(player, 0);
|
||||
}
|
||||
|
||||
private static void UpdateNinja(CCSPlayerController player)
|
||||
private static void UpdateNinja(CCSPlayerController? player)
|
||||
{
|
||||
var flags = (PlayerFlags)player.PlayerPawn.Value.Flags;
|
||||
if (player == null || !player.IsValid) return;
|
||||
var pawn = player.PlayerPawn?.Value;
|
||||
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE) return;
|
||||
|
||||
var flags = (PlayerFlags)pawn.Flags;
|
||||
var buttons = player.Buttons;
|
||||
var activeWeapon = player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value;
|
||||
|
||||
var weaponServices = pawn.WeaponServices;
|
||||
if (weaponServices == null) return;
|
||||
|
||||
var activeWeapon = weaponServices.ActiveWeapon.Value;
|
||||
float percentInvisibility = 0;
|
||||
|
||||
if (buttons.HasFlag(PlayerButtons.Duck))
|
||||
percentInvisibility += duckPercentInvisibility;
|
||||
if (activeWeapon.DesignerName == "weapon_knife")
|
||||
if (activeWeapon != null && activeWeapon.DesignerName == "weapon_knife")
|
||||
percentInvisibility += knifePercentInvisibility;
|
||||
if (!buttons.HasFlag(PlayerButtons.Moveleft) && !buttons.HasFlag(PlayerButtons.Moveright) && !buttons.HasFlag(PlayerButtons.Forward) && !buttons.HasFlag(PlayerButtons.Back) && flags.HasFlag(PlayerFlags.FL_ONGROUND))
|
||||
percentInvisibility += idlePercentInvisibility;
|
||||
|
|
@ -108,10 +116,11 @@ namespace jRandomSkills
|
|||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
if (playerPawn == null || !playerPawn.IsValid || playerPawn.WeaponServices == null) return;
|
||||
|
||||
var color = Color.FromArgb(Math.Max(255 - (int)(255 * percentInvisibility * 2), 0), 255, 255, 255);
|
||||
|
||||
foreach (var weapon in playerPawn.WeaponServices?.MyWeapons)
|
||||
foreach (var weapon in playerPawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
|
|
@ -121,17 +130,11 @@ namespace jRandomSkills
|
|||
}
|
||||
}
|
||||
|
||||
public class SkillConfig : Config.DefaultSkillInfo
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#dedede", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float idlePercentInvisibility = .3f, float duckPercentInvisibility = .3f, float knifePercentInvisibility = .3f) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
public float IdlePercentInvisibility { get; set; }
|
||||
public float DuckPercentInvisibility { get; set; }
|
||||
public float KnifePercentInvisibility { get; set; }
|
||||
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#dedede", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float idlePercentInvisibility = .3f, float duckPercentInvisibility = .3f, float knifePercentInvisibility = .3f) : base(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
IdlePercentInvisibility = idlePercentInvisibility;
|
||||
DuckPercentInvisibility = duckPercentInvisibility;
|
||||
KnifePercentInvisibility = knifePercentInvisibility;
|
||||
}
|
||||
public float IdlePercentInvisibility { get; set; } = idlePercentInvisibility;
|
||||
public float DuckPercentInvisibility { get; set; } = duckPercentInvisibility;
|
||||
public float KnifePercentInvisibility { get; set; } = knifePercentInvisibility;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue