-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add end of map vote functionality (#21)
* move files * WIP * More wip * wip * Finish
- Loading branch information
Showing
13 changed files
with
362 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Cvars; | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
|
||
namespace cs2_rockthevote | ||
{ | ||
public class MaxRoundsManager : IPluginDependency<Plugin, Config> | ||
{ | ||
private int CTWins = 0; | ||
private int TWins = 0; | ||
|
||
private GameRules _gameRules; | ||
private ConVar? _maxRounds; | ||
private int MaxRoundsValue => _maxRounds!.GetPrimitiveValue<int>(); | ||
public bool UnlimitedRounds => MaxRoundsValue <= 0; | ||
public int RemainingRounds | ||
{ | ||
get | ||
{ | ||
var played = MaxRoundsValue - _gameRules.TotalRoundsPlayed; | ||
if (played < 0) | ||
return 0; | ||
|
||
return played; | ||
} | ||
} | ||
|
||
public int RemainingWins | ||
{ | ||
get | ||
{ | ||
return MaxWins - CurrentHighestWins; | ||
} | ||
} | ||
|
||
public int MaxWins | ||
{ | ||
get | ||
{ | ||
if (MaxRoundsValue <= 0) | ||
return 0; | ||
|
||
return ((int)Math.Floor(MaxRoundsValue / 2M)) + 1; | ||
} | ||
} | ||
|
||
public int CurrentHighestWins => CTWins > TWins ? CTWins : TWins; | ||
|
||
public MaxRoundsManager(GameRules gameRules) | ||
{ | ||
_gameRules = gameRules; | ||
} | ||
|
||
void LoadCvar() | ||
{ | ||
_maxRounds = ConVar.Find("mp_maxrounds"); | ||
} | ||
|
||
|
||
public void ClearRounds() | ||
{ | ||
CTWins = 0; | ||
TWins = 0; | ||
} | ||
|
||
public void RoundWin(CsTeam team) | ||
{ | ||
if (team == CsTeam.CounterTerrorist) | ||
{ | ||
CTWins++; | ||
|
||
} | ||
else if (team == CsTeam.Terrorist) | ||
{ | ||
TWins++; | ||
} | ||
//Server.PrintToChatAll($"T Wins {TWins}, CTWins {CTWins}"); | ||
} | ||
|
||
public void OnMapStart(string map) | ||
{ | ||
LoadCvar(); | ||
ClearRounds(); | ||
} | ||
|
||
public void OnLoad(Plugin plugin) | ||
{ | ||
plugin.RegisterEventHandler<EventRoundEnd>((@event, info) => | ||
{ | ||
if (@event is null) | ||
return HookResult.Continue; | ||
|
||
CsTeam? winner = Enum.IsDefined(typeof(CsTeam), (byte)@event.Winner) ? (CsTeam)@event.Winner : null; | ||
if (winner is not null) | ||
RoundWin(winner.Value); | ||
|
||
return HookResult.Continue; | ||
}); | ||
|
||
|
||
plugin.RegisterEventHandler<EventRoundAnnounceMatchStart>((@event, info) => | ||
{ | ||
if (@event is null) | ||
return HookResult.Continue; | ||
|
||
ClearRounds(); | ||
return HookResult.Continue; | ||
}); | ||
|
||
LoadCvar(); | ||
ClearRounds(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Modules.Cvars; | ||
|
||
namespace cs2_rockthevote.Core | ||
{ | ||
public class TimeLimitManager : IPluginDependency<Plugin, Config> | ||
{ | ||
private GameRules _gameRules; | ||
|
||
private ConVar? _timeLimit; | ||
|
||
private decimal TimeLimitValue => (decimal)_timeLimit!.GetPrimitiveValue<float>() * 60M; | ||
|
||
public bool UnlimitedTime => TimeLimitValue <= 0; | ||
|
||
public decimal TimePlayed | ||
{ | ||
get | ||
{ | ||
if (_gameRules.WarmupRunning) | ||
return 0; | ||
|
||
return (decimal)(Server.CurrentTime - _gameRules.GameStartTime); | ||
} | ||
} | ||
|
||
public decimal TimeRemaining | ||
{ | ||
get | ||
{ | ||
if (UnlimitedTime || TimePlayed > TimeLimitValue) | ||
return 0; | ||
|
||
return TimeLimitValue - TimePlayed; | ||
} | ||
} | ||
|
||
public TimeLimitManager(GameRules gameRules) | ||
{ | ||
_gameRules = gameRules; | ||
} | ||
|
||
void LoadCvar() | ||
{ | ||
_timeLimit = ConVar.Find("mp_timelimit"); | ||
} | ||
|
||
public void OnMapStart(string map) | ||
{ | ||
LoadCvar(); | ||
} | ||
|
||
public void OnLoad(Plugin plugin) | ||
{ | ||
LoadCvar(); | ||
} | ||
} | ||
} |
Oops, something went wrong.