private bool HandleDrop(ICommonSession session, EntityCoordinates coords, EntityUid uid) { var ent = ((IPlayerSession)session).AttachedEntity; if (ent == null || !ent.IsValid()) { return(false); } if (!ent.TryGetComponent(out HandsComponent handsComp)) { return(false); } if (handsComp.GetActiveHand == null) { return(false); } var entCoords = ent.Transform.Coordinates.Position; var entToDesiredDropCoords = coords.Position - entCoords; var targetLength = Math.Min(entToDesiredDropCoords.Length, SharedInteractionSystem.InteractionRange - 0.001f); // InteractionRange is reduced due to InRange not dealing with floating point error var newCoords = coords.WithPosition(entToDesiredDropCoords.Normalized * targetLength + entCoords).ToMap(_entityManager); var rayLength = Get <SharedInteractionSystem>().UnobstructedDistance(ent.Transform.MapPosition, newCoords, ignoredEnt: ent); handsComp.Drop(handsComp.ActiveHand, coords.WithPosition(entCoords + entToDesiredDropCoords.Normalized * rayLength)); return(true); }
private bool HandleDrop(ICommonSession?session, EntityCoordinates coords, EntityUid uid) { var ent = ((IPlayerSession?)session)?.AttachedEntity; if (ent == null || !ent.IsValid()) { return(false); } if (!ent.TryGetComponent(out HandsComponent? handsComp)) { return(false); } if (handsComp.ActiveHand == null || handsComp.GetActiveHand == null) { return(false); } var entMap = ent.Transform.MapPosition; var targetPos = coords.ToMapPos(EntityManager); var dropVector = targetPos - entMap.Position; var targetVector = Vector2.Zero; if (dropVector != Vector2.Zero) { var targetLength = MathF.Min(dropVector.Length, SharedInteractionSystem.InteractionRange - 0.001f); // InteractionRange is reduced due to InRange not dealing with floating point error var newCoords = coords.WithPosition(dropVector.Normalized * targetLength + entMap.Position).ToMap(EntityManager); var rayLength = Get <SharedInteractionSystem>().UnobstructedDistance(entMap, newCoords, ignoredEnt: ent); targetVector = dropVector.Normalized * rayLength; } handsComp.Drop(handsComp.ActiveHand, coords.WithPosition(entMap.Position + targetVector)); return(true); }