From aa96a4af8642e3dbb5eade499464d10e8d169de9 Mon Sep 17 00:00:00 2001 From: Daniel Bomar Date: Sun, 17 Oct 2021 19:08:50 -0500 Subject: [PATCH] Fixed Ward countering wrong ability (fixes #8378) --- .../mage/abilities/keyword/WardAbility.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/keyword/WardAbility.java b/Mage/src/main/java/mage/abilities/keyword/WardAbility.java index 586ee2a118..0d9ce2405b 100644 --- a/Mage/src/main/java/mage/abilities/keyword/WardAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/WardAbility.java @@ -8,6 +8,7 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.stack.StackObject; +import mage.target.Target; import mage.target.targetpointer.FixedTarget; import mage.util.CardUtil; @@ -33,16 +34,29 @@ public class WardAbility extends TriggeredAbilityImpl { return event.getType() == GameEvent.EventType.TARGETED; } + private StackObject getTargetingObject(GameEvent event, Game game) { + for (StackObject stackObject : game.getStack()) { + if (stackObject.getId().equals(event.getSourceId()) || stackObject.getSourceId().equals(event.getSourceId())) { + for (Target target : stackObject.getStackAbility().getTargets()) { + if (target.contains(getSourceId())) { + return stackObject; + } + } + } + } + return null; + } + @Override public boolean checkTrigger(GameEvent event, Game game) { if (!getSourceId().equals(event.getTargetId())) { return false; } - StackObject stackObject = game.getStack().getStackObject(event.getSourceId()); + StackObject stackObject = getTargetingObject(event, game); if (stackObject == null || !game.getOpponents(getControllerId()).contains(stackObject.getControllerId())) { return false; } - getEffects().setTargetPointer(new FixedTarget(event.getSourceId(), game)); + getEffects().setTargetPointer(new FixedTarget(stackObject.getId(), game)); return true; }