diff --git a/Content.Client/State/GameScreenBase.cs b/Content.Client/State/GameScreenBase.cs index 28c1bf6a46..a673870c62 100644 --- a/Content.Client/State/GameScreenBase.cs +++ b/Content.Client/State/GameScreenBase.cs @@ -60,7 +60,7 @@ namespace Content.Client.State var playerPos = _playerManager.LocalPlayer.ControlledEntity.Transform.MapPosition; var entityPos = entityToClick.Transform.WorldPosition; inRange = _entitySystemManager.GetEntitySystem() - .InRangeUnobstructed(playerPos,entityPos,ignoredEnt: _playerManager.LocalPlayer.ControlledEntity); + .InRangeUnobstructed(playerPos, entityPos, predicate:entity => entity != _playerManager.LocalPlayer.ControlledEntity || entity != entityToClick); } InteractionOutlineComponent outline; diff --git a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs index a34ca1053b..756968907d 100644 --- a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs +++ b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs @@ -1,13 +1,15 @@ +using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Mobs; using JetBrains.Annotations; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.IoC; namespace Content.Shared.GameObjects.EntitySystems { public abstract class ExamineSystemShared : EntitySystem { - public const float ExamineRange = 8f; + public const float ExamineRange = 16f; public const float ExamineRangeSquared = ExamineRange * ExamineRange; [Pure] @@ -28,8 +30,10 @@ namespace Content.Shared.GameObjects.EntitySystems return false; } - var delta = examined.Transform.WorldPosition - examiner.Transform.WorldPosition; - return delta.LengthSquared <= ExamineRangeSquared; + return IoCManager.Resolve() + .GetEntitySystem() + .InRangeUnobstructed(examiner.Transform.MapPosition, examined.Transform.MapPosition.Position, + ExamineRange, predicate: entity => entity == examiner || entity == examined, insideBlockerValid:true); } } } diff --git a/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs b/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs index 9aaddba8a6..91947c35c0 100644 --- a/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs @@ -1,4 +1,5 @@ -using Content.Shared.Physics; +using System; +using Content.Shared.Physics; using JetBrains.Annotations; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; @@ -34,12 +35,12 @@ namespace Content.Server.GameObjects.EntitySystems /// Other set of coordinates to use. /// maximum distance between the two sets of coordinates. /// the mask to check for collisions - /// the entity to be ignored when checking for collisions. + /// . /// Map manager containing the two GridIds. /// if coordinates inside obstructions count as obstructed or not /// True if the two points are within a given range without being obstructed. public bool InRangeUnobstructed(MapCoordinates coords, Vector2 otherCoords, float range = InteractionRange, - int collisionMask = (int)CollisionGroup.Impassable, IEntity ignoredEnt = null, bool insideBlockerValid = false) + int collisionMask = (int)CollisionGroup.Impassable, Func predicate = null, bool insideBlockerValid = false) { var dir = otherCoords - coords.Position; @@ -47,18 +48,37 @@ namespace Content.Server.GameObjects.EntitySystems if (range > 0f && !(dir.LengthSquared <= range * range)) return false; var ray = new CollisionRay(coords.Position, dir.Normalized, collisionMask); - var rayResults = _physicsManager.IntersectRay(coords.MapId, ray, dir.Length, ignoredEnt, true); - if(!rayResults.DidHitObject || (insideBlockerValid && rayResults.DidHitObject && rayResults.Distance < 1f)) + var rayResults = _physicsManager.IntersectRayWithPredicate(coords.MapId, ray, dir.Length, predicate, true); + if(!rayResults.DidHitObject || (insideBlockerValid && rayResults.DidHitObject && (rayResults.HitPos - otherCoords).Length < 1f)) { _mapManager.TryFindGridAt(coords, out var mapGrid); var srcPos = mapGrid.MapToGrid(coords); var destPos = new GridCoordinates(otherCoords, mapGrid); - if (srcPos.InRange(_mapManager, destPos, InteractionRange)) + if (srcPos.InRange(_mapManager, destPos, range)) { return true; } } return false; } + + /// + /// Checks that these coordinates are within a certain distance without any + /// entity that matches the collision mask obstructing them. + /// If the is zero or negative, + /// this method will only check if nothing obstructs the two sets of coordinates.. + /// + /// Set of coordinates to use. + /// Other set of coordinates to use. + /// maximum distance between the two sets of coordinates. + /// the mask to check for collisions + /// the entity to be ignored when checking for collisions. + /// Map manager containing the two GridIds. + /// if coordinates inside obstructions count as obstructed or not + /// True if the two points are within a given range without being obstructed. + public bool InRangeUnobstructed(MapCoordinates coords, Vector2 otherCoords, float range = InteractionRange, + int collisionMask = (int)CollisionGroup.Impassable, IEntity ignoredEnt = null, bool insideBlockerValid = false) => + InRangeUnobstructed(coords, otherCoords, range, collisionMask, + ignoredEnt == null ? null : (Func)(entity => ignoredEnt == entity), insideBlockerValid); } }