use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class DwarvenShrineEffect 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("dwarvenShrine" + 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.damage(count * 2, mageObject.getId(), source, game);
return true;
}
}
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class MimeofactureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (controller == null || permanent == null) {
return false;
}
Player opponent = game.getPlayer(permanent.getControllerId());
if (opponent == null) {
return false;
}
FilterCard filter = new FilterCard("card named " + permanent.getName());
filter.add(new NamePredicate(permanent.getName()));
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
if (controller.searchLibrary(target, source, game, opponent.getId())) {
Card card = opponent.getLibrary().getCard(target.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
opponent.shuffleLibrary(source, game);
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class DestroyAllNamedPermanentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent == null) {
return false;
}
FilterPermanent filter = new FilterPermanent();
if (CardUtil.haveEmptyName(targetPermanent)) {
// if no name (face down creature) only the creature itself is selected
filter.add(new PermanentIdPredicate(targetPermanent.getId()));
} else {
filter.add(new NamePredicate(targetPermanent.getName()));
}
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
perm.destroy(source, game, false);
}
return true;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class MitoticManipulationEffect 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) {
Set<String> permanentNames = new HashSet<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
permanentNames.add(permanent.getName());
}
Cards cardsFromTop = new CardsImpl();
cardsFromTop.addAll(controller.getLibrary().getTopCards(game, 7));
controller.lookAtCards(sourceObject.getIdName(), cardsFromTop, game);
FilterCard filter = new FilterCard("card to put onto the battlefield");
List<NamePredicate> namePredicates = new ArrayList<>();
for (String name : permanentNames) {
namePredicates.add(new NamePredicate(name));
}
if (!namePredicates.isEmpty() && !cardsFromTop.isEmpty()) {
filter.add(Predicates.or(namePredicates));
TargetCard target = new TargetCard(Zone.LIBRARY, filter);
if (cardsFromTop.count(filter, source.getSourceId(), source.getControllerId(), game) > 0 && controller.chooseUse(Outcome.PutCardInPlay, "Put a card on the battlefield?", source, game)) {
if (controller.choose(Outcome.PutCardInPlay, cardsFromTop, target, game)) {
Card card = cardsFromTop.get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
cardsFromTop.remove(card);
}
}
}
}
controller.putCardsOnBottomOfLibrary(cardsFromTop, game, source, true);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class ArachnusSpinnerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterCard filter = new FilterCard("card named Arachnus Web");
filter.add(new NamePredicate("Arachnus Web"));
Card card = null;
if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for Arachnus Web?", source, game)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
card = game.getCard(target.getFirstTarget());
}
}
if (card == null) {
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
card = game.getCard(target.getFirstTarget());
}
controller.shuffleLibrary(source, game);
}
if (card != null) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
game.getState().setValue("attachTo:" + card.getId(), permanent.getId());
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
// shouldn't this be done automatically by the logic using the "attachTo:" calue?
permanent.addAttachment(card.getId(), source, game);
}
}
}
return true;
}
Aggregations