use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class MindblazeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Player playerControls = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (player == null || playerControls == null || sourceObject == null) {
return false;
}
Choice numberChoice = new ChoiceImpl();
numberChoice.setMessage("Choose a number greater than 0");
Set<String> numbers = new HashSet<>();
for (int i = 1; i <= 4; i++) {
numbers.add(Integer.toString(i));
}
numberChoice.setChoices(numbers);
String cardName = ChooseACardNameEffect.TypeOfName.NON_LAND_NAME.getChoice(playerControls, game, source, false);
playerControls.choose(Outcome.Neutral, numberChoice, game);
game.informPlayers(sourceObject.getIdName() + " - Chosen number: [" + numberChoice.getChoice() + ']');
Cards cards = new CardsImpl();
cards.addAll(player.getLibrary().getCards(game));
playerControls.revealCards("Library", cards, game);
FilterCard filter = new FilterCard();
filter.add(new NamePredicate(cardName));
int count = Integer.parseInt(numberChoice.getChoice());
if (player.getLibrary().count(filter, game) == count) {
player.damage(8, source.getSourceId(), source, game);
}
player.shuffleLibrary(source, game);
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class PackHuntEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
FilterCard filter = new FilterPermanentCard();
filter.add(new NamePredicate(permanent.getName()));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 3, filter), true).apply(game, source);
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class TibaltsTrickeryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
if (spell != null) {
String spellName = spell.getName();
Player controller = game.getPlayer(spell.getControllerId());
game.getStack().counter(spell.getId(), source, game);
if (controller != null) {
int random = RandomUtil.nextInt(3) + 1;
game.informPlayers(random + " was chosen at random");
controller.millCards(random, source, game);
Card cardToCast = null;
Set<Card> cardsToExile = new HashSet<>();
FilterCard filter = new FilterCard();
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(Predicates.not(new NamePredicate(spellName)));
for (Card card : controller.getLibrary().getCards(game)) {
cardsToExile.add(card);
if (filter.match(card, game)) {
cardToCast = card;
break;
}
}
controller.moveCardsToExile(cardsToExile, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
if (cardToCast != null) {
if (controller.chooseUse(Outcome.PlayForFree, "Cast " + cardToCast.getLogName() + " for free?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
}
ExileZone exile = game.getExile().getExileZone(source.getSourceId());
if (exile != null) {
controller.putCardsOnBottomOfLibrary(exile, game, source, false);
}
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class WoodSageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
String cardName = ChooseACardNameEffect.TypeOfName.CREATURE_NAME.getChoice(controller, game, source, false);
FilterCreatureCard filter = new FilterCreatureCard("all of them with that name");
filter.add(new NamePredicate(cardName));
new RevealLibraryPutIntoHandEffect(4, filter, Zone.GRAVEYARD).apply(game, source);
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class CloneTest method testCopyNightmare.
// copy Nightmare test, check that the P/T setting effect ends
// if the clone leaves battlefield
@Test
public void testCopyNightmare() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 5);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
addCard(Zone.BATTLEFIELD, playerB, "Swamp", 6);
addCard(Zone.BATTLEFIELD, playerB, "Forest", 1);
// Target creature you control gets +1/+1 and gains hexproof until end of turn. (It can't be the target of spells or abilities your opponents control.)
addCard(Zone.HAND, playerB, "Ranger's Guile");
addCard(Zone.HAND, playerA, "Clone");
// Return target nonland permanent to its owner's hand.
addCard(Zone.HAND, playerA, "Disperse");
addCard(Zone.BATTLEFIELD, playerB, "Nightmare", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Clone");
setChoice(playerA, "Nightmare");
castSpell(1, PhaseStep.BEGIN_COMBAT, playerB, "Ranger's Guile", "Nightmare");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Disperse", "Nightmare");
setStopAt(2, PhaseStep.UPKEEP);
execute();
assertPermanentCount(playerB, "Nightmare", 1);
assertPowerToughness(playerB, "Nightmare", 6, 6);
assertPermanentCount(playerA, "Nightmare", 0);
assertHandCount(playerA, "Disperse", 0);
FilterCard filter = new FilterCard();
filter.add(new NamePredicate("Clone"));
Card card = playerA.getHand().getCards(filter, currentGame).iterator().next();
if (card != null) {
Assert.assertEquals("Power has to be 0 because copy from nightmare P/T ability may no longer be applied", 0, card.getPower().getValue());
}
Logger.getLogger(CloneTest.class).debug("EXISTING CONTINUOUS EFFECTS:");
for (ContinuousEffectsList effectsList : currentGame.getContinuousEffects().allEffectsLists) {
for (Object anEffectsList : effectsList) {
ContinuousEffect effect = (ContinuousEffect) anEffectsList;
Logger.getLogger(CloneTest.class).debug("- " + effect.toString());
}
}
}
Aggregations