use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class BazaarOfWondersEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getSpell(targetPointer.getFirst(game, source));
if (spell == null) {
return false;
}
String spellName = spell.getName();
FilterPermanent filter1 = new FilterPermanent();
filter1.add(new NamePredicate(spellName));
filter1.add(TokenPredicate.FALSE);
if (!game.getBattlefield().getActivePermanents(filter1, source.getControllerId(), game).isEmpty()) {
game.getStack().counter(spell.getId(), source, game);
return true;
}
FilterCard filter2 = new FilterCard();
filter2.add(new NamePredicate(spellName));
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
if (player.getGraveyard().count(filter2, game) > 0) {
return game.getStack().counter(spell.getId(), source, game);
}
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class AvenShrineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null) {
String name = spell.getName();
FilterCard filterCardName = new FilterCard();
filterCardName.add(new NamePredicate(name));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
count += player.getGraveyard().count(filterCardName, game);
}
}
controller.gainLife(count, game, source);
return true;
}
}
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class DarkSupplicantEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
FilterCard filter = new FilterCard("card named Scion of Darkness");
filter.add(new NamePredicate("Scion of Darkness"));
if (controller == null) {
return false;
}
Card selectedCard = null;
// Graveyard check
if (controller.chooseUse(Outcome.Benefit, "Search your graveyard for Scion of Darkness?", source, game)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(1, 1, filter, true);
if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
selectedCard = game.getCard(target.getFirstTarget());
}
}
// Hand check
if (selectedCard == null && controller.chooseUse(Outcome.Benefit, "Search your hand for Scion of Darkness?", source, game)) {
TargetCardInHand target = new TargetCardInHand(0, 1, filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
if (!target.getTargets().isEmpty()) {
selectedCard = game.getCard(target.getFirstTarget());
}
}
}
// Library check
boolean librarySearched = false;
if (selectedCard == null && controller.chooseUse(Outcome.Benefit, "Search your library for Scion of Darkness?", source, game)) {
librarySearched = true;
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
selectedCard = game.getCard(target.getFirstTarget());
}
}
}
if (selectedCard != null) {
controller.moveCards(selectedCard, Zone.BATTLEFIELD, source, game);
}
if (librarySearched) {
controller.shuffleLibrary(source, game);
}
return true;
}
Aggregations