Skip to content

Commit

Permalink
bug fixes + how to message for command allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
LordFetznschaedl committed Apr 23, 2024
1 parent 7da63aa commit 443e1eb
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
using CS2Retake.Allocators.Implementations.CommandAllocator.Manager;
using CounterStrikeSharp.API.Modules.Utils;
using CS2Retake.Allocators.Implementations.CommandAllocator.Entities;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Modules.Timers;

namespace CS2Retake.Allocators.Implementations.CommandAllocator
{
public class CommandAllocator : BaseGrenadeAllocator, IAllocatorConfig<CommandAllocatorConfig>
public class CommandAllocator : BaseGrenadeAllocator, IAllocatorConfig<CommandAllocatorConfig>, IDisposable
{
public CommandAllocatorConfig Config { get; set; } = new CommandAllocatorConfig();

Expand All @@ -27,6 +29,8 @@ public class CommandAllocator : BaseGrenadeAllocator, IAllocatorConfig<CommandAl
private int _awpInUseCountCT { get; set; } = 0;
private int _awpInUseCountT { get; set; } = 0;

private CounterStrikeSharp.API.Modules.Timers.Timer? _howToTimer { get; set; } = null;

public CommandAllocator()
{

Expand Down Expand Up @@ -158,6 +162,13 @@ public void OnAllocatorConfigParsed(CommandAllocatorConfig config)
DBManager.Instance.Init();

PlayerUtils.GetValidPlayerControllers().ForEach(x => this.OnPlayerConnected(x));


if(this.Config.HowToMessageDelayInMinutes > 0)
{
this._howToTimer = new CounterStrikeSharp.API.Modules.Timers.Timer(this.Config.HowToMessageDelayInMinutes * 60, PrintHowToMessage, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
}

}

public override void OnGunsCommand(CCSPlayerController? player)
Expand Down Expand Up @@ -289,5 +300,15 @@ public override void ResetForNextRound(bool completeReset = true)
this._awpInUseCountCT = 0;
this._awpInUseCountT = 0;
}

private void PrintHowToMessage()
{
Server.PrintToChatAll($"[{ChatColors.Gold}CommandAllocator{ChatColors.White}] {this.Config.HowToMessage}");
}

public void Dispose()
{
this._howToTimer?.Kill();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ public class CommandAllocatorConfig : BaseAllocatorConfig

public DBType DatabaseType { get; set; } = DBType.SQLite;

public float HowToMessageDelayInMinutes { get; set; } = 3.5f;
public string HowToMessage { get; set; } = $"Customize your weapons by using !guns";

public CommandAllocatorConfig()
{
this.Version = 2;
this.Version = 3;
}
}
}
11 changes: 8 additions & 3 deletions CS2Retake/CS2Retake.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
Expand All @@ -20,7 +20,7 @@ namespace CS2Retake
public class CS2Retake : BasePlugin, IPluginConfig<CS2RetakeConfig>
{
public override string ModuleName => "CS2Retake";
public override string ModuleVersion => "2.1.0";
public override string ModuleVersion => "2.1.1";
public override string ModuleAuthor => "LordFetznschaedl";
public override string ModuleDescription => "Highly configurable and modular implementation Retake for CS2";

Expand Down Expand Up @@ -316,6 +316,7 @@ private HookResult OnRoundFreezeEnd(EventRoundFreezeEnd @event, GameEventInfo in
if(!GameRuleManager.Instance.IsWarmup && (ratios.ctRatio != PlayerUtils.GetCounterTerroristPlayers().Count || ratios.tRatio != PlayerUtils.GetTerroristPlayers().Count))
{
MessageUtils.PrintToChatAll($"Player ratios not matching how they should be. Resetting...");
TeamManager.Instance.FixTeams();
PlayerUtils.SuicideAll();
return HookResult.Continue;
}
Expand Down Expand Up @@ -375,7 +376,11 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)

var ratio = TeamManager.Instance.LatestRatio;

MessageUtils.PrintToChatAll($"Bombsite: {ChatColors.DarkRed}{MapManager.Instance.BombSite}{ChatColors.White} - Roundtype: {ChatColors.DarkRed}{RoundTypeManager.Instance.RoundType}{ChatColors.White} - {ChatColors.Blue}{ratio.ctRatio}CTs{ChatColors.White} VS {ChatColors.Red}{ratio.tRatio}Ts{ChatColors.White}");
MessageUtils.PrintToChatAll($"================================");
MessageUtils.PrintToChatAll($"{ChatColors.Blue}{ratio.ctRatio}CTs{ChatColors.White} VS {ChatColors.Red}{ratio.tRatio}Ts{ChatColors.White}");
MessageUtils.PrintToChatAll($"Roundtype: {ChatColors.DarkRed}{RoundTypeManager.Instance.RoundType}{ChatColors.White}");
MessageUtils.PrintToChatAll($"Bombsite: {ChatColors.DarkRed}{MapManager.Instance.BombSite}{ChatColors.White}");
MessageUtils.PrintToChatAll($"================================");

return HookResult.Continue;
}
Expand Down
2 changes: 1 addition & 1 deletion CS2Retake/CS2Retake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions CS2Retake/Managers/Interfaces/ITeamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface ITeamManager
public void AddQueuePlayers();
public void SwitchTeams();

public void FixTeams();

public void OnTick();


Expand Down
43 changes: 42 additions & 1 deletion CS2Retake/Managers/TeamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static TeamManager Instance

private TeamManager() { }

//TODO FIX: AddQueuePlayers does not rebalance properly
public void AddQueuePlayers()
{
MessageUtils.LogDebug($"Methode: AddQueuePlayers");
Expand Down Expand Up @@ -165,6 +164,48 @@ public void SwitchTeams()
queuedPlayers.ForEach(x => x.SwitchTeam(CsTeam.CounterTerrorist));
}

public void FixTeams()
{
MessageUtils.LogDebug($"Methode: FixTeams");

var playingPlayers = this.GetPlayingPlayers();

var playingCounterTerroristPlayers = playingPlayers.Where(x => x.TeamNum == (int)CsTeam.CounterTerrorist).Where(x => x.UserId.HasValue).Select(x => x.UserId).ToList();
var playingTerroristPlayers = playingPlayers.Where(x => x.TeamNum == (int)CsTeam.Terrorist).Where(x => x.UserId.HasValue).Select(x => x.UserId).ToList();

foreach(var ct in PlayerUtils.GetCounterTerroristPlayers())
{
if(!ct.UserId.HasValue)
{
continue;
}

if(playingCounterTerroristPlayers.Contains(ct.UserId.Value))
{
continue;
}

this.UpdatePlayerStateDict(ct.UserId.Value, PlayerStateEnum.Playing);
}

foreach(var t in PlayerUtils.GetTerroristPlayers())
{
if (!t.UserId.HasValue)
{
continue;
}

if (playingTerroristPlayers.Contains(t.UserId.Value))
{
continue;
}

this.UpdatePlayerStateDict(t.UserId.Value, PlayerStateEnum.Playing);
}

this.ScrambleTeams();
}

public void OnTick()
{
if(GameRuleManager.Instance.IsWarmup)
Expand Down
2 changes: 1 addition & 1 deletion CS2Retake/Managers/WeaponManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public override void ResetForNextRound(bool completeReset = true)
}

RoundTypeManager.Instance.HandleRoundType();
//this._allocator?.ResetForNextRound();
this._allocator?.ResetForNextRound();

}

Expand Down

0 comments on commit 443e1eb

Please sign in to comment.