From 5cf5990251d24397ebfb8c8c4b609126df3ed145 Mon Sep 17 00:00:00 2001 From: Marshall Date: Mon, 15 Jun 2015 20:48:56 -0400 Subject: [PATCH] Fertilid fix that actually lets the target player search library, not Fertilid's controller --- .../src/mage/sets/commander/Fertilid.java | 49 ++++++++++++++++++- .../search/SearchLibraryPutInPlayEffect.java | 4 +- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Mage.Sets/src/mage/sets/commander/Fertilid.java b/Mage.Sets/src/mage/sets/commander/Fertilid.java index ea820f44fed..fd4d14ce21a 100644 --- a/Mage.Sets/src/mage/sets/commander/Fertilid.java +++ b/Mage.Sets/src/mage/sets/commander/Fertilid.java @@ -36,12 +36,15 @@ import mage.abilities.costs.common.RemoveCountersSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect; +import mage.cards.Card; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; import mage.constants.Zone; import mage.counters.CounterType; import mage.filter.common.FilterBasicLandCard; +import mage.game.Game; +import mage.players.Player; import mage.target.TargetPlayer; import mage.target.common.TargetCardInLibrary; @@ -61,7 +64,7 @@ public class Fertilid extends CardImpl { // Fertilid enters the battlefield with two +1/+1 counters on it. this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(2)), "with two +1/+1 counters on it")); // {1}{G}, Remove a +1/+1 counter from Fertilid: Target player searches his or her library for a basic land card and puts it onto the battlefield tapped. Then that player shuffles his or her library. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(new FilterBasicLandCard()), true, true), new ManaCostsImpl("{1}{G}")); + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new FertilidEffect(new TargetCardInLibrary(new FilterBasicLandCard()), true, true), new ManaCostsImpl("{1}{G}")); ability.addCost(new RemoveCountersSourceCost(CounterType.P1P1.createInstance(1))); ability.addTarget(new TargetPlayer()); this.addAbility(ability); @@ -76,3 +79,47 @@ public class Fertilid extends CardImpl { return new Fertilid(this); } } + +class FertilidEffect extends SearchLibraryPutInPlayEffect { + + public FertilidEffect(TargetCardInLibrary target, boolean tapped, boolean forceShuffle) { + super(target, tapped, forceShuffle); + + this.staticText = "Target player searches his or her library for a basic land card and puts it onto the battlefield tapped. Then that player shuffles his or her library."; + } + + public FertilidEffect(final FertilidEffect effect) { + super(effect); + } + + @Override + public FertilidEffect copy() { + return new FertilidEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(targetPointer.getFirst(game, source)); + + if (player != null) { + if (player.searchLibrary(target, game)) { + if (target.getTargets().size() > 0) { + for (UUID cardId: target.getTargets()) { + Card card = player.getLibrary().getCard(cardId, game); + if (card != null) { + player.putOntoBattlefieldWithInfo(card, game, Zone.LIBRARY, source.getSourceId(), tapped); + } + } + } + player.shuffleLibrary(game); + return true; + } + + if (forceShuffle) { + player.shuffleLibrary(game); + } + } + + return false; + } +} diff --git a/Mage/src/mage/abilities/effects/common/search/SearchLibraryPutInPlayEffect.java b/Mage/src/mage/abilities/effects/common/search/SearchLibraryPutInPlayEffect.java index 01014677be6..6776adcc8ea 100644 --- a/Mage/src/mage/abilities/effects/common/search/SearchLibraryPutInPlayEffect.java +++ b/Mage/src/mage/abilities/effects/common/search/SearchLibraryPutInPlayEffect.java @@ -45,8 +45,8 @@ import mage.target.common.TargetCardInLibrary; */ public class SearchLibraryPutInPlayEffect extends SearchEffect { - private boolean tapped; - private boolean forceShuffle; + protected boolean tapped; + protected boolean forceShuffle; public SearchLibraryPutInPlayEffect(TargetCardInLibrary target) { this(target, false, true, Outcome.PutCardInPlay);