From 0fe8c895f6f40c7855abddabf580938754f0c6ca Mon Sep 17 00:00:00 2001 From: faketuna Date: Fri, 19 Sep 2025 20:44:18 +0900 Subject: [PATCH 1/2] add: implement map time config execution feature --- .../Modules/MapCycle/McsMapCycleController.cs | 55 +++++++++++++++++++ docs/en/configuration/MAP_CONFIG.md | 4 -- docs/ja/configuration/MAP_CONFIG.md | 4 -- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/MapChooserSharp/Modules/MapCycle/McsMapCycleController.cs b/MapChooserSharp/Modules/MapCycle/McsMapCycleController.cs index 31c9d98..ea470bf 100644 --- a/MapChooserSharp/Modules/MapCycle/McsMapCycleController.cs +++ b/MapChooserSharp/Modules/MapCycle/McsMapCycleController.cs @@ -270,6 +270,7 @@ private void OnMapStart(string mapName) CurrentMap = NextMap; NextMap = null; + Server.NextFrame(ExecuteMapLimitConfig); // Wait for first people joined // TODO() Maybe we can use Server.NextWorldUpdate() to execute things? @@ -468,6 +469,60 @@ private Func GetCorrespondTimelimitCheck() throw new InvalidOperationException($"This extend type {_timeLeftUtil.ExtendType} is not supported"); } } + + // Timelimit, Round time limit, Round Limit + private void ExecuteMapLimitConfig() + { + void LogConVarError(string cvarName) + { + Logger.LogError($"Failed to find ConVar: {cvarName}"); + } + + if (CurrentMap == null) + { + Logger.LogError("Failed to find current map config, we cannot execute map time/round limit config."); + return; + } + + switch (_timeLeftUtil.ExtendType) + { + case McsMapExtendType.TimeLimit: + var cvtl = ConVar.Find("mp_timelimit"); + if (cvtl == null) + { + LogConVarError("mp_timelimit"); + return; + } + + cvtl.SetValue((float)CurrentMap.MapTime); + return; + + case McsMapExtendType.RoundTime: + var cvrt = ConVar.Find("mp_roundtime"); + if (cvrt == null) + { + LogConVarError("mp_roundtime"); + return; + } + + cvrt.SetValue((float)CurrentMap.MapTime); + return; + + case McsMapExtendType.Rounds: + var cvmr = ConVar.Find("mp_maxrounds"); + if (cvmr == null) + { + LogConVarError("mp_maxrounds"); + return; + } + + cvmr.SetValue(CurrentMap.MapRounds); + return; + + default: + throw new InvalidOperationException($"This extend type {_timeLeftUtil.ExtendType} is not supported"); + } + } // tuna: I know same method exists in vote controller, but I don't have mutch time to refactor so I simply copy paste it. // TODO() Needs refactor diff --git a/docs/en/configuration/MAP_CONFIG.md b/docs/en/configuration/MAP_CONFIG.md index d200125..088d120 100644 --- a/docs/en/configuration/MAP_CONFIG.md +++ b/docs/en/configuration/MAP_CONFIG.md @@ -314,8 +314,6 @@ For time-based maps, specifies how many minutes to extend each time an extension ### MapTime -Currently not in use. - For time-based maps, specifies the duration of the map. ### ExtendRoundsPerExtends @@ -324,8 +322,6 @@ For round-based maps, specifies how many rounds to extend each time an extension ### MapRounds -Currently not in use. - For round-based maps, specifies the number of rounds for the map. ## Nomination Settings diff --git a/docs/ja/configuration/MAP_CONFIG.md b/docs/ja/configuration/MAP_CONFIG.md index 8cb72bc..a22c359 100644 --- a/docs/ja/configuration/MAP_CONFIG.md +++ b/docs/ja/configuration/MAP_CONFIG.md @@ -313,8 +313,6 @@ cost = 100 ### MapTime -現在は使用していません。 - マップが時間ベースの場合に、マップの時間を指定します。 ### ExtendRoundsPerExtends @@ -323,8 +321,6 @@ cost = 100 ### MapRounds -現在は使用していません。 - マップがラウンドベースの場合に、マップのラウンド数を指定します。 ## ノミネート関連 From 6aa72581ee1652ce38ab68282ed7b794f73d134a Mon Sep 17 00:00:00 2001 From: faketuna Date: Fri, 19 Sep 2025 20:49:35 +0900 Subject: [PATCH 2/2] modify: refactor code for better visibility --- .../Modules/MapCycle/McsMapCycleController.cs | 56 +++++++------------ 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/MapChooserSharp/Modules/MapCycle/McsMapCycleController.cs b/MapChooserSharp/Modules/MapCycle/McsMapCycleController.cs index ea470bf..47b2f26 100644 --- a/MapChooserSharp/Modules/MapCycle/McsMapCycleController.cs +++ b/MapChooserSharp/Modules/MapCycle/McsMapCycleController.cs @@ -473,54 +473,36 @@ private Func GetCorrespondTimelimitCheck() // Timelimit, Round time limit, Round Limit private void ExecuteMapLimitConfig() { - void LogConVarError(string cvarName) + if (CurrentMap == null) { - Logger.LogError($"Failed to find ConVar: {cvarName}"); + Logger.LogError("Failed to find current map config, we cannot execute map time/round limit config."); + return; } - if (CurrentMap == null) + var cvarName = _timeLeftUtil.ExtendType switch { - Logger.LogError("Failed to find current map config, we cannot execute map time/round limit config."); + McsMapExtendType.TimeLimit => "mp_timelimit", + McsMapExtendType.RoundTime => "mp_roundtime", + McsMapExtendType.Rounds => "mp_maxrounds", + _ => throw new InvalidOperationException($"This extend type {_timeLeftUtil.ExtendType} is not supported") + }; + + var cvar = ConVar.Find(cvarName); + if (cvar == null) + { + Logger.LogError($"Failed to find ConVar: {cvarName}"); return; } - + switch (_timeLeftUtil.ExtendType) { case McsMapExtendType.TimeLimit: - var cvtl = ConVar.Find("mp_timelimit"); - if (cvtl == null) - { - LogConVarError("mp_timelimit"); - return; - } - - cvtl.SetValue((float)CurrentMap.MapTime); - return; - case McsMapExtendType.RoundTime: - var cvrt = ConVar.Find("mp_roundtime"); - if (cvrt == null) - { - LogConVarError("mp_roundtime"); - return; - } - - cvrt.SetValue((float)CurrentMap.MapTime); - return; - + cvar.SetValue((float)CurrentMap.MapTime); + break; case McsMapExtendType.Rounds: - var cvmr = ConVar.Find("mp_maxrounds"); - if (cvmr == null) - { - LogConVarError("mp_maxrounds"); - return; - } - - cvmr.SetValue(CurrentMap.MapRounds); - return; - - default: - throw new InvalidOperationException($"This extend type {_timeLeftUtil.ExtendType} is not supported"); + cvar.SetValue(CurrentMap.MapRounds); + break; } }