implement [MKM] Deadly Cover-Up; refactor to common class (#12500)

* Genericize most variants of SearchTargetGraveyardHandLibraryForCardNameAndExileEffect

* Implement Deadly Cover-Up

* int maxAmount instead of boolean maxFour, use player.chooseTarget

* Fix Surgical Extraction test, use withNotTarget for exile choices

* Add tests, fix MDFC's back sides' names from being matched against
This commit is contained in:
ssk97 2024-06-24 20:58:57 -07:00 committed by GitHub
parent 0a23521ece
commit f53954d56a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 349 additions and 662 deletions

View file

@ -1,16 +1,15 @@
package mage.abilities.effects.common;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect;
import mage.cards.Card;
import mage.game.Game;
import mage.game.stack.StackObject;
import mage.target.TargetSpell;
import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author LevelX2
@ -20,11 +19,15 @@ public class CounterTargetAndSearchGraveyardHandLibraryEffect extends SearchTarg
public CounterTargetAndSearchGraveyardHandLibraryEffect() {
this(false,"its controller's", "all cards with the same name as that spell" );
this(false, "its controller's", "all cards with the same name as that spell");
}
public CounterTargetAndSearchGraveyardHandLibraryEffect(boolean graveyardExileOptional, String searchWhatText, String searchForText) {
super(graveyardExileOptional, searchWhatText, searchForText);
this(graveyardExileOptional, searchWhatText, searchForText, false);
}
public CounterTargetAndSearchGraveyardHandLibraryEffect(boolean graveyardExileOptional, String searchWhatText, String searchForText, boolean drawForEachHandCard) {
super(graveyardExileOptional, searchWhatText, searchForText, drawForEachHandCard);
}
protected CounterTargetAndSearchGraveyardHandLibraryEffect(final CounterTargetAndSearchGraveyardHandLibraryEffect effect) {
@ -39,26 +42,19 @@ public class CounterTargetAndSearchGraveyardHandLibraryEffect extends SearchTarg
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
String cardName = "";
UUID searchPlayerId = null;
if (source.getTargets().get(0) instanceof TargetSpell) {
UUID objectId = source.getFirstTarget();
StackObject stackObject = game.getStack().getStackObject(objectId);
if (stackObject != null) {
MageObject targetObject = game.getObject(stackObject.getSourceId());
if (targetObject instanceof Card) {
cardName = targetObject.getName();
}
searchPlayerId = stackObject.getControllerId();
String cardName = stackObject.getName();
UUID searchPlayerId = stackObject.getControllerId();
result = game.getStack().counter(objectId, source, game);
// 5/1/2008: If the targeted spell can't be countered (it's Vexing Shusher, for example),
// that spell will remain on the stack. Counterbore will continue to resolve. You still
// get to search for and exile all other cards with that name.
this.applySearchAndExile(game, source, cardName, searchPlayerId);
}
}
// 5/1/2008: If the targeted spell can't be countered (it's Vexing Shusher, for example),
// that spell will remain on the stack. Counterbore will continue to resolve. You still
// get to search for and exile all other cards with that name.
this.applySearchAndExile(game, source, cardName, searchPlayerId);
return result;
}

View file

@ -18,6 +18,11 @@ public class ExileTargetAndSearchGraveyardHandLibraryEffect extends SearchTarget
this.staticText = ""; // since parent class overrides static text but we need to use a target
}
public ExileTargetAndSearchGraveyardHandLibraryEffect(boolean graveyardExileOptional, String searchWhatText, String searchForText, boolean drawForEachHandCard) {
super(graveyardExileOptional, searchWhatText, searchForText, drawForEachHandCard);
this.staticText = ""; // since parent class overrides static text but we need to use a target
}
private ExileTargetAndSearchGraveyardHandLibraryEffect(final ExileTargetAndSearchGraveyardHandLibraryEffect effect) {
super(effect);
}

View file

@ -30,13 +30,25 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
* 2/1/2005: The copies must be found if they are in publicly viewable zones. Finding copies while searching private zones is optional.
*/
protected boolean graveyardExileOptional;
protected boolean drawForEachHandCard;
protected int maxAmount;
protected SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(boolean graveyardExileOptional, String searchWhatText, String searchForText) {
this(graveyardExileOptional, searchWhatText, searchForText, false);
}
protected SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(boolean graveyardExileOptional, String searchWhatText, String searchForText, boolean drawForEachHandCard) {
this(graveyardExileOptional, searchWhatText, searchForText, drawForEachHandCard, Integer.MAX_VALUE);
}
protected SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(boolean graveyardExileOptional, String searchWhatText, String searchForText, boolean drawForEachHandCard, int maxAmount) {
super(Outcome.Exile);
this.searchWhatText = searchWhatText;
this.searchForText = searchForText;
this.graveyardExileOptional = graveyardExileOptional;
this.staticText = "search " + searchWhatText + " graveyard, hand, and library for " + searchForText + " and exile them. Then that player shuffles";
this.drawForEachHandCard = drawForEachHandCard;
this.maxAmount = maxAmount;
this.staticText = "search " + searchWhatText + " graveyard, hand, and library for " + searchForText + " and exile them. " +
(drawForEachHandCard ? "That player shuffles, then draws a card for each card exiled from their hand this way" : "Then that player shuffles");
}
protected SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(final SearchTargetGraveyardHandLibraryForCardNameAndExileEffect effect) {
@ -44,6 +56,8 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
this.searchWhatText = effect.searchWhatText;
this.searchForText = effect.searchForText;
this.graveyardExileOptional = effect.graveyardExileOptional;
this.drawForEachHandCard = effect.drawForEachHandCard;
this.maxAmount = effect.maxAmount;
}
/**
@ -59,37 +73,50 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
if (cardName != null && controller != null) {
Player targetPlayer = game.getPlayer(targetPlayerId);
if (targetPlayer != null) {
int handCards = 0;
int maxRemaining = maxAmount;
FilterCard filter = new FilterCard("card named \"" + cardName + "\"");
filter.add(new NamePredicate(cardName));
// cards in Graveyard
int cardsCount = targetPlayer.getGraveyard().count(filter, game);
int cardsCount = Math.min(targetPlayer.getGraveyard().count(filter, game), maxRemaining);
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
TargetCard target = new TargetCard((graveyardExileOptional ? 0 : cardsCount), cardsCount, Zone.GRAVEYARD, filter);
target.withNotTarget(true);
if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, source, game)) {
maxRemaining -= target.getTargets().size();
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
}
// cards in Hand
cardsCount = targetPlayer.getHand().count(filter, game);
cardsCount = Math.min(targetPlayer.getHand().count(filter, game), maxRemaining);
filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
target.withNotTarget(true);
if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, source, game)) {
maxRemaining -= target.getTargets().size();
if (drawForEachHandCard) {
handCards = target.getTargets().size();
}
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
// cards in Library
Cards cardsInLibrary = new CardsImpl();
cardsInLibrary.addAllCards(targetPlayer.getLibrary().getCards(game));
cardsCount = cardsInLibrary.count(filter, game);
cardsCount = Math.min(cardsInLibrary.count(filter, game), maxRemaining);
filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, source, game)) {
controller.moveCards(new CardsImpl(targetLib.getTargets()), Zone.EXILED, source, game);
}
targetPlayer.shuffleLibrary(source, game);
if (handCards > 0) {
targetPlayer.drawCards(handCards, source, game);
}
}
return true;

View file

@ -44,8 +44,14 @@ public class NamePredicate implements Predicate<MageObject> {
}
// If a player names a card, the player may name either half of a split card, but not both.
// A split card has the chosen name if one of its two names matches the chosen name.
// Same for modal double faces cards
if (input instanceof CardWithHalves) {
// This is NOT the same for double faced cards, where only the front side matches
// Test of Talents ruling:
// If the back face of a modal double-faced card is countered, you will not be able to exile any cards,
// including the one that you countered, because those cards have only their front-face characteristics
// (including name) in the graveyard, hand, and library. (2021-04-16)
if (input instanceof SplitCard) {
return CardUtil.haveSameNames(name, ((CardWithHalves) input).getLeftHalfCard().getName(), this.ignoreMtgRuleForEmptyNames) ||
CardUtil.haveSameNames(name, ((CardWithHalves) input).getRightHalfCard().getName(), this.ignoreMtgRuleForEmptyNames) ||
CardUtil.haveSameNames(name, input.getName(), this.ignoreMtgRuleForEmptyNames);