Search in sources :

Example 96 with TargetPermanent

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

the class MistOfStagnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player activePlayer = game.getPlayer(game.getActivePlayerId());
    if (activePlayer != null) {
        int cardsInGrave = activePlayer.getGraveyard().size();
        if (cardsInGrave > 0) {
            TargetPermanent target = new TargetPermanent(cardsInGrave, cardsInGrave, new FilterPermanent("permanents to untap"), true);
            activePlayer.chooseTarget(outcome, target, source, game);
            for (UUID oneTarget : target.getTargets()) {
                Permanent p = game.getPermanent(oneTarget);
                if (p != null) {
                    p.untap(game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 97 with TargetPermanent

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

the class NahirisLithoformingSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || source.getManaCostsToPay().getX() == 0) {
        return false;
    }
    int landCount = game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_LAND_SHORT_TEXT, source.getSourceId(), source.getControllerId(), game);
    landCount = Math.min(source.getManaCostsToPay().getX(), landCount);
    TargetPermanent target = new TargetPermanent(landCount, landCount, StaticFilters.FILTER_CONTROLLED_LAND_SHORT_TEXT, true);
    player.choose(outcome, target, source.getSourceId(), game);
    int counter = 0;
    for (UUID permanentId : target.getTargets()) {
        Permanent permanent = game.getPermanent(permanentId);
        if (permanent != null && permanent.sacrifice(source, game)) {
            counter++;
        }
    }
    player.drawCards(counter, source, game);
    game.addEffect(new PlayAdditionalLandsControllerEffect(source.getManaCostsToPay().getX(), Duration.EndOfTurn), source);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PlayAdditionalLandsControllerEffect(mage.abilities.effects.common.continuous.PlayAdditionalLandsControllerEffect) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 98 with TargetPermanent

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

the class MythosOfSnapdaxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    boolean conditionMet = condition.apply(game, source);
    List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
    Set<UUID> toKeep = new HashSet();
    for (Player player : playerList) {
        for (CardType cardType : cardTypes) {
            String message = cardType.toString().equals("Artifact") ? "an " : "a ";
            message += cardType.toString().toLowerCase(Locale.ENGLISH);
            message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
            FilterPermanent filter = new FilterNonlandPermanent(message);
            filter.add(cardType.getPredicate());
            filter.add(new ControllerIdPredicate(player.getId()));
            if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
                continue;
            }
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (conditionMet) {
                controller.choose(outcome, target, source.getSourceId(), game);
            } else {
                player.choose(outcome, target, source.getSourceId(), game);
            }
            toKeep.add(target.getFirstTarget());
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
        if (permanent == null || toKeep.contains(permanent.getId())) {
            continue;
        }
        permanent.sacrifice(source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 99 with TargetPermanent

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

the class OldGrowthTrollContinuousEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    if (game.getState().getZoneChangeCounter(source.getSourceId()) > zoneChangeCounter) {
        discard();
        return false;
    }
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    if (sourceObject == null) {
        sourceObject = game.getPermanentEntering(source.getSourceId());
    }
    if (sourceObject == null) {
        return false;
    }
    Permanent troll = sourceObject;
    switch(layer) {
        case TypeChangingEffects_4:
            troll.removeAllCardTypes(game);
            troll.addCardType(game, CardType.ENCHANTMENT);
            troll.removeAllSubTypes(game);
            troll.addSubType(game, SubType.AURA);
            break;
        case AbilityAddingRemovingEffects_6:
            // Spell Ability can be null with clone effects (ex. Moritte)
            if (troll.getSpellAbility() == null) {
                troll.addAbility(new SpellAbility(null, null), source.getSourceId(), game);
            }
            troll.getSpellAbility().getTargets().clear();
            troll.getSpellAbility().getEffects().clear();
            TargetPermanent auraTarget = new TargetPermanent(filter);
            troll.getSpellAbility().addTarget(auraTarget);
            troll.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
            troll.addAbility(new EnchantAbility(auraTarget.getTargetName()), source.getSourceId(), game);
            // add the activated ability
            troll.addAbility(makeAbility(), source.getSourceId(), game);
    }
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) SpellAbility(mage.abilities.SpellAbility) TargetPermanent(mage.target.TargetPermanent) EnchantAbility(mage.abilities.keyword.EnchantAbility) AttachEffect(mage.abilities.effects.common.AttachEffect)

Example 100 with TargetPermanent

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

the class RavenousRotbellyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, 3, filter, true);
    player.choose(outcome, target, source.getSourceId(), game);
    int amount = 0;
    for (UUID permanentId : target.getTargets()) {
        Permanent permanent = game.getPermanent(permanentId);
        if (permanent != null && permanent.sacrifice(source, game)) {
            amount++;
        }
    }
    if (amount < 1) {
        return false;
    }
    game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new SacrificeOpponentsEffect(amount, StaticFilters.FILTER_PERMANENT_CREATURES), false, "each opponent sacrifices that many creatures"), source);
    return true;
}
Also used : SacrificeOpponentsEffect(mage.abilities.effects.common.SacrificeOpponentsEffect) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

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