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

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Jul 20, 2024
1 parent abe2f6d commit 6334991
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 274 deletions.
7 changes: 0 additions & 7 deletions TTT.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mod", "mod", "{14FF3D75-F9C
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TTT", "src\TTT\TTT.csproj", "{A917B0F5-762F-4C4A-9F50-02BA4A0C6B63}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Generic", "src\TTT.Generic\TTT.Generic.csproj", "{953B2EA0-EFFC-475D-85CA-F7E5224BBFE1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TTT.Public", "public\TTT.Public\TTT.Public.csproj", "{8B006910-4BE0-491C-9F28-C60443E3251D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TTT.Detective", "mod\TTT.Detective\TTT.Detective.csproj", "{B6A65935-2233-4C74-A7EA-C2D64967CE52}"
Expand Down Expand Up @@ -44,10 +42,6 @@ Global
{A917B0F5-762F-4C4A-9F50-02BA4A0C6B63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A917B0F5-762F-4C4A-9F50-02BA4A0C6B63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A917B0F5-762F-4C4A-9F50-02BA4A0C6B63}.Release|Any CPU.Build.0 = Release|Any CPU
{953B2EA0-EFFC-475D-85CA-F7E5224BBFE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{953B2EA0-EFFC-475D-85CA-F7E5224BBFE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{953B2EA0-EFFC-475D-85CA-F7E5224BBFE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{953B2EA0-EFFC-475D-85CA-F7E5224BBFE1}.Release|Any CPU.Build.0 = Release|Any CPU
{8B006910-4BE0-491C-9F28-C60443E3251D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B006910-4BE0-491C-9F28-C60443E3251D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B006910-4BE0-491C-9F28-C60443E3251D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -87,7 +81,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A917B0F5-762F-4C4A-9F50-02BA4A0C6B63} = {C7CCF187-9F99-4091-B092-6397C35BE9F1}
{953B2EA0-EFFC-475D-85CA-F7E5224BBFE1} = {C7CCF187-9F99-4091-B092-6397C35BE9F1}
{8B006910-4BE0-491C-9F28-C60443E3251D} = {C84CEB1F-0132-43EF-9A5F-12C7AA08B8E7}
{B6A65935-2233-4C74-A7EA-C2D64967CE52} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{0E7A451E-D56F-4D96-9B5C-5F1B0A6B0656} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
Expand Down
12 changes: 2 additions & 10 deletions mod/TTT.Detective/DetectiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class DetectiveManager(IPlayerService roleService)
public void Start(BasePlugin parent) {
parent.RegisterListener<Listeners.OnTick>(() => {
foreach (var player in Utilities.GetPlayers()
.Where(player => player.IsValid && player.IsReal())
.Where(player => (player.Buttons & PlayerButtons.Use) != 0))
OnPlayerUse(player);
});
Expand Down Expand Up @@ -63,15 +62,11 @@ public HookResult OnZeus(DynamicHook hook) {
private void OnPlayerUse(CCSPlayerController player) { IdentifyBody(player); }

private void IdentifyBody(CCSPlayerController caller) {
//add states

if (roleService.GetPlayer(caller).PlayerRole() != Role.Detective) return;

var entity = caller.GetClientRagdollAimTarget();

if (entity == null) return;

if (entity.PawnIsAlive) return;
if (entity == null || !entity.PawnIsAlive) return;

var player = roleService.GetPlayer(entity);

Expand All @@ -95,7 +90,6 @@ private void IdentifyBody(CCSPlayerController caller) {
.PlayerRole()
.FormatStringFullAfter(killerEntity.PlayerName));


player.SetFound(true);

Server.NextFrame(() => { Server.PrintToChatAll(message); });
Expand All @@ -117,9 +111,7 @@ private void IdentifyBody(CCSPlayerController caller) {
if (player_pawn == null || !player_pawn.IsValid) return null;

// controller valid
if (player_pawn.OriginalController == null
|| !player_pawn.OriginalController.IsValid)
return null;
if (player_pawn.OriginalController is not { IsValid: true }) return null;

// any further validity is up to the caller
return player_pawn.OriginalController.Value;
Expand Down
26 changes: 13 additions & 13 deletions mod/TTT.Logs/LogBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,49 @@
namespace TTT.Logs;

public class LogBehavior : ILogService, IPluginBehavior {
private readonly Dictionary<int, IRoundLogs> _logs = new();
private int _round = 1;
private readonly Dictionary<int, IRoundLogs> logs = new();
private int currentRound = 1;

public int GetCurrentRound() { return _round; }
public int GetCurrentRound() { return currentRound; }

public void AddLog(Action action) { _logs[_round].AddLog(action); }
public void AddLog(Action action) { logs[currentRound].AddLog(action); }

public bool PrintLogs(int round) {
if (_logs.ContainsKey(round)) return false;
foreach (var player in Utilities.GetPlayers().Where(plr => plr.IsReal()))
PrintToPlayer(player, round);
if (logs.ContainsKey(round)) return false;
foreach (var player in Utilities.GetPlayers()) PrintToPlayer(player, round);

PrintToConsole(round);
return true;
}

public bool PrintToPlayer(CCSPlayerController player, int round) {
if (!_logs.ContainsKey(round)) return false;
if (!logs.ContainsKey(round)) return false;
player.PrintToConsole(GetLogs(round).FormattedLogs());
return true;
}

public bool PrintToConsole(int round) {
if (!_logs.ContainsKey(round)) return false;
if (!logs.ContainsKey(round)) return false;
Server.PrintToConsole(GetLogs(round).FormattedLogs());
return true;
}

public IRoundLogs GetLogs(int round) { return _logs[round]; }
public IRoundLogs GetLogs(int round) { return logs[round]; }

public void CreateRound(int round) { _logs.Add(round, new RoundLog(round)); }
public void CreateRound(int round) { logs.Add(round, new RoundLog(round)); }

public void Start(BasePlugin plugin) { }

[GameEventHandler]
public HookResult OnRoundStart(EventRoundStart _, GameEventInfo __) {
CreateRound(_round++);
// TODO: This looks wrong, should be ++currentRound
CreateRound(currentRound++);
return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnRoundEnd(EventRoundEnd _, GameEventInfo __) {
PrintLogs(_round);
PrintLogs(currentRound);
return HookResult.Continue;
}
}
19 changes: 6 additions & 13 deletions mod/TTT.Logs/LogsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class LogsCommand(ILogService service) : IPluginBehavior {
public void Start(BasePlugin plugin) { }

[ConsoleCommand("css_logs", "Prints logs to console")]
[CommandHelper(0, whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void Command_Logs(CCSPlayerController? executor, CommandInfo info) {
if (!AdminManager.PlayerHasPermissions(executor, "@css/kick")) {
info.ReplyToCommand(
Expand All @@ -23,20 +22,14 @@ public void Command_Logs(CCSPlayerController? executor, CommandInfo info) {
return;
}

var roundIdString = info.GetArg(1);

var roundId = service.GetCurrentRound();

if (string.IsNullOrEmpty(roundIdString)
&& !int.TryParse(roundIdString, out roundId)) {
info.ReplyToCommand(
StringUtils.FormatTTT("Invalid round id, /logs <roundId>"));
return;
}

if (roundId <= 0) {
info.ReplyToCommand(StringUtils.FormatTTT("Invalid round id"));
return;
if (info.ArgCount == 2) {
if (!int.TryParse(info.GetArg(1), out roundId) || roundId <= 0) {
info.ReplyToCommand(
StringUtils.FormatTTT("Invalid round id, /logs <roundId>"));
return;
}
}

if (executor == null) {
Expand Down
66 changes: 31 additions & 35 deletions mod/TTT.Manager/InfoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,39 @@

namespace TTT.Manager;

public class InfoManager : IPluginBehavior {
private readonly IRoundService _manager;
public class InfoManager(IPlayerService playerService, IRoleService manager)
: IPluginBehavior {
private readonly IRoundService manager = manager.GetRoundService();

private readonly
Dictionary<CCSPlayerController, Tuple<CCSPlayerController, Role>>
_playerLookAtRole = new();

private readonly IPlayerService _playerService;
playerLookAtRole = new();

private readonly Dictionary<CCSPlayerController, Tuple<string, Role>>
_spectatorLookAtRole = new();

public InfoManager(IPlayerService playerService, IRoleService manager) {
_playerService = playerService;
_manager = manager.GetRoundService();
}
spectatorLookAtRole = new();

public void Start(BasePlugin plugin) {
plugin.RegisterListener<Listeners.OnTick>(OnTick);
plugin.AddTimer(0.1f, OnTickAll, TimerFlags.REPEAT);
}

public void Reset() {
_playerLookAtRole.Clear();
_spectatorLookAtRole.Clear();
playerLookAtRole.Clear();
spectatorLookAtRole.Clear();
}

public void RegisterLookAtRole(CCSPlayerController player,
Tuple<CCSPlayerController, Role> role) {
_playerLookAtRole.TryAdd(player, role);
playerLookAtRole.TryAdd(player, role);
}

public void RemoveLookAtRole(CCSPlayerController player) {
_playerLookAtRole.Remove(player);
playerLookAtRole.Remove(player);
}

public void OnTick() {
foreach (var gamePlayer in _playerService.Players()) {
if (_manager.GetRoundStatus() != RoundStatus.Started) return;

if (manager.GetRoundStatus() != RoundStatus.Started) return;
foreach (var gamePlayer in playerService.Players()) {
var player = gamePlayer.Player();

if (player == null) continue;
Expand All @@ -62,10 +55,9 @@ public void OnTick() {

if (!player.PawnIsAlive) continue;

if (!_playerLookAtRole.TryGetValue(player, out var value)) {
Server.NextFrame(()
=> player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()}"));
if (!playerLookAtRole.TryGetValue(player, out var value)) {
player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()}");
continue;
}

Expand All @@ -81,24 +73,24 @@ public void OnTick() {
public void
HandleDeadTarget(CCSPlayerController player, Role playerRole,
CCSPlayerController target, Role targetRole) {
Server.NextFrame(() => player.PrintToCenterHtml(
player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()} <br>"
+ $"<font class='fontsize=l' color='red'>{target.PlayerName}'s Corpse <br>"
+ $"<font class='fontsize=m' color='yellow'>{target.PlayerName}'s Role: {targetRole.GetCenterRole()}"));
+ $"<font class='fontsize=m' color='yellow'>{target.PlayerName}'s Role: {targetRole.GetCenterRole()}");
}

public void HandleAliveTarget(CCSPlayerController player, Role playerRole,
CCSPlayerController target, Role targetRole) {
switch (targetRole) {
case Role.Detective:
Server.NextFrame(() => player.PrintToCenterHtml(
player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()} <br>"
+ $"<font class='fontsize=m' color='yellow'>{target.PlayerName}'s Role: {targetRole.GetCenterRole()}"));
+ $"<font class='fontsize=m' color='yellow'>{target.PlayerName}'s Role: {targetRole.GetCenterRole()}");
return;
case Role.Traitor when playerRole == Role.Traitor:
Server.NextFrame(() => player.PrintToCenterHtml(
player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()} <br>"
+ $"<font class='fontsize=m' color='maroon'>{target.PlayerName}'s Role: {targetRole.GetCenterRole()}"));
+ $"<font class='fontsize=m' color='maroon'>{target.PlayerName}'s Role: {targetRole.GetCenterRole()}");
return;
default:
Server.NextFrame(() => player.PrintToCenterHtml(
Expand All @@ -109,22 +101,25 @@ public void HandleAliveTarget(CCSPlayerController player, Role playerRole,
}

public void OnTickAll() {
var players = _playerService.Players().Select(plr => plr.Player());
var players = playerService.Players()
.Select(plr => plr.Player())
.Where(p => p != null && p.IsReal())
.ToList();

_playerLookAtRole.Clear();
playerLookAtRole.Clear();

foreach (var player in players) {
if (player == null) continue;
if (!player.IsReal()) continue;

var target = player.GetClientPlayerAimTarget();

if (target == null) continue;
if (target == null || !target.IsReal()) continue;
if (!target.IsReal()) continue;

RegisterLookAtRole(player,
new Tuple<CCSPlayerController, Role>(target,
_playerService.GetPlayer(target).PlayerRole()));
playerService.GetPlayer(target).PlayerRole()));
}
}

Expand All @@ -134,11 +129,12 @@ private HookResult OnPlayerSpectateChange(EventSpecTargetUpdated @event,
var player = @event.Userid;
var target = new CCSPlayerController(@event.Target);

if (!player.IsReal() || !target.IsReal()) return HookResult.Continue;
if (player == null || !player.IsReal() || !target.IsReal())
return HookResult.Continue;

_spectatorLookAtRole.TryAdd(player,
spectatorLookAtRole.TryAdd(player,
new Tuple<string, Role>(target.PlayerName,
_playerService.GetPlayer(target).PlayerRole()));
playerService.GetPlayer(target).PlayerRole()));

return HookResult.Continue;
}
Expand Down
18 changes: 5 additions & 13 deletions mod/TTT.Manager/MuteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,16 @@ public void UnMute(CCSPlayerController player) {
}

public void UnMuteAll() {
foreach (var player in Utilities.GetPlayers()
.Where(player => player.IsReal() && player.Team == CsTeam.Terrorist))
UnMute(player);
foreach (var player in Utilities.GetPlayers()
.Where(player
=> player.IsReal() && player.Team == CsTeam.CounterTerrorist))
=> player.Team is CsTeam.Terrorist or CsTeam.CounterTerrorist))
UnMute(player);
}

public void MuteAll() {
foreach (var player in Utilities.GetPlayers()
.Where(player => player.IsReal() && player.Team == CsTeam.Terrorist))
Mute(player);
foreach (var player in Utilities.GetPlayers()
.Where(player
=> player.IsReal() && player.Team == CsTeam.CounterTerrorist))
=> player.Team is CsTeam.Terrorist or CsTeam.CounterTerrorist))
Mute(player);
}

Expand All @@ -59,18 +53,16 @@ public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) {

private void OnPlayerSpeak(int playerSlot) {
var player = Utilities.GetPlayerFromSlot(playerSlot);
if (!player.IsReal()) return;
if (player == null || !player.IsReal()) return;

if (!player.PawnIsAlive && !BypassMute(player)) {
// Normal players can't speak when dead
Mute(player);
Server.NextFrame(() => player.PrintToCenter("You are dead and muted!"));
player.PrintToCenter("You are dead and muted!");
return;
}

if (IsMuted(player)) {
Server.NextFrame(() => player.PrintToCenter("You are muted!"));
}
if (IsMuted(player)) player.PrintToCenter("You are muted!");
}

private bool IsMuted(CCSPlayerController player) {
Expand Down
13 changes: 1 addition & 12 deletions mod/TTT.Manager/TraitorRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,13 @@ public void Start(BasePlugin plugin) {
});
}


public void OpenTraitorRoom(CCSPlayerController player) {
if ((player.Buttons & PlayerButtons.Use) == 0) return;

var traitorRoom = player.GetClientPlayerTraitorRoom();

if (traitorRoom == null) {
Server.NextFrame(() => player.PrintToCenter("No door has been found!"));
return;
}

if (traitorRoom.Globalname is not "traitor_door") {
Server.NextFrame(
() => player.PrintToCenter("Door is not a traitor room!"));
return;
}
if (traitorRoom?.Globalname != "traitor_door") return;

traitorRoom.AcceptInput("Open");
Server.NextFrame(() => player.PrintToCenter("Found traitor room!"));
}
}
Loading

0 comments on commit 6334991

Please sign in to comment.