Refactor InRangeUnobstructed and add extension methods (#1925)

* Sort out InRangeUnobstructed and add extension methods

* Rename client RangeChecks to RangeExtensions

* Add container extension methods and test

* Add missing component methods

Component to container
Grid coordinates to container
Map coordinates to container
Local player to container

* Actually use the field

* Merge fixes

* Add popup argument to local player extension methods

* Reduce code repetition for client range extensions
This commit is contained in:
DrSmugleaf
2020-08-30 11:37:06 +02:00
committed by GitHub
parent 9ec3ddf368
commit 9d6c394f6b
39 changed files with 1287 additions and 359 deletions

View File

@@ -7,8 +7,8 @@ using Content.Server.GameObjects.Components.Movement;
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding;
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Pathfinders;
using Content.Server.GameObjects.EntitySystems.JobQueues;
using Content.Server.Utility;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Utility;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Systems;
@@ -281,7 +281,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
if (targetDistance <= steeringRequest.ArrivalDistance && steeringRequest.TimeUntilInteractionCheck <= 0.0f)
{
if (!steeringRequest.RequiresInRangeUnobstructed ||
InteractionChecks.InRangeUnobstructed(entity, steeringRequest.TargetMap, steeringRequest.ArrivalDistance, ignoredEnt: entity))
entity.InRangeUnobstructed(steeringRequest.TargetMap, steeringRequest.ArrivalDistance, popup: true))
{
// TODO: Need cruder LOS checks for ranged weaps
controller.VelocityDir = Vector2.Zero;

View File

@@ -12,8 +12,8 @@ using Content.Shared.GameObjects.EntitySystemMessages;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Input;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Physics;
using Content.Shared.Physics.Pull;
using Content.Shared.Utility;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Interfaces.Player;
@@ -71,7 +71,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
var interactionArgs = new DragDropEventArgs(performer, msg.DropLocation, dropped, target);
// must be in range of both the target and the object they are drag / dropping
if (!InteractionChecks.InRangeUnobstructed(interactionArgs)) return;
if (!interactionArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
// trigger dragdrops on the dropped entity
foreach (var dragDrop in dropped.GetAllComponents<IDragDrop>())
@@ -145,7 +145,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
// all activates should only fire when in range / unbostructed
var activateEventArgs = new ActivateEventArgs {User = user, Target = used};
if (InteractionChecks.InRangeUnobstructed(activateEventArgs))
if (activateEventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
{
activateComp.Activate(activateEventArgs);
}
@@ -453,7 +453,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
};
// all AttackBys should only happen when in range / unobstructed, so no range check is needed
if (InteractionChecks.InRangeUnobstructed(attackByEventArgs))
if (attackByEventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
{
foreach (var attackBy in attackBys)
{
@@ -501,8 +501,8 @@ namespace Content.Server.GameObjects.EntitySystems.Click
var attackHands = attacked.GetAllComponents<IInteractHand>().ToList();
var attackHandEventArgs = new InteractHandEventArgs {User = user, Target = attacked};
// all attackHands should only fire when in range / unbostructed
if (InteractionChecks.InRangeUnobstructed(attackHandEventArgs))
// all attackHands should only fire when in range / unobstructed
if (attackHandEventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
{
foreach (var attackHand in attackHands)
{

View File

@@ -6,19 +6,18 @@ using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems.Click;
using Content.Server.Utility;
using Content.Shared.Construction;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.Map;
@@ -91,8 +90,7 @@ namespace Content.Server.GameObjects.EntitySystems
if(targetEnt is null || handEnt is null)
return;
var interaction = Get<InteractionSystem>();
if(!interaction.InRangeUnobstructed(handEnt.Transform.MapPosition, targetEnt.Transform.MapPosition, ignoredEnt: targetEnt, ignoreInsideBlocker: true))
if (!handEnt.InRangeUnobstructed(targetEnt, ignoreInsideBlocker: true))
return;
// Cannot deconstruct an entity with no prototype.
@@ -246,8 +244,7 @@ namespace Content.Server.GameObjects.EntitySystems
{
var prototype = _prototypeManager.Index<ConstructionPrototype>(prototypeName);
if (!InteractionChecks.InRangeUnobstructed(placingEnt, loc.ToMap(_mapManager),
ignoredEnt: placingEnt, ignoreInsideBlocker: prototype.CanBuildInImpassable))
if (!placingEnt.InRangeUnobstructed(loc, ignoreInsideBlocker: prototype.CanBuildInImpassable, popup: true))
{
return false;
}
@@ -377,7 +374,7 @@ namespace Content.Server.GameObjects.EntitySystems
var constructPrototype = constructionComponent.Prototype;
if (constructPrototype.CanBuildInImpassable == false)
{
if (!InteractionChecks.InRangeUnobstructed(user, constructEntity.Transform.MapPosition))
if (!user.InRangeUnobstructed(constructEntity, popup: true))
return false;
}

View File

@@ -3,6 +3,7 @@ using System;
using System.Threading;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Physics;
using Content.Shared.Utility;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
@@ -13,17 +14,17 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter
public sealed class DoAfterEventArgs
{
// Premade checks
public Func<bool> GetInRangeUnobstructed(int collisionMask = (int) CollisionGroup.MobMask)
public Func<bool> GetInRangeUnobstructed(CollisionGroup collisionMask = CollisionGroup.MobMask)
{
if (Target == null)
{
throw new InvalidOperationException("Can't supply a null target to DoAfterEventArgs.GetInRangeUnobstructed");
}
var interactionSystem = EntitySystem.Get<SharedInteractionSystem>();
Func<IEntity, bool> ignored = entity => entity == User || entity == Target;
return () => interactionSystem.InRangeUnobstructed(User.Transform.MapPosition, Target.Transform.MapPosition, collisionMask: collisionMask, predicate: ignored);
bool Ignored(IEntity entity) => entity == User || entity == Target;
return () => User.InRangeUnobstructed(Target, collisionMask: collisionMask, predicate: Ignored);
}
/// <summary>
/// The entity invoking do_after
/// </summary>
@@ -71,7 +72,7 @@ namespace Content.Server.GameObjects.EntitySystems.DoAfter
/// Anything that needs a pre-check should do it itself so no DoAfterState is ever sent to the client.
/// </remarks>
public Func<bool>? PostCheck { get; set; } = null;
/// <summary>
/// Additional conditions that need to be met. Return false to cancel.
/// </summary>

View File

@@ -125,7 +125,7 @@ namespace Content.Server.GameObjects.EntitySystems
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 = new GridCoordinates((entToDesiredDropCoords.Normalized * targetLength) + entCoords, coords.GridID);
var rayLength = Get<SharedInteractionSystem>().UnobstructedRayLength(ent.Transform.MapPosition, newCoords.ToMap(_mapManager), ignoredEnt: ent);
var rayLength = Get<SharedInteractionSystem>().UnobstructedDistance(ent.Transform.MapPosition, newCoords.ToMap(_mapManager), ignoredEnt: ent);
handsComp.Drop(handsComp.ActiveHand, new GridCoordinates(entCoords + (entToDesiredDropCoords.Normalized * rayLength), coords.GridID));