Search in sources :

Example 71 with Target

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

the class GainControlTargetEffect method getText.

@Override
public String getText(Mode mode) {
    if (!staticText.isEmpty()) {
        return staticText;
    }
    if (mode.getTargets().isEmpty()) {
        return "gain control of target permanent";
    }
    Target target = mode.getTargets().get(0);
    StringBuilder sb = new StringBuilder("gain control of ");
    if (target.getMaxNumberOfTargets() > 1) {
        if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
            sb.append("up to ");
        }
        sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(" target ");
    } else if (!target.getTargetName().startsWith("another")) {
        sb.append("target ");
    }
    sb.append(mode.getTargets().get(0).getTargetName());
    if (!duration.toString().isEmpty()) {
        sb.append(' ').append(duration.toString());
    }
    return sb.toString();
}
Also used : Target(mage.target.Target)

Example 72 with Target

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

the class BurnAwayDelayedTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.isDiesEvent() && zEvent.getTarget() != null && zEvent.getTargetId().equals(getTargets().getFirstTarget())) {
        // else spell fizzles because target creature died
        this.getTargets().clear();
        Target target = new TargetPlayer();
        target.add(zEvent.getTarget().getControllerId(), game);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Target(mage.target.Target) TargetPlayer(mage.target.TargetPlayer)

Example 73 with Target

use of mage.target.Target 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 74 with Target

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

the class CryptChampionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Set<Card> toBattlefield = new HashSet<>();
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterCard filter = new FilterCreatureCard("creature card with mana value 3 or less from your graveyard");
                filter.add(new OwnerIdPredicate(playerId));
                filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 4));
                Target target = new TargetCardInGraveyard(filter);
                if (target.canChoose(source.getSourceId(), playerId, game) && player.chooseTarget(outcome, target, source, game)) {
                    Card card = game.getCard(target.getFirstTarget());
                    if (card != null) {
                        toBattlefield.add(card);
                    }
                }
            }
        }
        // must happen simultaneously Rule 101.4
        controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) HashSet(java.util.HashSet)

Example 75 with Target

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

the class CrushUnderfootEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Choose a Giant creature you control (not targeted, happens during effect resolving )
        Target target = new TargetControlledCreaturePermanent(1, 1, filter, false);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
            Permanent giant = game.getPermanent(target.getFirstTarget());
            if (giant != null) {
                game.informPlayers("Crush Underfoot: Chosen Giant is " + giant.getName());
                Permanent targetCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
                if (targetCreature != null) {
                    targetCreature.damage(giant.getPower().getValue(), source.getSourceId(), source, game, false, true);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Aggregations

Target (mage.target.Target)385 Player (mage.players.Player)291 Permanent (mage.game.permanent.Permanent)223 UUID (java.util.UUID)155 Card (mage.cards.Card)86 TargetPermanent (mage.target.TargetPermanent)80 FilterCard (mage.filter.FilterCard)62 FilterPermanent (mage.filter.FilterPermanent)56 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)54 FixedTarget (mage.target.targetpointer.FixedTarget)49 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)45 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)45 MageObject (mage.MageObject)43 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)42 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 TargetOpponent (mage.target.common.TargetOpponent)35 CardsImpl (mage.cards.CardsImpl)32 ArrayList (java.util.ArrayList)31 ContinuousEffect (mage.abilities.effects.ContinuousEffect)31 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)30