From f8a64bcd5cdeb846d2ab1382f3896ed2b0e59354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= <6766154+Zumorica@users.noreply.github.com> Date: Wed, 12 Feb 2020 00:01:44 +0100 Subject: [PATCH] Prevent items from being dropped across impassable entities (#670) --- .../GameObjects/EntitySystems/HandsSystem.cs | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs index 902511511f..94b1b2b5d7 100644 --- a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs @@ -1,4 +1,4 @@ -using System; +using System; using Content.Server.GameObjects.Components; using Content.Server.GameObjects.Components.Stack; using Content.Server.Interfaces.GameObjects; @@ -15,8 +15,10 @@ using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; +using Robust.Shared.Interfaces.Physics; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; +using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; @@ -124,18 +126,25 @@ namespace Content.Server.GameObjects.EntitySystems if (handsComp.GetActiveHand == null) return false; - if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange)) - { - handsComp.Drop(handsComp.ActiveIndex, coords); - } - else - { - var entCoords = ent.Transform.GridPosition.Position; - var entToDesiredDropCoords = coords.Position - entCoords; - var clampedDropCoords = ((entToDesiredDropCoords.Normalized * InteractionSystem.InteractionRange) + entCoords); + var dir = (coords.Position - ent.Transform.GridPosition.Position); + var ray = new CollisionRay(ent.Transform.GridPosition.Position, dir.Normalized, (int) CollisionGroup.Impassable); + var rayResults = IoCManager.Resolve().IntersectRay(ent.Transform.MapID, ray, dir.Length, ent); - handsComp.Drop(handsComp.ActiveIndex, new GridCoordinates(clampedDropCoords, coords.GridID)); - } + if(!rayResults.DidHitObject) + if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange)) + { + handsComp.Drop(handsComp.ActiveIndex, coords); + } + else + { + var entCoords = ent.Transform.GridPosition.Position; + var entToDesiredDropCoords = coords.Position - entCoords; + var clampedDropCoords = ((entToDesiredDropCoords.Normalized * InteractionSystem.InteractionRange) + entCoords); + + handsComp.Drop(handsComp.ActiveIndex, new GridCoordinates(clampedDropCoords, coords.GridID)); + } + else + handsComp.Drop(handsComp.ActiveIndex, ent.Transform.GridPosition); return true; }