66 lines
No EOL
3 KiB
C#
66 lines
No EOL
3 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using src.utils;
|
|
using static src.jRandomSkills;
|
|
|
|
namespace src.player.skills
|
|
{
|
|
public class Watchmaker : ISkill
|
|
{
|
|
private const Skills skillName = Skills.Watchmaker;
|
|
private static bool bombPlanted = false;
|
|
|
|
public static void LoadSkill()
|
|
{
|
|
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
|
}
|
|
|
|
public static void NewRound()
|
|
{
|
|
bombPlanted = false;
|
|
}
|
|
|
|
public static void BombPlanted(EventBombPlanted _)
|
|
{
|
|
bombPlanted = true;
|
|
}
|
|
|
|
public static void OnEntitySpawned(CEntityInstance entity)
|
|
{
|
|
if (bombPlanted) return;
|
|
var name = entity.DesignerName;
|
|
if (!name.EndsWith("_projectile")) return;
|
|
|
|
var grenade = entity.As<CBaseCSGrenadeProjectile>();
|
|
if (grenade.OwnerEntity.Value == null || !grenade.OwnerEntity.Value.IsValid) return;
|
|
|
|
var pawn = grenade.OwnerEntity.Value.As<CCSPlayerPawn>();
|
|
if (pawn == null || !pawn.IsValid || pawn.Controller == null || !pawn.Controller.IsValid || pawn.Controller.Value == null || !pawn.Controller.Value.IsValid) return;
|
|
var player = pawn.Controller.Value.As<CCSPlayerController>();
|
|
|
|
var playerInfo = PlayerManager.GetPlayerByIndex(PlayerManager.GetPlayerEvent(player)!.Index);
|
|
if (playerInfo?.Skill != skillName || Instance.GameRules == null) return;
|
|
|
|
var roundTime = SkillsInfo.GetValue<int>(skillName, "changeRoundTime");
|
|
Instance.GameRules.RoundTime += player.Team == CsTeam.Terrorist ? roundTime : -roundTime;
|
|
|
|
if (player.Team == CsTeam.Terrorist)
|
|
Localization.PrintTranslationToChatAll($" {ChatColors.Orange}{{0}}", ["watchmaker_tt"], [roundTime]);
|
|
else
|
|
Localization.PrintTranslationToChatAll($" {ChatColors.LightBlue}{{0}}", ["watchmaker_ct"], [roundTime]);
|
|
|
|
player.EmitSound(SkillsInfo.GetValue<string>(skillName, "SoundEvent"));
|
|
|
|
var proxy = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").FirstOrDefault();
|
|
if (proxy == null) return;
|
|
Utilities.SetStateChanged(proxy, "CCSGameRulesProxy", "m_pGameRules");
|
|
}
|
|
|
|
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#ff462e", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", int maxPerServer = 1, Rarity rarity = Rarity.Common, int changeRoundTime = 7, string soundEvent = "UIPanorama.sidemenu_select") : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, maxPerServer, rarity)
|
|
{
|
|
public int ChangeRoundTime { get; set; } = changeRoundTime;
|
|
public string SoundEvent { get; set; } = soundEvent;
|
|
}
|
|
}
|
|
} |