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 }, + }); } }