[STX] Implemented Test of Talents

This commit is contained in:
Evan Kranzler 2021-04-07 09:18:36 -04:00
parent 2f50958e53
commit 8950d35ec7
3 changed files with 110 additions and 5 deletions

View file

@ -0,0 +1,102 @@
package mage.cards.t;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.stack.StackObject;
import mage.players.Player;
import mage.target.TargetSpell;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class TestOfTalents extends CardImpl {
public TestOfTalents(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{U}");
// Counter target instant or sorcery spell. Search its controller's graveyard, hand, and library for any number of cards with the same name as that spell and exile them. That player shuffles, then draws a card for each card exiled from their hand this way.
this.getSpellAbility().addEffect(new TestOfTalentsEffect());
this.getSpellAbility().addTarget(new TargetSpell(StaticFilters.FILTER_SPELL_INSTANT_OR_SORCERY));
}
private TestOfTalents(final TestOfTalents card) {
super(card);
}
@Override
public TestOfTalents copy() {
return new TestOfTalents(this);
}
}
class TestOfTalentsEffect extends SearchTargetGraveyardHandLibraryForCardNameAndExileEffect {
TestOfTalentsEffect() {
super(false, "its controller's", "all cards with the same name as that spell");
staticText = "counter target instant or sorcery spell. Search its controller's graveyard, hand, " +
"and library for any number of cards with the same name as that spell and exile them. " +
"That player shuffles, then draws a card for each card exiled from their hand this way";
}
private TestOfTalentsEffect(final TestOfTalentsEffect effect) {
super(effect);
}
@Override
public TestOfTalentsEffect copy() {
return new TestOfTalentsEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
if (stackObject == null) {
return false;
}
MageObject targetObject = game.getObject(stackObject.getSourceId());
String cardName;
if (targetObject instanceof Card) {
cardName = targetObject.getName();
} else {
cardName = "";
}
UUID searchPlayerId = stackObject.getControllerId();
Player player = game.getPlayer(searchPlayerId);
if (player == null) {
return false;
}
int previousCount = player
.getHand()
.getCards(game)
.stream()
.map(MageObject::getName)
.filter(Objects::nonNull)
.mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0)
.sum();
game.getStack().counter(source.getFirstTarget(), source, game);
this.applySearchAndExile(game, source, cardName, searchPlayerId);
int newCount = player
.getHand()
.getCards(game)
.stream()
.map(MageObject::getName)
.filter(Objects::nonNull)
.mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0)
.sum();
if (previousCount > newCount) {
player.drawCards(previousCount - newCount, source, game);
}
return true;
}
}

View file

@ -244,6 +244,7 @@ public final class StrixhavenSchoolOfMages extends ExpansionSet {
cards.add(new SetCardInfo("Tempted by the Oriq", 58, Rarity.RARE, mage.cards.t.TemptedByTheOriq.class));
cards.add(new SetCardInfo("Tend the Pests", 242, Rarity.UNCOMMON, mage.cards.t.TendThePests.class));
cards.add(new SetCardInfo("Tenured Inkcaster", 88, Rarity.UNCOMMON, mage.cards.t.TenuredInkcaster.class));
cards.add(new SetCardInfo("Test of Talents", 59, Rarity.UNCOMMON, mage.cards.t.TestOfTalents.class));
cards.add(new SetCardInfo("Thrilling Discovery", 243, Rarity.COMMON, mage.cards.t.ThrillingDiscovery.class));
cards.add(new SetCardInfo("Thunderous Orator", 35, Rarity.UNCOMMON, mage.cards.t.ThunderousOrator.class));
cards.add(new SetCardInfo("Tome Shredder", 117, Rarity.COMMON, mage.cards.t.TomeShredder.class));

View file

@ -1,7 +1,6 @@
package mage.abilities.effects.common.search;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
@ -16,8 +15,9 @@ import mage.players.Player;
import mage.target.TargetCard;
import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect extends OneShotEffect {
@ -48,12 +48,11 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
}
/**
*
* @param game
* @param source
* @param cardName name of the card to exile
* @param cardName name of the card to exile
* @param targetPlayerId id of the target player to exile card name from his
* or her zones
* or her zones
* @return
*/
public boolean applySearchAndExile(Game game, Ability source, String cardName, UUID targetPlayerId) {
@ -102,6 +101,9 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
sb.append("search ").append(this.searchWhatText);
sb.append(" graveyard, hand, and library for ");