From 1a93d3a96d249381f0553b72f0ee30ab623201a7 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 11 Aug 2015 16:30:28 +0200 Subject: [PATCH] Fixed that if cards from opponents were cast, that spell cast triggered abilities from this cards or optional additional costs from this card (e.g. Buyback) were controlled by the casting player. --- .../sets/khansoftarkir/VillainousWealth.java | 42 +++++++++---------- .../UlamogTheInfiniteGyre.java | 12 +++--- .../mage/abilities/TriggeredAbilities.java | 4 ++ .../costs/OptionalAdditionalSourceCosts.java | 7 +++- .../abilities/keyword/BuybackAbility.java | 5 ++- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/Mage.Sets/src/mage/sets/khansoftarkir/VillainousWealth.java b/Mage.Sets/src/mage/sets/khansoftarkir/VillainousWealth.java index 05f841c7266..919ade12531 100644 --- a/Mage.Sets/src/mage/sets/khansoftarkir/VillainousWealth.java +++ b/Mage.Sets/src/mage/sets/khansoftarkir/VillainousWealth.java @@ -33,6 +33,8 @@ import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; +import mage.cards.Cards; +import mage.cards.CardsImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; @@ -41,7 +43,6 @@ import mage.filter.Filter; import mage.filter.FilterCard; import mage.filter.common.FilterNonlandCard; import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; -import mage.game.ExileZone; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInExile; @@ -58,7 +59,6 @@ public class VillainousWealth extends CardImpl { super(ownerId, 211, "Villainous Wealth", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{X}{B}{G}{U}"); this.expansionSetCode = "KTK"; - // Target opponent exiles the top X cards of his or her library. You may cast any number of nonland cards with converted mana cost X or less from among them without paying their mana cost. this.getSpellAbility().addTarget(new TargetOpponent()); this.getSpellAbility().addEffect(new VillainousWealthEffect()); @@ -101,30 +101,26 @@ class VillainousWealthEffect extends OneShotEffect { filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan, source.getManaCostsToPay().getX() + 1)); UUID exileId = CardUtil.getCardExileZoneId(game, source); if (player != null) { - - // putting cards to exile shouldn't end the game, so getting minimun available - int cardsCount = Math.min(source.getManaCostsToPay().getX(), player.getLibrary().size()); - for (int i = 0; i < cardsCount; i++) { - Card card = player.getLibrary().getFromTop(game); - if (card != null) { - controller.moveCardToExileWithInfo(card, exileId, mageObject.getIdName(), source.getSourceId(), game, Zone.LIBRARY, true); + Cards cardsToExile = new CardsImpl(); + cardsToExile.addAll(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX())); + controller.moveCards(cardsToExile, null, Zone.EXILED, source, game, true); + if (controller.chooseUse(Outcome.PlayForFree, "Cast cards exiled with " + mageObject.getLogName() + " without paying its mana cost?", source, game)) { + OuterLoop: + while (cardsToExile.count(filter, game) > 0) { + TargetCardInExile target = new TargetCardInExile(0, 1, filter, exileId, false); + while (cardsToExile.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, cardsToExile, target, game)) { + Card card = game.getCard(target.getFirstTarget()); + if (card != null) { + controller.cast(card.getSpellAbility(), game, true); + cardsToExile.remove(card); + } else { + break OuterLoop; + } + target.clearChosen(); + } } } } - ExileZone exileZone = game.getExile().getExileZone(exileId); - while (exileZone != null && exileZone.count(filter, game) > 0 - && controller.chooseUse(Outcome.PlayForFree, "Cast cards exiled with " + mageObject.getLogName() +" without paying its mana cost?", source, game)) { - TargetCardInExile target = new TargetCardInExile(0,1, filter, exileId, false); - while (exileZone.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, exileZone, target, game)) { - Card card = game.getCard(target.getFirstTarget()); - if (card != null) { - controller.cast(card.getSpellAbility(), game, true); - } else { - break; - } - target.clearChosen(); - } - } return true; } diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/UlamogTheInfiniteGyre.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/UlamogTheInfiniteGyre.java index cbf82ffea26..7f3cf02de88 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/UlamogTheInfiniteGyre.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/UlamogTheInfiniteGyre.java @@ -64,7 +64,7 @@ public class UlamogTheInfiniteGyre extends CardImpl { this.power = new MageInt(10); this.toughness = new MageInt(10); - + // When you cast Ulamog, the Infinite Gyre, destroy target permanent. this.addAbility(new UlamogTheInfiniteGyreDestroyOnCastAbility()); // Annihilator 4 (Whenever this creature attacks, defending player sacrifices four permanents.) @@ -87,7 +87,7 @@ public class UlamogTheInfiniteGyre extends CardImpl { class UlamogTheInfiniteGyreDestroyOnCastAbility extends TriggeredAbilityImpl { - UlamogTheInfiniteGyreDestroyOnCastAbility ( ) { + UlamogTheInfiniteGyreDestroyOnCastAbility() { super(Zone.STACK, new DestroyTargetEffect()); this.addTarget(new TargetPermanent()); } @@ -114,13 +114,13 @@ class UlamogTheInfiniteGyreDestroyOnCastAbility extends TriggeredAbilityImpl { @Override public String getRule() { - return new StringBuilder("When you cast {this}, ").append(super.getRule()).toString(); + return "When you cast {this}, " + super.getRule(); } } class UlamogTheInfiniteGyreEnterGraveyardEffect extends OneShotEffect { - UlamogTheInfiniteGyreEnterGraveyardEffect ( ) { + UlamogTheInfiniteGyreEnterGraveyardEffect() { super(Outcome.Benefit); staticText = "its owner shuffles his or her graveyard into his or her library"; } @@ -144,9 +144,9 @@ class UlamogTheInfiniteGyreEnterGraveyardEffect extends OneShotEffect { } Player player = game.getPlayer(ownerId); if (player != null) { - for (Card cardToMove: player.getGraveyard().getCards(game)) { + for (Card cardToMove : player.getGraveyard().getCards(game)) { cardToMove.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true); - } + } player.shuffleLibrary(game); return true; } diff --git a/Mage/src/mage/abilities/TriggeredAbilities.java b/Mage/src/mage/abilities/TriggeredAbilities.java index 5bf7818a30a..969e3cb78fa 100644 --- a/Mage/src/mage/abilities/TriggeredAbilities.java +++ b/Mage/src/mage/abilities/TriggeredAbilities.java @@ -43,6 +43,7 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; +import mage.game.stack.Spell; /** * @@ -95,6 +96,9 @@ public class TriggeredAbilities extends ConcurrentHashMap