diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 38715a9..41ed204 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -516,7 +516,11 @@ public static class AbilitySystem player.Field.OfType().Where(f => f.CardType == "Spirit").Cast(), _ => Enumerable.Empty() }; - var candidateItems = rawCandidates + // Apply cost filters so only eligible cards are offered to the picker. + var filteredCandidates = cost.Filters is not null && cost.Filters.Length > 0 + ? rawCandidates.Where(c => FiltersMatch(cost.Filters, c, ctx)) + : rawCandidates; + var candidateItems = filteredCandidates .Select(c => new { instanceId = c.InstanceId, name = c.Name, cardType = c.CardType }) .ToArray(); @@ -778,6 +782,17 @@ public static class AbilitySystem var player = state.Players[pending.ActorId]; + // Resolve source early so the filter context can evaluate source-relative filters + // (IsSelf, IsAdjacentToSource, etc.). Source may have left the field — that's OK; + // those spatial filters simply return false and thus never apply to hand/field cost picks. + var earlySource = state.Players.Values + .SelectMany(p => p.Field).OfType() + .FirstOrDefault(f => f.InstanceId == pending.SourceInstanceId); + var filterCtx = new AbilityContext { State = state, ActorId = pending.ActorId, Source = earlySource }; + var pickFilters = pending.FiltersJson is not null + ? JsonSerializer.Deserialize(pending.FiltersJson, _jsonOpts) + : null; + // Validate and pay the interactive cost using the client-selected IDs. switch (pending.CostType) { @@ -790,6 +805,8 @@ public static class AbilitySystem .ToList(); if (toDiscard.Count < pending.Amount) throw new GameException("INVALID_COST_PICK_SELECTION"); + if (pickFilters is not null && toDiscard.Any(c => !FiltersMatch(pickFilters, c, filterCtx))) + throw new GameException("INVALID_COST_PICK_SELECTION"); foreach (var c in toDiscard) { player.Hand.Remove(c); player.Discard.Add(c); } break; } @@ -800,6 +817,8 @@ public static class AbilitySystem var spirit = player.Field.OfType() .FirstOrDefault(f => f.InstanceId == picked) ?? throw new GameException("INVALID_COST_PICK_SELECTION"); + if (pickFilters is not null && !FiltersMatch(pickFilters, spirit, filterCtx)) + throw new GameException("INVALID_COST_PICK_SELECTION"); state.Board?.RemoveUnit(spirit.InstanceId); player.Field.Remove(spirit); player.Discard.Add(spirit); @@ -812,6 +831,8 @@ public static class AbilitySystem var spirit = player.Field.OfType() .FirstOrDefault(f => f.InstanceId == picked) ?? throw new GameException("INVALID_COST_PICK_SELECTION"); + if (pickFilters is not null && !FiltersMatch(pickFilters, spirit, filterCtx)) + throw new GameException("INVALID_COST_PICK_SELECTION"); // Temporary context for damage application. var dmgCtx = new AbilityContext { State = state, ActorId = pending.ActorId }; ApplyDamageToUnit(spirit, pending.Amount, bypassDefense: false, dmgCtx);