Ability Range fix

This commit is contained in:
dingo
2026-03-13 17:36:57 -04:00
parent 60268fd310
commit 92f61dcd76
2 changed files with 33 additions and 4 deletions
+17 -1
View File
@@ -431,9 +431,10 @@ public static class AbilitySystem
if (selector.Filters is { Length: > 0 })
candidates = candidates.Where(c => FiltersMatch(selector.Filters, c, ctx)).ToList();
HashSet<string> clientIds = [];
if (clientTargets is not null)
{
var clientIds = clientTargets
clientIds = clientTargets
.Where(t => t.ActionIndex == actionIndex && t.InstanceId is not null)
.Select(t => t.InstanceId!).ToHashSet();
if (clientIds.Count > 0)
@@ -446,9 +447,24 @@ public static class AbilitySystem
}
if (activationRange is not null)
{
// If the client explicitly picked unit targets, validate range before filtering so the
// error is unambiguous (TARGET_OUT_OF_RANGE rather than INSUFFICIENT_TARGETS).
if (clientIds.Count > 0 && ctx.Source is FieldCard srcFc && srcFc.Position.HasValue)
{
bool anyOutOfRange = candidates
.OfType<FieldCard>()
.Where(fc => clientIds.Contains(fc.InstanceId))
.Any(fc => !fc.Position.HasValue ||
!IsTargetInAbilityRange(ctx.State, srcFc.Position.Value, fc.Position.Value, activationRange));
if (anyOutOfRange)
throw new GameException("TARGET_OUT_OF_RANGE");
}
candidates = FilterTargetsByAbilityRange(candidates.Cast<object>().ToList(), ctx, activationRange)
.OfType<CardInstance>()
.ToList();
}
if (!selector.Count.All)
{