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,8 +11,8 @@ namespace jRandomSkills
|
|||
public class SoundMaker : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.SoundMaker;
|
||||
private static float timerCooldown = Config.GetValue<float>(skillName, "Cooldown");
|
||||
private static readonly Dictionary<ulong, PlayerSkillInfo> SkillPlayerInfo = new Dictionary<ulong, PlayerSkillInfo>();
|
||||
private static readonly float timerCooldown = Config.GetValue<float>(skillName, "Cooldown");
|
||||
private static readonly Dictionary<ulong, PlayerSkillInfo> SkillPlayerInfo = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
|
|
@ -25,7 +25,7 @@ namespace jRandomSkills
|
|||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
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);
|
||||
}
|
||||
|
|
@ -43,11 +43,10 @@ namespace jRandomSkills
|
|||
Instance.RegisterEventHandler<EventPlayerDeath>((@event, info) =>
|
||||
{
|
||||
var player = @event.Userid;
|
||||
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill == skillName)
|
||||
if (SkillPlayerInfo.ContainsKey(player.SteamID))
|
||||
SkillPlayerInfo.Remove(player.SteamID);
|
||||
SkillPlayerInfo.Remove(player.SteamID);
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
|
|
@ -55,7 +54,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)
|
||||
if (SkillPlayerInfo.TryGetValue(player.SteamID, out var skillInfo))
|
||||
UpdateHUD(player, skillInfo);
|
||||
|
|
@ -75,8 +74,7 @@ namespace jRandomSkills
|
|||
|
||||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
if (SkillPlayerInfo.ContainsKey(player.SteamID))
|
||||
SkillPlayerInfo.Remove(player.SteamID);
|
||||
SkillPlayerInfo.Remove(player.SteamID);
|
||||
}
|
||||
|
||||
private static void UpdateHUD(CCSPlayerController player, PlayerSkillInfo skillInfo)
|
||||
|
|
@ -122,7 +120,7 @@ namespace jRandomSkills
|
|||
private static void MakeSound(CCSPlayerController player)
|
||||
{
|
||||
foreach (var enemy in Utilities.GetPlayers().Where(p => p.Team != player.Team))
|
||||
if (enemy != null && enemy.IsValid && enemy.PawnIsAlive)
|
||||
if (enemy != null && enemy.IsValid && enemy.PawnIsAlive && enemy.PlayerPawn.Value != null && enemy.PlayerPawn.Value.IsValid)
|
||||
enemy.PlayerPawn.Value.EmitSound($"C4.PlantSoundB", volume: 1f);
|
||||
}
|
||||
|
||||
|
|
@ -133,13 +131,9 @@ namespace jRandomSkills
|
|||
public DateTime Cooldown { get; set; }
|
||||
}
|
||||
|
||||
public class SkillConfig : Config.DefaultSkillInfo
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#e3ed8c", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float cooldown = 5f) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
public float Cooldown { get; set; }
|
||||
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#e3ed8c", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float cooldown = 5f) : base(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
Cooldown = cooldown;
|
||||
}
|
||||
public float Cooldown { get; set; } = cooldown;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue