New TriggerEventKind.UnitSentToDiscard fires whenever a unit is moved to the
discard pile, carrying SourceId = the killer unit's instance ID and
ActorId = the victim's player — consistent with UnitDeath convention.
Wired in 4 paths:
- GameEngine.cs attack: attacker killed by counterattack (SourceId = target)
- GameEngine.cs attack: target killed by attacker (SourceId = attacker)
- AbilitySystem KillUnit: ability/effect-driven death (SourceId = ctx.Source)
- AbilitySystem SendToDiscardEffect: direct discard effect (SourceId = ctx.Source)
OnUnitSentToDiscardTrigger is now matched in TriggerMatches. CausedBy field
acts as killer ownership scope; CausedBy="ExactSelf" checks SourceId == this
unit's InstanceId via the existing Own() helper, enabling:
Bloodlust Aggression:
{ type:"OnUnitSentToDiscard", unitType:"Spirit", ownership:"Enemy",
causedBy:"ExactSelf" }
→ ModifyDamageEffect { Amount:1 }, Duration: PermanentInMatch
Bloodlust Vitality:
{ type:"OnUnitSentToDiscard", unitType:"Spirit", ownership:"Enemy",
causedBy:"ExactSelf" }
→ ModifyMPEffect { Amount:1, StatTarget:"Max" }, Duration: UntilEndOfTurn
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>
- Bazaar Deck tab crash: null-safe float conversion for usdPrice in store_item_row.gd
- Leaderboard crash: freed-object guard in _on_leaderboard_ok (is_instance_valid check)
- Add ModifyMinAttackRangeEffect / ModifyMaxAttackRangeEffect with clamp-to-0 and correct reversal tracking
- AbilityBuilder: add new range effects to Stat Modification group + _amountOnlyTypes
- collection.set_arch_spirit: new handler, request record, and service registration
- Deck editor: show Tier-1 commander row with Change button + ArchSpirit picker panel
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>
Previously, Aura abilities only fired OnEnterAuraRange / OnLeaveAuraRange
trigger events — their own Actions were never executed. Auras now directly
apply their Actions to any unit that enters range (using WhileSourceOnBattlefield
by default) and handle departure via three modes:
- Persist (default): effects expire at their configured Duration unchanged
- ClearOnLeave: effects are reverted immediately when the unit leaves range
- LingerDuration: effects switch to the specified duration when leaving range,
allowing them to outlive the aura's reach (and the source if it leaves)
Server:
- AbilityDefinition: add ClearOnLeave (bool) and LingerDuration (DurationModel?)
- AbilitySystem: add ApplyAuraEffects + HandleAuraLeave helpers;
refactor FireAuraTransition to take FieldCard + AbilityDefinition and call
both helpers; update all six call sites in EvaluateAuraTransitions /
EvaluateAurasOnEnter / EvaluateAurasOnLeave to use the unified path
Admin:
- AbilityBuilder: add AuraClearOnLeave / AuraLingerDurationStr / N draft fields;
parse + compile round-trip; 3-radio On Leave UI + optional Linger duration select;
update Aura help row to describe the new behaviour
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>
- AbilitySystem: add TileAffinityMatchesCondition case for FieldCard subject
so activation conditions check the tile the unit is currently standing on
(previously only handled Coord subjects; triggered abilities pass FieldCard)
- AbilityBuilder: add "ExactSelf" to OwnershipValues dropdown for trigger events
so designers can restrict triggers to only this specific unit instance
- AbilityBuilder help section: add Trigger Ownership table documenting all
ownership values including ExactSelf with clear explanation of instance-level scope
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>
SetAffinity previously hardcoded Base1=Void which is only correct for
basic affinities. Non-basics like Jungle need (Forest,Forest), Island
needs (Lake,Hill), etc. — Void+Jungle would fall through to PureVoid.
Added AffinitySystem.Decompose(Affinity) which reverse-maps every
resolved affinity to its canonical (Base1, Base2) pair. SetAffinity
on tiles now calls Decompose so any affinity — basic or non-basic —
is stored correctly and Resolve() returns the intended value.
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>
Setting both slots to the same basic affinity produces the wrong
resolved value (Lake+Lake→Ocean). Basic tiles are represented as
(Void, Basic) per §8, so SetAffinity now sets Base1=Void and
Base2=newAffinity. Both original slot values are still tracked
for reversal when the duration expires.
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>
Bug: Battlefield/All tile targets were always empty — the tile
resolution path required client-provided coords for every case,
but board-wide abilities (Scope=Battlefield, All=true) never send
coords from the client. Added server-side enumeration of all board
tiles for this case.
Fix: SetAffinity on a tile now writes both Base1 and Base2 to
the new affinity so AffinitySystem.Resolve returns the correct
value unambiguously. Reversal tracks both slots independently so
both are restored when the duration expires.
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>
Bug 1 — SetAffinityEffect silently ignored for Coord targets:
ExecuteEffect had no tile case for SetAffinityEffect (only handled
CardInstance). Added case that writes to Base2 and tracks the original
value for duration reversal using a "tile:X,Y" target ref.
Bug 2 — ApplyReversal couldn't find tile targets:
The reversal lookup only searched players' card zones. Added parsing
of the "tile:X,Y" ref format to produce the Coord used to re-execute
the SetBaseAffinity2 reversal effect.
Bug 3 — TileIsOccupied / TileIsUnoccupied / TileAffinityMatches
conditions not implemented in EvaluateCondition:
All three tile condition types fell through to the default (return true),
so conditions like TileIsOccupied were silently no-ops. Implemented all
three with proper tile lookup and occupant/affinity checks.
Wavecrasher (SetAffinity Lake on occupied tiles, ForNTurns:2) now
correctly selects only occupied tiles, changes their affinity, and
reverts them automatically after two turns.
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>
- AbilityBuilder.razor: replace raw JSON textarea with full structured
editor for SummonToken effects. Supports two modes:
• Existing Card — searchable autocomplete from Spirit card catalog
• Custom Token — inline editor for all Spirit stats (name, affinity,
health/defense/damage, movement type/MP, attack range, LOS, all
permission flags, genus tags, abilities JSON, 2D art URL, 3D model URL)
Compiles TileFilter[TileAffinityMatchesFilter] when affinity is non-Void,
enabling client-side tile highlighting to match server enforcement.
- AbilitySystem.cs (SummonTokenEffect): validate that the target tile's
affinity is compatible with the token's affinity before placing.
- GameState.cs (CardInstance): add Art2dUrl + ModelUrl so summoned tokens
can carry visual asset references through the game state.
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>
- AbilitySystem.cs: ActivateAbility was only searching player.Field for the
source unit, but player.ArchSpirit is stored in a separate field and was never
checked. Active abilities on an ArchSpirit now work correctly.
- game_screen.gd: Add "Target" to auto_ownerships so the client skips the
player-picker UI for Ownership:Target actions. The server auto-resolves them
from ctx.ResolvedTargets (the owner of the previously targeted card), which
is exactly what Bounce needs: refund SP to the owner of the returned spirit
without asking the user to choose a player.
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>
- AbilityBuilder.razor: ReadFixed now checks if the JSON node is a JsonObject
before calling GetValue<int>() on it. Previously, a ValueExpr like
{"Ref":"Target.SpCost"} caused an InvalidOperationException that was swallowed
silently by ParseJson's catch block, leaving the builder showing no abilities.
- AbilitySystem.cs: TargetOwnership.Target on Player-type selectors now resolves
to the owner of the last CardInstance in ctx.ResolvedTargets. This enables
abilities like Bounce: Action 1 returns a spirit to hand, Action 2 targets that
spirit's owner (Ownership:Target) to refund its channel cost via a Ref value.
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>
- Skip ActivationConditions with Subject=="Target" in ActivateAbility (mirrors
AbilitiesJson code path) so conditions like IsOnTileWithAffinity{Target,Lake}
aren't evaluated against the source unit at activation time
- Add RevokePassivesForSource call in ReturnToHandEffect before removing the
unit from the field, matching SendToDiscardEffect pattern
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>
Client: Repentance/Instinct cards with Active abilities in abilitiesJson now
enter ABILITY_TARGET mode instead of sending play_card immediately. Units on
matching tile affinities (IsOnTileWithAffinity) are highlighted in blue; the
player clicks a target unit and the card is sent with the selected unit target.
Server: FireCardEffects now also processes Active abilities from AbilitiesJson
(after the existing EffectsJson path). Source-side ActivationConditions are
checked; target-side conditions (Subject=Target) are trusted from the client.
New Game.gd helper: send_play_card_with_targets sends play_card with a targets
array so the server can route unit selections to the active ability handler.
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>
Issue 1 — ActivationConditions on passives were never checked:
- ApplyPassivesForSource and ApplyPassivesToNewTarget now evaluate
ActivationConditions against the source unit before executing each
passive ability (e.g. IsOnTileWithAffinity: Lake only grants the buff
when the unit is actually on a Lake tile).
Issue 1 — Passives not re-evaluated on movement / tile changes:
- Added ReEvaluateConditionalPassives(state): for every unit with at
least one conditional passive, revoke all WhileSourceOnBattlefield
effects then reapply with conditions re-checked. Units without
conditional passives are skipped with zero overhead.
- Called after MoveUnit (unit changes tile affinity),
ActivateAbility (ability may change board state),
and ChannelCard Terramorpha path (tile affinities change).
Issue 2 — INSUFFICIENT_TARGETS thrown from ApplyPassivesToNewTarget:
- ResolveTargets: when restrictTargets is set (passive-to-new-target
mode only) and filtering produces zero candidates, return [] silently
instead of throwing. An ExactSelf source-buff simply has no valid
target among the new unit — that is expected, not an error.
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>
AbilityDefinition gains an optional Duration property. When set it is used
as forceDuration for every ExecuteActions call that resolves that ability,
overriding whatever per-action Duration individual effects specify.
- Active abilities: def.Duration is threaded through as forceDuration
- Triggered abilities: same
- Passive abilities: def.Duration ?? WhileSourceOnBattlefield (both
ApplyPassivesForSource and ApplyPassivesToNewTarget paths)
AbilityBuilder admin panel:
- Duration row added after type-specific fields (dropdown + N input for ForNTurns)
- "WhileSourceOnBattlefield" added to the DurationTypeValues list
- Parse and compile paths updated for the new Duration field
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>
DefinitionToInstance and ToFieldCard both omitted copying Genus, so
HasGenusCondition and GenusContainsFilter always evaluated against null
(returning false). All three data-flow gaps are now fixed:
- DefinitionToInstance: def.Genus?.ToList() → CardInstance.Genus
- ToFieldCard: source.Genus?.ToList() → FieldCard.Genus
- FilterMatches: GenusContainsFilter now handled (was falling to _ => true)
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>
Passive abilities (e.g. 'All Merfolk +1 attack') were never executed
because AbilityType.Passive had no runtime processing.
Three root causes fixed:
1. Passive abilities are now applied when units enter the battlefield
and reversed when they leave (new DurationType.WhileSourceOnBattlefield).
- ApplyPassivesForSource: runs a unit's passives against all current targets
- ApplyPassivesToNewTarget: applies existing passives to a newly-entered unit
- RevokePassivesForSource: reverses all passive effects on source death/leave
- Hooked into GameEngine.Channel, Transition and AbilitySystem
ReturnToBattlefield, SummonToken, KillUnit, SendToDiscard
2. Action conditions with Subject="Target" now filter per-target instead of
aborting the entire action (which evaluated against ctx.Source).
Source-level conditions still gate the whole action; target-level ones
are evaluated individually and skip non-matching targets.
3. ExecuteActions/ResolveTargets gain a restrictTargets parameter used by
ApplyPassivesToNewTarget to avoid double-applying existing passive buffs
to units that already received them when the passive source entered.
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>
- AbilitySystem: implement WithinRangeFilter (Manhattan distance min/max) and
IsAdjacentToSourceFilter in FilterMatches — both were falling through to
_ => true, so range constraints on targeting were silently ignored
- Program.cs: add GET /cdn/{**path} proxy endpoint with
Access-Control-Allow-Origin: * so browser web clients can fetch GLB models
(Ceph RadosGW / cdn.aeternalisgames.com has no CORS headers)
- ModelCache.gd: on web export, rewrite cdn.aeternalisgames.com URLs to go
through hub.aeternalisgames.com/cdn proxy; disk/memory cache still keyed
on the original CDN URL for consistency across platforms
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>
BuildCandidates only added p.Field to the candidate pool for
Scope=Battlefield, leaving p.ArchSpirit (stored as a separate
PlayerState property) out. A Unit-typed ability targeting the
opponent's ArchSpirit would match zero candidates → INSUFFICIENT_TARGETS.
Also include p.ArchSpirit in the AnyZone pool for consistency.
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>
Refactor EffectPolymorphicConverter into a generic PolymorphicAbilityConverter<T>
base class, add concrete converters for all four abstract ability model types:
Effect, Condition, TriggerEvent, and Filter — all share the same abstract +
[JsonPolymorphic] pattern and the same ordering constraint from the admin builder.
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>
[JsonPolymorphic] on an abstract base class requires $type to appear first in
the JSON object. Card abilities authored in the admin tool don't guarantee this
ordering (e.g. {"N":1,"$type":"DrawCards","Player":"Owner"}), causing a
NotSupportedException at ParseAbilities time.
Add EffectPolymorphicConverter which overrides CanConvert to intercept only
typeof(Effect) (not concrete derived types). It buffers the full JSON object,
finds $type at any position, looks up the concrete type from the [JsonDerivedType]
attribute map, then deserializes via the default converter. Because CanConvert
returns false for concrete types, there is no infinite recursion even for nested
Effect[] (e.g. ApplyOnEventEffect.Effects).
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>
`ExactSelf` was accepted by the admin builder dropdown but crashed on
deserialization because the TargetOwnership enum was missing the value.
- Added `ExactSelf` to `TargetOwnership` enum in Action.cs
- BuildCandidates treats ExactSelf like Self/Owner (actor's player pool)
- ResolveTargets post-filters to ctx.Source.InstanceId when ExactSelf
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>
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>
• Light/dark mode toggle: Bootstrap 5.3 data-bs-theme, theme persisted to
localStorage via admin.js, Moon/Sun icon button in sidebar, flash-free
inline <script> in App.razor applies saved theme before first render.
• Account management: Add "Create Account" button + new /accounts/new page
(email, display name, password, role checkboxes). AccountDetail now has
interactive role assignment (Add/Remove Admin/SuperAdmin — SuperAdmin
actions gated with <AuthorizeView Roles="SuperAdmin">) and a force-reset
password section (RemovePasswordAsync + AddPasswordAsync, no current
password required).
• Chat fixes: stat card labels changed from text-muted → text-white-50 for
readability on bg-dark; card-headers now have border-bottom border-secondary
to visually separate from card bodies; "View" button relabeled "View & Post"
to surface the hidden compose feature.
• Ability builder (AbilityBuilder.razor): structured UI replacing the raw
textarea in CardEditor. Supports all 4 ability types (Active/Passive/Aura/
Triggered) with type-specific fields (range, uses/turn, aura range, trigger
dropdown). Each ability holds structured actions (scope/type/ownership/count
dropdowns) and effects (59 types in 11 grouped optgroups; each auto-populates
a JSON fields template on type selection). Description field stores plain-
English text in the JSON. Raw JSON toggle + Apply for power users. Live
compiled JSON preview.
• AbilitySystem: added JsonStringEnumConverter so JSONB enums serialize as
human-readable strings ("Active" vs 0, "Battlefield" vs 3, etc.).
• AbilityDefinition: added optional Description property (admin-only metadata).
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>
- Add EnterAuraRange and LeaveAuraRange to TriggerEventKind enum
- Add TriggerMatches cases for OnEnterAuraRangeTrigger / OnLeaveAuraRangeTrigger
with AuraOwnership + UnitOwnerMatches (ally/enemy/any) scope filtering
- Add EvaluateAuraTransitions (on move), EvaluateAurasOnEnter (on channel),
EvaluateAurasOnLeave (on sacrifice/kill) public methods to AbilitySystem
- Bidirectional evaluation: moving unit vs. stationary auras + moving unit's
own auras vs. stationary units
- Hook into GameEngine: MoveUnit, ChannelCard (Spirit), Sacrifice
- KillUnit now calls EvaluateAurasOnLeave before board removal
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>
- ExecuteEffect now builds and stores reversal effects in GameState.ActiveEffects
for all non-Instant durations (stat deltas, flag toggles, genus, affinity)
- DOT/HOT effects register tick entries instead of reversals
- TrackedDuration wrapper records owner + IsTick flag alongside DurationModel
- ExpireActiveEffects handles UntilEndOfTurn, UntilStartOfOwnerTurn, ForNTurns,
WhileCondition; applies reversal on expiry for non-tick entries
- TickActiveEffects fires DOT/HOT damage/healing each turn end
- GameEngine.EndTurn: tick → expire(end) after TurnEnd trigger;
expire(start) after player switch, before TurnStart trigger
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>