v1.2.2.b1
This commit is contained in:
parent
0fb3d63cd8
commit
46195c2663
147 changed files with 3470 additions and 2161 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
|
|
@ -11,9 +11,10 @@ namespace src.player.skills
|
|||
public class CarefulBullets : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.CarefulBullets;
|
||||
private static readonly ConcurrentDictionary<ulong, byte> targetPlayers = [];
|
||||
private static readonly ConcurrentDictionary<ulong, bool> lastShot = [];
|
||||
private static readonly ConcurrentDictionary<ulong, int> hitPlayer = [];
|
||||
private static readonly ConcurrentDictionary<uint, byte> targetPlayers = [];
|
||||
private static readonly ConcurrentDictionary<uint, bool> lastShot = [];
|
||||
private static readonly ConcurrentDictionary<uint, int> hitPlayer = [];
|
||||
private static readonly ConcurrentDictionary<uint, uint> playersToTarget = [];
|
||||
private static readonly object setLock = new();
|
||||
|
||||
public static void LoadSkill()
|
||||
|
|
@ -25,22 +26,17 @@ namespace src.player.skills
|
|||
{
|
||||
lock (setLock)
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
DisableSkill(player);
|
||||
SkillUtils.CloseMenu(player);
|
||||
}
|
||||
|
||||
targetPlayers.Clear();
|
||||
lastShot.Clear();
|
||||
hitPlayer.Clear();
|
||||
playersToTarget.Clear();
|
||||
}
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
DisableSkill(player);
|
||||
SkillUtils.CloseMenu(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlayerDeath(EventPlayerDeath @event)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (player == null) return;
|
||||
DisableSkill(player);
|
||||
}
|
||||
|
||||
public static void OnTick()
|
||||
|
|
@ -49,10 +45,10 @@ namespace src.player.skills
|
|||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
if (!SkillUtils.HasMenu(player)) continue;
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
||||
|
||||
if (playerInfo == null || playerInfo.Skill != skillName) continue;
|
||||
var enemies = Utilities.GetPlayers().Where(p => p.PawnIsAlive && p.Team != player.Team && p.IsValid && !p.IsBot && !p.IsHLTV && p.Team != CsTeam.Spectator && p.Team != CsTeam.None).ToArray();
|
||||
var enemies = Utilities.GetPlayers().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()))];
|
||||
SkillUtils.UpdateMenu(player, menuItems);
|
||||
|
|
@ -61,8 +57,8 @@ namespace src.player.skills
|
|||
|
||||
public static void TypeSkill(CCSPlayerController player, string[] commands)
|
||||
{
|
||||
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (player == null || !player.IsValid || player.LifeState != (byte)LifeState_t.LIFE_ALIVE) return;
|
||||
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
||||
if (playerInfo?.Skill != skillName) return;
|
||||
|
||||
if (playerInfo.SkillUsed)
|
||||
|
|
@ -72,7 +68,8 @@ namespace src.player.skills
|
|||
}
|
||||
|
||||
string enemyId = commands[0];
|
||||
var enemy = Utilities.GetPlayers().FirstOrDefault(p => p.Team != player.Team && p.Index.ToString() == enemyId);
|
||||
if (!uint.TryParse(enemyId, out uint enemyIndex)) { player.PrintToChat($" {ChatColors.Red}" + player.GetTranslation("selectplayerskill_incorrect_enemy_index")); return; }
|
||||
var enemy = Utilities.GetPlayerFromIndex((int)enemyIndex);
|
||||
|
||||
if (enemy == null)
|
||||
{
|
||||
|
|
@ -80,19 +77,21 @@ namespace src.player.skills
|
|||
return;
|
||||
}
|
||||
|
||||
targetPlayers.TryAdd(enemy.SteamID, 0);
|
||||
targetPlayers.TryAdd(enemy.Index, 0);
|
||||
playersToTarget[player.Index] = enemy.Index;
|
||||
playerInfo.SkillUsed = true;
|
||||
|
||||
player.PrintToChat($" {ChatColors.Green}" + player.GetTranslation("carefulbullets_player_info", enemy.PlayerName));
|
||||
enemy.PrintToChat($" {ChatColors.Red}" + enemy.GetTranslation("carefulbullets_enemy_info"));
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
||||
if (playerInfo == null) return;
|
||||
playerInfo.SkillUsed = false;
|
||||
|
||||
var enemies = Utilities.GetPlayers().Where(p => p.PawnIsAlive && p.Team != player.Team && p.IsValid && !p.IsBot && !p.IsHLTV && p.Team != CsTeam.Spectator && p.Team != CsTeam.None).ToArray();
|
||||
var enemies = Utilities.GetPlayers().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();
|
||||
if (enemies.Length > 0)
|
||||
{
|
||||
ConcurrentBag<(string, string)> menuItems = [.. enemies.Select(e => (e.PlayerName, e.Index.ToString()))];
|
||||
|
|
@ -104,37 +103,37 @@ namespace src.player.skills
|
|||
|
||||
public static void BulletImpact(EventBulletImpact @event)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
var player = PlayerManager.GetPlayerEvent(@event.Userid);
|
||||
if (player == null || !player.IsValid) return;
|
||||
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
if (playerPawn == null || !playerPawn.IsValid) return;
|
||||
|
||||
if (!targetPlayers.ContainsKey(player.SteamID) || !player.PawnIsAlive)
|
||||
if (!targetPlayers.ContainsKey(player.Index) || player.LifeState != (byte)LifeState_t.LIFE_ALIVE)
|
||||
return;
|
||||
|
||||
ulong steamID = player.SteamID;
|
||||
uint playerIndex = player.Index;
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (playerPawn == null || !playerPawn.IsValid) return;
|
||||
|
||||
bool ishitPlayer = hitPlayer.TryGetValue(steamID, out int tick) && tick + 10 >= Server.TickCount;
|
||||
bool ishitPlayer = hitPlayer.TryGetValue(playerIndex, out int tick) && tick + 10 >= Server.TickCount;
|
||||
|
||||
if (!lastShot.ContainsKey(steamID))
|
||||
if (!lastShot.ContainsKey(playerIndex))
|
||||
{
|
||||
lastShot.TryAdd(steamID, ishitPlayer);
|
||||
lastShot.TryAdd(playerIndex, ishitPlayer);
|
||||
|
||||
Instance.AddTickTimer(1, () =>
|
||||
{
|
||||
if (lastShot.TryRemove(steamID, out bool didHit) && !didHit)
|
||||
if (lastShot.TryRemove(playerIndex, out bool didHit) && !didHit)
|
||||
SkillUtils.TakeHealth(playerPawn, SkillsInfo.GetValue<int>(skillName, "damageAfterMiss"));
|
||||
lastShot.TryRemove(steamID, out _);
|
||||
lastShot.TryRemove(playerIndex, out _);
|
||||
});
|
||||
}
|
||||
else if (ishitPlayer)
|
||||
lastShot.TryUpdate(steamID, true, false);
|
||||
lastShot.TryUpdate(playerIndex, true, false);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -155,17 +154,37 @@ namespace src.player.skills
|
|||
if (attackerPawn == null || attackerPawn.Controller?.Value == null || victimPawn == null || victimPawn.Controller?.Value == null)
|
||||
return;
|
||||
|
||||
CCSPlayerController attacker = attackerPawn.Controller.Value.As<CCSPlayerController>();
|
||||
if (!targetPlayers.ContainsKey(attacker.SteamID)) return;
|
||||
CCSPlayerController attacker = PlayerManager.GetPlayerEvent(attackerPawn.Controller.Value.As<CCSPlayerController>())!;
|
||||
if (!targetPlayers.ContainsKey(attacker.Index)) return;
|
||||
|
||||
hitPlayer.AddOrUpdate(attacker.SteamID, Server.TickCount, (_, _) => Server.TickCount);
|
||||
hitPlayer.AddOrUpdate(attacker.Index, Server.TickCount, (_, _) => Server.TickCount);
|
||||
}
|
||||
|
||||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
targetPlayers.TryRemove(player.SteamID, out _);
|
||||
lastShot.TryRemove(player.SteamID, out _);
|
||||
hitPlayer.TryRemove(player.SteamID, out _);
|
||||
targetPlayers.TryRemove(player.Index, out _);
|
||||
lastShot.TryRemove(player.Index, out _);
|
||||
hitPlayer.TryRemove(player.Index, out _);
|
||||
|
||||
if (playersToTarget.TryRemove(player.Index, out uint targetIndex))
|
||||
{
|
||||
targetPlayers.TryRemove(targetIndex, out _);
|
||||
lastShot.TryRemove(targetIndex, out _);
|
||||
hitPlayer.TryRemove(targetIndex, out _);
|
||||
}
|
||||
|
||||
SkillUtils.CloseMenu(player);
|
||||
}
|
||||
|
||||
public static void PlayerDeath(EventPlayerDeath @event)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (player == null || !player.IsValid) return;
|
||||
|
||||
targetPlayers.TryRemove(player.Index, out _);
|
||||
lastShot.TryRemove(player.Index, out _);
|
||||
hitPlayer.TryRemove(player.Index, out _);
|
||||
|
||||
SkillUtils.CloseMenu(player);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue