Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Add debug cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Jul 20, 2024
1 parent 6334991 commit e35aa38
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 43 deletions.
7 changes: 7 additions & 0 deletions TTT.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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
Expand Down Expand Up @@ -78,6 +80,10 @@ 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}
Expand All @@ -90,5 +96,6 @@ 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
30 changes: 30 additions & 0 deletions mod/TTT.Debug/Commands/GetRagdoll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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);
}
}
11 changes: 11 additions & 0 deletions mod/TTT.Debug/DebugServiceExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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<GetRagdoll>();
}
}
17 changes: 17 additions & 0 deletions mod/TTT.Debug/TTT.Debug.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\public\TTT.Public\TTT.Public.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion mod/TTT.Detective/DetectiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
73 changes: 33 additions & 40 deletions mod/TTT.Roles/RoleBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,32 @@ 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;

Expand Down Expand Up @@ -90,7 +89,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.Terrorist);
player.SwitchTeam(CsTeam.Spectator);
player.PrintToCenter(
Role.Traitor.FormatStringFullBefore("You are now a"));
player.PrintToChat(Role.Traitor.FormatStringFullBefore("You are now a"));
Expand All @@ -114,7 +113,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.Terrorist);
player.SwitchTeam(CsTeam.Spectator);
ModelHandler.SetModel(player, ModelHandler.ModelPathTmPhoenix);
}
}
Expand All @@ -139,7 +138,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)) {
Expand All @@ -155,10 +154,8 @@ public HookResult
[GameEventHandler]
public HookResult OnPlayerConnect(EventPlayerConnectFull @event,
GameEventInfo info) {
if (Utilities.GetPlayers()
.Count(player => player.IsReal() && player.Team != CsTeam.None
|| player.Team == CsTeam.Spectator) < 3)
_roundService.ForceEnd();
if (Utilities.GetPlayers().Count(player => player.PawnIsAlive) < 3)
roundService.ForceEnd();

return HookResult.Continue;
}
Expand All @@ -177,26 +174,25 @@ 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.NextFrame(() => {
Server.PrintToChatAll(StringUtils.FormatTTT(
$"{GetRole(playerWhoWasDamaged).FormatStringFullAfter(" has been found.")}"));
// Server.PrintToChatAll(StringUtils.FormatTTT(
// $"{GetRole(playerWhoWasDamaged).FormatStringFullAfter(" has been found.")}"));

if (attacker == playerWhoWasDamaged || attacker == null) return;
if (attacker == playerWhoWasDamaged || attacker == null)
return HookResult.Continue;

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;
}
Expand All @@ -205,26 +201,23 @@ 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!"));

Server.NextFrame(Clear);

Clear();
return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event,
GameEventInfo info) {
var player = @event.Userid;
Server.NextFrame(() => {
service.RemovePlayer(player);
if (service.Players().Count == 0)
_roundService.SetRoundStatus(RoundStatus.Paused);
});
if (player == null) return HookResult.Continue;
service.RemovePlayer(player);
if (service.Players().Count == 0)
roundService.SetRoundStatus(RoundStatus.Paused);

return HookResult.Continue;
}
Expand All @@ -234,7 +227,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) {
Expand Down
1 change: 0 additions & 1 deletion mod/TTT.Round/Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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))
Expand Down
2 changes: 1 addition & 1 deletion public/TTT.Formatting/Extensions/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static IView ToPlayerConsole(this IView view,

public static IView
ToPlayerChat(this IView view, CCSPlayerController player) {
if (!player.IsReal() || player.IsBot) return view;
if (player.IsBot) return view;

var writer = view.ToWriter();

Expand Down
1 change: 1 addition & 0 deletions src/TTT/TTT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\mod\TTT.Debug\TTT.Debug.csproj" />
<ProjectReference Include="..\..\public\TTT.Public\TTT.Public.csproj"/>
<ProjectReference Include="..\..\mod\TTT.Detective\TTT.Detective.csproj"/>
<ProjectReference Include="..\..\mod\TTT.Roles\TTT.Roles.csproj"/>
Expand Down
2 changes: 2 additions & 0 deletions src/TTT/TTTServiceCollection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API.Core;
using Microsoft.Extensions.DependencyInjection;
using TTT.Debug;
using TTT.Detective;
using TTT.Logs;
using TTT.Manager;
Expand All @@ -15,5 +16,6 @@ public void ConfigureServices(IServiceCollection serviceCollection) {
serviceCollection.AddDetectiveBehavior();
serviceCollection.AddLogsService();
serviceCollection.AddManagerService();
serviceCollection.AddDebugBehavior();
}
}

0 comments on commit e35aa38

Please sign in to comment.