Search in sources :

Example 91 with TargetPermanent

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

the class GryffsBoonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card aura = game.getCard(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (aura != null && controller != null && game.getState().getZone(aura.getId()) == Zone.GRAVEYARD) {
        Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (!targetPermanent.cantBeAttachedBy(aura, source, game, false)) {
            game.getState().setValue("attachTo:" + aura.getId(), targetPermanent);
            controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
            return targetPermanent.addAttachment(aura.getId(), source, game);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Card(mage.cards.Card)

Example 92 with TargetPermanent

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

the class HeraldOfLeshracLeavesEffect method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Target target = new TargetPermanent(filter);
    if (target.choose(Outcome.GainControl, controllerId, source.getSourceId(), game)) {
        ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
        effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
        game.addEffect(effect, ability);
        game.getState().processAction(game);
        paid = true;
    }
    return paid;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 93 with TargetPermanent

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

the class HexParasiteEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    TargetPermanent target = (TargetPermanent) source.getTargets().get(0);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (permanent != null && controller != null) {
        int toRemove = source.getManaCostsToPay().getX();
        int removed = 0;
        String[] counterNames = permanent.getCounters(game).keySet().toArray(new String[0]);
        for (String counterName : counterNames) {
            if (controller.chooseUse(Outcome.Neutral, "Remove " + counterName + " counters?", source, game)) {
                if (permanent.getCounters(game).get(counterName).getCount() == 1 || (toRemove - removed == 1)) {
                    permanent.removeCounters(counterName, 1, source, game);
                    removed++;
                } else {
                    int amount = controller.getAmount(1, Math.min(permanent.getCounters(game).get(counterName).getCount(), toRemove - removed), "How many?", game);
                    if (amount > 0) {
                        removed += amount;
                        permanent.removeCounters(counterName, amount, source, game);
                    }
                }
            }
            if (removed >= toRemove) {
                break;
            }
        }
        if (removed > 0) {
            game.addEffect(new BoostSourceEffect(removed, 0, Duration.EndOfTurn), source);
        }
        return true;
    }
    return false;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 94 with TargetPermanent

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

the class HighcliffFelidarEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<UUID> toDestroy = new HashSet();
    game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(opponent -> {
        int maxPower = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game).stream().map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(Integer.MIN_VALUE);
        if (maxPower > Integer.MIN_VALUE) {
            FilterPermanent filter = new FilterCreaturePermanent("creature with the greatest power controlled by " + opponent.getName());
            filter.add(new ControllerIdPredicate(opponent.getId()));
            filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (controller.choose(outcome, target, source.getSourceId(), game)) {
                toDestroy.add(target.getFirstTarget());
            }
        }
    });
    toDestroy.stream().map(game::getPermanent).filter(Objects::nonNull).forEachOrdered(permanent -> permanent.destroy(source, game, false));
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) MageInt(mage.MageInt) HashSet(java.util.HashSet)

Example 95 with TargetPermanent

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

the class LilianaOfTheVeilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (player != null && targetPlayer != null) {
        int count = game.getBattlefield().countAll(new FilterPermanent(), targetPlayer.getId(), game);
        TargetPermanent target = new TargetPermanent(0, count, new FilterPermanent("permanents to put in the first pile"), true);
        List<Permanent> pile1 = new ArrayList<>();
        target.setRequired(false);
        if (player.choose(Outcome.Neutral, target, source.getSourceId(), game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Permanent p = game.getPermanent(targetId);
                if (p != null) {
                    pile1.add(p);
                }
            }
        }
        List<Permanent> pile2 = new ArrayList<>();
        for (Permanent p : game.getBattlefield().getAllActivePermanents(targetPlayer.getId())) {
            if (!pile1.contains(p)) {
                pile2.add(p);
            }
        }
        boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to sacrifice.", pile1, pile2, game);
        if (choice) {
            sacrificePermanents(pile1, game, source);
        } else {
            sacrificePermanents(pile2, game, source);
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) 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) 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