Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix two pointing bugs #5766

Merged
merged 3 commits into from
Dec 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions Content.Server/Pointing/EntitySystems/PointingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Shared.Input;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.MobState.Components;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using JetBrains.Annotations;
Expand Down Expand Up @@ -76,9 +77,9 @@ private void SendMessage(EntityUid source, IEnumerable<ICommonSession> viewers,

public bool InRange(EntityUid pointer, EntityCoordinates coordinates)
{
if (EntityManager.HasComponent<GhostComponent>(pointer))
if (HasComp<GhostComponent>(pointer))
{
return EntityManager.GetComponent<TransformComponent>(pointer).Coordinates.InRange(EntityManager, coordinates, 15);
return Transform(pointer).Coordinates.InRange(EntityManager, coordinates, 15);
}
else
{
Expand All @@ -100,12 +101,19 @@ public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUi
return false;
}

if (EntityManager.EntityExists(pointed))
if (HasComp<PointingArrowComponent>(pointed))
{
// this is a pointing arrow. no pointing here...
return false;
}

// Checking mob state directly instead of some action blocker, as many action blockers are blocked for
// ghosts and there is no obvious choice for pointing.
if (TryComp(player, out MobStateComponent? mob) && mob.IsIncapacitated())
{
return false;
}

if (!InRange(player, coords))
{
player.PopupMessage(Loc.GetString("pointing-system-try-point-cannot-reach"));
Expand All @@ -117,7 +125,7 @@ public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUi
var arrow = EntityManager.SpawnEntity("pointingarrow", mapCoords);

var layer = (int) VisibilityFlags.Normal;
if (EntityManager.TryGetComponent(player, out VisibilityComponent? playerVisibility))
if (TryComp(player, out VisibilityComponent? playerVisibility))
{
var arrowVisibility = arrow.EnsureComponent<VisibilityComponent>();
layer = arrowVisibility.Layer = playerVisibility.Layer;
Expand All @@ -127,11 +135,11 @@ public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUi
bool ViewerPredicate(IPlayerSession playerSession)
{
if (playerSession.ContentData()?.Mind?.CurrentEntity is not {Valid: true} ent ||
!EntityManager.TryGetComponent<EyeComponent?>(ent, out var eyeComp) ||
!TryComp(ent, out EyeComponent? eyeComp) ||
(eyeComp.VisibilityMask & layer) == 0)
return false;

return EntityManager.GetComponent<TransformComponent>(ent).MapPosition.InRange(EntityManager.GetComponent<TransformComponent>(player).MapPosition, PointingRange);
return Transform(ent).MapPosition.InRange(Transform(player).MapPosition, PointingRange);
}

var viewers = Filter.Empty()
Expand All @@ -141,18 +149,21 @@ bool ViewerPredicate(IPlayerSession playerSession)
string selfMessage;
string viewerMessage;
string? viewerPointedAtMessage = null;
var playerName = Name(player);

if (EntityManager.EntityExists(pointed))
if (Exists(pointed))
{
var pointedName = Name(pointed);

selfMessage = player == pointed
? Loc.GetString("pointing-system-point-at-self")
: Loc.GetString("pointing-system-point-at-other", ("other", pointed));
: Loc.GetString("pointing-system-point-at-other", ("other", pointedName));

viewerMessage = player == pointed
? Loc.GetString("pointing-system-point-at-self-others", ("otherName", Name: EntityManager.GetComponent<MetaDataComponent>(player).EntityName), ("other", player))
: Loc.GetString("pointing-system-point-at-other-others", ("otherName", Name: EntityManager.GetComponent<MetaDataComponent>(player).EntityName), ("other", pointed));
? Loc.GetString("pointing-system-point-at-self-others", ("otherName", playerName), ("other", playerName))
: Loc.GetString("pointing-system-point-at-other-others", ("otherName", playerName), ("other", pointedName));

viewerPointedAtMessage = Loc.GetString("pointing-system-point-at-you-other", ("otherName", Name: EntityManager.GetComponent<MetaDataComponent>(player).EntityName));
viewerPointedAtMessage = Loc.GetString("pointing-system-point-at-you-other", ("otherName", playerName));
}
else
{
Expand All @@ -167,7 +178,7 @@ bool ViewerPredicate(IPlayerSession playerSession)

selfMessage = Loc.GetString("pointing-system-point-at-tile", ("tileName", tileDef.DisplayName));

viewerMessage = Loc.GetString("pointing-system-other-point-at-tile", ("otherName", Name: EntityManager.GetComponent<MetaDataComponent>(player).EntityName), ("tileName", tileDef.DisplayName));
viewerMessage = Loc.GetString("pointing-system-other-point-at-tile", ("otherName", playerName), ("tileName", tileDef.DisplayName));
}

_pointers[session] = _gameTiming.CurTime;
Expand Down Expand Up @@ -196,17 +207,19 @@ private void AddPointingVerb(GetOtherVerbsEvent args)
return;

//Check if the object is already being pointed at
if (EntityManager.HasComponent<PointingArrowComponent>(args.Target))
if (HasComp<PointingArrowComponent>(args.Target))
return;

var transform = Transform(args.Target);

if (!EntityManager.TryGetComponent<ActorComponent?>(args.User, out var actor) ||
!InRange(args.User, EntityManager.GetComponent<TransformComponent>(args.Target).Coordinates))
!InRange(args.User, transform.Coordinates))
return;

Verb verb = new();
verb.Text = Loc.GetString("pointing-verb-get-data-text");
verb.IconTexture = "/Textures/Interface/VerbIcons/point.svg.192dpi.png";
verb.Act = () => TryPoint(actor.PlayerSession, EntityManager.GetComponent<TransformComponent>(args.Target).Coordinates, args.Target); ;
verb.Act = () => TryPoint(actor.PlayerSession, transform.Coordinates, args.Target);
args.Verbs.Add(verb);
}

Expand Down