Search in sources :

Example 1 with SharesColorPredicate

use of mage.filter.predicate.mageobject.SharesColorPredicate in project mage by magefree.

the class KasminaEnigmaSageSearchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentOrLKI(game);
    if (controller == null || permanent == null) {
        return false;
    }
    FilterCard filter = new FilterInstantOrSorceryCard("an instant, or sorcery card which shares a color with " + permanent.getLogName());
    filter.add(new SharesColorPredicate(permanent.getColor(game)));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    controller.searchLibrary(target, source, game);
    Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
    if (card != null) {
        controller.moveCards(card, Zone.EXILED, source, game);
    }
    controller.shuffleLibrary(source, game);
    if (card == null || !controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
        return true;
    }
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
    Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) SharesColorPredicate(mage.filter.predicate.mageobject.SharesColorPredicate) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 2 with SharesColorPredicate

use of mage.filter.predicate.mageobject.SharesColorPredicate in project mage by magefree.

the class MournersShieldEffect method init.

@Override
public void init(Ability source, Game game) {
    ObjectColor colorsAmongImprinted = new ObjectColor();
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source.getSourceId()));
    if (sourceObject == null || sourceObject.getImprinted() == null) {
        noneExiled = true;
        return;
    }
    for (UUID imprinted : sourceObject.getImprinted()) {
        if (imprinted != null && exileZone.contains(imprinted)) {
            Card card = game.getCard(imprinted);
            if (card != null) {
                colorsAmongImprinted = colorsAmongImprinted.union(card.getColor(game));
            }
        }
    }
    FilterObject filterObject = new FilterObject("a source of your choice that shares a color with the exiled card");
    filterObject.add(new SharesColorPredicate(colorsAmongImprinted));
    this.target = new TargetSource(filterObject);
    this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
    if (target.getFirstTarget() != null) {
        mageObjectReference = new MageObjectReference(target.getFirstTarget(), game);
    } else {
        mageObjectReference = null;
    }
}
Also used : TargetSource(mage.target.TargetSource) Permanent(mage.game.permanent.Permanent) SharesColorPredicate(mage.filter.predicate.mageobject.SharesColorPredicate) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Aggregations

Card (mage.cards.Card)2 SharesColorPredicate (mage.filter.predicate.mageobject.SharesColorPredicate)2 Permanent (mage.game.permanent.Permanent)2 UUID (java.util.UUID)1 ApprovingObject (mage.ApprovingObject)1 MageObjectReference (mage.MageObjectReference)1 ObjectColor (mage.ObjectColor)1 FilterCard (mage.filter.FilterCard)1 FilterObject (mage.filter.FilterObject)1 FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)1 ExileZone (mage.game.ExileZone)1 Player (mage.players.Player)1 TargetSource (mage.target.TargetSource)1 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)1