Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Content.Client/Outline/TargetOutlineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public sealed class TargetOutlineSystem : EntitySystem
/// <remarks>
/// If a target is further than this distance, they will still be highlighted in a different color.
/// </remarks>
public float Range = -1;
public float? Range = null;

/// <summary>
/// Whether to check if the player is unobstructed to the target;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void Disable()
RemoveHighlights();
}

public void Enable(float range, bool checkObstructions, Func<EntityUid, bool>? predicate, EntityWhitelist? whitelist, EntityWhitelist? blacklist, CancellableEntityEventArgs? validationEvent)
public void Enable(float? range, bool checkObstructions, Func<EntityUid, bool>? predicate, EntityWhitelist? whitelist, EntityWhitelist? blacklist, CancellableEntityEventArgs? validationEvent)
{
Range = range;
CheckObstruction = checkObstructions;
Expand Down Expand Up @@ -130,7 +130,8 @@ private void HighlightTargets()
// TODO: Duplicated in SpriteSystem and DragDropSystem. Should probably be cached somewhere for a frame?
var mousePos = _eyeManager.PixelToMap(_inputManager.MouseScreenPosition).Position;
var bounds = new Box2(mousePos - LookupVector, mousePos + LookupVector);
var pvsEntities = _lookup.GetEntitiesIntersecting(_eyeManager.CurrentEye.Position.MapId, bounds, LookupFlags.Approximate | LookupFlags.Static);
var pvsEntities = _lookup.GetEntitiesIntersecting(_eyeManager.CurrentEye.Position.MapId, bounds,
LookupFlags.Approximate | LookupFlags.Static | LookupFlags.Dynamic | LookupFlags.Sundries);

foreach (var entity in pvsEntities)
{
Expand All @@ -141,8 +142,8 @@ private void HighlightTargets()
var valid = Predicate?.Invoke(entity) ?? true;

// check the entity whitelist
if (valid && Whitelist != null)
valid = _whitelistSystem.IsWhitelistPass(Whitelist, entity);
if (valid)
valid = _whitelistSystem.CheckBoth(entity, Blacklist, Whitelist);

// and check the cancellable event
if (valid && ValidationEvent != null)
Expand All @@ -165,19 +166,19 @@ private void HighlightTargets()
}

// Range check
if (CheckObstruction)
valid = _interactionSystem.InRangeUnobstructed(player, entity, Range);
else if (Range >= 0)
if (CheckObstruction && Range is not null)
valid = _interactionSystem.InRangeUnobstructed(player, entity, Range.Value);
else if (Range is not null)
{
var origin = _transformSystem.GetWorldPosition(player);
var target = _transformSystem.GetWorldPosition(entity);
valid = (origin - target).LengthSquared() <= Range;
valid = (origin - target).LengthSquared() <= Range * Range;
}

if (sprite.PostShader != null &&
sprite.PostShader != _shaderTargetValid &&
sprite.PostShader != _shaderTargetInvalid)
return;
continue;

// highlight depending on whether its in or out of range
sprite.PostShader = valid ? _shaderTargetValid : _shaderTargetInvalid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ private void StartTargeting(Entity<ActionComponent, TargetActionComponent> ent)
if (!entity.CanTargetSelf)
predicate = e => e != attachedEnt;

var range = target.CheckCanAccess ? target.Range : -1;
var range = target.CheckCanAccess ? target.Range : (float?)null;

_interactionOutline?.SetEnabled(false);
_targetOutline?.Enable(range, target.CheckCanAccess, predicate, entity.Whitelist, entity.Blacklist, null);
Expand Down
Loading