From 4afdcc860a5be7d1af4f617a20ed50874d91896d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 18 Mar 2018 23:38:24 +0100 Subject: [PATCH] * Alhammarret, High Arbiter - Fixed not working ability that prevents spell casting (fixes #4561). --- .../mage/cards/a/AlhammarretHighArbiter.java | 33 +++++++++++-------- .../mage/test/cards/rules/CantCastTest.java | 28 ++++++++++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java b/Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java index 28e94077ce7..5b16fa0ef08 100644 --- a/Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java +++ b/Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java @@ -27,7 +27,6 @@ */ package mage.cards.a; -import java.util.Objects; import java.util.UUID; import mage.MageInt; import mage.MageObject; @@ -56,7 +55,7 @@ import mage.util.GameLog; public class AlhammarretHighArbiter extends CardImpl { public AlhammarretHighArbiter(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{5}{U}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{U}{U}"); addSuperType(SuperType.LEGENDARY); this.subtype.add(SubType.SPHINX); this.power = new MageInt(5); @@ -101,14 +100,12 @@ class AlhammarretHighArbiterEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Cards revealedCards = new CardsImpl(); - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - if (!Objects.equals(playerId, controller.getId())) { - Player opponent = game.getPlayer(playerId); - if (opponent != null) { - Cards cards = new CardsImpl(opponent.getHand()); - opponent.revealCards(opponent.getName() + "'s hand", cards, game); - revealedCards.addAll(cards); - } + for (UUID playerId : game.getOpponents(controller.getId())) { + Player opponent = game.getPlayer(playerId); + if (opponent != null) { + Cards cards = new CardsImpl(opponent.getHand()); + opponent.revealCards(opponent.getName() + "'s hand", cards, game); + revealedCards.addAll(cards); } } TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard("nonland card from an opponents hand")); @@ -116,7 +113,10 @@ class AlhammarretHighArbiterEffect extends OneShotEffect { Card card = game.getCard(target.getFirstTarget()); if (card != null) { game.informPlayers("The choosen card name is [" + GameLog.getColoredObjectName(card) + ']'); - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); + Permanent sourcePermanent = game.getPermanentEntering(source.getSourceId()); + if (sourcePermanent == null) { + sourcePermanent = game.getPermanentEntering(source.getSourceId()); + } if (sourcePermanent != null) { sourcePermanent.addInfo("chosen card name", CardUtil.addToolTipMarkTags("Chosen card name: " + card.getName()), game); } @@ -132,6 +132,7 @@ class AlhammarretHighArbiterEffect extends OneShotEffect { class AlhammarretHighArbiterCantCastEffect extends ContinuousRuleModifyingEffectImpl { String cardName; + int zoneChangeCounter; public AlhammarretHighArbiterCantCastEffect(String cardName) { super(Duration.Custom, Outcome.Benefit); @@ -142,6 +143,13 @@ class AlhammarretHighArbiterCantCastEffect extends ContinuousRuleModifyingEffect public AlhammarretHighArbiterCantCastEffect(final AlhammarretHighArbiterCantCastEffect effect) { super(effect); this.cardName = effect.cardName; + this.zoneChangeCounter = effect.zoneChangeCounter; + } + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + zoneChangeCounter = game.getState().getZoneChangeCounter(source.getId()); } @Override @@ -151,8 +159,7 @@ class AlhammarretHighArbiterCantCastEffect extends ContinuousRuleModifyingEffect @Override public boolean isInactive(Ability source, Game game) { - Permanent sourceObject = game.getPermanent(source.getSourceId()); - return sourceObject == null || sourceObject.getZoneChangeCounter(game) != source.getSourceObjectZoneChangeCounter(); + return game.getState().getZoneChangeCounter(source.getId()) != zoneChangeCounter; } @Override diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java index 7c031f75f44..3f875d6fa98 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/rules/CantCastTest.java @@ -236,4 +236,32 @@ public class CantCastTest extends CardTestPlayerBase { } + /** + * Alhammarret, High Arbiter's ability doesn't work Despite naming the + * Damnation in my hand, I was able to cast it next turn without issue. + */ + @Test + public void testAlhammarret() { + // Flying + // As Alhammarret, High Arbiter enters the battlefield, each opponent reveals his or her hand. You choose the name of a nonland card revealed this way. + // Your opponents can't cast spells with the chosen name. + addCard(Zone.HAND, playerA, "Alhammarret, High Arbiter", 4); // Creature - {5}{U}{U} + addCard(Zone.BATTLEFIELD, playerA, "Island", 7); + + // Destroy all creatures. They can't be regenerated. + addCard(Zone.HAND, playerB, "Damnation", 1); // SORCERY {2}{B}{B} + addCard(Zone.BATTLEFIELD, playerB, "Swamp", 4); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Alhammarret, High Arbiter"); + setChoice(playerA, "Damnation"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Damnation"); + setStopAt(2, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Alhammarret, High Arbiter", 1); + assertHandCount(playerB, "Damnation", 1); + + } + }