Search in sources :

Example 21 with TargetPermanent

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

the class MeldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Find the two permanents to meld.
        UUID sourceId = source.getSourceId();
        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature named " + meldWithName);
        filter.add(new NamePredicate(meldWithName));
        TargetPermanent target = new TargetControlledCreaturePermanent(filter);
        Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
        if (meldWithList.isEmpty()) {
            // possible permanent has left the battlefield meanwhile
            return false;
        }
        UUID meldWithId = null;
        if (meldWithList.size() == 1) {
            meldWithId = meldWithList.iterator().next();
        } else {
            if (controller.choose(Outcome.BoostCreature, target, sourceId, game)) {
                meldWithId = target.getFirstTarget();
            }
        }
        // Exile the two permanents to meld.
        Permanent sourcePermanent = game.getPermanent(sourceId);
        Permanent meldWithPermanent = game.getPermanent(meldWithId);
        if (sourcePermanent != null && meldWithPermanent != null) {
            Set<Card> toExile = new HashSet<>();
            toExile.add(sourcePermanent);
            toExile.add(meldWithPermanent);
            controller.moveCards(toExile, Zone.EXILED, source, game);
            // Create the meld card and move it to the battlefield.
            Card sourceCard = game.getExile().getCard(sourceId, game);
            Card meldWithCard = game.getExile().getCard(meldWithId, game);
            if (sourceCard != null && !sourceCard.isCopy() && meldWithCard != null && !meldWithCard.isCopy()) {
                meldCard.setOwnerId(controller.getId());
                meldCard.setTopHalfCard(meldWithCard, game);
                meldCard.setBottomHalfCard(sourceCard, game);
                meldCard.setMelded(true, game);
                game.addMeldCard(meldCard.getId(), meldCard);
                game.getState().addCard(meldCard);
                meldCard.setZone(Zone.EXILED, game);
                controller.moveCards(meldCard, Zone.BATTLEFIELD, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 22 with TargetPermanent

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

the class ArdennIntrepidArchaeologistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(source.getFirstTarget());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (controller == null || (player == null && permanent == null)) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
    controller.choose(outcome, target, source.getSourceId(), game);
    for (UUID targetId : target.getTargets()) {
        if (player != null) {
            player.addAttachment(targetId, source, game);
        } else if (permanent != null) {
            permanent.addAttachment(targetId, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 23 with TargetPermanent

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

the class BronzehideLionContinuousEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !(game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD)) {
        return false;
    }
    Card card = game.getCard(source.getSourceId());
    if (card == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (controller.choose(outcome, target, source.getSourceId(), game) && game.getPermanent(target.getFirstTarget()) != null) {
        game.getState().setValue("attachTo:" + source.getSourceId(), target.getFirstTarget());
    }
    game.addEffect(new BronzehideLionContinuousEffect(game.getState().getZoneChangeCounter(source.getSourceId()) + 1), source);
    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    Permanent aura = game.getPermanent(card.getId());
    Permanent creature = game.getPermanent(target.getFirstTarget());
    if (aura == null || creature == null) {
        return true;
    }
    creature.addAttachment(aura.getId(), source, game);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Card(mage.cards.Card)

Example 24 with TargetPermanent

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

the class CemeteryDesecratorRemoveCountersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
        target.setNotTarget(true);
        controller.choose(outcome, target, source.getSourceId(), game);
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            int manaValue = card.getManaValue();
            if (controller.moveCards(card, Zone.EXILED, source, game)) {
                ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new CemeteryDesecratorRemoveCountersEffect(manaValue), false, triggerText);
                ability.addTarget(new TargetPermanent());
                Mode mode = new Mode(new BoostTargetEffect(-manaValue, -manaValue, Duration.EndOfTurn).setText("Target creature an opponent controls gets -X/-X until end of turn, where X is the mana value of the exiled card"));
                mode.addTarget(new TargetOpponentsCreaturePermanent());
                ability.addMode(mode);
                game.fireReflexiveTriggeredAbility(ability, source);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Mode(mage.abilities.Mode) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) TargetOpponentsCreaturePermanent(mage.target.common.TargetOpponentsCreaturePermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 25 with TargetPermanent

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

the class CelestialJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
    Map<Integer, List<Permanent>> powerMap = permanents.stream().collect(Collectors.toMap(permanent -> permanent.getPower().getValue(), permanent -> Arrays.asList(permanent), (a1, a2) -> {
        a1.addAll(a2);
        return a1;
    }));
    Set<UUID> toKeep = new HashSet<>();
    for (Map.Entry<Integer, List<Permanent>> entry : powerMap.entrySet()) {
        if (entry.getValue().size() == 1) {
            toKeep.add(entry.getValue().get(0).getId());
            continue;
        }
        FilterPermanent filter = new FilterCreaturePermanent("creature with power " + entry.getKey() + " to save");
        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, entry.getKey()));
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        toKeep.add(target.getFirstTarget());
    }
    for (Permanent permanent : permanents) {
        if (!toKeep.contains(permanent.getId())) {
            permanent.destroy(source, game);
        }
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) java.util(java.util) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) ComparisonType(mage.constants.ComparisonType) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) 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