Fix: abilitiesJson null crash, battlefield popup, ExactSelf ability filter

Client (game_screen.gd):
- Fix crash when clicking a unit with null abilitiesJson: server sends the key
  with a null value, so dict.get(key,default) returns null — guard both uses
  (_show_ability_panel and _on_hold_timer_fired) with explicit null check.
- Add double-click on battlefield units to open a full CardDetailPopup showing
  name, affinity, stats, and ability descriptions. Popup is instantiated once
  in _ready() and reused; aliases movementPoints/abilities keys as expected.

Server (Filters.cs / AbilitySystem.cs):
- IsSelf filter now matches by CardDefinitionId (definition-level: any copy of
  the same card). This is the appropriate semantic for "self" as a type scope.
- IsExactSelf filter added: matches by InstanceId (instance-level: only this
  specific unit on the battlefield). Use this to prevent duplicate-instance
  trigger bleed where two copies of a card both fire when only one acted.
- TriggerMatches now accepts the evaluating FieldCard and forwards its
  InstanceId to Own() for all ownership checks.
- Own() gains "ExactSelf" scope: fires only when occ.Data.SourceId matches the
  evaluating unit's InstanceId — eliminating the definition-level bleed bug.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-08 16:28:06 -04:00
co-authored by Claude Happy
parent 94f39be8a7
commit 11ebdc40d7
3 changed files with 93 additions and 33 deletions
@@ -26,6 +26,7 @@ using SOR.Database.Enums;
[JsonDerivedType(typeof(CardSTCostRangeFilter), "CardSTCostRange")]
[JsonDerivedType(typeof(WithinRangeFilter), "WithinRange")]
[JsonDerivedType(typeof(IsSelfFilter), "IsSelf")]
[JsonDerivedType(typeof(IsExactSelfFilter), "IsExactSelf")]
// ── Tile filters ─────────────────────────────────────────────────────────────
[JsonDerivedType(typeof(TileAffinityMatchesFilter), "TileAffinityMatches")]
[JsonDerivedType(typeof(TileIsOccupiedFilter), "TileIsOccupied")]
@@ -86,9 +87,18 @@ public sealed class CardSTCostRangeFilter : Filter { public int Min { get; set;
/// <summary>Unit must be within Min..Max Manhattan distance of the ability's source unit.</summary>
public sealed class WithinRangeFilter : Filter { public int Min { get; set; } public int Max { get; set; } }
/// <summary>Matches only the exact unit that owns this ability (not all friendly units).</summary>
/// <summary>
/// Matches any unit that shares the same card definition as the ability source.
/// Use for abilities that affect "all copies of this card type".
/// </summary>
public sealed class IsSelfFilter : Filter { }
/// <summary>
/// Matches only the exact unit instance that owns this ability (by InstanceId).
/// Use this instead of IsSelf when only the specific unit on the battlefield should be affected.
/// </summary>
public sealed class IsExactSelfFilter : Filter { }
// ── Tile filter implementations ───────────────────────────────────────────────
public sealed class TileAffinityMatchesFilter : Filter