diff --git a/Content.Client/Utility/RangeExtensions.cs b/Content.Client/Utility/UnobstructedExtensions.cs similarity index 98% rename from Content.Client/Utility/RangeExtensions.cs rename to Content.Client/Utility/UnobstructedExtensions.cs index b32de2edf6..ab204bdf96 100644 --- a/Content.Client/Utility/RangeExtensions.cs +++ b/Content.Client/Utility/UnobstructedExtensions.cs @@ -10,7 +10,7 @@ using static Content.Shared.GameObjects.EntitySystems.SharedInteractionSystem; namespace Content.Client.Utility { - public static class RangeExtensions + public static class UnobstructedExtensions { private static SharedInteractionSystem SharedInteractionSystem => EntitySystem.Get(); diff --git a/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs b/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs index c9d4186d09..b6b5afc111 100644 --- a/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs +++ b/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs @@ -13,8 +13,8 @@ namespace Content.IntegrationTests.Tests.Interaction { [TestFixture] [TestOf(typeof(SharedInteractionSystem))] - [TestOf(typeof(SharedRangeExtensions))] - [TestOf(typeof(RangeExtensions))] + [TestOf(typeof(SharedUnobstructedExtensions))] + [TestOf(typeof(UnobstructedExtensions))] public class InRangeUnobstructed : ContentIntegrationTest { private const string HumanId = "BaseHumanMob_Content"; diff --git a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs index 6bf071c03a..8a8310aad3 100644 --- a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs +++ b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs @@ -1,5 +1,6 @@ using System.Linq; using Content.Shared.GameObjects.Components.Mobs; +using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Shared.Containers; @@ -92,6 +93,61 @@ namespace Content.Shared.GameObjects.EntitySystems return (rayResults[0].HitPos - other.Position).Length < 1f; } + public static bool InRangeUnOccluded(IEntity origin, IEntity other, float range, Ignored predicate, bool ignoreInsideBlocker = true) + { + var originPos = origin.Transform.MapPosition; + var otherPos = other.Transform.MapPosition; + + return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded(IEntity origin, IComponent other, float range, Ignored predicate, bool ignoreInsideBlocker = true) + { + var originPos = origin.Transform.MapPosition; + var otherPos = other.Owner.Transform.MapPosition; + + return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded(IEntity origin, EntityCoordinates other, float range, Ignored predicate, bool ignoreInsideBlocker = true) + { + var originPos = origin.Transform.MapPosition; + var otherPos = other.ToMap(origin.EntityManager); + + return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded(IEntity origin, MapCoordinates other, float range, Ignored predicate, bool ignoreInsideBlocker = true) + { + var originPos = origin.Transform.MapPosition; + + return InRangeUnOccluded(originPos, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded(ITargetedInteractEventArgs args, float range, Ignored predicate, bool ignoreInsideBlocker = true) + { + var originPos = args.User.Transform.MapPosition; + var otherPos = args.Target.Transform.MapPosition; + + return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded(DragDropEventArgs args, float range, Ignored predicate, bool ignoreInsideBlocker = true) + { + var originPos = args.User.Transform.MapPosition; + var otherPos = args.DropLocation.ToMap(args.User.EntityManager); + + return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded(AfterInteractEventArgs args, float range, Ignored predicate, bool ignoreInsideBlocker = true) + { + var originPos = args.User.Transform.MapPosition; + var otherPos = args.Target.Transform.MapPosition; + + return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker); + } + public static FormattedMessage GetExamineText(IEntity entity, IEntity examiner) { var message = new FormattedMessage(); diff --git a/Content.Shared/Utility/SharedRangeExtensions.cs b/Content.Shared/Utility/SharedUnobstructedExtensions.cs similarity index 99% rename from Content.Shared/Utility/SharedRangeExtensions.cs rename to Content.Shared/Utility/SharedUnobstructedExtensions.cs index 5e8e9a50c0..fa564940de 100644 --- a/Content.Shared/Utility/SharedRangeExtensions.cs +++ b/Content.Shared/Utility/SharedUnobstructedExtensions.cs @@ -10,7 +10,7 @@ using static Content.Shared.GameObjects.EntitySystems.SharedInteractionSystem; namespace Content.Shared.Utility { - public static class SharedRangeExtensions + public static class SharedUnobstructedExtensions { private static SharedInteractionSystem SharedInteractionSystem => EntitySystem.Get(); diff --git a/Content.Shared/Utility/SharedUnoccludedExtensions.cs b/Content.Shared/Utility/SharedUnoccludedExtensions.cs new file mode 100644 index 0000000000..cd092cbb79 --- /dev/null +++ b/Content.Shared/Utility/SharedUnoccludedExtensions.cs @@ -0,0 +1,372 @@ +using Content.Shared.GameObjects.EntitySystems; +using Content.Shared.Interfaces.GameObjects.Components; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.GameObjects.Components; +using Robust.Shared.IoC; +using Robust.Shared.Map; +using static Content.Shared.GameObjects.EntitySystems.ExamineSystemShared; +using static Content.Shared.GameObjects.EntitySystems.SharedInteractionSystem; + +namespace Content.Shared.Utility +{ + public static class SharedUnoccludedExtensions + { + #region Entities + public static bool InRangeUnOccluded( + this IEntity origin, + IEntity other, + float range = ExamineRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + return ExamineSystemShared.InRangeUnOccluded(origin, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IEntity origin, + IComponent other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + return ExamineSystemShared.InRangeUnOccluded(origin, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IEntity origin, + IContainer other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var otherEntity = other.Owner; + + return ExamineSystemShared.InRangeUnOccluded(origin, otherEntity, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IEntity origin, + EntityCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + return ExamineSystemShared.InRangeUnOccluded(origin, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IEntity origin, + MapCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + return ExamineSystemShared.InRangeUnOccluded(origin, other, range, predicate, ignoreInsideBlocker); + } + #endregion + + #region Components + public static bool InRangeUnOccluded( + this IComponent origin, + IEntity other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IComponent origin, + IComponent other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IComponent origin, + IContainer other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + var otherEntity = other.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, otherEntity, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IComponent origin, + EntityCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IComponent origin, + MapCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, + ignoreInsideBlocker); + } + #endregion + + #region Containers + public static bool InRangeUnOccluded( + this IContainer origin, + IEntity other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IContainer origin, + IComponent other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IContainer origin, + IContainer other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + var otherEntity = other.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, otherEntity, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IContainer origin, + EntityCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this IContainer origin, + MapCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var originEntity = origin.Owner; + + return ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, ignoreInsideBlocker); + } + #endregion + + #region EntityCoordinates + public static bool InRangeUnOccluded( + this EntityCoordinates origin, + IEntity other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var entityManager = IoCManager.Resolve(); + var originPosition = origin.ToMap(entityManager); + var otherPosition = other.Transform.MapPosition; + + return ExamineSystemShared.InRangeUnOccluded(originPosition, otherPosition, range, + predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this EntityCoordinates origin, + IComponent other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var entityManager = IoCManager.Resolve(); + var originPosition = origin.ToMap(entityManager); + var otherPosition = other.Owner.Transform.MapPosition; + + return ExamineSystemShared.InRangeUnOccluded(originPosition, otherPosition, range, + predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this EntityCoordinates origin, + IContainer other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var entityManager = IoCManager.Resolve(); + var originPosition = origin.ToMap(entityManager); + var otherPosition = other.Owner.Transform.MapPosition; + + return ExamineSystemShared.InRangeUnOccluded(originPosition, otherPosition, range, + predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this EntityCoordinates origin, + EntityCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var entityManager = IoCManager.Resolve(); + var originPosition = origin.ToMap(entityManager); + var otherPosition = other.ToMap(entityManager); + + return ExamineSystemShared.InRangeUnOccluded(originPosition, otherPosition, range, + predicate, ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this EntityCoordinates origin, + MapCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var entityManager = IoCManager.Resolve(); + var originPosition = origin.ToMap(entityManager); + + return ExamineSystemShared.InRangeUnOccluded(originPosition, other, range, predicate, + ignoreInsideBlocker); + } + #endregion + + #region MapCoordinates + public static bool InRangeUnOccluded( + this MapCoordinates origin, + IEntity other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var otherPosition = other.Transform.MapPosition; + + return ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this MapCoordinates origin, + IComponent other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var otherPosition = other.Owner.Transform.MapPosition; + + return ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this MapCoordinates origin, + IContainer other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var otherPosition = other.Owner.Transform.MapPosition; + + return ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this MapCoordinates origin, + EntityCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + var entityManager = IoCManager.Resolve(); + var otherPosition = other.ToMap(entityManager); + + return ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this MapCoordinates origin, + MapCoordinates other, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + return ExamineSystemShared.InRangeUnOccluded(origin, other, range, predicate, + ignoreInsideBlocker); + } + #endregion + + #region EventArgs + public static bool InRangeUnOccluded( + this ITargetedInteractEventArgs args, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + return ExamineSystemShared.InRangeUnOccluded(args, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this DragDropEventArgs args, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + return ExamineSystemShared.InRangeUnOccluded(args, range, predicate, + ignoreInsideBlocker); + } + + public static bool InRangeUnOccluded( + this AfterInteractEventArgs args, + float range = InteractionRange, + Ignored predicate = null, + bool ignoreInsideBlocker = false) + { + return ExamineSystemShared.InRangeUnOccluded(args, range, predicate, + ignoreInsideBlocker); + } + #endregion + } +} diff --git a/SpaceStation14.sln.DotSettings b/SpaceStation14.sln.DotSettings index 729f14f63c..9fb16d013f 100644 --- a/SpaceStation14.sln.DotSettings +++ b/SpaceStation14.sln.DotSettings @@ -147,6 +147,7 @@ True True True + True True True True