Adds overload to InRangeUnoccluded that takes in a state for the predicate. (#7325)
This commit is contained in:
committed by
GitHub
parent
85c3490990
commit
5447edbabf
@@ -203,6 +203,10 @@ namespace Content.Client.DoAfter
|
|||||||
if (_attachedEntity is not {Valid: true} entity || Deleted(entity))
|
if (_attachedEntity is not {Valid: true} entity || Deleted(entity))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// ReSharper disable once ConvertToLocalFunction
|
||||||
|
var predicate = (EntityUid uid, (EntityUid compOwner, EntityUid? attachedEntity) data)
|
||||||
|
=> uid == data.compOwner || uid == data.attachedEntity;
|
||||||
|
|
||||||
var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f);
|
var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f);
|
||||||
var entXform = Transform(entity);
|
var entXform = Transform(entity);
|
||||||
var playerPos = entXform.MapPosition;
|
var playerPos = entXform.MapPosition;
|
||||||
@@ -226,7 +230,7 @@ namespace Content.Client.DoAfter
|
|||||||
!ExamineSystemShared.InRangeUnOccluded(
|
!ExamineSystemShared.InRangeUnOccluded(
|
||||||
playerPos,
|
playerPos,
|
||||||
compPos, range,
|
compPos, range,
|
||||||
ent => ent == comp.Owner || ent == _attachedEntity))
|
(comp.Owner, _attachedEntity), predicate))
|
||||||
{
|
{
|
||||||
Disable(comp);
|
Disable(comp);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -120,7 +120,18 @@ namespace Content.Shared.Examine
|
|||||||
return ExamineRange;
|
return ExamineRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool InRangeUnOccluded(MapCoordinates origin, MapCoordinates other, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
public static bool InRangeUnOccluded(MapCoordinates origin, MapCoordinates other, float range, Ignored? predicate, bool ignoreInsideBlocker = true, IEntityManager? entMan = null)
|
||||||
|
{
|
||||||
|
// No, rider. This is better.
|
||||||
|
// ReSharper disable once ConvertToLocalFunction
|
||||||
|
var wrapped = (EntityUid uid, Ignored? wrapped)
|
||||||
|
=> wrapped != null && wrapped(uid);
|
||||||
|
|
||||||
|
return InRangeUnOccluded(origin, other, range, predicate, wrapped, ignoreInsideBlocker, entMan);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool InRangeUnOccluded<TState>(MapCoordinates origin, MapCoordinates other, float range,
|
||||||
|
TState state, Func<EntityUid, TState, bool> predicate, bool ignoreInsideBlocker = true, IEntityManager? entMan = null)
|
||||||
{
|
{
|
||||||
if (other.MapId != origin.MapId ||
|
if (other.MapId != origin.MapId ||
|
||||||
other.MapId == MapId.Nullspace) return false;
|
other.MapId == MapId.Nullspace) return false;
|
||||||
@@ -140,13 +151,11 @@ namespace Content.Shared.Examine
|
|||||||
}
|
}
|
||||||
|
|
||||||
var occluderSystem = Get<OccluderSystem>();
|
var occluderSystem = Get<OccluderSystem>();
|
||||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
IoCManager.Resolve(ref entMan);
|
||||||
|
|
||||||
predicate ??= _ => false;
|
|
||||||
|
|
||||||
var ray = new Ray(origin.Position, dir.Normalized);
|
var ray = new Ray(origin.Position, dir.Normalized);
|
||||||
var rayResults = occluderSystem
|
var rayResults = occluderSystem
|
||||||
.IntersectRayWithPredicate(origin.MapId, ray, length, predicate.Invoke, false).ToList();
|
.IntersectRayWithPredicate(origin.MapId, ray, length, state, predicate, false).ToList();
|
||||||
|
|
||||||
if (rayResults.Count == 0) return true;
|
if (rayResults.Count == 0) return true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user