2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Examine;
|
2020-10-09 18:57:09 +02:00
|
|
|
using Robust.Client.Graphics;
|
2021-01-04 09:17:44 +01:00
|
|
|
using Robust.Client.Player;
|
2020-10-09 18:57:09 +02:00
|
|
|
using Robust.Client.ResourceManagement;
|
2021-09-20 08:40:22 +02:00
|
|
|
using Robust.Shared.Containers;
|
2021-03-09 04:33:41 -06:00
|
|
|
using Robust.Shared.Enums;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-01-04 09:17:44 +01:00
|
|
|
using Robust.Shared.IoC;
|
2020-10-09 18:57:09 +02:00
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Maths;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Shared.Physics;
|
2020-10-09 18:57:09 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Suspicion
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class TraitorOverlay : Overlay
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
|
|
|
|
private readonly IEntityManager _entityManager;
|
2021-01-04 09:17:44 +01:00
|
|
|
private readonly IPlayerManager _playerManager;
|
2020-10-09 18:57:09 +02:00
|
|
|
|
|
|
|
|
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
|
|
|
|
|
private readonly Font _font;
|
|
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
private readonly string _traitorText = Loc.GetString("traitor-overlay-traitor-text");
|
2020-10-09 18:57:09 +02:00
|
|
|
|
|
|
|
|
public TraitorOverlay(
|
|
|
|
|
IEntityManager entityManager,
|
2021-12-10 16:51:06 +11:00
|
|
|
IPlayerManager playerManager,
|
2021-12-10 05:47:21 +00:00
|
|
|
IResourceCache resourceCache)
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
2021-12-10 16:51:06 +11:00
|
|
|
_playerManager = playerManager;
|
2021-01-04 09:17:44 +01:00
|
|
|
|
2020-10-09 18:57:09 +02:00
|
|
|
_entityManager = entityManager;
|
|
|
|
|
|
|
|
|
|
_font = new VectorFont(resourceCache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-19 09:52:40 +02:00
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
2021-12-10 05:47:21 +00:00
|
|
|
var viewport = args.WorldAABB;
|
2020-10-09 18:57:09 +02:00
|
|
|
|
2021-01-04 09:17:44 +01:00
|
|
|
var ent = _playerManager.LocalPlayer?.ControlledEntity;
|
2021-12-06 14:00:39 +01:00
|
|
|
if (_entityManager.TryGetComponent(ent, out SuspicionRoleComponent? sus) != true)
|
2021-01-04 09:17:44 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
foreach (var (_, ally) in sus.Allies)
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
|
|
|
|
// Otherwise the entity can not exist yet
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!_entityManager.EntityExists(ally))
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
2021-01-10 15:50:04 -08:00
|
|
|
continue;
|
2020-10-09 18:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!_entityManager.TryGetComponent(ally, out IPhysBody? physics))
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
2021-01-10 15:50:04 -08:00
|
|
|
continue;
|
2020-10-09 18:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-10 16:51:06 +11:00
|
|
|
var allyXform = _entityManager.GetComponent<TransformComponent>(ally);
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
var entPosition = _entityManager.GetComponent<TransformComponent>(ent.Value).MapPosition;
|
2021-12-10 16:51:06 +11:00
|
|
|
var allyPosition = allyXform.MapPosition;
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!ExamineSystemShared.InRangeUnOccluded(entPosition, allyPosition, 15,
|
2021-01-04 09:17:44 +01:00
|
|
|
entity => entity == ent || entity == ally))
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
2021-01-10 15:50:04 -08:00
|
|
|
continue;
|
2020-10-09 18:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if not on the same map, continue
|
2021-12-10 16:51:06 +11:00
|
|
|
if (allyXform.MapID != args.Viewport.Eye!.Position.MapId
|
|
|
|
|
|| physics.Owner.IsInContainer())
|
2020-10-09 18:57:09 +02:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 16:51:06 +11:00
|
|
|
var (allyWorldPos, allyWorldRot) = allyXform.GetWorldPositionRotation();
|
|
|
|
|
|
|
|
|
|
var worldBox = physics.GetWorldAABB(allyWorldPos, allyWorldRot);
|
2020-10-09 18:57:09 +02:00
|
|
|
|
|
|
|
|
// if not on screen, or too small, continue
|
|
|
|
|
if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 16:51:06 +11:00
|
|
|
var screenCoordinates = args.ViewportControl!.WorldToScreen(worldBox.TopLeft + (0, 0.5f));
|
2021-06-26 03:26:57 +02:00
|
|
|
args.ScreenHandle.DrawString(_font, screenCoordinates, _traitorText, Color.OrangeRed);
|
2020-10-09 18:57:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|