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

@@ -1,11 +1,13 @@
using System;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.Utility;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using static Content.Shared.GameObjects.EntitySystems.SharedInteractionSystem;
namespace Content.Shared.GameObjects.EntitySystems
{
@@ -26,11 +28,8 @@ namespace Content.Shared.GameObjects.EntitySystems
private static bool IsInDetailsRange(IEntity examiner, IEntity entity)
{
return Get<SharedInteractionSystem>()
.InRangeUnobstructed(examiner.Transform.MapPosition, entity.Transform.MapPosition,
ExamineDetailsRange, predicate: entity0 => entity0 == examiner || entity0 == entity,
ignoreInsideBlocker: true) &&
examiner.IsInSameOrNoContainer(entity);
return examiner.InRangeUnobstructed(entity, ExamineDetailsRange, ignoreInsideBlocker: true) &&
examiner.IsInSameOrNoContainer(entity);
}
[Pure]
@@ -51,16 +50,14 @@ namespace Content.Shared.GameObjects.EntitySystems
return false;
}
Func<IEntity, bool> predicate = entity => entity == examiner || entity == examined;
Ignored predicate = entity => entity == examiner || entity == examined;
if (ContainerHelpers.TryGetContainer(examiner, out var container))
{
predicate += entity => entity == container.Owner;
}
return Get<SharedInteractionSystem>()
.InRangeUnobstructed(examiner.Transform.MapPosition, examined.Transform.MapPosition,
ExamineRange, predicate: predicate, ignoreInsideBlocker:true);
return examiner.InRangeUnobstructed(examined, ExamineRange, predicate: predicate, ignoreInsideBlocker: true);
}
public static FormattedMessage GetExamineText(IEntity entity, IEntity examiner)