diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor
index 1ca8a81..81a04e9 100644
--- a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor
+++ b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor
@@ -350,6 +350,8 @@
+
+
@@ -856,6 +858,8 @@
| IsSelf | Target shares the same card definition as the source (matches all copies of this card type on the board) |
| IsExactSelf | Target is the exact unit instance that owns this ability (use when only this specific unit should be affected) |
| IsAdjacentToSource | Target must be orthogonally adjacent to the ability's source unit |
+ | IsAdjacentToUnitMatching | Target is adjacent to a unit matching ownership/filter defaults |
+ | IsAdjacentToTileMatching | Target is adjacent to a tile matching supplied tile filter(s) |
@@ -916,6 +920,9 @@
| IsOnTileWithAffinity | Subject's tile matches the specified affinity |
| DestinationTileAffinityIs / PreviousTileAffinityIs | On move-triggered abilities, checks the moved-to / moved-from tile affinity |
| MovedFromOrIntoAffinity | On move-triggered abilities, passes if either origin or destination tile matches affinity |
+ | IsAdjacentToTileWithAffinity / IsOnOrAdjacentToTileWithAffinity | Positional affinity checks around the subject unit |
+ | IsCurrentlyMoving | True only inside movement-trigger context for the moving source |
+ | ControlledTileCountWithAffinity | Counts occupied tiles by affinity and compares via comparator/N |
| IsAdjacentTo | Subject is adjacent to a unit matching Ownership |
| WithinRangeOf | Subject is within N tiles of a unit matching Ownership |
| UnitCountOnBattlefield | Total matching units on board satisfies comparator |
@@ -1172,11 +1179,12 @@
new("Turn / Timing", ["IsOwnTurn", "IsOpponentTurn", "IsAllyTurn", "IsActivePlayerTurn"]),
new("Unit", ["HealthBelow", "HealthAbove", "DefenseIs", "HasGenus", "HasAbility",
"IsOnTileWithAffinity", "IsAdjacentTo", "WithinRangeOf", "MovementTypeIs",
- "DestinationTileAffinityIs", "PreviousTileAffinityIs", "MovedFromOrIntoAffinity"]),
+ "DestinationTileAffinityIs", "PreviousTileAffinityIs", "MovedFromOrIntoAffinity",
+ "IsAdjacentToTileWithAffinity", "IsOnOrAdjacentToTileWithAffinity", "IsCurrentlyMoving"]),
new("Player", ["SPAtLeast", "SPAtMost", "STAtLeast", "STAtMost",
"HandSizeAtLeast", "HandSizeAtMost", "DeckSizeAtLeast", "DiscardSizeAtLeast"]),
new("Tile", ["TileAffinityMatches", "TileIsOccupied", "TileIsUnoccupied"]),
- new("Battlefield", ["UnitCountOnBattlefield", "CardInZone"]),
+ new("Battlefield", ["UnitCountOnBattlefield", "CardInZone", "ControlledTileCountWithAffinity"]),
new("Composite", ["AND", "OR", "XOR", "NOT"]),
];
@@ -1296,6 +1304,7 @@
ab.TriggerCardType = trig["CardType"]?.GetValue() ?? "Spirit";
ab.TriggerDamageType = trig["DamageType"]?.GetValue() ?? "Any";
ab.TriggerAmount = trig["Amount"] is JsonNode amtNode ? amtNode.GetValue() : null;
+ ab.TriggerSourceFilterType = trig["SourceFilter"]?["$type"]?.GetValue() ?? "";
ab.TriggerStat = trig["Stat"]?.GetValue() ?? "";
ab.TriggerCause = trig["Cause"]?.GetValue() ?? "";
ab.TriggerCausedBy = trig["CausedBy"]?.GetValue() ?? "";
@@ -1732,6 +1741,8 @@
case "DestinationTileAffinityIs":
case "PreviousTileAffinityIs":
case "MovedFromOrIntoAffinity":
+ case "IsAdjacentToTileWithAffinity":
+ case "IsOnOrAdjacentToTileWithAffinity":
node["Affinity"] = c.Affinity; break;
case "IsAdjacentTo":
node["UnitType"] = c.UnitType; node["Ownership"] = c.Ownership; break;
@@ -1748,6 +1759,12 @@
node["Comparator"] = c.Comparator; node["N"] = c.N; break;
case "CardInZone":
node["CardRef"] = c.CardRef; node["Zone"] = c.Zone; break;
+ case "ControlledTileCountWithAffinity":
+ node["Ownership"] = c.Ownership;
+ node["Affinity"] = c.Affinity;
+ node["Comparator"] = c.Comparator;
+ node["N"] = c.N;
+ break;
case "NOT":
try
{
@@ -1834,6 +1851,8 @@
n["TargetOwnership"] = ab.TriggerTargetOwnership;
if (ab.TriggerDamageType != "Any") n["DamageType"] = ab.TriggerDamageType;
if (ab.TriggerAmount.HasValue) n["Amount"] = ab.TriggerAmount.Value;
+ if (!string.IsNullOrWhiteSpace(ab.TriggerSourceFilterType))
+ n["SourceFilter"] = new JsonObject { ["$type"] = ab.TriggerSourceFilterType };
}
else if (t == "BeforeDamageApplied")
{
@@ -2109,7 +2128,7 @@
this, e => { c.AbilityRef = e.Value?.ToString() ?? ""; Compile(); }));
__builder.CloseElement();
}
- else if (t is "IsOnTileWithAffinity" or "TileAffinityMatches" or "DestinationTileAffinityIs" or "PreviousTileAffinityIs" or "MovedFromOrIntoAffinity")
+ else if (t is "IsOnTileWithAffinity" or "TileAffinityMatches" or "DestinationTileAffinityIs" or "PreviousTileAffinityIs" or "MovedFromOrIntoAffinity" or "IsAdjacentToTileWithAffinity" or "IsOnOrAdjacentToTileWithAffinity")
{
BuildSelect(__builder, AffinityValues, c.Affinity, v => { c.Affinity = v; Compile(); }, 120);
}
@@ -2154,6 +2173,13 @@
__builder.CloseElement();
BuildSelect(__builder, ZoneValues, c.Zone, v => { c.Zone = v; Compile(); }, 110);
}
+ else if (t == "ControlledTileCountWithAffinity")
+ {
+ BuildSelect(__builder, OwnershipValues, c.Ownership, v => { c.Ownership = v; Compile(); }, 100);
+ BuildSelect(__builder, AffinityValues, c.Affinity, v => { c.Affinity = v; Compile(); }, 120);
+ BuildSelect(__builder, ComparatorValues, c.Comparator, v => { c.Comparator = v; Compile(); }, 150);
+ BuildIntInput(__builder, c.N, v => { c.N = v; Compile(); }, 60, "N");
+ }
else if (t == "NOT")
{
__builder.OpenElement(0, "input");
@@ -2459,6 +2485,10 @@
v => { ab.TriggerDamageType = v; Compile(); }, 100);
BuildOptionalAmountInput(__builder, ab.TriggerAmount,
v => { ab.TriggerAmount = v; Compile(); });
+ BuildOptionalStringSelect(__builder,
+ ["IsSelf", "IsExactSelf", "IsAdjacentToSource", "IsAdjacentToUnitMatching", "IsAdjacentToTileMatching"],
+ ab.TriggerSourceFilterType,
+ v => { ab.TriggerSourceFilterType = v; Compile(); }, 170, "Any source");
}
else if (t == "BeforeDamageApplied")
{
@@ -2709,6 +2739,7 @@
ab.TriggerCardType = "Spirit";
ab.TriggerDamageType = "Any";
ab.TriggerAmount = null;
+ ab.TriggerSourceFilterType = "";
ab.TriggerStat = "";
ab.TriggerCause = "";
ab.TriggerCausedBy = "";
@@ -2795,6 +2826,7 @@
public string TriggerCardType { get; set; } = "Spirit";
public string TriggerDamageType { get; set; } = "Any";
public int? TriggerAmount { get; set; }
+ public string TriggerSourceFilterType { get; set; } = "";
public string TriggerStat { get; set; } = "";
public string TriggerCause { get; set; } = "";
public string TriggerCausedBy { get; set; } = "";
diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs
index 69ceb59..9c742ac 100644
--- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs
+++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs
@@ -1515,11 +1515,51 @@ public static class AbilitySystem
{
foreach (var f in filters)
{
- if (f is AffinityMatchesFilter amf)
+ switch (f)
{
- var resolved = AffinitySystem.Resolve(tile.Base1, tile.Base2);
- if (!Enum.TryParse(amf.Affinity.ToString(), out var expected)
- || resolved != expected) return false;
+ case AffinityMatchesFilter amf:
+ {
+ var resolved = AffinitySystem.Resolve(tile.Base1, tile.Base2);
+ if (!Enum.TryParse(amf.Affinity.ToString(), out var expected)
+ || resolved != expected) return false;
+ break;
+ }
+ case TileAffinityMatchesFilter tam:
+ if (AffinitySystem.Resolve(tile.Base1, tile.Base2) != tam.Affinity) return false;
+ break;
+ case TileIsOccupiedFilter tio:
+ if (tile.IsEmpty) return false;
+ if (!string.IsNullOrEmpty(tio.UnitType) && tile.OccupantId is not null)
+ {
+ var utype = FindUnitType(ctx.State, tile.OccupantId);
+ if (!string.Equals(utype, tio.UnitType, StringComparison.OrdinalIgnoreCase)) return false;
+ }
+ break;
+ case TileIsUnoccupiedFilter:
+ if (!tile.IsEmpty) return false;
+ break;
+ case TileWithinRangeFilter twr:
+ if (ctx.Source is not FieldCard src || !src.Position.HasValue) return false;
+ var d = src.Position.Value.ManhattanDistance(tile.Coord);
+ if (d < twr.Min || d > twr.Max) return false;
+ break;
+ case TileIsAdjacentToUnitFilter tau:
+ {
+ if (ctx.State.Board is null) return false;
+ var any = OrthogonalNeighbours(tile.Coord).Any(n =>
+ {
+ var nt = ctx.State.Board.GetTile(n);
+ if (nt is null || nt.IsEmpty || nt.OccupantId is null || nt.OccupantOwner is null) return false;
+ if (!OwnershipMatchesForPlayer(tau.Ownership, nt.OccupantOwner, ctx.ActorId, ctx.State)) return false;
+ if (tau.UnitFilter is null) return true;
+ var nu = ctx.State.Players.Values.SelectMany(p => p.Field).FirstOrDefault(u => u.InstanceId == nt.OccupantId);
+ return nu is not null && FilterMatches(tau.UnitFilter, nu, ctx);
+ });
+ if (!any) return false;
+ break;
+ }
+ default:
+ break;
}
}
return true;
@@ -1754,6 +1794,15 @@ public static class AbilitySystem
return null;
}
+ private static IEnumerable OrthogonalNeighbours(Coord c)
+ =>
+ [
+ new Coord(c.X - 1, c.Y),
+ new Coord(c.X + 1, c.Y),
+ new Coord(c.X, c.Y - 1),
+ new Coord(c.X, c.Y + 1),
+ ];
+
private static PlayerState ResolvePlayerForEffect(string playerRef, AbilityContext ctx)
=> playerRef.ToLowerInvariant() switch
{
@@ -1831,6 +1880,38 @@ public static class AbilitySystem
}
return fromOk || toOk;
}
+ case IsAdjacentToTileWithAffinityCondition iat:
+ {
+ if (subject is not FieldCard afc || !afc.Position.HasValue || ctx.State.Board is null) return false;
+ foreach (var n in OrthogonalNeighbours(afc.Position.Value))
+ {
+ var tile = ctx.State.Board.GetTile(n);
+ if (tile is not null && AffinitySystem.Resolve(tile.Base1, tile.Base2) == iat.Affinity)
+ return true;
+ }
+ return false;
+ }
+ case IsOnOrAdjacentToTileWithAffinityCondition ioat:
+ {
+ if (subject is not FieldCard ofc || !ofc.Position.HasValue || ctx.State.Board is null) return false;
+ var here = ctx.State.Board.GetTile(ofc.Position.Value);
+ if (here is not null && AffinitySystem.Resolve(here.Base1, here.Base2) == ioat.Affinity)
+ return true;
+ foreach (var n in OrthogonalNeighbours(ofc.Position.Value))
+ {
+ var tile = ctx.State.Board.GetTile(n);
+ if (tile is not null && AffinitySystem.Resolve(tile.Base1, tile.Base2) == ioat.Affinity)
+ return true;
+ }
+ return false;
+ }
+ case IsCurrentlyMovingCondition:
+ {
+ if (ctx.EventData?.PreviousTile is null || ctx.EventData?.DestinationTile is null) return false;
+ if (subject is CardInstance sci)
+ return ctx.EventData?.SourceId == sci.InstanceId;
+ return true;
+ }
case SPAtLeastCondition spal: return player.CurrentSp >= spal.N;
case SPAtMostCondition spam: return player.CurrentSp <= spam.N;
@@ -1901,6 +1982,24 @@ public static class AbilitySystem
return tile is not null
&& AffinitySystem.Resolve(tile.Base1, tile.Base2) == tamc.Affinity;
}
+ case ControlledTileCountWithAffinityCondition ctc:
+ {
+ if (ctx.State.Board is null) return false;
+ var count = ctx.State.Board.Tiles.Values.Count(t =>
+ !string.IsNullOrEmpty(t.OccupantOwner)
+ && AffinitySystem.Resolve(t.Base1, t.Base2) == ctc.Affinity
+ && OwnershipMatchesForPlayer(ctc.Ownership, t.OccupantOwner!, ctx.ActorId, ctx.State));
+ return ctc.Comparator switch
+ {
+ Comparator.Equal => count == ctc.N,
+ Comparator.NotEqual => count != ctc.N,
+ Comparator.LessThan => count < ctc.N,
+ Comparator.LessThanOrEqual => count <= ctc.N,
+ Comparator.GreaterThan => count > ctc.N,
+ Comparator.GreaterThanOrEqual => count >= ctc.N,
+ _ => false,
+ };
+ }
default:
return true;
@@ -1942,6 +2041,24 @@ public static class AbilitySystem
card is FieldCard wrTgt && wrTgt.Position.HasValue &&
srcWr.Position.Value.ManhattanDistance(wrTgt.Position.Value) >= wrf.Min &&
srcWr.Position.Value.ManhattanDistance(wrTgt.Position.Value) <= wrf.Max,
+ IsAdjacentToUnitMatchingFilter iau =>
+ card is FieldCard afc && afc.Position.HasValue && ctx.State.Board is not null &&
+ OrthogonalNeighbours(afc.Position.Value).Any(n =>
+ {
+ var t = ctx.State.Board.GetTile(n);
+ if (t is null || t.IsEmpty || t.OccupantId is null || t.OccupantOwner is null) return false;
+ if (!OwnershipMatchesForPlayer(iau.Ownership, t.OccupantOwner, ctx.ActorId, ctx.State)) return false;
+ var neighbour = ctx.State.Players.Values.SelectMany(p => p.Field).FirstOrDefault(u => u.InstanceId == t.OccupantId);
+ if (neighbour is null) return false;
+ return iau.UnitFilters is null || iau.UnitFilters.All(f => FilterMatches(f, neighbour, ctx));
+ }),
+ IsAdjacentToTileMatchingFilter iat =>
+ card is FieldCard tfc && tfc.Position.HasValue && ctx.State.Board is not null &&
+ OrthogonalNeighbours(tfc.Position.Value).Any(n =>
+ {
+ var t = ctx.State.Board.GetTile(n);
+ return t is not null && (iat.TileFilters is null || TileMatchesFilters(iat.TileFilters, t, ctx));
+ }),
_ => true,
};
@@ -1976,8 +2093,11 @@ public static class AbilitySystem
&& UnitType(t.UnitType, occurrence.UnitType)
&& Own(t.Ownership, occurrence, ownerId, state, uid)
&& (t.CausedBy is null || Own(t.CausedBy, occurrence, ownerId, state, uid)),
- OnDamageDealtTrigger =>
- occurrence.Kind == TriggerEventKind.DamageDealt,
+ OnDamageDealtTrigger t =>
+ occurrence.Kind == TriggerEventKind.DamageDealt
+ && Own(t.SourceOwnership, occurrence, ownerId, state, uid)
+ && UnitOwnerMatches(t.TargetOwnership, occurrence.Data?.TargetId, state, ownerId)
+ && TriggerSourceMatchesFilter(t.SourceFilter, occurrence, state, ownerId),
OnDamagePreventedTrigger t =>
occurrence.Kind == TriggerEventKind.DamagePrevented
&& UnitOwnerMatches(t.TargetOwnership, occurrence.Data?.TargetId, state, ownerId),
@@ -2078,15 +2198,35 @@ public static class AbilitySystem
if (scope.ToLowerInvariant() == "any" || unitInstanceId is null) return true;
foreach (var (ownerId, player) in state.Players)
if (player.Field.Any(c => c.InstanceId == unitInstanceId))
- return scope.ToLowerInvariant() switch
- {
- "ally" or "owner" => ownerId == referenceOwnerId,
- "enemy" => ownerId != referenceOwnerId,
- _ => true,
- };
+ return OwnershipMatchesForPlayer(scope, ownerId, referenceOwnerId, state);
return true;
}
+ private static bool OwnershipMatchesForPlayer(string scope, string ownerId, string referenceOwnerId, GameState state)
+ => scope.ToLowerInvariant() switch
+ {
+ "any" => true,
+ "owner" or "self" or "ally" => state.AreAllies(ownerId, referenceOwnerId),
+ "enemy" => !state.AreAllies(ownerId, referenceOwnerId),
+ _ => true,
+ };
+
+ private static bool TriggerSourceMatchesFilter(Filter? filter, TriggerOccurrence occ, GameState state, string ownerId)
+ {
+ if (filter is null) return true;
+ if (occ.Data?.SourceId is not { Length: > 0 } sourceId) return false;
+ var source = state.Players.Values.SelectMany(p => p.Field).FirstOrDefault(c => c.InstanceId == sourceId);
+ if (source is null) return false;
+ var tmpCtx = new AbilityContext
+ {
+ State = state,
+ ActorId = ownerId,
+ Source = source,
+ EventData = occ.Data,
+ };
+ return FilterMatches(filter, source, tmpCtx);
+ }
+
private static bool UnitType(string? required, string? actual)
=> required is null or "Unit" or "Any" || required == actual;
diff --git a/Server/src/SOR.Game/Abilities/Models/Conditions.cs b/Server/src/SOR.Game/Abilities/Models/Conditions.cs
index 38226c8..c85ff35 100644
--- a/Server/src/SOR.Game/Abilities/Models/Conditions.cs
+++ b/Server/src/SOR.Game/Abilities/Models/Conditions.cs
@@ -27,6 +27,9 @@ using SOR.Database.Enums;
[PolyType(typeof(DestinationTileAffinityIsCondition), "DestinationTileAffinityIs")]
[PolyType(typeof(PreviousTileAffinityIsCondition), "PreviousTileAffinityIs")]
[PolyType(typeof(MovedFromOrIntoAffinityCondition), "MovedFromOrIntoAffinity")]
+[PolyType(typeof(IsAdjacentToTileWithAffinityCondition), "IsAdjacentToTileWithAffinity")]
+[PolyType(typeof(IsOnOrAdjacentToTileWithAffinityCondition), "IsOnOrAdjacentToTileWithAffinity")]
+[PolyType(typeof(IsCurrentlyMovingCondition), "IsCurrentlyMoving")]
// Player (§6.2)
[PolyType(typeof(SPAtLeastCondition), "SPAtLeast")]
[PolyType(typeof(SPAtMostCondition), "SPAtMost")]
@@ -48,6 +51,7 @@ using SOR.Database.Enums;
// Battlefield (§6.5)
[PolyType(typeof(UnitCountOnBattlefieldCondition), "UnitCountOnBattlefield")]
[PolyType(typeof(CardInZoneCondition), "CardInZone")]
+[PolyType(typeof(ControlledTileCountWithAffinityCondition), "ControlledTileCountWithAffinity")]
public abstract class Condition
{
///
@@ -93,6 +97,9 @@ public sealed class MovementTypeIsCondition : Condition { public MovementType Mo
public sealed class DestinationTileAffinityIsCondition : Condition { public Affinity Affinity { get; set; } }
public sealed class PreviousTileAffinityIsCondition : Condition { public Affinity Affinity { get; set; } }
public sealed class MovedFromOrIntoAffinityCondition : Condition { public Affinity Affinity { get; set; } }
+public sealed class IsAdjacentToTileWithAffinityCondition : Condition { public Affinity Affinity { get; set; } }
+public sealed class IsOnOrAdjacentToTileWithAffinityCondition : Condition { public Affinity Affinity { get; set; } }
+public sealed class IsCurrentlyMovingCondition : Condition { }
// ── Player conditions (§6.2) ──────────────────────────────────────────────────
@@ -136,3 +143,11 @@ public sealed class CardInZoneCondition : Condition
public string CardRef { get; set; } = string.Empty;
public string Zone { get; set; } = "Hand";
}
+
+public sealed class ControlledTileCountWithAffinityCondition : Condition
+{
+ public Affinity Affinity { get; set; }
+ public Comparator Comparator { get; set; } = Comparator.GreaterThanOrEqual;
+ public int N { get; set; }
+ public string Ownership { get; set; } = "Owner";
+}
diff --git a/Server/src/SOR.Game/Abilities/Models/Filters.cs b/Server/src/SOR.Game/Abilities/Models/Filters.cs
index ecb1581..3fcbc8e 100644
--- a/Server/src/SOR.Game/Abilities/Models/Filters.cs
+++ b/Server/src/SOR.Game/Abilities/Models/Filters.cs
@@ -25,6 +25,8 @@ using SOR.Database.Enums;
[PolyType(typeof(WithinRangeFilter), "WithinRange")]
[PolyType(typeof(IsSelfFilter), "IsSelf")]
[PolyType(typeof(IsExactSelfFilter), "IsExactSelf")]
+[PolyType(typeof(IsAdjacentToUnitMatchingFilter), "IsAdjacentToUnitMatching")]
+[PolyType(typeof(IsAdjacentToTileMatchingFilter), "IsAdjacentToTileMatching")]
// ── Tile filters ─────────────────────────────────────────────────────────────
[PolyType(typeof(TileAffinityMatchesFilter), "TileAffinityMatches")]
[PolyType(typeof(TileAffinityMatchesFilter), "TileAffinityMatchesFilter")] // legacy alias (typo in admin v1)
@@ -98,6 +100,17 @@ public sealed class IsSelfFilter : Filter { }
///
public sealed class IsExactSelfFilter : Filter { }
+public sealed class IsAdjacentToUnitMatchingFilter : Filter
+{
+ public string Ownership { get; set; } = "Any";
+ public Filter[]? UnitFilters { get; set; }
+}
+
+public sealed class IsAdjacentToTileMatchingFilter : Filter
+{
+ public Filter[]? TileFilters { get; set; }
+}
+
// ── Tile filter implementations ───────────────────────────────────────────────
public sealed class TileAffinityMatchesFilter : Filter
diff --git a/Server/src/SOR.Game/Abilities/Models/Triggers.cs b/Server/src/SOR.Game/Abilities/Models/Triggers.cs
index c7ffc98..10c203d 100644
--- a/Server/src/SOR.Game/Abilities/Models/Triggers.cs
+++ b/Server/src/SOR.Game/Abilities/Models/Triggers.cs
@@ -97,6 +97,7 @@ public sealed class OnDamageDealtTrigger : TriggerEvent
public string TargetOwnership { get; set; } = "Any";
public string DamageType { get; set; } = "Any"; // "HP" | "Defense" | "Any"
public int? Amount { get; set; }
+ public Filter? SourceFilter { get; set; }
}
public sealed class OnDamagePreventedTrigger : TriggerEvent { public string TargetOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } }
public sealed class OnHealedTrigger : TriggerEvent { public string TargetOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } public int? Amount { get; set; } }