From 04cf4d4a20103811a6894ca548288d93ce7f5dc2 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Wed, 28 Oct 2020 13:04:29 +0100 Subject: [PATCH] Fix ignoreInsideBlocker not working correctly for inRangeUnobstructed and inRangeUnoccluded (#2417) * Fix ignoreInsideBlocker not working correctly for range checks * Other way around --- .../EntitySystems/ExamineSystemShared.cs | 21 +++++++++++++++++-- .../EntitySystems/SharedInteractionSystem.cs | 20 ++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs index 8a8310aad3..a28c7b6d35 100644 --- a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs +++ b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs @@ -4,6 +4,8 @@ using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Shared.Containers; +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Map; @@ -88,9 +90,24 @@ namespace Content.Shared.GameObjects.EntitySystems if (!ignoreInsideBlocker) return false; - if (rayResults.Count <= 0) return false; + foreach (var result in rayResults) + { + if (!result.HitEntity.TryGetComponent(out OccluderComponent o)) + { + continue; + } - return (rayResults[0].HitPos - other.Position).Length < 1f; + var bBox = o.BoundingBox.Translated(o.Owner.Transform.WorldPosition); + + if (bBox.Contains(origin.Position) || bBox.Contains(other.Position)) + { + continue; + } + + return false; + } + + return true; } public static bool InRangeUnOccluded(IEntity origin, IEntity other, float range, Ignored predicate, bool ignoreInsideBlocker = true) diff --git a/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs b/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs index d6c2122457..838dafcb09 100644 --- a/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs @@ -3,6 +3,7 @@ using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Physics; using JetBrains.Annotations; +using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Physics; @@ -132,9 +133,24 @@ namespace Content.Shared.GameObjects.EntitySystems if (!ignoreInsideBlocker) return false; - if (rayResults.Count <= 0) return false; + foreach (var result in rayResults) + { + if (!result.HitEntity.TryGetComponent(out IPhysicsComponent p)) + { + continue; + } - return (rayResults[0].HitPos - other.Position).Length < 1f; + var bBox = p.WorldAABB; + + if (bBox.Contains(origin.Position) || bBox.Contains(other.Position)) + { + continue; + } + + return false; + } + + return true; } ///