diff --git a/Content.Shared/Construction/Conditions/WallmountCondition.cs b/Content.Shared/Construction/Conditions/WallmountCondition.cs index e9b4866c62..aaec9a2233 100644 --- a/Content.Shared/Construction/Conditions/WallmountCondition.cs +++ b/Content.Shared/Construction/Conditions/WallmountCondition.cs @@ -21,14 +21,17 @@ namespace Content.Shared.Construction.Conditions var entManager = IoCManager.Resolve(); // get blueprint and user position - var userWorldPosition = IoCManager.Resolve().GetComponent(user).WorldPosition; + var userWorldPosition = entManager.GetComponent(user).WorldPosition; var objWorldPosition = location.ToMap(entManager).Position; // find direction from user to blueprint var userToObject = (objWorldPosition - userWorldPosition); + // get direction of the grid being placed on as an offset. + var gridRotation = entManager.GetComponent(location.EntityId).WorldRotation; + var directionWithOffset = gridRotation.RotateVec(direction.ToVec()); // dot product will be positive if user direction and blueprint are co-directed - var dotProd = Vector2.Dot(direction.ToVec(), userToObject); + var dotProd = Vector2.Dot(directionWithOffset.Normalized, userToObject.Normalized); if (dotProd > 0) return false; @@ -36,7 +39,7 @@ namespace Content.Shared.Construction.Conditions var physics = EntitySystem.Get(); var rUserToObj = new CollisionRay(userWorldPosition, userToObject.Normalized, (int) CollisionGroup.Impassable); var length = userToObject.Length; - var userToObjRaycastResults = physics.IntersectRayWithPredicate(IoCManager.Resolve().GetComponent(user).MapID, rUserToObj, maxLength: length, + var userToObjRaycastResults = physics.IntersectRayWithPredicate(entManager.GetComponent(user).MapID, rUserToObj, maxLength: length, predicate: (e) => !e.HasTag("Wall")); if (!userToObjRaycastResults.Any()) return false; @@ -45,8 +48,8 @@ namespace Content.Shared.Construction.Conditions var targetWall = userToObjRaycastResults.First().HitEntity; // check that we didn't try to build wallmount that facing another adjacent wall - var rAdjWall = new CollisionRay(objWorldPosition, direction.ToVec(), (int) CollisionGroup.Impassable); - var adjWallRaycastResults = physics.IntersectRayWithPredicate(IoCManager.Resolve().GetComponent(user).MapID, rAdjWall, maxLength: 0.5f, + var rAdjWall = new CollisionRay(objWorldPosition, directionWithOffset.Normalized, (int) CollisionGroup.Impassable); + var adjWallRaycastResults = physics.IntersectRayWithPredicate(entManager.GetComponent(user).MapID, rAdjWall, maxLength: 0.5f, predicate: (e) => e == targetWall || !e.HasTag("Wall")); return !adjWallRaycastResults.Any(); }