From 443e1eb7134e1c436e0fd263f263041ddfc24eb4 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 23 Apr 2024 21:19:26 +0200 Subject: [PATCH] bug fixes + how to message for command allocator --- .../CommandAllocator/CommandAllocator.cs | 23 +++++++++- .../Configs/CommandAllocatorConfig.cs | 5 ++- CS2Retake/CS2Retake.cs | 11 +++-- CS2Retake/CS2Retake.csproj | 2 +- CS2Retake/Managers/Interfaces/ITeamManager.cs | 2 + CS2Retake/Managers/TeamManager.cs | 43 ++++++++++++++++++- CS2Retake/Managers/WeaponManager.cs | 2 +- 7 files changed, 80 insertions(+), 8 deletions(-) diff --git a/CS2Retake/Allocators/Implementations/CommandAllocator/CommandAllocator.cs b/CS2Retake/Allocators/Implementations/CommandAllocator/CommandAllocator.cs index f3e7c4a..0faef82 100644 --- a/CS2Retake/Allocators/Implementations/CommandAllocator/CommandAllocator.cs +++ b/CS2Retake/Allocators/Implementations/CommandAllocator/CommandAllocator.cs @@ -14,10 +14,12 @@ using CS2Retake.Allocators.Implementations.CommandAllocator.Manager; using CounterStrikeSharp.API.Modules.Utils; using CS2Retake.Allocators.Implementations.CommandAllocator.Entities; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Modules.Timers; namespace CS2Retake.Allocators.Implementations.CommandAllocator { - public class CommandAllocator : BaseGrenadeAllocator, IAllocatorConfig + public class CommandAllocator : BaseGrenadeAllocator, IAllocatorConfig, IDisposable { public CommandAllocatorConfig Config { get; set; } = new CommandAllocatorConfig(); @@ -27,6 +29,8 @@ public class CommandAllocator : BaseGrenadeAllocator, IAllocatorConfig this.OnPlayerConnected(x)); + + + if(this.Config.HowToMessageDelayInMinutes > 0) + { + this._howToTimer = new CounterStrikeSharp.API.Modules.Timers.Timer(this.Config.HowToMessageDelayInMinutes * 60, PrintHowToMessage, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT); + } + } public override void OnGunsCommand(CCSPlayerController? player) @@ -289,5 +300,15 @@ public override void ResetForNextRound(bool completeReset = true) this._awpInUseCountCT = 0; this._awpInUseCountT = 0; } + + private void PrintHowToMessage() + { + Server.PrintToChatAll($"[{ChatColors.Gold}CommandAllocator{ChatColors.White}] {this.Config.HowToMessage}"); + } + + public void Dispose() + { + this._howToTimer?.Kill(); + } } } diff --git a/CS2Retake/Allocators/Implementations/CommandAllocator/Configs/CommandAllocatorConfig.cs b/CS2Retake/Allocators/Implementations/CommandAllocator/Configs/CommandAllocatorConfig.cs index c1bf3f5..7344902 100644 --- a/CS2Retake/Allocators/Implementations/CommandAllocator/Configs/CommandAllocatorConfig.cs +++ b/CS2Retake/Allocators/Implementations/CommandAllocator/Configs/CommandAllocatorConfig.cs @@ -23,9 +23,12 @@ public class CommandAllocatorConfig : BaseAllocatorConfig public DBType DatabaseType { get; set; } = DBType.SQLite; + public float HowToMessageDelayInMinutes { get; set; } = 3.5f; + public string HowToMessage { get; set; } = $"Customize your weapons by using !guns"; + public CommandAllocatorConfig() { - this.Version = 2; + this.Version = 3; } } } diff --git a/CS2Retake/CS2Retake.cs b/CS2Retake/CS2Retake.cs index e7ef143..d0555aa 100644 --- a/CS2Retake/CS2Retake.cs +++ b/CS2Retake/CS2Retake.cs @@ -1,4 +1,4 @@ -using CounterStrikeSharp.API; +using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; using CounterStrikeSharp.API.Core.Attributes.Registration; @@ -20,7 +20,7 @@ namespace CS2Retake public class CS2Retake : BasePlugin, IPluginConfig { public override string ModuleName => "CS2Retake"; - public override string ModuleVersion => "2.1.0"; + public override string ModuleVersion => "2.1.1"; public override string ModuleAuthor => "LordFetznschaedl"; public override string ModuleDescription => "Highly configurable and modular implementation Retake for CS2"; @@ -316,6 +316,7 @@ private HookResult OnRoundFreezeEnd(EventRoundFreezeEnd @event, GameEventInfo in if(!GameRuleManager.Instance.IsWarmup && (ratios.ctRatio != PlayerUtils.GetCounterTerroristPlayers().Count || ratios.tRatio != PlayerUtils.GetTerroristPlayers().Count)) { MessageUtils.PrintToChatAll($"Player ratios not matching how they should be. Resetting..."); + TeamManager.Instance.FixTeams(); PlayerUtils.SuicideAll(); return HookResult.Continue; } @@ -375,7 +376,11 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) var ratio = TeamManager.Instance.LatestRatio; - MessageUtils.PrintToChatAll($"Bombsite: {ChatColors.DarkRed}{MapManager.Instance.BombSite}{ChatColors.White} - Roundtype: {ChatColors.DarkRed}{RoundTypeManager.Instance.RoundType}{ChatColors.White} - {ChatColors.Blue}{ratio.ctRatio}CTs{ChatColors.White} VS {ChatColors.Red}{ratio.tRatio}Ts{ChatColors.White}"); + MessageUtils.PrintToChatAll($"================================"); + MessageUtils.PrintToChatAll($"{ChatColors.Blue}{ratio.ctRatio}CTs{ChatColors.White} VS {ChatColors.Red}{ratio.tRatio}Ts{ChatColors.White}"); + MessageUtils.PrintToChatAll($"Roundtype: {ChatColors.DarkRed}{RoundTypeManager.Instance.RoundType}{ChatColors.White}"); + MessageUtils.PrintToChatAll($"Bombsite: {ChatColors.DarkRed}{MapManager.Instance.BombSite}{ChatColors.White}"); + MessageUtils.PrintToChatAll($"================================"); return HookResult.Continue; } diff --git a/CS2Retake/CS2Retake.csproj b/CS2Retake/CS2Retake.csproj index dc60156..274f1aa 100644 --- a/CS2Retake/CS2Retake.csproj +++ b/CS2Retake/CS2Retake.csproj @@ -5,7 +5,7 @@ enable enable true - 2.1.0 + 2.1.1 diff --git a/CS2Retake/Managers/Interfaces/ITeamManager.cs b/CS2Retake/Managers/Interfaces/ITeamManager.cs index 1be8caa..6a0dbba 100644 --- a/CS2Retake/Managers/Interfaces/ITeamManager.cs +++ b/CS2Retake/Managers/Interfaces/ITeamManager.cs @@ -15,6 +15,8 @@ public interface ITeamManager public void AddQueuePlayers(); public void SwitchTeams(); + public void FixTeams(); + public void OnTick(); diff --git a/CS2Retake/Managers/TeamManager.cs b/CS2Retake/Managers/TeamManager.cs index a611654..b809dd6 100644 --- a/CS2Retake/Managers/TeamManager.cs +++ b/CS2Retake/Managers/TeamManager.cs @@ -38,7 +38,6 @@ public static TeamManager Instance private TeamManager() { } - //TODO FIX: AddQueuePlayers does not rebalance properly public void AddQueuePlayers() { MessageUtils.LogDebug($"Methode: AddQueuePlayers"); @@ -165,6 +164,48 @@ public void SwitchTeams() queuedPlayers.ForEach(x => x.SwitchTeam(CsTeam.CounterTerrorist)); } + public void FixTeams() + { + MessageUtils.LogDebug($"Methode: FixTeams"); + + var playingPlayers = this.GetPlayingPlayers(); + + var playingCounterTerroristPlayers = playingPlayers.Where(x => x.TeamNum == (int)CsTeam.CounterTerrorist).Where(x => x.UserId.HasValue).Select(x => x.UserId).ToList(); + var playingTerroristPlayers = playingPlayers.Where(x => x.TeamNum == (int)CsTeam.Terrorist).Where(x => x.UserId.HasValue).Select(x => x.UserId).ToList(); + + foreach(var ct in PlayerUtils.GetCounterTerroristPlayers()) + { + if(!ct.UserId.HasValue) + { + continue; + } + + if(playingCounterTerroristPlayers.Contains(ct.UserId.Value)) + { + continue; + } + + this.UpdatePlayerStateDict(ct.UserId.Value, PlayerStateEnum.Playing); + } + + foreach(var t in PlayerUtils.GetTerroristPlayers()) + { + if (!t.UserId.HasValue) + { + continue; + } + + if (playingTerroristPlayers.Contains(t.UserId.Value)) + { + continue; + } + + this.UpdatePlayerStateDict(t.UserId.Value, PlayerStateEnum.Playing); + } + + this.ScrambleTeams(); + } + public void OnTick() { if(GameRuleManager.Instance.IsWarmup) diff --git a/CS2Retake/Managers/WeaponManager.cs b/CS2Retake/Managers/WeaponManager.cs index f2b8f8a..5b80ec8 100644 --- a/CS2Retake/Managers/WeaponManager.cs +++ b/CS2Retake/Managers/WeaponManager.cs @@ -297,7 +297,7 @@ public override void ResetForNextRound(bool completeReset = true) } RoundTypeManager.Instance.HandleRoundType(); - //this._allocator?.ResetForNextRound(); + this._allocator?.ResetForNextRound(); }