Skip to content

Commit

Permalink
DelayToChangeInTheEnd config and fix vote trigger when mp_match_can_c…
Browse files Browse the repository at this point in the history
…linch is 0
  • Loading branch information
abnerfs committed Mar 17, 2024
1 parent 5e83cd2 commit 4eb0b43
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions Core/ChangeMapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ChangeMapManager : IPluginDependency<Plugin, Config>
private bool _mapEnd = false;

private Map[] _maps = new Map[0];

private Config _config;

public ChangeMapManager(StringLocalizer localizer, PluginState pluginState, MapLister mapLister)

Check warning on line 40 in Core/ChangeMapManager.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

Non-nullable field '_config' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 40 in Core/ChangeMapManager.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

Non-nullable field '_config' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
{
Expand Down Expand Up @@ -92,14 +92,23 @@ public bool ChangeNextMap(bool mapEnd = false)
return true;
}

public void OnConfigParsed(Config config)
{
_config = config;
}

public void OnLoad(Plugin plugin)
{
_plugin = plugin;
plugin.RegisterEventHandler<EventCsWinPanelMatch>((ev, info) =>
{
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);
});
Expand Down
8 changes: 4 additions & 4 deletions Core/MaxRoundsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class MaxRoundsManager : IPluginDependency<Plugin, Config>

private GameRules _gameRules;
private ConVar? _maxRounds;
private ConVar? _halfTime;
private ConVar? _canClinch;
private int MaxRoundsValue => _maxRounds?.GetPrimitiveValue<int>() ?? 0;
private bool HalfTime => _halfTime?.GetPrimitiveValue<bool>() ?? true;
public bool CanClinch => _canClinch?.GetPrimitiveValue<bool>() ?? true;

public bool UnlimitedRounds => MaxRoundsValue <= 0;
private bool _lastBeforeHalf = false;
Expand Down Expand Up @@ -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;
Expand All @@ -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");
}


Expand Down
2 changes: 1 addition & 1 deletion Core/TimeLimitManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TimeLimitManager : IPluginDependency<Plugin, Config>

private ConVar? _timeLimit;

private decimal TimeLimitValue => (decimal)_timeLimit!.GetPrimitiveValue<float>() * 60M;
private decimal TimeLimitValue => (decimal)(_timeLimit?.GetPrimitiveValue<float>() ?? 0F) * 60M;

public bool UnlimitedTime => TimeLimitValue <= 0;

Expand Down
10 changes: 8 additions & 2 deletions Features/EndOfMapVote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 1 addition & 1 deletion Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void ConfigureServices(IServiceCollection serviceCollection)
public partial class Plugin : BasePlugin, IPluginConfig<Config>
{
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";

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mapname> command
Expand Down

0 comments on commit 4eb0b43

Please sign in to comment.