v.1.1.7
This commit is contained in:
parent
a36fdbf92d
commit
04a4fdce0d
143 changed files with 3565 additions and 2344 deletions
|
|
@ -4,31 +4,35 @@ using CounterStrikeSharp.API.Modules.Utils;
|
|||
using jRandomSkills.src.player;
|
||||
using jRandomSkills.src.utils;
|
||||
using static jRandomSkills.jRandomSkills;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace jRandomSkills
|
||||
{
|
||||
public class Darkness : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.Darkness;
|
||||
private static readonly float brightness = Config.GetValue<float>(skillName, "brightness");
|
||||
private static readonly Dictionary<CCSPlayerController, List<CPostProcessingVolume>> defaultPostProcessings = [];
|
||||
private static readonly List<CPostProcessingVolume> newPostProcessing = [];
|
||||
private static readonly ConcurrentDictionary<CCSPlayerController, List<CPostProcessingVolume>> defaultPostProcessings = [];
|
||||
private static readonly ConcurrentBag<CPostProcessingVolume> newPostProcessing = [];
|
||||
private static readonly object setLock = new();
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"));
|
||||
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
||||
}
|
||||
|
||||
public static void NewRound()
|
||||
{
|
||||
foreach (var player in defaultPostProcessings.Keys)
|
||||
DisableSkill(player);
|
||||
foreach (var postProcessing in newPostProcessing)
|
||||
if (postProcessing != null && postProcessing.IsValid)
|
||||
postProcessing.AcceptInput("Kill");
|
||||
newPostProcessing.Clear();
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
SkillUtils.CloseMenu(player);
|
||||
lock (setLock)
|
||||
{
|
||||
foreach (var player in defaultPostProcessings.Keys)
|
||||
DisableSkill(player);
|
||||
foreach (var postProcessing in newPostProcessing)
|
||||
if (postProcessing != null && postProcessing.IsValid)
|
||||
postProcessing.AcceptInput("Kill");
|
||||
newPostProcessing.Clear();
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
SkillUtils.CloseMenu(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlayerDeath(EventPlayerDeath @event)
|
||||
|
|
@ -49,7 +53,7 @@ namespace jRandomSkills
|
|||
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();
|
||||
|
||||
HashSet<(string, string)> menuItems = enemies.Select(e => (e.PlayerName, e.Index.ToString())).ToHashSet();
|
||||
ConcurrentBag<(string, string)> menuItems = new(enemies.Select(e => (e.PlayerName, e.Index.ToString())));
|
||||
SkillUtils.UpdateMenu(player, menuItems);
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +94,7 @@ namespace jRandomSkills
|
|||
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();
|
||||
if (enemies.Length > 0)
|
||||
{
|
||||
HashSet<(string, string)> menuItems = enemies.Select(e => (e.PlayerName, e.Index.ToString())).ToHashSet();
|
||||
ConcurrentBag<(string, string)> menuItems = new(enemies.Select(e => (e.PlayerName, e.Index.ToString())));
|
||||
SkillUtils.CreateMenu(player, menuItems);
|
||||
}
|
||||
else
|
||||
|
|
@ -99,8 +103,11 @@ namespace jRandomSkills
|
|||
|
||||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
SetUpPostProcessing(player, true);
|
||||
SkillUtils.CloseMenu(player);
|
||||
lock (setLock)
|
||||
{
|
||||
SetUpPostProcessing(player, true);
|
||||
SkillUtils.CloseMenu(player);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetUpPostProcessing(CCSPlayerController player, bool dontCreateNew = false)
|
||||
|
|
@ -109,8 +116,8 @@ namespace jRandomSkills
|
|||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid || pawn.CameraServices == null) return;
|
||||
|
||||
if (!defaultPostProcessings.TryGetValue(player, out _))
|
||||
defaultPostProcessings[player] = [];
|
||||
if (!defaultPostProcessings.ContainsKey(player))
|
||||
defaultPostProcessings.TryAdd(player, []);
|
||||
|
||||
int i = 0;
|
||||
foreach (var postProcessingVolume in pawn.CameraServices.PostProcessingVolumes)
|
||||
|
|
@ -120,16 +127,18 @@ namespace jRandomSkills
|
|||
|
||||
if (dontCreateNew)
|
||||
{
|
||||
if (i < defaultPostProcessings[player].Count)
|
||||
postProcessingVolume.Raw = defaultPostProcessings[player][i].EntityHandle.Raw;
|
||||
if (defaultPostProcessings.TryGetValue(player, out var defaultList) && i < defaultList.Count)
|
||||
postProcessingVolume.Raw = defaultList[i].EntityHandle.Raw;
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultPostProcessings[player].Add(postProcessingVolume.Value);
|
||||
if (defaultPostProcessings.TryGetValue(player, out var defaultList))
|
||||
defaultList.Add(postProcessingVolume.Value);
|
||||
|
||||
var postProcessing = Utilities.CreateEntityByName<CPostProcessingVolume>("post_processing_volume");
|
||||
if (postProcessing == null) return;
|
||||
|
||||
var brightness = SkillsInfo.GetValue<float>(skillName, "brightness");
|
||||
postProcessing.ExposureControl = true;
|
||||
postProcessing.MaxExposure = brightness;
|
||||
postProcessing.MinExposure = brightness;
|
||||
|
|
@ -142,10 +151,10 @@ namespace jRandomSkills
|
|||
|
||||
Utilities.SetStateChanged(pawn, "CBasePlayerPawn", "m_pCameraServices");
|
||||
if (dontCreateNew)
|
||||
defaultPostProcessings.Remove(player);
|
||||
defaultPostProcessings.TryRemove(player, out _);
|
||||
}
|
||||
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#383838", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float brightness = .01f) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#383838", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, float brightness = .01f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates)
|
||||
{
|
||||
public float Brightness { get; set; } = brightness;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue