Implemented Desperate Research

This commit is contained in:
Evan Kranzler 2018-06-06 13:59:35 -04:00
parent 78c288358b
commit d2e8016a10
4 changed files with 109 additions and 2 deletions

View file

@ -0,0 +1,76 @@
package mage.cards.d;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.NameACardEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author TheElk801
*/
public final class DesperateResearch extends CardImpl {
public DesperateResearch(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{B}");
// Choose a card name other than a basic land card name. Reveal the top seven cards of your library and put all of them with that name into your hand. Exile the rest.
this.getSpellAbility().addEffect(new NameACardEffect(NameACardEffect.TypeOfName.NOT_BASIC_LAND_NAME));
this.getSpellAbility().addEffect(new DesperateResearchEffect());
}
public DesperateResearch(final DesperateResearch card) {
super(card);
}
@Override
public DesperateResearch copy() {
return new DesperateResearch(this);
}
}
class DesperateResearchEffect extends OneShotEffect {
public DesperateResearchEffect() {
super(Outcome.Benefit);
this.staticText = "Reveal the top seven cards of your library and put all of them with that name into your hand. Exile the rest";
}
public DesperateResearchEffect(final DesperateResearchEffect effect) {
super(effect);
}
@Override
public DesperateResearchEffect copy() {
return new DesperateResearchEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + NameACardEffect.INFO_KEY);
Player player = game.getPlayer(source.getControllerId());
if (player == null || cardName == null) {
return false;
}
Cards cardsToExile = new CardsImpl(player.getLibrary().getTopCards(game, 7));
player.revealCards(source, cardsToExile, game);
FilterCard filter = new FilterCard();
filter.add(new NamePredicate(cardName));
Cards cardsToKeep = new CardsImpl(cardsToExile.getCards(filter, game));
cardsToExile.removeAll(cardsToKeep);
player.moveCards(cardsToKeep, Zone.HAND, source, game);
player.moveCards(cardsToExile, Zone.EXILED, source, game);
return true;
}
}

View file

@ -88,6 +88,7 @@ public final class Invasion extends ExpansionSet {
cards.add(new SetCardInfo("Darigaaz's Attendant", 301, Rarity.UNCOMMON, mage.cards.d.DarigaazsAttendant.class));
cards.add(new SetCardInfo("Darigaaz, the Igniter", 243, Rarity.RARE, mage.cards.d.DarigaazTheIgniter.class));
cards.add(new SetCardInfo("Defiling Tears", 99, Rarity.UNCOMMON, mage.cards.d.DefilingTears.class));
cards.add(new SetCardInfo("Desperate Research", 100, Rarity.RARE, mage.cards.d.DesperateResearch.class));
cards.add(new SetCardInfo("Devouring Strossus", 101, Rarity.RARE, mage.cards.d.DevouringStrossus.class));
cards.add(new SetCardInfo("Dismantling Blow", 14, Rarity.COMMON, mage.cards.d.DismantlingBlow.class));
cards.add(new SetCardInfo("Disrupt", 51, Rarity.UNCOMMON, mage.cards.d.Disrupt.class));

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.common;
import mage.MageObject;
@ -24,6 +23,7 @@ public class NameACardEffect extends OneShotEffect {
public enum TypeOfName {
ALL,
NOT_BASIC_LAND_NAME,
NON_ARTIFACT_AND_NON_LAND_NAME,
NON_LAND_NAME,
NON_LAND_AND_NON_CREATURE_NAME,
@ -58,6 +58,10 @@ public class NameACardEffect extends OneShotEffect {
cardChoice.setChoices(CardRepository.instance.getNames());
cardChoice.setMessage("Choose a card name");
break;
case NOT_BASIC_LAND_NAME:
cardChoice.setChoices(CardRepository.instance.getNotBasicLandNames());
cardChoice.setMessage("Choose a card name other than a basic land card name");
break;
case NON_ARTIFACT_AND_NON_LAND_NAME:
cardChoice.setChoices(CardRepository.instance.getNonArtifactAndNonLandNames());
cardChoice.setMessage("Choose a nonartifact, nonland card name");
@ -106,6 +110,9 @@ public class NameACardEffect extends OneShotEffect {
case ALL:
sb.append("card");
break;
case NOT_BASIC_LAND_NAME:
sb.append("card name other than a basic land card");
break;
case NON_ARTIFACT_AND_NON_LAND_NAME:
sb.append("nonartifact, nonland card");
break;

View file

@ -1,4 +1,3 @@
package mage.cards.repository;
import com.j256.ormlite.dao.Dao;
@ -17,6 +16,7 @@ import java.util.*;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SetType;
import mage.constants.SuperType;
import mage.util.RandomUtil;
import org.apache.log4j.Logger;
@ -153,6 +153,29 @@ public enum CardRepository {
return names;
}
public Set<String> getNotBasicLandNames() {
Set<String> names = new TreeSet<>();
try {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("name");
qb.where().not().like("supertypes", new SelectArg('%' + SuperType.BASIC.name() + '%'));
List<CardInfo> results = cardDao.query(qb.prepare());
for (CardInfo card : results) {
int result = card.getName().indexOf(" // ");
if (result > 0) {
names.add(card.getName().substring(0, result));
names.add(card.getName().substring(result + 4));
} else {
names.add(card.getName());
}
}
} catch (SQLException ex) {
Logger.getLogger(CardRepository.class).error("Error getting non-land names from DB : " + ex);
}
return names;
}
public Set<String> getCreatureNames() {
Set<String> names = new TreeSet<>();
try {