Implement UnitSentToDiscard trigger — enables Bloodlust abilities

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>
This commit is contained in:
dingo
2026-03-25 21:14:44 -04:00
co-authored by Claude Happy
parent ff973ce9c3
commit c692d8ec64
3 changed files with 43 additions and 3 deletions
@@ -58,6 +58,7 @@ public enum TriggerEventKind
UnitAbilityActivated,
DamageDealt,
UnitDeath,
UnitSentToDiscard,
SpiritSacrificed,
UnitEnterBattlefield,
UnitLeaveBattlefield,
+26 -3
View File
@@ -691,7 +691,7 @@ public static class AbilitySystem
ci.CurrentHealth = (ci.CurrentHealth ?? 0) + amt;
if (ci.MaxHealth.HasValue)
ci.CurrentHealth = Math.Min(ci.CurrentHealth.Value, ci.MaxHealth.Value);
if (ci.CurrentHealth <= 0) KillUnit(ci, ctx);
if (ci.CurrentHealth <= 0) KillUnit(ci, ctx, ctx.Source?.InstanceId);
}
else
{
@@ -1151,6 +1151,14 @@ public static class AbilitySystem
RevokePassivesForSource(ctx.State, ci.InstanceId);
RemoveFromAllZones(owner, ci, ctx.State.Board);
owner.Discard.Add(ci);
FireTrigger(ctx.State, new TriggerOccurrence
{
Kind = TriggerEventKind.UnitSentToDiscard,
ActorId = owner.AccountId,
Data = new TriggerEventData { TargetId = ci.InstanceId, SourceId = ctx.Source?.InstanceId },
UnitType = ci.CardType,
});
}
break;
}
@@ -1412,10 +1420,10 @@ public static class AbilitySystem
? rawAmount
: Math.Max(0, rawAmount - (unit.CurrentDefense ?? 0));
unit.CurrentHealth = (unit.CurrentHealth ?? 0) - net;
if (unit.CurrentHealth <= 0) KillUnit(unit, ctx);
if (unit.CurrentHealth <= 0) KillUnit(unit, ctx, ctx.Source?.InstanceId);
}
private static void KillUnit(CardInstance unit, AbilityContext ctx)
private static void KillUnit(CardInstance unit, AbilityContext ctx, string? killerInstanceId = null)
{
var owner = FindCardOwner(ctx.State, unit.InstanceId);
if (owner is null) return;
@@ -1441,6 +1449,14 @@ public static class AbilitySystem
Data = new TriggerEventData { TargetId = unit.InstanceId },
UnitType = unit.CardType,
});
FireTrigger(ctx.State, new TriggerOccurrence
{
Kind = TriggerEventKind.UnitSentToDiscard,
ActorId = owner.AccountId,
Data = new TriggerEventData { TargetId = unit.InstanceId, SourceId = killerInstanceId },
UnitType = unit.CardType,
});
}
// ── Displacement helper ───────────────────────────────────────────────────
@@ -1718,6 +1734,13 @@ public static class AbilitySystem
occurrence.Kind == TriggerEventKind.UnitDeath
&& UnitType(t.UnitType, occurrence.UnitType)
&& Own(t.Ownership, occurrence, ownerId, state, uid),
// Ownership = victim's side ("Enemy" = opponent spirit was discarded).
// CausedBy = killer scope; "ExactSelf" = this specific unit caused the discard.
OnUnitSentToDiscardTrigger t =>
occurrence.Kind == TriggerEventKind.UnitSentToDiscard
&& 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,
OnUnitEnterBattlefieldTrigger t =>
+16
View File
@@ -708,6 +708,14 @@ public static class GameEngine
UnitType = attacker.CardType,
Data = new TriggerEventData { TargetId = attacker.InstanceId },
});
// Attacker was killed by the target's counterattack.
AbilitySystem.FireTrigger(state, new TriggerOccurrence
{
Kind = TriggerEventKind.UnitSentToDiscard,
ActorId = actorId, // victim's player
UnitType = attacker.CardType,
Data = new TriggerEventData { TargetId = attacker.InstanceId, SourceId = target.InstanceId },
});
}
if (target.CurrentHealth <= 0)
@@ -731,6 +739,14 @@ public static class GameEngine
UnitType = target.CardType,
Data = new TriggerEventData { TargetId = target.InstanceId },
});
// Target was killed by the attacker.
AbilitySystem.FireTrigger(state, new TriggerOccurrence
{
Kind = TriggerEventKind.UnitSentToDiscard,
ActorId = opponentId, // victim's player
UnitType = target.CardType,
Data = new TriggerEventData { TargetId = target.InstanceId, SourceId = attacker.InstanceId },
});
}
}