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,15 +11,12 @@ namespace jRandomSkills
|
|||
public class FrozenDecoy : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.FrozenDecoy;
|
||||
private static float decoyRadius = Config.GetValue<float>(skillName, "triggerRadius");
|
||||
private static int slownessMultiplier = Config.GetValue<int>(skillName, "slownessMultiplier");
|
||||
private static List<Vector> decoys = new List<Vector>();
|
||||
private static readonly float decoyRadius = Config.GetValue<float>(skillName, "triggerRadius");
|
||||
private static readonly int slownessMultiplier = Config.GetValue<int>(skillName, "slownessMultiplier");
|
||||
private static readonly List<Vector> decoys = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
if (Config.config.SkillsInfo.FirstOrDefault(s => s.Name == skillName.ToString())?.Active != true)
|
||||
return;
|
||||
|
||||
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"));
|
||||
|
||||
Instance.RegisterEventHandler<EventRoundStart>((@event, info) =>
|
||||
|
|
@ -35,7 +32,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) continue;
|
||||
EnableSkill(player);
|
||||
}
|
||||
|
|
@ -47,7 +44,8 @@ namespace jRandomSkills
|
|||
Instance.RegisterEventHandler<EventDecoyStarted>((@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) return HookResult.Continue;
|
||||
decoys.Add(new Vector(@event.X, @event.Y, @event.Z));
|
||||
return HookResult.Continue;
|
||||
|
|
@ -56,7 +54,8 @@ namespace jRandomSkills
|
|||
Instance.RegisterEventHandler<EventDecoyDetonate>((@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) return HookResult.Continue;
|
||||
decoys.RemoveAll(v => v.X == @event.X && v.Y == @event.Y && v.Z == @event.Z);
|
||||
return HookResult.Continue;
|
||||
|
|
@ -67,11 +66,13 @@ namespace jRandomSkills
|
|||
foreach (Vector decoyPos in decoys)
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
double distance = SkillUtils.GetDistance(decoyPos, player.PlayerPawn.Value.AbsOrigin);
|
||||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid || pawn.AbsOrigin == null) return;
|
||||
double distance = SkillUtils.GetDistance(decoyPos, pawn.AbsOrigin);
|
||||
if (distance <= decoyRadius)
|
||||
{
|
||||
double modifier = Math.Clamp(distance / decoyRadius, 0f, 1f);
|
||||
player.PlayerPawn.Value.VelocityModifier = (float)Math.Pow(modifier, slownessMultiplier);
|
||||
pawn.VelocityModifier = (float)Math.Pow(modifier, slownessMultiplier);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -82,15 +83,10 @@ namespace jRandomSkills
|
|||
SkillUtils.TryGiveWeapon(player, CsItem.DecoyGrenade);
|
||||
}
|
||||
|
||||
public class SkillConfig : Config.DefaultSkillInfo
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#00eaff", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float triggerRadius = 180, int slownessMultiplier = 5) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
public float TriggerRadius { get; set; }
|
||||
public int SlownessMultiplier { get; set; }
|
||||
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#00eaff", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float triggerRadius = 180, int slownessMultiplier = 5) : base(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
TriggerRadius = triggerRadius;
|
||||
SlownessMultiplier = slownessMultiplier;
|
||||
}
|
||||
public float TriggerRadius { get; set; } = triggerRadius;
|
||||
public int SlownessMultiplier { get; set; } = slownessMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue