96 lines
3.0 KiB
C#
96 lines
3.0 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 PlayerRoles;
|
|
using PlayerRoles.PlayableScps.Scp096;
|
|
using Timer = System.Timers.Timer;
|
|
|
|
namespace SCPTeamHint
|
|
{
|
|
public class Plugin : LabApi.Loader.Features.Plugins.Plugin
|
|
{
|
|
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 Dictionary<Player,Hint> _spectatorHints = new();
|
|
|
|
public override void Enable()
|
|
{
|
|
Logger.Debug("Apple juice");
|
|
PlayerEvents.Joined += OnJoin;
|
|
|
|
_timer = new Timer(1000);
|
|
_timer.Elapsed += (_,_) => UpdateHints();
|
|
_timer.Start();
|
|
}
|
|
|
|
public override void Disable()
|
|
{
|
|
PlayerEvents.Joined -= OnJoin;
|
|
_timer.Stop();
|
|
}
|
|
|
|
private void UpdateHints()
|
|
{
|
|
var hintTexts = new List<string>();
|
|
|
|
foreach (var player in Player.List)
|
|
{
|
|
if (!player.IsSCP) continue;
|
|
|
|
var text = $"{player.RoleBase.RoleName} | {player.HumeShield} | {player.Health} | {player.Zone}";
|
|
|
|
if (player.RoleBase is Scp096Role scp)
|
|
{
|
|
text += "\n";
|
|
|
|
scp.SubroutineModule.TryGetSubroutine(out Scp096TargetsTracker tracker);
|
|
|
|
text += $"Targets: {tracker.Targets.Count}";
|
|
}
|
|
|
|
hintTexts.Add(text);
|
|
}
|
|
|
|
foreach (var player in Player.List.Where(x=>!x.IsHost))
|
|
{
|
|
Logger.Debug($"Updating hint for {player.DisplayName}");
|
|
UpdateHint(player, string.Join("\n", hintTexts));
|
|
}
|
|
}
|
|
|
|
private void UpdateHint(Player player, string hintText)
|
|
{
|
|
var hint = _spectatorHints[player];
|
|
|
|
Logger.Debug($"Player {player.Nickname} is on team {player.RoleBase.Team} | hide: {player.RoleBase.Team != Team.SCPs}");
|
|
hint.Hide = player.RoleBase.Team != Team.SCPs;
|
|
|
|
hint.Text = hintText;
|
|
}
|
|
|
|
private void OnJoin(PlayerJoinedEventArgs ev)
|
|
{
|
|
|
|
var hint = new Hint
|
|
{
|
|
Text = "Apfelsaft", Alignment = HintAlignment.Left, YCoordinate = 300, Hide = true
|
|
};
|
|
|
|
var playerDisplay = PlayerDisplay.Get(ev.Player);
|
|
playerDisplay.AddHint(hint);
|
|
|
|
_spectatorHints[ev.Player] = hint;
|
|
|
|
}
|
|
}
|
|
} |