143 lines
4.6 KiB
C#
143 lines
4.6 KiB
C#
using HintServiceMeow.Core.Enum;
|
|
using HintServiceMeow.Core.Models.Hints;
|
|
using HintServiceMeow.Core.Utilities;
|
|
using LabApi.Events.Arguments.PlayerEvents;
|
|
using LabApi.Events.Handlers;
|
|
using LabApi.Features;
|
|
using LabApi.Features.Console;
|
|
using LabApi.Features.Wrappers;
|
|
using MEC;
|
|
using PlayerRoles;
|
|
using PlayerRoles.PlayableScps.Scp079;
|
|
using PlayerRoles.PlayableScps.Scp096;
|
|
using PlayerRoles.PlayableScps.Scp3114;
|
|
|
|
namespace SCPTeamHint;
|
|
|
|
public class Plugin : LabApi.Loader.Features.Plugins.Plugin
|
|
{
|
|
private readonly object _hintsLock = new();
|
|
private readonly Dictionary<Player, Hint> _spectatorHints = new();
|
|
|
|
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()
|
|
{
|
|
Logger.Debug("Apple juice");
|
|
PlayerEvents.Joined += OnJoin;
|
|
PlayerEvents.Left += OnLeft;
|
|
|
|
Timing.CallContinuously(1, UpdateHints);
|
|
}
|
|
|
|
public override void Disable()
|
|
{
|
|
PlayerEvents.Joined -= OnJoin;
|
|
PlayerEvents.Left -= OnLeft;
|
|
}
|
|
|
|
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> ";
|
|
|
|
switch (player.RoleBase)
|
|
{
|
|
case Scp096Role scp:
|
|
text += "\n";
|
|
|
|
scp.SubroutineModule.TryGetSubroutine(out Scp096TargetsTracker tracker);
|
|
|
|
if (!tracker) break;
|
|
|
|
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;
|
|
}
|
|
|
|
hintTexts.Add(text);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |