From cd4b93a71acf0f3b061bee6e74ee37112055ddcd Mon Sep 17 00:00:00 2001 From: Daniel Bomar Date: Sat, 27 Feb 2021 12:36:57 -0600 Subject: [PATCH] [KHM] Fixed Battle Mammoth triggering too many times --- Mage.Sets/src/mage/cards/b/BattleMammoth.java | 34 ++++++++++++++++--- .../src/mage/cards/l/LeylineOfCombustion.java | 3 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Mage.Sets/src/mage/cards/b/BattleMammoth.java b/Mage.Sets/src/mage/cards/b/BattleMammoth.java index e2e1297b70..868a36c2bc 100644 --- a/Mage.Sets/src/mage/cards/b/BattleMammoth.java +++ b/Mage.Sets/src/mage/cards/b/BattleMammoth.java @@ -13,9 +13,10 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; +import mage.game.stack.StackObject; import mage.players.Player; -import java.util.UUID; +import java.util.*; /** * @author TheElk801 @@ -71,13 +72,38 @@ class BattleMammothTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { + StackObject sourceObject = game.getStack().getStackObject(event.getSourceId()); + if (sourceObject == null) { + return false; + } + Player targetter = game.getPlayer(event.getPlayerId()); + if (targetter == null || !targetter.hasOpponent(this.controllerId, game)) { + return false; + } Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId()); if (permanent == null || !permanent.isControlledBy(this.getControllerId())) { return false; } - Player targetter = game.getPlayer(event.getPlayerId()); - Object object = game.getObject(event.getSourceId()); - return object != null && targetter != null && targetter.hasOpponent(this.getControllerId(), game); + // If a spell or ability an opponent controls targets a single permanent you control more than once, + // Battle Mammoth’s triggered ability will trigger only once. + // However, if a spell or ability an opponent controls targets multiple permanents you control, + // Battle Mammoth’s triggered ability will trigger once for each of those permanents. + + // targetMap - key - targetId, value - Set of stackObject Ids + Map> targetMap = (Map>) game.getState().getValue("targetMap" + this.id); + if (targetMap == null) { + targetMap = new HashMap<>(); + } + Set sourceObjects = targetMap.get(event.getTargetId()); + if (sourceObjects == null) { + sourceObjects = new HashSet<>(); + } + if (!sourceObjects.add(sourceObject.getId())) { + return false; + } + targetMap.put(event.getTargetId(), sourceObjects); + game.getState().setValue("targetMap" + this.id, targetMap); + return true; } @Override diff --git a/Mage.Sets/src/mage/cards/l/LeylineOfCombustion.java b/Mage.Sets/src/mage/cards/l/LeylineOfCombustion.java index d01e767e31..cc442623c3 100644 --- a/Mage.Sets/src/mage/cards/l/LeylineOfCombustion.java +++ b/Mage.Sets/src/mage/cards/l/LeylineOfCombustion.java @@ -87,10 +87,9 @@ class LeylineOfCombustionTriggeredAbility extends TriggeredAbilityImpl { if (sourceObjects == null) { sourceObjects = new HashSet<>(); } - if (sourceObjects.contains(sourceObject.getId())) { + if (!sourceObjects.add(sourceObject.getId())) { return false; } - sourceObjects.add(sourceObject.getId()); game.getState().setValue("sourceObjects" + this.id, sourceObjects); this.getEffects().clear(); Effect effect = new DamageTargetEffect(2);