jRandomSkills/jRandomSkills - SRC Files/src/player/skills/Dwarf.cs
Juzlus e33975fe8b 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.
2025-09-04 04:53:23 +02:00

93 lines
No EOL
4 KiB
C#

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using jRandomSkills.src.player;
using jRandomSkills.src.utils;
using static jRandomSkills.jRandomSkills;
namespace jRandomSkills
{
public class Dwarf : ISkill
{
private const Skills skillName = Skills.Dwarf;
public static void LoadSkill()
{
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"), false);
Instance.RegisterEventHandler<EventRoundFreezeEnd>((@event, info) =>
{
Instance.AddTimer(0.1f, () =>
{
foreach (var player in Utilities.GetPlayers())
{
if (!Instance.IsPlayerValid(player)) continue;
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
if (playerInfo?.Skill != skillName) continue;
EnableSkill(player);
player.Respawn();
}
});
return HookResult.Continue;
});
Instance.RegisterEventHandler<EventRoundEnd>((@event, info) =>
{
Instance.AddTimer(0.1f, () =>
{
foreach (var player in Utilities.GetPlayers())
{
if (!Instance.IsPlayerValid(player)) continue;
DisableSkill(player);
}
});
return HookResult.Continue;
});
Instance.RegisterEventHandler<EventPlayerDeath>((@event, info) =>
{
var player = @event.Userid;
if (player == null || !player.IsValid) return HookResult.Continue;
DisableSkill(player);
return HookResult.Continue;
});
}
public static void EnableSkill(CCSPlayerController player)
{
var playerPawn = player.PlayerPawn?.Value;
if (playerPawn != null && player.IsValid)
{
float newSize = (float)Instance.Random.NextDouble() * (Config.GetValue<float>(skillName, "maxScale") - Config.GetValue<float>(skillName, "minScale")) + Config.GetValue<float>(skillName, "minScale");
newSize = (float)Math.Round(newSize, 2);
// playerPawn.CBodyComponent.SceneNode.GetSkeletonInstance().Scale = newSize;
if (playerPawn.CBodyComponent == null || playerPawn.CBodyComponent.SceneNode == null) return;
playerPawn.CBodyComponent.SceneNode.Scale = newSize;
Utilities.SetStateChanged(playerPawn, "CBaseEntity", "m_CBodyComponent");
SkillUtils.PrintToChat(player, $"{ChatColors.DarkRed}{Localization.GetTranslation("dwarf")}{ChatColors.Lime}: " + Localization.GetTranslation("dwarf_desc2", newSize), false);
}
}
public static void DisableSkill(CCSPlayerController player)
{
var playerPawn = player.PlayerPawn?.Value;
if (playerPawn != null && playerPawn?.CBodyComponent != null)
{
// playerPawn.CBodyComponent.SceneNode.GetSkeletonInstance().Scale = 1;
if (playerPawn.CBodyComponent == null || playerPawn.CBodyComponent.SceneNode == null) return;
playerPawn.CBodyComponent.SceneNode.Scale = 1;
Utilities.SetStateChanged(playerPawn, "CBaseEntity", "m_CBodyComponent");
}
}
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#ffff00", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float minScale = .6f, float maxScale = .95f) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
{
public float MinScale { get; set; } = minScale;
public float MaxScale { get; set; } = maxScale;
}
}
}