From c692d8ec6404ea65fcbedb3f054745e895987cf7 Mon Sep 17 00:00:00 2001 From: dingo Date: Wed, 25 Mar 2026 21:14:44 -0400 Subject: [PATCH] =?UTF-8?q?Implement=20UnitSentToDiscard=20trigger=20?= =?UTF-8?q?=E2=80=94=20enables=20Bloodlust=20abilities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-Authored-By: Happy --- .../src/SOR.Game/Abilities/AbilityContext.cs | 1 + .../src/SOR.Game/Abilities/AbilitySystem.cs | 29 +++++++++++++++++-- Server/src/SOR.Game/GameEngine.cs | 16 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Server/src/SOR.Game/Abilities/AbilityContext.cs b/Server/src/SOR.Game/Abilities/AbilityContext.cs index 230467c..b71412e 100644 --- a/Server/src/SOR.Game/Abilities/AbilityContext.cs +++ b/Server/src/SOR.Game/Abilities/AbilityContext.cs @@ -58,6 +58,7 @@ public enum TriggerEventKind UnitAbilityActivated, DamageDealt, UnitDeath, + UnitSentToDiscard, SpiritSacrificed, UnitEnterBattlefield, UnitLeaveBattlefield, diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 147c6fc..d5f5f48 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -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 => diff --git a/Server/src/SOR.Game/GameEngine.cs b/Server/src/SOR.Game/GameEngine.cs index 6709735..1e49e67 100644 --- a/Server/src/SOR.Game/GameEngine.cs +++ b/Server/src/SOR.Game/GameEngine.cs @@ -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 }, + }); } }