refactor
This commit is contained in:
+114
-120
@@ -12,144 +12,138 @@ using PlayerRoles.PlayableScps.Scp096;
|
||||
using PlayerRoles.PlayableScps.Scp3114;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
namespace SCPTeamHint
|
||||
namespace SCPTeamHint;
|
||||
|
||||
public class Plugin : LabApi.Loader.Features.Plugins.Plugin
|
||||
{
|
||||
public class Plugin : LabApi.Loader.Features.Plugins.Plugin
|
||||
private readonly object _hintsLock = new();
|
||||
private readonly Dictionary<Player, Hint> _spectatorHints = new();
|
||||
|
||||
private Timer _timer;
|
||||
public override string Name => "SCPTeamHint";
|
||||
public override string Author => "HoherGeist, Code002Lover";
|
||||
public override Version Version { get; } = new(1, 0, 0);
|
||||
public override string Description => "Displays information about your SCP Teammates";
|
||||
public override Version RequiredApiVersion { get; } = new(LabApiProperties.CompiledVersion);
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
public override string Name => "SCPTeamHint";
|
||||
public override string Author => "HoherGeist, Code002Lover";
|
||||
public override Version Version { get; } = new(1, 0, 0);
|
||||
public override string Description => "Displays information about your SCP Teammates";
|
||||
public override Version RequiredApiVersion { get; } = new(LabApiProperties.CompiledVersion);
|
||||
|
||||
private Timer _timer;
|
||||
private readonly object _hintsLock = new();
|
||||
private readonly Dictionary<Player,Hint> _spectatorHints = new();
|
||||
|
||||
public override void Enable()
|
||||
Logger.Debug("Apple juice");
|
||||
PlayerEvents.Joined += OnJoin;
|
||||
PlayerEvents.Left += OnLeft;
|
||||
|
||||
_timer = new Timer(1000);
|
||||
_timer.Elapsed += (_, _) => UpdateHints();
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
PlayerEvents.Joined -= OnJoin;
|
||||
PlayerEvents.Left -= OnLeft;
|
||||
_timer?.Stop();
|
||||
_timer?.Dispose();
|
||||
_timer = null;
|
||||
}
|
||||
|
||||
private void UpdateHints()
|
||||
{
|
||||
var hintTexts = new List<string>();
|
||||
|
||||
lock (_hintsLock)
|
||||
{
|
||||
Logger.Debug("Apple juice");
|
||||
PlayerEvents.Joined += OnJoin;
|
||||
PlayerEvents.Left += OnLeft;
|
||||
|
||||
_timer = new Timer(1000);
|
||||
_timer.Elapsed += (_,_) => UpdateHints();
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
PlayerEvents.Joined -= OnJoin;
|
||||
PlayerEvents.Left -= OnLeft;
|
||||
_timer?.Stop();
|
||||
_timer?.Dispose();
|
||||
_timer = null;
|
||||
}
|
||||
|
||||
private void UpdateHints()
|
||||
{
|
||||
var hintTexts = new List<string>();
|
||||
|
||||
lock (_hintsLock)
|
||||
foreach (var player in Player.ReadyList.Where(x => !x.IsHost && !x.IsDummy && x.IsSCP))
|
||||
{
|
||||
var text =
|
||||
$" <size=25><color=red>{player.RoleBase.RoleName}</color> | <color=#6761cd>{player.HumeShield}</color> | <color=#da0101>{player.Health}</color> | <color=grey>{player.Zone}</color></size> ";
|
||||
|
||||
|
||||
foreach (var player in Player.ReadyList.Where(x => !x.IsHost && !x.IsDummy && x.IsSCP))
|
||||
switch (player.RoleBase)
|
||||
{
|
||||
var text =
|
||||
$" <size=25><color=red>{player.RoleBase.RoleName}</color> | <color=#6761cd>{player.HumeShield}</color> | <color=#da0101>{player.Health}</color> | <color=grey>{player.Zone}</color></size> ";
|
||||
case Scp096Role scp:
|
||||
text += "\n";
|
||||
|
||||
switch (player.RoleBase)
|
||||
scp.SubroutineModule.TryGetSubroutine(out Scp096TargetsTracker tracker);
|
||||
|
||||
if (!tracker) break;
|
||||
|
||||
text += $"Targets: {tracker.Targets.Count}";
|
||||
break;
|
||||
case Scp3114Role scp3114:
|
||||
{
|
||||
case Scp096Role scp:
|
||||
text += "\n";
|
||||
text += "\n";
|
||||
|
||||
scp.SubroutineModule.TryGetSubroutine(out Scp096TargetsTracker tracker);
|
||||
|
||||
if(!tracker) break;
|
||||
var stolenRole = scp3114.CurIdentity.StolenRole;
|
||||
|
||||
text += $"Targets: {tracker.Targets.Count}";
|
||||
break;
|
||||
case Scp3114Role scp3114:
|
||||
{
|
||||
text += "\n";
|
||||
|
||||
var stolenRole = scp3114.CurIdentity.StolenRole;
|
||||
|
||||
text += $" {stolenRole}";
|
||||
break;
|
||||
}
|
||||
case Scp079Role scp079:
|
||||
text =
|
||||
$" <size=25><color=red>{player.RoleBase.RoleName}</color> | <color=grey>{scp079.CurrentCamera.Room.Zone}</color></size> ";
|
||||
text += "\n";
|
||||
|
||||
scp079.SubroutineModule.TryGetSubroutine(out Scp079AuxManager auxManager);
|
||||
scp079.SubroutineModule.TryGetSubroutine(out Scp079TierManager tierManager);
|
||||
|
||||
if(!auxManager || !tierManager) break;
|
||||
|
||||
text +=
|
||||
$" <color=grey>AUX: {auxManager.CurrentAuxFloored} / {auxManager.MaxAux} | Level {tierManager.AccessTierLevel}</color>";
|
||||
break;
|
||||
text += $" {stolenRole}";
|
||||
break;
|
||||
}
|
||||
case Scp079Role scp079:
|
||||
text =
|
||||
$" <size=25><color=red>{player.RoleBase.RoleName}</color> | <color=grey>{scp079.CurrentCamera.Room.Zone}</color></size> ";
|
||||
text += "\n";
|
||||
|
||||
hintTexts.Add(text);
|
||||
scp079.SubroutineModule.TryGetSubroutine(out Scp079AuxManager auxManager);
|
||||
scp079.SubroutineModule.TryGetSubroutine(out Scp079TierManager tierManager);
|
||||
|
||||
if (!auxManager || !tierManager) break;
|
||||
|
||||
text +=
|
||||
$" <color=grey>AUX: {auxManager.CurrentAuxFloored} / {auxManager.MaxAux} | Level {tierManager.AccessTierLevel}</color>";
|
||||
break;
|
||||
}
|
||||
|
||||
var hintText = string.Join("\n", hintTexts);
|
||||
|
||||
foreach (var player in Player.ReadyList.Where(x => !x.IsHost && !x.IsDummy))
|
||||
{
|
||||
Logger.Debug($"Updating hint for {player.DisplayName}");
|
||||
UpdateHint(player, hintText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHint(Player player, string hintText)
|
||||
{
|
||||
if (!_spectatorHints.TryGetValue(player, out var hint))
|
||||
{
|
||||
Logger.Debug($"No hint found for player {player.DisplayName}");
|
||||
return;
|
||||
hintTexts.Add(text);
|
||||
}
|
||||
|
||||
Logger.Debug($"Player {player.Nickname} is on team {player.RoleBase.Team} | hide: {player.RoleBase.Team != Team.SCPs}");
|
||||
hint.Hide = player.RoleBase.Team != Team.SCPs;
|
||||
if (!hint.Hide)
|
||||
var hintText = string.Join("\n", hintTexts);
|
||||
|
||||
foreach (var player in Player.ReadyList.Where(x => !x.IsHost && !x.IsDummy))
|
||||
{
|
||||
hint.Text = hintText;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnJoin(PlayerJoinedEventArgs ev)
|
||||
{
|
||||
if(ev.Player.IsDummy || ev.Player.IsHost) return;
|
||||
|
||||
var hint = new Hint
|
||||
{
|
||||
Text = "", Alignment = HintAlignment.Left, YCoordinate = 100, Hide = true
|
||||
};
|
||||
|
||||
var playerDisplay = PlayerDisplay.Get(ev.Player);
|
||||
playerDisplay.AddHint(hint);
|
||||
|
||||
lock (_hintsLock)
|
||||
{
|
||||
_spectatorHints[ev.Player] = hint;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnLeft(PlayerLeftEventArgs ev)
|
||||
{
|
||||
if(ev.Player.IsDummy || ev.Player.IsHost) return;
|
||||
|
||||
lock (_hintsLock)
|
||||
{
|
||||
_spectatorHints.Remove(ev.Player);
|
||||
Logger.Debug($"Updating hint for {player.DisplayName}");
|
||||
UpdateHint(player, hintText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHint(Player player, string hintText)
|
||||
{
|
||||
if (!_spectatorHints.TryGetValue(player, out var hint))
|
||||
{
|
||||
Logger.Debug($"No hint found for player {player.DisplayName}");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Debug(
|
||||
$"Player {player.Nickname} is on team {player.RoleBase.Team} | hide: {player.RoleBase.Team != Team.SCPs}");
|
||||
hint.Hide = player.RoleBase.Team != Team.SCPs;
|
||||
if (!hint.Hide) hint.Text = hintText;
|
||||
}
|
||||
|
||||
private void OnJoin(PlayerJoinedEventArgs ev)
|
||||
{
|
||||
if (ev.Player.IsDummy || ev.Player.IsHost) return;
|
||||
|
||||
var hint = new Hint
|
||||
{
|
||||
Text = "", Alignment = HintAlignment.Left, YCoordinate = 100, Hide = true
|
||||
};
|
||||
|
||||
var playerDisplay = PlayerDisplay.Get(ev.Player);
|
||||
playerDisplay.AddHint(hint);
|
||||
|
||||
lock (_hintsLock)
|
||||
{
|
||||
_spectatorHints[ev.Player] = hint;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLeft(PlayerLeftEventArgs ev)
|
||||
{
|
||||
if (ev.Player.IsDummy || ev.Player.IsHost) return;
|
||||
|
||||
lock (_hintsLock)
|
||||
{
|
||||
_spectatorHints.Remove(ev.Player);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user