Search in sources :

Example 41 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class DebtToTheKamiExileEnchantmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    if (player == null) {
        return false;
    }
    Target target = new TargetControlledPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    return player.moveCards(permanent, Zone.EXILED, source, game);
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 42 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class DevourFleshSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
    if (realCount > 0) {
        Target target = new TargetControlledPermanent(1, 1, filter, true);
        while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
            player.chooseTarget(Outcome.Sacrifice, target, source, game);
        }
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            int gainLife = permanent.getToughness().getValue();
            permanent.sacrifice(source, game);
            game.getState().processAction(game);
            player.gainLife(gainLife, game, source);
        } else {
            return false;
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 43 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class DevoutInvocationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledPermanent(0, Integer.MAX_VALUE, DevoutInvocation.filter, true);
    controller.choose(outcome, target, source.getSourceId(), game);
    if (target.getTargets().isEmpty()) {
        return false;
    }
    int tappedAmount = 0;
    for (UUID permanentId : target.getTargets()) {
        Permanent permanent = game.getPermanent(permanentId);
        if (permanent != null && permanent.tap(source, game)) {
            tappedAmount++;
        }
    }
    if (tappedAmount > 0) {
        AngelToken angelToken = new AngelToken();
        angelToken.putOntoBattlefield(tappedAmount, game, source, source.getControllerId());
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) AngelToken(mage.game.permanent.token.AngelToken) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) ValueHint(mage.abilities.hint.ValueHint)

Example 44 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class GraveExchangeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getTargets().get(1).getFirstTarget());
    if (player == null) {
        return false;
    }
    Target target = new TargetControlledPermanent(new FilterControlledCreaturePermanent());
    if (target.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            return permanent.sacrifice(source, game);
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 45 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class KathrilAspectWarperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game) == 0) {
        return false;
    }
    Set<CounterType> counterSet = player.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game).stream().map(Card::getAbilities).flatMap(Collection::stream).map(this::checkAbility).collect(Collectors.toSet());
    if (counterSet == null || counterSet.size() == 0) {
        return false;
    }
    int countersAdded = 0;
    for (CounterType counterType : counterSet) {
        if (counterType == null) {
            continue;
        }
        FilterControlledPermanent filter = new FilterControlledCreaturePermanent("creature to give a " + counterType + " counter");
        Target target = new TargetControlledPermanent(filter);
        target.setNotTarget(true);
        if (!player.choose(outcome, target, source.getSourceId(), game)) {
            continue;
        }
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent == null) {
            continue;
        }
        if (permanent.addCounters(counterType.createInstance(), source.getControllerId(), source, game)) {
            countersAdded++;
        }
    }
    if (countersAdded == 0) {
        return false;
    }
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        return true;
    }
    permanent.addCounters(CounterType.P1P1.createInstance(countersAdded), source.getControllerId(), source, game);
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) CounterType(mage.counters.CounterType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Collection(java.util.Collection) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Aggregations

TargetControlledPermanent (mage.target.common.TargetControlledPermanent)100 Player (mage.players.Player)94 Permanent (mage.game.permanent.Permanent)87 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)49 UUID (java.util.UUID)47 Target (mage.target.Target)45 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)23 Card (mage.cards.Card)17 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)16 ArrayList (java.util.ArrayList)13 TargetPermanent (mage.target.TargetPermanent)13 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)10 FilterCard (mage.filter.FilterCard)10 TargetPlayer (mage.target.TargetPlayer)10 FilterPermanent (mage.filter.FilterPermanent)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)8 Cost (mage.abilities.costs.Cost)7 FilterControlledArtifactPermanent (mage.filter.common.FilterControlledArtifactPermanent)7 TargetCardInHand (mage.target.common.TargetCardInHand)6 OneShotEffect (mage.abilities.effects.OneShotEffect)5