use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId in project mage by magefree.
the class LightPawsEmperorsVoiceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent aura = (Permanent) getValue("permanentEnteringBattlefield");
if (player == null || aura == null || !player.chooseUse(outcome, "Search for an Aura?", source, game)) {
return false;
}
FilterCard filter = new FilterCard("Aura card with mana value less than or equal to " + aura.getManaValue());
filter.add(SubType.AURA.getPredicate());
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, aura.getManaValue() + 1));
filter.add(LightPawsEmperorsVoiceEffectPredicate.instance);
TargetCardInLibrary target = new TargetCardInLibrary(filter);
player.searchLibrary(target, source, game);
Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (card != null && permanent != null && new AuraCardCanAttachToPermanentId(permanent.getId()).apply(card, game)) {
game.getState().setValue("attachTo:" + card.getId(), permanent);
player.moveCards(card, Zone.BATTLEFIELD, source, game);
permanent.addAttachment(card.getId(), source, game);
}
player.shuffleLibrary(source, game);
return true;
}
use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId in project mage by magefree.
the class HolyAvengerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = source.getSourcePermanentOrLKI(game);
if (player == null || sourcePermanent == null) {
return false;
}
Permanent permanent = game.getPermanent(sourcePermanent.getAttachedTo());
if (permanent == null) {
return false;
}
FilterCard filter = new FilterCard("an Aura than can enchant " + permanent.getName());
filter.add(SubType.AURA.getPredicate());
filter.add(new AuraCardCanAttachToPermanentId(permanent.getId()));
TargetCardInHand target = new TargetCardInHand(0, 1, filter);
player.choose(Outcome.PutCardInPlay, player.getHand(), target, game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
game.getState().setValue("attachTo:" + card.getId(), permanent);
player.moveCards(card, Zone.BATTLEFIELD, source, game);
if (!permanent.addAttachment(card.getId(), source, game)) {
return false;
}
game.informPlayers(player.getLogName() + " put " + card.getLogName() + " on the battlefield attached to " + permanent.getLogName() + '.');
return true;
}
use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId in project mage by magefree.
the class EvershrikeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card evershrikeCard = game.getCard(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || evershrikeCard == null) {
return false;
}
int xAmount = source.getManaCostsToPay().getX();
controller.moveCards(evershrikeCard, Zone.BATTLEFIELD, source, game);
Permanent evershrikePermanent = game.getPermanent(evershrikeCard.getId());
if (evershrikePermanent == null) {
if (game.getState().getZone(evershrikeCard.getId()) != Zone.EXILED) {
controller.moveCards(evershrikeCard, Zone.EXILED, source, game);
}
return false;
}
boolean exileSource = true;
FilterCard filterAuraCard = new FilterCard("Aura card with mana value X or less from your hand");
filterAuraCard.add(CardType.ENCHANTMENT.getPredicate());
filterAuraCard.add(SubType.AURA.getPredicate());
filterAuraCard.add(new AuraCardCanAttachToPermanentId(evershrikePermanent.getId()));
filterAuraCard.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xAmount + 1));
int count = controller.getHand().count(filterAuraCard, game);
if (count > 0 && controller.chooseUse(Outcome.Benefit, "Put an Aura card from your hand onto the battlefield attached to " + evershrikeCard.getIdName() + "?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.HAND, filterAuraCard);
if (controller.choose(Outcome.Benefit, controller.getHand(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
game.getState().setValue("attachTo:" + aura.getId(), evershrikePermanent);
if (controller.moveCards(aura, Zone.BATTLEFIELD, source, game)) {
evershrikePermanent.addAttachment(aura.getId(), source, game);
}
exileSource = false;
}
}
}
if (exileSource) {
controller.moveCards(evershrikeCard, Zone.EXILED, source, game);
}
return true;
}
use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId in project mage by magefree.
the class IridescentDrakeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
Card targetAuraCard = game.getCard(source.getFirstTarget());
if (controller != null && permanent != null && controller.canRespond() && targetAuraCard != null && new AuraCardCanAttachToPermanentId(permanent.getId()).apply(targetAuraCard, game)) {
Target target = targetAuraCard.getSpellAbility().getTargets().get(0);
if (target != null) {
game.getState().setValue("attachTo:" + targetAuraCard.getId(), permanent);
controller.moveCards(targetAuraCard, Zone.BATTLEFIELD, source, game);
return permanent.addAttachment(targetAuraCard.getId(), source, game);
}
}
return false;
}
Aggregations