diff --git a/TTT.sln b/TTT.sln index 7ea60c6..f66b749 100644 --- a/TTT.sln +++ b/TTT.sln @@ -29,8 +29,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Player", "mod\TTT.Playe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Manager", "mod\TTT.Manager\TTT.Manager.csproj", "{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Debug", "mod\TTT.Debug\TTT.Debug.csproj", "{5617C94C-B2F9-429C-B4C1-DDD03380A108}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -80,10 +78,6 @@ Global {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Debug|Any CPU.Build.0 = Debug|Any CPU {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Release|Any CPU.ActiveCfg = Release|Any CPU {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Release|Any CPU.Build.0 = Release|Any CPU - {5617C94C-B2F9-429C-B4C1-DDD03380A108}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5617C94C-B2F9-429C-B4C1-DDD03380A108}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5617C94C-B2F9-429C-B4C1-DDD03380A108}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5617C94C-B2F9-429C-B4C1-DDD03380A108}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {A917B0F5-762F-4C4A-9F50-02BA4A0C6B63} = {C7CCF187-9F99-4091-B092-6397C35BE9F1} @@ -96,6 +90,5 @@ Global {E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B} = {14FF3D75-F9CF-4A32-9F59-83765EA68874} {D9327D60-67EE-4AF3-BD99-8A95634600B5} = {14FF3D75-F9CF-4A32-9F59-83765EA68874} {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB} = {14FF3D75-F9CF-4A32-9F59-83765EA68874} - {5617C94C-B2F9-429C-B4C1-DDD03380A108} = {14FF3D75-F9CF-4A32-9F59-83765EA68874} EndGlobalSection EndGlobal diff --git a/mod/TTT.Debug/Commands/GetRagdoll.cs b/mod/TTT.Debug/Commands/GetRagdoll.cs deleted file mode 100644 index dd75b0e..0000000 --- a/mod/TTT.Debug/Commands/GetRagdoll.cs +++ /dev/null @@ -1,30 +0,0 @@ -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Core.Attributes.Registration; -using CounterStrikeSharp.API.Modules.Commands; -using TTT.Public.Behaviors; -using TTT.Public.Extensions; - -namespace TTT.Debug.Commands; - -public class GetRagdoll : IPluginBehavior { - [ConsoleCommand("css_getragdoll")] - [CommandHelper(0, "", CommandUsage.CLIENT_ONLY)] - public void Command_GetRagdoll(CCSPlayerController? executor, - CommandInfo command) { - if (executor == null) return; - - var body = executor.GetClientRagdollAimTarget(); - if (body == null) { - command.ReplyToCommand("No body found"); - return; - } - - if (!body.IsValid) { - command.ReplyToCommand("Found body, but is invalid"); - return; - } - - command.ReplyToCommand("Found " + body.DesignerName + " of " - + body.PlayerName); - } -} \ No newline at end of file diff --git a/mod/TTT.Debug/DebugServiceExtension.cs b/mod/TTT.Debug/DebugServiceExtension.cs deleted file mode 100644 index 070c27f..0000000 --- a/mod/TTT.Debug/DebugServiceExtension.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using TTT.Debug.Commands; -using TTT.Public.Extensions; - -namespace TTT.Debug; - -public static class DebugServiceExtension { - public static void AddDebugBehavior(this IServiceCollection collection) { - collection.AddPluginBehavior(); - } -} \ No newline at end of file diff --git a/mod/TTT.Debug/TTT.Debug.csproj b/mod/TTT.Debug/TTT.Debug.csproj deleted file mode 100644 index f6aaca5..0000000 --- a/mod/TTT.Debug/TTT.Debug.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - - - diff --git a/mod/TTT.Detective/DetectiveManager.cs b/mod/TTT.Detective/DetectiveManager.cs index 78d2bb0..535bc7a 100644 --- a/mod/TTT.Detective/DetectiveManager.cs +++ b/mod/TTT.Detective/DetectiveManager.cs @@ -62,7 +62,7 @@ public HookResult OnZeus(DynamicHook hook) { private void OnPlayerUse(CCSPlayerController player) { IdentifyBody(player); } private void IdentifyBody(CCSPlayerController caller) { - // if (roleService.GetPlayer(caller).PlayerRole() != Role.Detective) return; + if (roleService.GetPlayer(caller).PlayerRole() != Role.Detective) return; var entity = caller.GetClientRagdollAimTarget(); diff --git a/mod/TTT.Roles/RoleBehavior.cs b/mod/TTT.Roles/RoleBehavior.cs index b21b5eb..b48ae0e 100644 --- a/mod/TTT.Roles/RoleBehavior.cs +++ b/mod/TTT.Roles/RoleBehavior.cs @@ -18,32 +18,33 @@ public class RoleBehavior : IRoleService, IPluginBehavior { private const int MaxDetectives = 3; private readonly IPlayerService service; - private int innocentsLeft; - private readonly IRoundService roundService; - private int traitorsLeft; + private int _innocentsLeft; + private readonly IRoundService _roundService; + private int _traitorsLeft; public RoleBehavior(IPlayerService playerService) { - roundService = new RoundBehavior(this); - service = playerService; + _roundService = new RoundBehavior(this); + service = playerService; } public void Start(BasePlugin parent) { ModelHandler.RegisterListener(parent); - roundService.Start(parent); + _roundService.Start(parent); } - public IRoundService GetRoundService() { return roundService; } + public IRoundService GetRoundService() { return _roundService; } public void AddRoles() { var eligible = Utilities.GetPlayers() + .Where(player => player.IsReal()) .Where(player => player.Team is not (CsTeam.Spectator or CsTeam.None)) .ToList(); var traitorCount = (int)Math.Floor(Convert.ToDouble(eligible.Count / 3)); var detectiveCount = (int)Math.Floor(Convert.ToDouble(eligible.Count / 8)); - traitorsLeft = traitorCount; - innocentsLeft = eligible.Count - traitorCount; + _traitorsLeft = traitorCount; + _innocentsLeft = eligible.Count - traitorCount; if (detectiveCount > MaxDetectives) detectiveCount = MaxDetectives; @@ -89,7 +90,7 @@ public Role GetRole(CCSPlayerController player) { public void AddTraitor(params CCSPlayerController[] players) { foreach (var player in players) { service.GetPlayer(player).SetPlayerRole(Role.Traitor); - player.SwitchTeam(CsTeam.Spectator); + player.SwitchTeam(CsTeam.Terrorist); player.PrintToCenter( Role.Traitor.FormatStringFullBefore("You are now a")); player.PrintToChat(Role.Traitor.FormatStringFullBefore("You are now a")); @@ -113,7 +114,7 @@ public void AddInnocents(params CCSPlayerController[] players) { service.GetPlayer(player).SetPlayerRole(Role.Innocent); player.PrintToCenter( Role.Innocent.FormatStringFullBefore("You are now an")); - player.SwitchTeam(CsTeam.Spectator); + player.SwitchTeam(CsTeam.Terrorist); ModelHandler.SetModel(player, ModelHandler.ModelPathTmPhoenix); } } @@ -138,7 +139,7 @@ public void Clear() { [GameEventHandler] public HookResult OnRoundStart(EventRoundFreezeEnd @event, GameEventInfo info) { - roundService.SetRoundStatus(RoundStatus.Waiting); + _roundService.SetRoundStatus(RoundStatus.Waiting); foreach (var player in Utilities.GetPlayers() .Where(player => player.IsReal() && player.Team != CsTeam.None || player.Team != CsTeam.Spectator)) { @@ -154,8 +155,10 @@ public HookResult [GameEventHandler] public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info) { - if (Utilities.GetPlayers().Count(player => player.PawnIsAlive) < 3) - roundService.ForceEnd(); + if (Utilities.GetPlayers() + .Count(player => player.IsReal() && player.Team != CsTeam.None + || player.Team == CsTeam.Spectator) < 3) + _roundService.ForceEnd(); return HookResult.Continue; } @@ -174,25 +177,26 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { service.GetPlayer(playerWhoWasDamaged).SetKiller(attacker); - if (IsTraitor(playerWhoWasDamaged)) traitorsLeft--; + if (IsTraitor(playerWhoWasDamaged)) _traitorsLeft--; if (IsDetective(playerWhoWasDamaged) || IsInnocent(playerWhoWasDamaged)) - innocentsLeft--; + _innocentsLeft--; - if (traitorsLeft == 0 || innocentsLeft == 0) - Server.NextFrame(() => roundService.ForceEnd()); + if (_traitorsLeft == 0 || _innocentsLeft == 0) + Server.NextFrame(() => _roundService.ForceEnd()); - // Server.PrintToChatAll(StringUtils.FormatTTT( - // $"{GetRole(playerWhoWasDamaged).FormatStringFullAfter(" has been found.")}")); + Server.NextFrame(() => { + Server.PrintToChatAll(StringUtils.FormatTTT( + $"{GetRole(playerWhoWasDamaged).FormatStringFullAfter(" has been found.")}")); - if (attacker == playerWhoWasDamaged || attacker == null) - return HookResult.Continue; + if (attacker == playerWhoWasDamaged || attacker == null) return; - attacker.ModifyScoreBoard(); + attacker.ModifyScoreBoard(); - playerWhoWasDamaged.PrintToChat(StringUtils.FormatTTT( - $"You were killed by {GetRole(attacker).FormatStringFullAfter(" " + attacker.PlayerName)}.")); - attacker.PrintToChat(StringUtils.FormatTTT( - $"You killed {GetRole(playerWhoWasDamaged).FormatStringFullAfter(" " + playerWhoWasDamaged.PlayerName)}.")); + playerWhoWasDamaged.PrintToChat(StringUtils.FormatTTT( + $"You were killed by {GetRole(attacker).FormatStringFullAfter(" " + attacker.PlayerName)}.")); + attacker.PrintToChat(StringUtils.FormatTTT( + $"You killed {GetRole(playerWhoWasDamaged).FormatStringFullAfter(" " + playerWhoWasDamaged.PlayerName)}.")); + }); return HookResult.Continue; } @@ -201,12 +205,14 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) { var players = Utilities.GetPlayers() .Where(player => player.IsValid) + .Where(player => player.IsReal()) .ToList(); foreach (var player in players) player.PrintToCenter(GetWinner().FormatStringFullAfter("s has won!")); - Clear(); + Server.NextFrame(Clear); + return HookResult.Continue; } @@ -214,10 +220,11 @@ public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) { public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) { var player = @event.Userid; - if (player == null) return HookResult.Continue; - service.RemovePlayer(player); - if (service.Players().Count == 0) - roundService.SetRoundStatus(RoundStatus.Paused); + Server.NextFrame(() => { + service.RemovePlayer(player); + if (service.Players().Count == 0) + _roundService.SetRoundStatus(RoundStatus.Paused); + }); return HookResult.Continue; } @@ -227,7 +234,7 @@ public bool IsInnocent(CCSPlayerController player) { } private Role GetWinner() { - return traitorsLeft == 0 ? Role.Traitor : Role.Innocent; + return _traitorsLeft == 0 ? Role.Traitor : Role.Innocent; } public void SetColor(CCSPlayerController player) { diff --git a/mod/TTT.Round/Round.cs b/mod/TTT.Round/Round.cs index d32d351..2dd3296 100644 --- a/mod/TTT.Round/Round.cs +++ b/mod/TTT.Round/Round.cs @@ -33,6 +33,7 @@ public void Tick() { public void Start() { foreach (var player in Utilities.GetPlayers() + .Where(player => player.IsReal()) .Where(player => !player.PawnIsAlive) .Where(player => player.Team is CsTeam.Terrorist or CsTeam.CounterTerrorist)) diff --git a/public/TTT.Formatting/Extensions/ViewExtensions.cs b/public/TTT.Formatting/Extensions/ViewExtensions.cs index 5b75929..8d17538 100644 --- a/public/TTT.Formatting/Extensions/ViewExtensions.cs +++ b/public/TTT.Formatting/Extensions/ViewExtensions.cs @@ -56,7 +56,7 @@ public static IView ToPlayerConsole(this IView view, public static IView ToPlayerChat(this IView view, CCSPlayerController player) { - if (player.IsBot) return view; + if (!player.IsReal() || player.IsBot) return view; var writer = view.ToWriter(); diff --git a/src/TTT/TTT.csproj b/src/TTT/TTT.csproj index a05e9e5..a561d3a 100644 --- a/src/TTT/TTT.csproj +++ b/src/TTT/TTT.csproj @@ -6,7 +6,6 @@ - diff --git a/src/TTT/TTTServiceCollection.cs b/src/TTT/TTTServiceCollection.cs index 2a04d54..7b5db9f 100644 --- a/src/TTT/TTTServiceCollection.cs +++ b/src/TTT/TTTServiceCollection.cs @@ -1,6 +1,5 @@ using CounterStrikeSharp.API.Core; using Microsoft.Extensions.DependencyInjection; -using TTT.Debug; using TTT.Detective; using TTT.Logs; using TTT.Manager; @@ -16,6 +15,5 @@ public void ConfigureServices(IServiceCollection serviceCollection) { serviceCollection.AddDetectiveBehavior(); serviceCollection.AddLogsService(); serviceCollection.AddManagerService(); - serviceCollection.AddDebugBehavior(); } } \ No newline at end of file