119 lines
No EOL
4.9 KiB
C#
119 lines
No EOL
4.9 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Entities.Constants;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using src.utils;
|
|
using System.Collections.Concurrent;
|
|
using static src.jRandomSkills;
|
|
|
|
namespace src.player.skills
|
|
{
|
|
public class HealingSmoke : ISkill
|
|
{
|
|
private const Skills skillName = Skills.HealingSmoke;
|
|
private static readonly ConcurrentDictionary<Vector, byte> smokes = [];
|
|
|
|
public static void LoadSkill()
|
|
{
|
|
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
|
}
|
|
|
|
public static void NewRound()
|
|
{
|
|
smokes.Clear();
|
|
}
|
|
|
|
public static void SmokegrenadeDetonate(EventSmokegrenadeDetonate @event)
|
|
{
|
|
var player = @event.Userid;
|
|
if (player == null || !player.IsValid) return;
|
|
|
|
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
|
if (playerInfo?.Skill != skillName) return;
|
|
|
|
smokes.TryAdd(new Vector(@event.X, @event.Y, @event.Z), 0);
|
|
}
|
|
|
|
public static void SmokegrenadeExpired(EventSmokegrenadeExpired @event)
|
|
{
|
|
var player = @event.Userid;
|
|
if (player == null || !player.IsValid) return;
|
|
|
|
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
|
if (playerInfo?.Skill != skillName) return;
|
|
|
|
foreach (var smoke in smokes.Keys.Where(v => v.X == @event.X && v.Y == @event.Y && v.Z == @event.Z))
|
|
smokes.TryRemove(smoke, out _);
|
|
}
|
|
|
|
public static void OnEntitySpawned(CEntityInstance entity)
|
|
{
|
|
var name = entity.DesignerName;
|
|
if (name != "smokegrenade_projectile") return;
|
|
|
|
var grenade = entity.As<CBaseCSGrenadeProjectile>();
|
|
if (grenade == null || !grenade.IsValid || grenade.OwnerEntity == null || !grenade.OwnerEntity.IsValid || 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>();
|
|
if (player == null || !player.IsValid) return;
|
|
|
|
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
|
if (playerInfo?.Skill != skillName) return;
|
|
|
|
Server.NextFrame(() =>
|
|
{
|
|
if (entity == null || !entity.IsValid) return;
|
|
var smoke = entity.As<CSmokeGrenadeProjectile>();
|
|
smoke.SmokeColor.X = 0;
|
|
smoke.SmokeColor.Y = 255;
|
|
smoke.SmokeColor.Z = 0;
|
|
});
|
|
}
|
|
|
|
public static void OnTick()
|
|
{
|
|
int tick = SkillsInfo.GetValue<int>(skillName, "tickCooldown");
|
|
if (Server.TickCount % tick != 0) return;
|
|
|
|
float smokeRadius = SkillsInfo.GetValue<float>(skillName, "smokeRadius");
|
|
int smokeHeal = SkillsInfo.GetValue<int>(skillName, "smokeHeal");
|
|
|
|
foreach (Vector smokePos in smokes.Keys)
|
|
foreach (var player in Utilities.GetPlayers().Where(p => p.IsValid && p.PawnIsAlive))
|
|
{
|
|
var pawn = player.PlayerPawn.Value;
|
|
if (pawn == null || !pawn.IsValid || pawn.AbsOrigin == null) continue;
|
|
|
|
if (SkillUtils.GetDistance(smokePos, pawn.AbsOrigin) <= smokeRadius)
|
|
AddHealth(pawn, smokeHeal);
|
|
}
|
|
}
|
|
|
|
public static void EnableSkill(CCSPlayerController player)
|
|
{
|
|
SkillUtils.TryGiveWeapon(player, CsItem.SmokeGrenade);
|
|
}
|
|
|
|
private static void AddHealth(CCSPlayerPawn player, int health)
|
|
{
|
|
if (player.LifeState != (byte)LifeState_t.LIFE_ALIVE)
|
|
return;
|
|
|
|
if (player.Health != player.MaxHealth)
|
|
player.EmitSound("Healthshot.Success");
|
|
|
|
player.Health = Math.Min(player.Health + health, player.MaxHealth);
|
|
Utilities.SetStateChanged(player, "CBaseEntity", "m_iHealth");
|
|
}
|
|
|
|
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#1fe070", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", int smokeHeal = 1, float smokeRadius = 180, int tickCooldown = 16) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission)
|
|
{
|
|
public int SmokeHeal { get; set; } = smokeHeal;
|
|
public float SmokeRadius { get; set; } = smokeRadius;
|
|
public int TickCooldown { get; set; } = tickCooldown;
|
|
}
|
|
}
|
|
} |