fighting crashes #1
This commit is contained in:
parent
10dbf6629e
commit
0fb3d63cd8
145 changed files with 677278 additions and 1703 deletions
|
|
@ -1,9 +1,8 @@
|
|||
using CounterStrikeSharp.API;
|
||||
using System.Collections.Concurrent;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using src.utils;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Immutable;
|
||||
using static src.jRandomSkills;
|
||||
|
||||
namespace src.player.skills
|
||||
|
|
@ -11,16 +10,22 @@ namespace src.player.skills
|
|||
public class RandomWeapon : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.RandomWeapon;
|
||||
private static readonly ConcurrentDictionary<ulong, PlayerSkillInfo> SkillPlayerInfo = [];
|
||||
private static readonly ConcurrentDictionary<ulong, PlayerSkillInfo> SkillPlayerInfo = new();
|
||||
private static readonly object setLock = new();
|
||||
|
||||
private static readonly string[] pistols = [ "weapon_deagle", "weapon_revolver", "weapon_glock", "weapon_usp_silencer",
|
||||
"weapon_cz75a", "weapon_fiveseven", "weapon_p250", "weapon_tec9", "weapon_elite", "weapon_hkp2000" ];
|
||||
private static readonly HashSet<string> pistols = new(StringComparer.Ordinal)
|
||||
{
|
||||
"weapon_deagle", "weapon_revolver", "weapon_glock", "weapon_usp_silencer",
|
||||
"weapon_cz75a", "weapon_fiveseven", "weapon_p250", "weapon_tec9", "weapon_elite", "weapon_hkp2000"
|
||||
};
|
||||
|
||||
private static readonly string[] rifles = [ "weapon_mp9", "weapon_mac10", "weapon_bizon", "weapon_mp7", "weapon_ump45", "weapon_p90",
|
||||
"weapon_mp5sd", "weapon_famas", "weapon_galilar", "weapon_m4a1", "weapon_m4a1_silencer", "weapon_ak47",
|
||||
"weapon_aug", "weapon_sg553", "weapon_ssg08", "weapon_awp", "weapon_scar20", "weapon_g3sg1",
|
||||
"weapon_nova", "weapon_xm1014", "weapon_mag7", "weapon_sawedoff", "weapon_m249", "weapon_negev" ];
|
||||
private static readonly HashSet<string> rifles = new(StringComparer.Ordinal)
|
||||
{
|
||||
"weapon_mp9", "weapon_mac10", "weapon_bizon", "weapon_mp7", "weapon_ump45", "weapon_p90",
|
||||
"weapon_mp5sd", "weapon_famas", "weapon_galilar", "weapon_m4a1", "weapon_m4a1_silencer", "weapon_ak47",
|
||||
"weapon_aug", "weapon_sg553", "weapon_ssg08", "weapon_awp", "weapon_scar20", "weapon_g3sg1",
|
||||
"weapon_nova", "weapon_xm1014", "weapon_mag7", "weapon_sawedoff", "weapon_m249", "weapon_negev"
|
||||
};
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
|
|
@ -35,12 +40,12 @@ namespace src.player.skills
|
|||
|
||||
public static void OnTick()
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
var players = Utilities.GetPlayers().ToArray();
|
||||
foreach (var player in players)
|
||||
{
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill == skillName)
|
||||
if (SkillPlayerInfo.TryGetValue(player.SteamID, out var skillInfo))
|
||||
UpdateHUD(player, skillInfo);
|
||||
if (playerInfo?.Skill == skillName && SkillPlayerInfo.TryGetValue(player.SteamID, out var skillInfo))
|
||||
UpdateHUD(player, skillInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +61,7 @@ namespace src.player.skills
|
|||
|
||||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
SkillPlayerInfo.TryRemove(player.SteamID, out _);
|
||||
SkillPlayerInfo.TryRemove(player.SteamID, out _);
|
||||
SkillUtils.ResetPrintHTML(player);
|
||||
}
|
||||
|
||||
|
|
@ -68,34 +73,34 @@ namespace src.player.skills
|
|||
float time = (int)Math.Ceiling((skillInfo.Cooldown.AddSeconds(SkillsInfo.GetValue<float>(skillName, "cooldown")) - DateTime.Now).TotalSeconds);
|
||||
cooldown = Math.Max(time, 0);
|
||||
|
||||
if (cooldown == 0 && skillInfo?.CanUse == false)
|
||||
if (cooldown == 0 && skillInfo.CanUse == false)
|
||||
skillInfo.CanUse = true;
|
||||
}
|
||||
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(s => s.SteamID == player?.SteamID);
|
||||
if (playerInfo == null) return;
|
||||
|
||||
if (cooldown == 0)
|
||||
playerInfo.PrintHTML = null;
|
||||
else
|
||||
playerInfo.PrintHTML = $"{player.GetTranslation("hud_info", $"<font color='#FF0000'>{cooldown}</font>")}";
|
||||
playerInfo.PrintHTML = cooldown == 0
|
||||
? null
|
||||
: $"{player.GetTranslation("hud_info", $"<font color='#FF0000'>{cooldown}</font>")}";
|
||||
}
|
||||
|
||||
public static void UseSkill(CCSPlayerController player)
|
||||
{
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
if (playerPawn?.CBodyComponent == null) return;
|
||||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn?.CBodyComponent == null) return;
|
||||
|
||||
if (SkillPlayerInfo.TryGetValue(player.SteamID, out var skillInfo))
|
||||
if (!SkillPlayerInfo.TryGetValue(player.SteamID, out var skillInfo)) return;
|
||||
if (!player.IsValid || !player.PawnIsAlive) return;
|
||||
|
||||
if (!skillInfo.CanUse)
|
||||
{
|
||||
if (!player.IsValid || !player.PawnIsAlive) return;
|
||||
if (skillInfo.CanUse)
|
||||
{
|
||||
skillInfo.CanUse = false;
|
||||
skillInfo.Cooldown = DateTime.Now;
|
||||
RemoveAndGiveWeapon(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
skillInfo.CanUse = false;
|
||||
skillInfo.Cooldown = DateTime.Now;
|
||||
RemoveAndGiveWeapon(player);
|
||||
}
|
||||
|
||||
private static void RemoveAndGiveWeapon(CCSPlayerController player)
|
||||
|
|
@ -103,41 +108,50 @@ namespace src.player.skills
|
|||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid || pawn.WeaponServices == null) return;
|
||||
|
||||
ConcurrentBag<string> playerWeapons = [];
|
||||
var playerWeapons = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var item in pawn.WeaponServices.MyWeapons)
|
||||
if (item != null && item.IsValid && item.Value != null && item.Value.IsValid && !string.IsNullOrEmpty(item.Value.DesignerName))
|
||||
playerWeapons.Add(item.Value.DesignerName);
|
||||
|
||||
if (playerWeapons.IsEmpty)
|
||||
if (playerWeapons.Count == 0)
|
||||
return;
|
||||
|
||||
ConcurrentBag<string> weaponList = [.. pistols.Concat(rifles).Where(w => !playerWeapons.Contains(w))];
|
||||
|
||||
if (weaponList.IsEmpty)
|
||||
var available = pistols.Concat(rifles).Where(w => !playerWeapons.Contains(w)).ToArray();
|
||||
if (available.Length == 0)
|
||||
return;
|
||||
|
||||
string weapon = weaponList.ToArray()[Instance.Random.Next(weaponList.Count)];
|
||||
bool isPistol = pistols.Contains(weapon);
|
||||
string newWeapon = available[Instance.Random.Next(available.Length)];
|
||||
bool isPistol = pistols.Contains(newWeapon);
|
||||
|
||||
string? weaponToRemove = playerWeapons.FirstOrDefault(itemName =>
|
||||
(isPistol && pistols.Contains(itemName)) || (!isPistol && rifles.Contains(itemName)));
|
||||
string? weaponToRemove = null;
|
||||
foreach (var item in pawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (item == null || !item.IsValid || item.Value == null || !item.Value.IsValid) continue;
|
||||
var name = item.Value.DesignerName;
|
||||
if (string.IsNullOrEmpty(name)) continue;
|
||||
if ((isPistol && pistols.Contains(name)) || (!isPistol && rifles.Contains(name)))
|
||||
{
|
||||
weaponToRemove = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(weaponToRemove))
|
||||
{
|
||||
foreach (var item in pawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (item != null && item.IsValid && item.Value != null && item.Value.IsValid && item.Value.DesignerName == weaponToRemove)
|
||||
item.Value.AcceptInput("Kill");
|
||||
if (item == null || !item.IsValid || item.Value == null || !item.Value.IsValid) continue;
|
||||
if (item.Value.DesignerName == weaponToRemove)
|
||||
SkillUtils.SafeKillEntity<CBasePlayerWeapon>((uint)item.Value.Index);
|
||||
}
|
||||
}
|
||||
|
||||
ulong steamId = player.SteamID;
|
||||
Instance.AddTimer(.1f, () =>
|
||||
{
|
||||
var player = Utilities.GetPlayerFromSteamId(steamId);
|
||||
if (player == null || !player.IsValid) return;
|
||||
|
||||
player.GiveNamedItem(weapon);
|
||||
var pl = Utilities.GetPlayerFromSteamId(steamId);
|
||||
if (pl == null || !pl.IsValid) return;
|
||||
pl.GiveNamedItem(newWeapon);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +162,7 @@ namespace src.player.skills
|
|||
public DateTime Cooldown { get; set; }
|
||||
}
|
||||
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#e0873a", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", float cooldown = 15f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission)
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#e0873a", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", int maxPerServer = -1, Rarity rarity = Rarity.Common, float cooldown = 15f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, maxPerServer, rarity)
|
||||
{
|
||||
public float Cooldown { get; set; } = cooldown;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue