use of mage.filter.FilterCard in project mage by magefree.
the class SkullwinderEffect 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) {
TargetOpponent targetOpponent = new TargetOpponent(true);
if (controller.choose(Outcome.Detriment, targetOpponent, source.getSourceId(), game)) {
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName());
// That player returns a card from their graveyard to their hand
TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(new FilterCard("a card from your graveyard to return to your hand"));
targetCard.setNotTarget(true);
if (opponent.choose(outcome, targetCard, source.getSourceId(), game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
opponent.moveCards(card, Zone.HAND, source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class StormHeraldAttachableToPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCard filter = new FilterCard("aura cards to attach to creatures you control");
filter.add(SubType.AURA.getPredicate());
filter.add(new StormHeraldAttachablePredicate(controller.getId()));
Set<Card> possibleTargets = controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game);
if (!possibleTargets.isEmpty()) {
TargetCard targetAuras = new TargetCard(0, Integer.MAX_VALUE, Zone.GRAVEYARD, filter);
targetAuras.setNotTarget(true);
controller.chooseTarget(outcome, new CardsImpl(possibleTargets), targetAuras, source, game);
// Move the cards to the battlefield to a creature you control
List<Permanent> toExile = new ArrayList<>();
for (UUID auraId : targetAuras.getTargets()) {
Card auraCard = game.getCard(auraId);
if (auraCard != null) {
FilterPermanent filterAttachTo = new FilterControlledCreaturePermanent("creature you control to attach " + auraCard.getIdName() + " to");
filterAttachTo.add(new StormHeraldAttachableToPredicate(auraCard));
TargetPermanent targetCreature = new TargetPermanent(filterAttachTo);
targetCreature.setNotTarget(true);
if (controller.choose(Outcome.PutCardInPlay, targetCreature, source.getSourceId(), game)) {
Permanent targetPermanent = game.getPermanent(targetCreature.getFirstTarget());
if (!targetPermanent.cantBeAttachedBy(auraCard, source, game, true)) {
game.getState().setValue("attachTo:" + auraCard.getId(), targetPermanent);
controller.moveCards(auraCard, Zone.BATTLEFIELD, source, game);
targetPermanent.addAttachment(auraCard.getId(), source, game);
Permanent permanent = game.getPermanent(auraId);
if (permanent != null) {
toExile.add(permanent);
}
}
}
}
}
ContinuousEffect continuousEffect = new StormHeraldReplacementEffect();
continuousEffect.setTargetPointer(new FixedTargets(toExile, game));
game.addEffect(continuousEffect, source);
Effect exileEffect = new ExileTargetEffect("exile those Auras");
exileEffect.setTargetPointer(new FixedTargets(toExile, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class StonehewerGiantEffect 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("Equipment");
filter.add(SubType.EQUIPMENT.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent equipment = game.getPermanent(card.getId());
Target targetCreature = new TargetControlledCreaturePermanent();
targetCreature.setNotTarget(true);
if (equipment != null && controller.choose(Outcome.BoostCreature, targetCreature, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(targetCreature.getFirstTarget());
permanent.addAttachment(equipment.getId(), source, game);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.filter.FilterCard in project mage by magefree.
the class VoidEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int number = controller.announceXMana(0, Integer.MAX_VALUE, this.staticText, game, source);
game.informPlayers(controller.getLogName() + " chooses " + number + '.');
for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
if ((permanent.isArtifact(game) || permanent.isCreature(game)) && permanent.getManaValue() == number) {
permanent.destroy(source, game, false);
}
}
FilterCard filterCard = new FilterCard();
filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, number));
filterCard.add(Predicates.not(CardType.LAND.getPredicate()));
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (targetPlayer == null) {
return true;
}
targetPlayer.revealCards(source, targetPlayer.getHand(), game);
targetPlayer.discard(new CardsImpl(targetPlayer.getHand().getCards(filterCard, game)), false, source, game);
return true;
}
use of mage.filter.FilterCard in project mage by magefree.
the class VoidMawCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getCardExileZoneId(game, ability));
target.setNotTarget(true);
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, ability));
if (cards != null && !cards.isEmpty() && controller.choose(Outcome.Benefit, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
if (controller.moveCardToGraveyardWithInfo(card, source, game, Zone.EXILED)) {
paid = true;
}
}
}
}
return paid;
}
Aggregations