Skip to content

Commit

Permalink
bug fix for queue system. roundtype configuration: sequence, specific…
Browse files Browse the repository at this point in the history
…, random

round type mode can be configured in the plugin base config. default: sequence.
The sequence of the round types in configurable in the plugin base config.
RoundTypeMode Options: Sequence, Specific, Random
  • Loading branch information
LordFetznschaedl committed Feb 4, 2024
1 parent 54b9823 commit f5ebd99
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 54 deletions.
27 changes: 9 additions & 18 deletions CS2Retake/CS2Retake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace CS2Retake
public class CS2Retake : BasePlugin, IPluginConfig<CS2RetakeConfig>
{
public override string ModuleName => "CS2Retake";
public override string ModuleVersion => "1.2.0";
public override string ModuleVersion => "1.3.0";
public override string ModuleAuthor => "LordFetznschaedl";
public override string ModuleDescription => "Retake Plugin implementation for CS2";
public override string ModuleDescription => "Highly configurable and modular implementation Retake for CS2";

public CS2RetakeConfig Config { get; set; } = new CS2RetakeConfig();
private bool _scrambleAfterWarmupDone = false;
Expand Down Expand Up @@ -241,6 +241,8 @@ private HookResult OnCommandJoinTeam(CCSPlayerController? player, CommandInfo co
return HookResult.Handled;
}

MessageUtils.LogDebug($"CommandInfo: ArgString: {commandInfo.ArgString}, CommandString: {commandInfo.GetCommandString}");

var oldTeam = (CsTeam)player.TeamNum;

if (commandInfo.ArgCount < 2)
Expand All @@ -264,20 +266,6 @@ private HookResult OnCommandJoinTeam(CCSPlayerController? player, CommandInfo co
}

return HookResult.Continue;

//if (GameRuleManager.Instance.IsWarmup || !FeatureConfig.EnableQueue)
//{
// return HookResult.Continue;
//}
//else if(!PlayerUtils.AreMoreThenPlayersConnected(2))
//{
// return HookResult.Continue;
//}
//else
//{
// return HookResult.Handled;
//}


}

Expand Down Expand Up @@ -373,7 +361,7 @@ 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}{WeaponManager.Instance.RoundType}{ChatColors.White} - {ChatColors.Blue}{ratio.ctRatio}CTs{ChatColors.White} VS {ChatColors.Red}{ratio.tRatio}Ts{ChatColors.White}");
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}");

return HookResult.Continue;
}
Expand Down Expand Up @@ -481,6 +469,8 @@ private HookResult OnBeginNewMatch(EventBeginNewMatch @event, GameEventInfo info

private HookResult OnCsIntermission(EventCsIntermission @event, GameEventInfo info)
{
RoundTypeManager.Instance.ResetForNextMap();

return HookResult.Continue;
}

Expand All @@ -491,7 +481,8 @@ public void OnMapStart(string mapName)
RetakeManager.Instance.ConfigureForRetake();
GameRuleManager.Instance.GameRules = null;
this._scrambleAfterWarmupDone = false;
}
RoundTypeManager.Instance.ResetForNextMap();
}


public void OnTick()
Expand Down
16 changes: 15 additions & 1 deletion CS2Retake/Configs/CS2RetakeConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using CS2Retake.Entities;
using CS2Retake.Utils;
using System;
using System.Collections.Generic;
Expand All @@ -12,6 +13,16 @@ namespace CS2Retake.Configs
public class CS2RetakeConfig : BasePluginConfig
{
public PlantTypeEnum PlantType { get; set; } = PlantTypeEnum.AutoPlant;
public RoundTypeModeEnum RoundTypeMode { get; set; } = RoundTypeModeEnum.Sequence;

public List<RoundTypeSequenceEntity> RoundTypeSequence { get; set; } = new List<RoundTypeSequenceEntity>()
{
new RoundTypeSequenceEntity(RoundTypeEnum.Pistol, 5),
new RoundTypeSequenceEntity(RoundTypeEnum.Mid, 3),
new RoundTypeSequenceEntity(RoundTypeEnum.FullBuy, -1),
};

public RoundTypeEnum RoundTypeSpecific { get; set; } = RoundTypeEnum.FullBuy;

public float SecondsUntilBombPlantedCheck { get; set; } = 5.0f;

Expand All @@ -28,9 +39,12 @@ public class CS2RetakeConfig : BasePluginConfig

public bool EnableThankYouMessage { get; set; } = true;




public bool EnableDebug { get; set; } = false;
public CS2RetakeConfig() {
this.Version = 3;
this.Version = 4;
}
}
}
18 changes: 17 additions & 1 deletion CS2Retake/Configs/RuntimeConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CS2Retake.Utils;
using CS2Retake.Entities;
using CS2Retake.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -21,6 +22,17 @@ public static class RuntimeConfig
public static float TeamBalanceRatio { get; set; } = 0.499f;

public static PlantTypeEnum PlantType { get; set; } = PlantTypeEnum.AutoPlant;
public static RoundTypeModeEnum RoundTypeMode { get; set; } = RoundTypeModeEnum.Sequence;

public static List<RoundTypeSequenceEntity> RoundTypeSequence { get; set; } = new List<RoundTypeSequenceEntity>()
{
new RoundTypeSequenceEntity(RoundTypeEnum.Pistol, 5),
new RoundTypeSequenceEntity(RoundTypeEnum.Mid, 3),
new RoundTypeSequenceEntity(RoundTypeEnum.FullBuy, -1),
};

public static RoundTypeEnum RoundTypeSpecific { get; set; } = RoundTypeEnum.FullBuy;


public static void SetModuleInfo(string moduleName, string moduleDirectory)
{
Expand All @@ -38,6 +50,10 @@ public static void SetBaseConfig(CS2RetakeConfig baseConfig)
TeamBalanceRatio = baseConfig.TeamBalanceRatio;

PlantType = baseConfig.PlantType;

RoundTypeMode = baseConfig.RoundTypeMode;
RoundTypeSequence = baseConfig.RoundTypeSequence;
RoundTypeSpecific = baseConfig.RoundTypeSpecific;
}
}
}
23 changes: 23 additions & 0 deletions CS2Retake/Entities/RoundTypeSequenceEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using CS2Retake.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS2Retake.Entities
{
public class RoundTypeSequenceEntity
{
public RoundTypeEnum RoundType { get; set; } = RoundTypeEnum.Undefined;
public int AmountOfRounds { get; set; } = 5;

public RoundTypeSequenceEntity(RoundTypeEnum roundType, int amountOfRounds)
{
this.RoundType = roundType;
this.AmountOfRounds = amountOfRounds;
}

public RoundTypeSequenceEntity(){}
}
}
2 changes: 2 additions & 0 deletions CS2Retake/Managers/Base/BaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ namespace CS2Retake.Managers.Base
public abstract class BaseManager
{
public abstract void ResetForNextRound(bool completeReset = true);

public abstract void ResetForNextMap(bool completeReset = true);
}
}
67 changes: 59 additions & 8 deletions CS2Retake/Managers/GameRuleManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CS2Retake.Managers.Base;
using CS2Retake.Managers.Interfaces;
using CS2Retake.Utils;
Expand Down Expand Up @@ -58,24 +59,69 @@ public float WarmupEnd
}
}

public void ModifyBombPlanted(bool bombPlanted)
public bool BombPlanted
{
if (this.GameRules == null)
get
{
this.GetGameRules();
if (this.GameRules == null)
{
this.GetGameRules();
}

return this.GameRules!.BombPlanted;
}

set
{
if (this.GameRules == null)
{
this.GetGameRules();
}

this.GameRules!.BombPlanted = value;
}
this.GameRules!.BombPlanted = bombPlanted;
}

public void ModifyBombDefused(bool bombDefused)
public bool BombDefused
{
if (this.GameRules == null)
get
{
this.GetGameRules();
if (this.GameRules == null)
{
this.GetGameRules();
}

return this.GameRules!.BombDefused;
}

set
{
if (this.GameRules == null)
{
this.GetGameRules();
}

this.GameRules!.BombDefused = value;
}
}

public int TotalRoundsPlayed
{
get
{
if (this.GameRules == null)
{
this.GetGameRules();
}

return this.GameRules!.TotalRoundsPlayed;
}
this.GameRules!.BombDefused = bombDefused;
}

public void TerminateRound(RoundEndReason reason = RoundEndReason.RoundDraw)
{
this.GameRules?.TerminateRound(0, reason);
}

private void GetGameRules()
{
Expand Down Expand Up @@ -121,5 +167,10 @@ public override void ResetForNextRound(bool completeReset = true)
{

}

public override void ResetForNextMap(bool completeReset = true)
{

}
}
}
7 changes: 6 additions & 1 deletion CS2Retake/Managers/Interfaces/IGameRuleManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -11,7 +12,11 @@ public interface IGameRuleManager
{
public CCSGameRules? GameRules { get; set; }
public bool IsWarmup { get; }
public float WarmupEnd { get; }
public bool BombPlanted { get; set; }
public bool BombDefused { get; set; }
public int TotalRoundsPlayed { get; }


public void TerminateRound(RoundEndReason reason = RoundEndReason.RoundDraw);
}
}
16 changes: 16 additions & 0 deletions CS2Retake/Managers/Interfaces/IRoundTypeManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CS2Retake.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS2Retake.Managers.Interfaces
{
public interface IRoundTypeManager
{
public RoundTypeEnum RoundType { get; }
public void HandleRoundType();
}
}
5 changes: 5 additions & 0 deletions CS2Retake/Managers/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,10 @@ public override void ResetForNextRound(bool completeReset = true)

this.HasToBeInBombZone = true;
}

public override void ResetForNextMap(bool completeReset = true)
{

}
}
}
17 changes: 13 additions & 4 deletions CS2Retake/Managers/PlantManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static PlantManager Instance
}
}


private PlantManager() { }

public void HandlePlant()
{
Expand Down Expand Up @@ -112,6 +112,9 @@ private void AutoPlant()

plantedc4.DispatchSpawn();

GameRuleManager.Instance.BombPlanted = true;
GameRuleManager.Instance.BombDefused = false;

this.FireBombPlantedEvent(planterPlayerController, MapManager.Instance.BombSite);
}

Expand Down Expand Up @@ -168,12 +171,13 @@ public void HasBombBeenPlantedCallback()

if (planterPlayerController != null)
{
Server.PrintToChatAll($"{MessageUtils.PluginPrefix} Player {ChatColors.Darkred}{planterPlayerController.PlayerName}{ChatColors.White} failed to plant the bomb in time. Counter-Terrorists win this round.");
Server.PrintToChatAll($"{MessageUtils.PluginPrefix} Player {ChatColors.DarkRed}{planterPlayerController.PlayerName}{ChatColors.White} failed to plant the bomb in time. Counter-Terrorists win this round.");
}

var terroristPlayerList = Utilities.GetPlayers().Where(x => x != null && x.IsValid && x.PlayerPawn != null && x.PlayerPawn.IsValid && x.PlayerPawn.Value != null && x.PlayerPawn.Value.IsValid && x.TeamNum == (int)CsTeam.Terrorist).ToList();
terroristPlayerList.ForEach(x => x?.PlayerPawn?.Value?.CommitSuicide(true, true));
//var terroristPlayerList = Utilities.GetPlayers().Where(x => x != null && x.IsValid && x.PlayerPawn != null && x.PlayerPawn.IsValid && x.PlayerPawn.Value != null && x.PlayerPawn.Value.IsValid && x.TeamNum == (int)CsTeam.Terrorist).ToList();
//terroristPlayerList.ForEach(x => x?.PlayerPawn?.Value?.CommitSuicide(true, true));

GameRuleManager.Instance.TerminateRound(CounterStrikeSharp.API.Modules.Entities.Constants.RoundEndReason.CTsWin);
}

private void FireBombPlantedEvent(CCSPlayerController planterController, BombSiteEnum bombsite)
Expand Down Expand Up @@ -211,5 +215,10 @@ public override void ResetForNextRound(bool completeReset = true)
this.HasBombBeenPlantedTimer?.Kill();
}
}

public override void ResetForNextMap(bool completeReset = true)
{

}
}
}
5 changes: 5 additions & 0 deletions CS2Retake/Managers/RetakeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,10 @@ public override void ResetForNextRound(bool completeReset = true)

this.BombHasBeenPlanted = false;
}

public override void ResetForNextMap(bool completeReset = true)
{

}
}
}
Loading

0 comments on commit f5ebd99

Please sign in to comment.