This commit is contained in:
ByDexter 2026-07-30 01:15:32 +03:00
parent 0e86f54e0a
commit 98f6e65b01
98 changed files with 3391 additions and 397 deletions

View file

@ -15,6 +15,7 @@ namespace src.player.skills
private static readonly ConcurrentDictionary<uint, bool> lastShot = [];
private static readonly ConcurrentDictionary<uint, int> hitPlayer = [];
private static readonly ConcurrentDictionary<uint, uint> playersToTarget = [];
private static readonly ConcurrentDictionary<uint, uint> targetToPlayer = [];
private static readonly object setLock = new();
public static void LoadSkill()
@ -36,6 +37,7 @@ namespace src.player.skills
lastShot.Clear();
hitPlayer.Clear();
playersToTarget.Clear();
targetToPlayer.Clear();
}
}
@ -44,10 +46,11 @@ namespace src.player.skills
if (Server.TickCount % 32 != 0) return;
foreach (var player in PlayerManager.GetTickPlayers())
{
if (!SkillUtils.HasMenu(player)) continue;
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
if (playerInfo == null || playerInfo.Skill != skillName) continue;
if (!SkillUtils.HasMenu(player)) continue;
var enemies = PlayerManager.GetTickPlayers().Where(p => p != null && p.IsValid).Select(p => PlayerManager.GetPlayerEvent(p)).Where(p => p != null && p.IsValid && p.Team != player.Team && p.PlayerPawn?.Value != null && p.PlayerPawn.Value.IsValid && p.PlayerPawn.Value.Health > 0 && !p.IsHLTV && p.Team != CsTeam.Spectator && p.Team != CsTeam.None).ToArray();
ConcurrentBag<(string, string)> menuItems = [.. enemies.Select(e => (e.PlayerName, e.Index.ToString()))];
@ -88,6 +91,7 @@ namespace src.player.skills
targetPlayers.TryAdd(enemy.Index, 0);
playersToTarget[player.Index] = enemy.Index;
targetToPlayer[enemy.Index] = player.Index;
playerInfo.SkillUsed = true;
var enemyEvent = PlayerManager.GetPlayerFromEvent(enemy);
@ -131,13 +135,14 @@ namespace src.player.skills
return;
uint playerIndex = player.Index;
int impactTick = Server.TickCount;
Server.NextFrame(() =>
{
if (player == null || !player.IsValid) return;
if (playerPawn == null || !playerPawn.IsValid) return;
bool ishitPlayer = hitPlayer.TryGetValue(playerIndex, out int tick) && tick + 10 >= Server.TickCount;
bool ishitPlayer = hitPlayer.TryGetValue(playerIndex, out int tick) && tick + 1 >= impactTick;
if (!lastShot.ContainsKey(playerIndex))
{
@ -148,7 +153,8 @@ namespace src.player.skills
if (lastShot.TryRemove(playerIndex, out bool didHit) && !didHit)
{
eventPlayer.ExecuteClientCommand($"play player/player_damagebody_0{Instance.Random.Next(4, 8)}");
SkillUtils.TakeHealth(playerPawn, SkillsInfo.GetValue<int>(skillName, "damageAfterMiss"));
SkillUtils.TakeHealth(playerPawn, SkillsInfo.GetValue<int>(skillName, "damageAfterMiss"), GetSkillOwner(playerIndex), "planted_c4");
}
lastShot.TryRemove(playerIndex, out _);
});
@ -158,6 +164,14 @@ namespace src.player.skills
});
}
private static CCSPlayerController? GetSkillOwner(uint targetIndex)
{
if (!targetToPlayer.TryGetValue(targetIndex, out uint ownerIndex)) return null;
var owner = Utilities.GetPlayerFromIndex((int)ownerIndex);
return owner != null && owner.IsValid ? owner : null;
}
public static void OnTakeDamage(DynamicHook h)
{
CEntityInstance param = h.GetParam<CEntityInstance>(0);
@ -188,12 +202,14 @@ namespace src.player.skills
targetPlayers.TryRemove(player.Index, out _);
lastShot.TryRemove(player.Index, out _);
hitPlayer.TryRemove(player.Index, out _);
targetToPlayer.TryRemove(player.Index, out _);
if (playersToTarget.TryRemove(player.Index, out uint targetIndex))
{
targetPlayers.TryRemove(targetIndex, out _);
lastShot.TryRemove(targetIndex, out _);
hitPlayer.TryRemove(targetIndex, out _);
targetToPlayer.TryRemove(targetIndex, out _);
var target = PlayerManager.GetPlayerFromEvent(Utilities.GetPlayerFromIndex((int)targetIndex));
if (target != null && target.IsValid && target.PawnIsAlive && !SkillUtils.IsFreezeTime())
@ -212,6 +228,8 @@ namespace src.player.skills
lastShot.TryRemove(player.Index, out _);
hitPlayer.TryRemove(player.Index, out _);
targetToPlayer.TryRemove(player.Index, out _);
SkillUtils.CloseMenu(player);
}
@ -220,4 +238,4 @@ namespace src.player.skills
public int DamageAfterMiss { get; set; } = damageAfterMiss;
}
}
}
}