Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nickj609 committed Nov 17, 2024
2 parents 6d7c725 + 6b05c94 commit c823501
Show file tree
Hide file tree
Showing 22 changed files with 250 additions and 184 deletions.
14 changes: 0 additions & 14 deletions GameModeManager.Shared/GameModeManager.Shared.sln

This file was deleted.

4 changes: 2 additions & 2 deletions GameModeManager/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ public class GameModeSettings
{
new ModeEntry() { Name = "Casual", Config = "casual.cfg", DefaultMap = "de_dust2", MapGroups = new List<string>(){"mg_active", "mg_comp"} },
new ModeEntry() { Name = "Deathmatch", Config = "dm.cfg", DefaultMap = "de_assembly", MapGroups = new List<string>(){"mg_dm"}},
new ModeEntry() { Name = "ArmsRace", Config = "armsrace.cfg", DefaultMap = "ar_pool_day", MapGroups = new List<string>(){"mg_gg"}},
new ModeEntry() { Name = "Armsrace", Config = "ar.cfg", DefaultMap = "ar_pool_day", MapGroups = new List<string>(){"mg_gg"}},
new ModeEntry() { Name = "Competitive", Config = "comp.cfg", DefaultMap = "de_dust2", MapGroups = new List<string>(){"mg_active", "mg_comp"}},
new ModeEntry() { Name = "Wingman", Config = "wingman.cfg", DefaultMap = "de_memento", MapGroups = new List<string>(){"mg_active", "mg_comp"}},
new ModeEntry() { Name = "Practice", Config = "prac.cfg", DefaultMap = "de_dust2", MapGroups = new List<string>(){"mg_comp"}},
new ModeEntry() { Name = "Prefire", Config = "prefire.cfg", DefaultMap = "de_inferno", MapGroups = new List<string>(){"mg_comp"} },
new ModeEntry() { Name = "Retakes", Config = "retake.cfg", DefaultMap = "de_dust2", MapGroups = new List<string>(){"mg_comp"}},
new ModeEntry() { Name = "Executes", Config = "executes.cfg", DefaultMap = "de_mirage", MapGroups = new List<string>(){"mg_comp"}},
new ModeEntry() { Name = "Casual 1.6", Config = "Casual-1.6.cfg", DefaultMap = "3212419403", MapGroups = new List<string>(){"mg_active", "mg_comp"} },
new ModeEntry() { Name = "Casual 1.6", Config = "Casual-1.6.cfg", DefaultMap = "3212419403", MapGroups = new List<string>(){"mg_Casual-1.6"} },
new ModeEntry() { Name = "Deathmatch Multicfg", Config = "dm-multicfg.cfg", DefaultMap = "de_mirage", MapGroups = new List<string>(){"mg_dm"}},
new ModeEntry() { Name = "GG", Config = "gg.cfg", DefaultMap = "ar_pool_day", MapGroups = new List<string>(){"mg_gg"}},
new ModeEntry() { Name = "45", Config = "45.cfg", DefaultMap = "3276886893", MapGroups = new List<string>(){"mg_45"} },
Expand Down
2 changes: 1 addition & 1 deletion GameModeManager/Contracts/IPluginDependency.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Decalre namespace
// Declare namespace
namespace GameModeManager.Contracts
{
// Define interface
Expand Down
42 changes: 30 additions & 12 deletions GameModeManager/Core/MapGroupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,52 @@ public void OnLoad(Plugin plugin)
long _mapWorkshopId = long.Parse(parts[1]);
string _mapNameFormatted = parts[parts.Length - 1];

// Add map to all maps list if it doesn't already exist
if (!_pluginState.Maps.Any(m => m.Name == _mapNameFormatted && m.WorkshopId == _mapWorkshopId))
// Add map to maps lists
if (!string.IsNullOrEmpty(_mapDisplayName))
{
if (!string.IsNullOrEmpty(_mapDisplayName))
// Add to mapgroup map list
_group.Maps.Add(new Map(_mapNameFormatted, _mapWorkshopId, _mapDisplayName));

// Add to all maps list only if it doesn't already exist
if (!_pluginState.Maps.Any(m => m.Name == _mapNameFormatted && m.WorkshopId == _mapWorkshopId))
{
_group.Maps.Add(new Map(_mapNameFormatted, _mapWorkshopId, _mapDisplayName));
_pluginState.Maps.Add(new Map(_mapNameFormatted, _mapWorkshopId, _mapDisplayName));
}
else
}
else
{
// Add to mapgroup map list
_group.Maps.Add(new Map(_mapNameFormatted, _mapWorkshopId));

// Add to all maps list only if it doesn't already exist
if (!_pluginState.Maps.Any(m => m.Name == _mapNameFormatted && m.WorkshopId == _mapWorkshopId))
{
_group.Maps.Add(new Map(_mapNameFormatted, _mapWorkshopId));
_pluginState.Maps.Add(new Map(_mapNameFormatted, _mapWorkshopId));
}
}
}
else
{
// Add map to all maps list if it doesn't already exist
if (!_pluginState.Maps.Any(m => m.Name == _mapName))
// Add map to maps lists
if (!string.IsNullOrEmpty(_mapDisplayName))
{
if (!string.IsNullOrEmpty(_mapDisplayName))
// Add to mapgroup map list
_group.Maps.Add(new Map(_mapName, _mapDisplayName));

// Add to all maps list only if it doesn't already exist
if (!_pluginState.Maps.Any(m => m.Name == _mapName))
{
_group.Maps.Add(new Map(_mapName, _mapDisplayName));
_pluginState.Maps.Add(new Map(_mapName, _mapDisplayName));
}
else
}
else
{
// Add to mapgroup map list
_group.Maps.Add(new Map(_mapName));

// Add to all maps list only if it doesn't already exist
if (!_pluginState.Maps.Any(m => m.Name == _mapName))
{
_group.Maps.Add(new Map(_mapName));
_pluginState.Maps.Add(new Map(_mapName));
}
}
Expand Down
2 changes: 1 addition & 1 deletion GameModeManager/Core/ModeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void OnConfigParsed(Config config)
// Define on map start behavior
public void OnMapStart(string map)
{
new Timer(3.0f, () =>
new Timer(3.5f, () =>
{
Server.ExecuteCommand($"exec {_pluginState.CurrentMode.Config}");
Server.ExecuteCommand("mp_restartgame 1");
Expand Down
5 changes: 4 additions & 1 deletion GameModeManager/Core/RotationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public HookResult EventCsWinPanelMatchHandler(EventCsWinPanelMatch @event, GameE
// Define event player connect full handler
public HookResult EventPlayerConnectFullHandler(EventPlayerConnectFull @event, GameEventInfo info)
{
_rotationTimer?.Kill();
if (Extensions.ValidPlayerCount(false) > 0)
{
_rotationTimer?.Kill();
}
return HookResult.Continue;
}

Expand Down
27 changes: 26 additions & 1 deletion GameModeManager/Core/TimeLimitManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public void OnLoad(Plugin plugin)
// Load convars
LoadCvar();

// Register event handler
// Register event handlers
plugin.RegisterEventHandler<EventGameEnd>(EventGameEndHandler);
plugin.RegisterEventHandler<EventPlayerDisconnect>(EventPlayerDisconnectHandler);
plugin.RegisterEventHandler<EventRoundAnnounceMatchStart>(EventRoundAnnounceMatchStartHandler);
}

Expand Down Expand Up @@ -147,6 +149,29 @@ public HookResult EventRoundAnnounceMatchStartHandler(EventRoundAnnounceMatchSta
return HookResult.Continue;
}

// Define event game end handler
public HookResult EventGameEndHandler(EventGameEnd @event, GameEventInfo info)
{
if (_pluginState.TimeLimitEnabled)
{
DisableTimeLimit();
}
return HookResult.Continue;
}

// Define event player disconnect handler
public HookResult EventPlayerDisconnectHandler(EventPlayerDisconnect @event, GameEventInfo info)
{
if (Extensions.IsServerEmpty())
{
if (_pluginState.TimeLimitEnabled)
{
DisableTimeLimit();
}
}
return HookResult.Continue;
}

// Define reusable method to get time limit message
public string GetTimeLeftMessage()
{
Expand Down
62 changes: 46 additions & 16 deletions GameModeManager/Core/WarmupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ namespace GameModeManager.Core
public class WarmupManager : IPluginDependency<Plugin, Config>
{
// Define dependencies
private GameRules _gameRules;
private PluginState _pluginState;
private StringLocalizer _localizer;
private Config _config = new Config();
private ILogger<WarmupManager> _logger;

// Define class instance
public WarmupManager(PluginState pluginState, ILogger<WarmupManager> logger, StringLocalizer localizer)
public WarmupManager(PluginState pluginState, ILogger<WarmupManager> logger, StringLocalizer localizer, GameRules gameRules)
{
_logger = logger;
_gameRules = gameRules;
_localizer = localizer;
_pluginState = pluginState;
}
Expand All @@ -37,6 +39,7 @@ public void OnLoad(Plugin plugin)
{
// Register event handlers
plugin.RegisterEventHandler<EventWarmupEnd>(EventWarmupEndHandler, HookMode.Post);
plugin.RegisterEventHandler<EventPlayerDisconnect>(EventPlayerDisconnectHandler, HookMode.Post);
plugin.RegisterEventHandler<EventPlayerConnectFull>(EventPlayerConnectFullHandler, HookMode.Post);

// Create warmup mode list from config
Expand Down Expand Up @@ -77,34 +80,32 @@ public void OnLoad(Plugin plugin)
}

// Define on warmup start behavior
public HookResult EventPlayerConnectFullHandler(EventPlayerConnectFull @event, GameEventInfo info)
public HookResult EventPlayerConnectFullHandler(EventPlayerConnectFull @event, GameEventInfo info)
{
if (_pluginState.WarmupScheduled)
if (Extensions.ValidPlayerCount(false) == 1)
{
Server.ExecuteCommand($"exec {_pluginState.WarmupMode.Config}");
Server.PrintToChatAll(_localizer.LocalizeWithPrefix("warmup.start.message", _pluginState.WarmupMode.Name));
StartWarmup(_pluginState.WarmupMode);
}
return HookResult.Continue;
}

// Define on warmup end behavior
public HookResult EventWarmupEndHandler(EventWarmupEnd @event, GameEventInfo info)
{
if (_pluginState.WarmupScheduled)
{
Server.ExecuteCommand($"exec {_pluginState.CurrentMode.Config}");
Server.ExecuteCommand($"mp_restartgame 1");
Server.PrintToChatAll(_localizer.LocalizeWithPrefix("warmup.end.message", _pluginState.CurrentMode.Name));
EndWarmup();
return HookResult.Continue;
}

if (_pluginState.PerMapWarmup)
{
_pluginState.WarmupScheduled = false;
}
public HookResult EventPlayerDisconnectHandler(EventPlayerDisconnect @event, GameEventInfo info)
{
if (Extensions.IsServerEmpty())
{
_pluginState.WarmupRunning = false;
}
return HookResult.Continue;
}

//Define reusable methods to schedule warmup mode
//Define reusable method to schedule warmup mode
public bool ScheduleWarmup(string modeName)
{
Mode? warmupMode = _pluginState.WarmupModes.FirstOrDefault(m => m.Name.Equals(modeName, StringComparison.OrdinalIgnoreCase) || m.Config.Contains(modeName, StringComparison.OrdinalIgnoreCase));
Expand All @@ -121,5 +122,34 @@ public bool ScheduleWarmup(string modeName)
return false;
}
}

//Define reusable method to start warmup
public void StartWarmup(Mode warmupMode)
{
if (_pluginState.WarmupScheduled && !_pluginState.WarmupRunning && !_gameRules.HasMatchStarted)
{
_pluginState.WarmupRunning = true;
Server.ExecuteCommand($"exec {warmupMode.Config}");
Server.PrintToChatAll(_localizer.LocalizeWithPrefix("warmup.start.message", warmupMode.Name));
}
}

//Define reusable method to end warmup
public void EndWarmup()
{
if (_pluginState.WarmupRunning)
{
Server.ExecuteCommand($"exec {_pluginState.CurrentMode.Config}");
Server.ExecuteCommand($"mp_warmup_end");
Server.PrintToChatAll(_localizer.LocalizeWithPrefix("warmup.end.message", _pluginState.CurrentMode.Name));

if (_pluginState.PerMapWarmup)
{
_pluginState.WarmupScheduled = false;
}

_pluginState.WarmupRunning = false;
}
}
}
}
1 change: 0 additions & 1 deletion GameModeManager/CrossCutting/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Entities;


// Declare namespace
namespace GameModeManager.CrossCutting
{
Expand Down
1 change: 1 addition & 0 deletions GameModeManager/CrossCutting/GameRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class GameRules : IPluginDependency<Plugin, Config>
public float GameStartTime => _gameRules?.GameStartTime ?? 0;
public bool WarmupRunning => _gameRules?.WarmupPeriod ?? false;
public int TotalRoundsPlayed => _gameRules?.TotalRoundsPlayed ?? 0;
public bool HasMatchStarted => _gameRules?.HasMatchStarted ?? false;

// Define on load behavior
public void OnLoad(Plugin plugin)
Expand Down
Loading

0 comments on commit c823501

Please sign in to comment.