Search in sources :

Example 46 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class BerserkersFrenzyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetCreaturePermanent(0, Integer.MAX_VALUE);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    game.addEffect(new BlocksIfAbleTargetEffect(Duration.EndOfTurn).setTargetPointer(new FixedTargets(new CardsImpl(target.getTargets()), game)), source);
    return true;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) BlocksIfAbleTargetEffect(mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect) FixedTargets(mage.target.targetpointer.FixedTargets) TargetPermanent(mage.target.TargetPermanent) CardsImpl(mage.cards.CardsImpl)

Example 47 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class BrunaLightOfAlabasterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID bruna = source.getSourceId();
    Player controller = game.getPlayer(source.getControllerId());
    FilterPermanent filterAura = new FilterPermanent("Aura");
    FilterCard filterAuraCard = new FilterCard("Aura card");
    filterAura.add(CardType.ENCHANTMENT.getPredicate());
    filterAura.add(SubType.AURA.getPredicate());
    filterAura.add(new AuraPermanentCanAttachToPermanentId(bruna));
    filterAuraCard.add(CardType.ENCHANTMENT.getPredicate());
    filterAuraCard.add(SubType.AURA.getPredicate());
    filterAuraCard.add(new AuraCardCanAttachToPermanentId(bruna));
    if (controller == null) {
        return false;
    }
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent == null) {
        return false;
    }
    List<Permanent> fromBattlefield = new ArrayList<>();
    List<Card> fromHandGraveyard = new ArrayList<>();
    int countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
    while (controller.canRespond() && countBattlefield > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", source, game)) {
        Target targetAura = new TargetPermanent(filterAura);
        targetAura.setNotTarget(true);
        if (controller.choose(Outcome.Benefit, targetAura, source.getSourceId(), game)) {
            Permanent aura = game.getPermanent(targetAura.getFirstTarget());
            if (aura != null) {
                Target target = aura.getSpellAbility().getTargets().get(0);
                if (target != null) {
                    fromBattlefield.add(aura);
                    filterAura.add(Predicates.not(new CardIdPredicate(aura.getId())));
                }
            }
        }
        countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
    }
    int countHand = controller.getHand().count(filterAuraCard, game);
    while (controller.canRespond() && countHand > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from your hand?", 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) {
                Target target = aura.getSpellAbility().getTargets().get(0);
                if (target != null) {
                    fromHandGraveyard.add(aura);
                    filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
                }
            }
        }
        countHand = controller.getHand().count(filterAuraCard, game);
    }
    int countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
    while (controller.canRespond() && countGraveyard > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from your graveyard?", source, game)) {
        TargetCard targetAura = new TargetCard(Zone.GRAVEYARD, filterAuraCard);
        if (controller.choose(Outcome.Benefit, controller.getGraveyard(), targetAura, game)) {
            Card aura = game.getCard(targetAura.getFirstTarget());
            if (aura != null) {
                Target target = aura.getSpellAbility().getTargets().get(0);
                if (target != null) {
                    fromHandGraveyard.add(aura);
                    filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
                }
            }
        }
        countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
    }
    // Move permanents
    for (Permanent aura : fromBattlefield) {
        Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
        if (attachedTo != null) {
            attachedTo.removeAttachment(aura.getId(), source, game);
        }
        sourcePermanent.addAttachment(aura.getId(), source, game);
    }
    // Move cards
    for (Card aura : fromHandGraveyard) {
        if (aura != null) {
            game.getState().setValue("attachTo:" + aura.getId(), sourcePermanent);
            controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
            sourcePermanent.addAttachment(aura.getId(), source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) AuraPermanentCanAttachToPermanentId(mage.filter.predicate.permanent.AuraPermanentCanAttachToPermanentId) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 48 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class CrystallineResonanceCopyApplier method createAbility.

static Ability createAbility() {
    Ability ability = new CycleControllerTriggeredAbility(new CopyPermanentEffect(StaticFilters.FILTER_PERMANENT_CREATURE, new CrystallineResonanceCopyApplier(), true).setDuration(Duration.UntilYourNextTurn).setText("have {this} become a copy of another target permanent until your next turn, " + "except it has this ability"), true);
    ability.addTarget(new TargetPermanent(filter));
    return ability;
}
Also used : Ability(mage.abilities.Ability) CycleControllerTriggeredAbility(mage.abilities.common.CycleControllerTriggeredAbility) CycleControllerTriggeredAbility(mage.abilities.common.CycleControllerTriggeredAbility) CopyPermanentEffect(mage.abilities.effects.common.CopyPermanentEffect) TargetPermanent(mage.target.TargetPermanent)

Example 49 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class DesolationWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    DesolationWatcher watcher = game.getState().getWatcher(DesolationWatcher.class);
    if (watcher == null) {
        return false;
    }
    List<Permanent> permanents = new ArrayList<>();
    for (UUID playerId : watcher.getPlayersTappedForMana()) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        TargetPermanent target = new TargetControlledPermanent(StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND);
        target.setNotTarget(true);
        if (!target.canChoose(source.getSourceId(), player.getId(), game)) {
            continue;
        }
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            permanents.add(permanent);
        }
    }
    for (Permanent permanent : permanents) {
        Player player = game.getPlayer(permanent.getControllerId());
        if (permanent != null && permanent.sacrifice(source, game) && permanent.hasSubtype(SubType.PLAINS, game) && player != null) {
            player.damage(2, source.getSourceId(), source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 50 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class DrakeFamiliarEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(StaticFilters.FILTER_PERMANENT_ENCHANTMENT);
    target.setNotTarget(true);
    if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Return an enchantment to its owner's hand?", source, game)) {
        controller.chooseTarget(Outcome.ReturnToHand, target, source, game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            return controller.moveCards(permanent, Zone.HAND, source, game);
        }
    }
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    return permanent != null && permanent.sacrifice(source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Aggregations

TargetPermanent (mage.target.TargetPermanent)222 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)167 FilterPermanent (mage.filter.FilterPermanent)108 UUID (java.util.UUID)65 Target (mage.target.Target)58 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)47 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)36 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)32 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)24 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)19 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)19 FixedTarget (mage.target.targetpointer.FixedTarget)19 MageObject (mage.MageObject)18 Ability (mage.abilities.Ability)18 Card (mage.cards.Card)17 ArrayList (java.util.ArrayList)15 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)14 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13