From 4eb0b432e4d3c6524a4047c19380235d4567fa32 Mon Sep 17 00:00:00 2001 From: abnerfs Date: Sat, 16 Mar 2024 23:06:20 -0300 Subject: [PATCH] DelayToChangeInTheEnd config and fix vote trigger when mp_match_can_clinch is 0 --- Config.cs | 1 + Core/ChangeMapManager.cs | 13 +++++++++++-- Core/MaxRoundsManager.cs | 8 ++++---- Core/TimeLimitManager.cs | 2 +- Features/EndOfMapVote.cs | 10 ++++++++-- Plugin.cs | 2 +- README.md | 1 + 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Config.cs b/Config.cs index 5e06bb3..c4f31a2 100644 --- a/Config.cs +++ b/Config.cs @@ -36,6 +36,7 @@ public class EndOfMapConfig : IEndOfMapConfig public bool HideHudAfterVote { get; set; } = false; public int TriggerSecondsBeforeEnd { get; set; } = 120; public int TriggerRoundsBeforEnd { get; set; } = 2; + public float DelayToChangeInTheEnd { get; set; } = 6F; } public class RtvConfig : ICommandConfig, IVoteConfig, IEndOfMapConfig diff --git a/Core/ChangeMapManager.cs b/Core/ChangeMapManager.cs index 4c114c0..75ab03e 100644 --- a/Core/ChangeMapManager.cs +++ b/Core/ChangeMapManager.cs @@ -35,7 +35,7 @@ public class ChangeMapManager : IPluginDependency private bool _mapEnd = false; private Map[] _maps = new Map[0]; - + private Config _config; public ChangeMapManager(StringLocalizer localizer, PluginState pluginState, MapLister mapLister) { @@ -92,6 +92,11 @@ public bool ChangeNextMap(bool mapEnd = false) return true; } + public void OnConfigParsed(Config config) + { + _config = config; + } + public void OnLoad(Plugin plugin) { _plugin = plugin; @@ -99,7 +104,11 @@ public void OnLoad(Plugin plugin) { if (_pluginState.MapChangeScheduled) { - _plugin.AddTimer(3.0F, () => + var delay = _config.EndOfMapVote.DelayToChangeInTheEnd - 3.0F; //subtracting the delay that is going to be applied by ChangeNextMap function anyway + if (delay < 0) + delay = 0; + + _plugin.AddTimer(delay, () => { ChangeNextMap(true); }); diff --git a/Core/MaxRoundsManager.cs b/Core/MaxRoundsManager.cs index 281c1f1..5c0687a 100644 --- a/Core/MaxRoundsManager.cs +++ b/Core/MaxRoundsManager.cs @@ -13,9 +13,9 @@ public class MaxRoundsManager : IPluginDependency private GameRules _gameRules; private ConVar? _maxRounds; - private ConVar? _halfTime; + private ConVar? _canClinch; private int MaxRoundsValue => _maxRounds?.GetPrimitiveValue() ?? 0; - private bool HalfTime => _halfTime?.GetPrimitiveValue() ?? true; + public bool CanClinch => _canClinch?.GetPrimitiveValue() ?? true; public bool UnlimitedRounds => MaxRoundsValue <= 0; private bool _lastBeforeHalf = false; @@ -46,7 +46,7 @@ public int MaxWins if (MaxRoundsValue <= 0) return 0; - if (!HalfTime) + if (!CanClinch) return MaxRoundsValue; return ((int)Math.Floor(MaxRoundsValue / 2M)) + 1; @@ -63,7 +63,7 @@ public MaxRoundsManager(GameRules gameRules) void LoadCvar() { _maxRounds = ConVar.Find("mp_maxrounds"); - _halfTime = ConVar.Find("mp_halftime"); + _canClinch = ConVar.Find("mp_match_can_clinch"); } diff --git a/Core/TimeLimitManager.cs b/Core/TimeLimitManager.cs index 67da6cb..aeb2712 100644 --- a/Core/TimeLimitManager.cs +++ b/Core/TimeLimitManager.cs @@ -9,7 +9,7 @@ public class TimeLimitManager : IPluginDependency private ConVar? _timeLimit; - private decimal TimeLimitValue => (decimal)_timeLimit!.GetPrimitiveValue() * 60M; + private decimal TimeLimitValue => (decimal)(_timeLimit?.GetPrimitiveValue() ?? 0F) * 60M; public bool UnlimitedTime => TimeLimitValue <= 0; diff --git a/Features/EndOfMapVote.cs b/Features/EndOfMapVote.cs index efb09f2..e7ba403 100644 --- a/Features/EndOfMapVote.cs +++ b/Features/EndOfMapVote.cs @@ -31,8 +31,14 @@ public EndOfMapVote(TimeLimitManager timeLimit, MaxRoundsManager maxRounds, Plug bool CheckMaxRounds() { - //Server.PrintToChatAll($"Remaining rounds {_maxRounds.RemainingRounds}, Remaining wins {_maxRounds.RemainingWins}"); - return !_maxRounds.UnlimitedRounds && (_maxRounds.RemainingRounds <= 2 || _maxRounds.RemainingWins <= _config.TriggerRoundsBeforEnd); + Server.PrintToChatAll($"Remaining rounds {_maxRounds.RemainingRounds}, remaining wins: {_maxRounds.RemainingWins}, triggerBefore {_config.TriggerRoundsBeforEnd}"); + if (_maxRounds.UnlimitedRounds) + return false; + + if (_maxRounds.RemainingRounds <= _config.TriggerRoundsBeforEnd) + return true; + + return _maxRounds.CanClinch && _maxRounds.RemainingWins <= _config.TriggerRoundsBeforEnd; } diff --git a/Plugin.cs b/Plugin.cs index a5f5762..564487b 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -21,7 +21,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) public partial class Plugin : BasePlugin, IPluginConfig { public override string ModuleName => "RockTheVote"; - public override string ModuleVersion => "1.8.0"; + public override string ModuleVersion => "1.8.1"; public override string ModuleAuthor => "abnerfs"; public override string ModuleDescription => "General purpose map voting plugin"; diff --git a/README.md b/README.md index 29c1502..a7acc15 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Based on mp_timelimit and mp_maxrounds cvar before the map ends a RTV like vote | HudMenu | Whether to use HudMenu or just the chat one, when false the hud only shows which map is winning instead of actual menu | true | false | true | | TriggerSecondsBeforeEnd | Amount of seconds before end of the map that should trigger the vote, only used when mp_timelimit is greater than 0 | 120 | 1 | | | TriggerRoundsBeforEnd | Amount of rounds before end of map that should trigger the vote, only used when mp_maxrounds is set | 2 | 1 | | +| DelayToChangeInTheEnd | Delay in seconds that plugin will take to change the map after the win panel is shown to the players | 6 | 3 | | ## Votemap Players can vote to change to an specific map by using the votemap command