Search in sources :

Example 71 with TargetControlledPermanent

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

the class ShimatsuTheBloodcloakedEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (creature != null && controller != null) {
        Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledPermanent(), true);
        if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            return false;
        }
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        if (!target.getTargets().isEmpty()) {
            int sacrificedCreatures = target.getTargets().size();
            game.informPlayers(controller.getLogName() + " sacrifices " + sacrificedCreatures + " creatures for " + creature.getLogName());
            for (UUID targetId : target.getTargets()) {
                Permanent targetCreature = game.getPermanent(targetId);
                if (targetCreature == null || !targetCreature.sacrifice(source, game)) {
                    return false;
                }
            }
            creature.addCounters(CounterType.P1P1.createInstance(sacrificedCreatures), source.getControllerId(), source, game);
        }
    }
    return false;
}
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) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) UUID(java.util.UUID)

Example 72 with TargetControlledPermanent

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

the class SmokestackEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player activePlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (activePlayer != null && sourcePermanent != null) {
        int count = sourcePermanent.getCounters(game).getCount(CounterType.SOOT);
        if (count > 0) {
            int amount = Math.min(count, game.getBattlefield().countAll(new FilterControlledPermanent(), activePlayer.getId(), game));
            Target target = new TargetControlledPermanent(amount, amount, new FilterControlledPermanent(), true);
            // had, if thats the case this ability should fizzle.
            if (target.canChoose(source.getSourceId(), activePlayer.getId(), game)) {
                while (!target.isChosen() && target.canChoose(source.getSourceId(), activePlayer.getId(), game) && activePlayer.canRespond()) {
                    activePlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
                }
                for (int idx = 0; idx < target.getTargets().size(); idx++) {
                    Permanent permanent = game.getPermanent(target.getTargets().get(idx));
                    if (permanent != null) {
                        permanent.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
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) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 73 with TargetControlledPermanent

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

the class TwistedJusticeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getTargets().getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    FilterControlledPermanent filter = new FilterControlledPermanent("creature");
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(TargetController.YOU.getControllerPredicate());
    TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
    // had, if thats the case this ability should fizzle.
    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) {
            permanent.sacrifice(source, game);
            controller.drawCards(permanent.getPower().getValue(), source, game);
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 74 with TargetControlledPermanent

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

the class DevourEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (creature == null || controller == null) {
        return false;
    }
    Target target = new TargetControlledPermanent(1, Integer.MAX_VALUE, devourFactor.getFilter(), true);
    target.setRequired(false);
    if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
        return false;
    }
    if (!controller.chooseUse(Outcome.Detriment, "Devour " + devourFactor.getCardType().toString().toLowerCase() + "s?", source, game)) {
        return false;
    }
    controller.chooseTarget(Outcome.Detriment, target, source, game);
    if (target.getTargets().isEmpty()) {
        return false;
    }
    List<Permanent> creaturesDevoured = new ArrayList<>();
    int devouredCreatures = 0;
    for (UUID targetId : target.getTargets()) {
        Permanent targetCreature = game.getPermanent(targetId);
        if (targetCreature != null && targetCreature.sacrifice(source, game)) {
            creaturesDevoured.add(targetCreature);
            devouredCreatures++;
        }
    }
    if (!game.isSimulation()) {
        game.informPlayers(creature.getLogName() + " devours " + devouredCreatures + " " + devourFactor.getCardType().toString().toLowerCase() + "s");
    }
    // need for multistep effects
    game.getState().processAction(game);
    int amountCounters;
    if (devourFactor == DevourFactor.DevourX) {
        amountCounters = devouredCreatures * devouredCreatures;
    } else {
        amountCounters = devouredCreatures * devourFactor.getFactor();
    }
    creature.addCounters(CounterType.P1P1.createInstance(amountCounters), source.getControllerId(), source, game);
    game.getState().setValue(creature.getId().toString() + "devoured", creaturesDevoured);
    return false;
}
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) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 75 with TargetControlledPermanent

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

the class JalumGrifterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getTargets().get(0).getFirstTarget());
    if (controller != null && opponent != null) {
        List<Card> shellGamePile = new ArrayList<>();
        Card sourceCard = game.getCard(source.getSourceId());
        if (sourceCard != null) {
            sourceCard = sourceCard.copy();
            sourceCard.setFaceDown(true, game);
            shellGamePile.add(sourceCard);
            game.informPlayers(controller.getLogName() + " turns " + sourceCard.getLogName() + " face down");
        }
        Target target = new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent(), true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
                controller.chooseTarget(outcome, target, source, game);
            }
        }
        for (UUID cardId : target.getTargets()) {
            Card card = game.getCard(cardId);
            if (card != null) {
                card = card.copy();
                card.setFaceDown(true, game);
                shellGamePile.add(card);
                game.informPlayers(controller.getLogName() + " turns " + card.getLogName() + " face down");
            }
        }
        if (shellGamePile.isEmpty()) {
            return true;
        }
        Collections.shuffle(shellGamePile);
        game.informPlayers(controller.getLogName() + " shuffles the face-down pile");
        TargetCard targetCard = new TargetCard(Zone.HAND, new FilterCard());
        CardsImpl cards = new CardsImpl();
        cards.addAll(shellGamePile);
        if (opponent.choose(Outcome.Sacrifice, cards, targetCard, game)) {
            Card card = game.getCard(targetCard.getFirstTarget());
            if (card != null) {
                card.setFaceDown(false, game);
                game.informPlayers(opponent.getLogName() + " reveals " + card.getLogName());
                if (card.getId().equals(sourceCard.getId())) {
                    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
                    if (sourcePermanent != null) {
                        sourcePermanent.sacrifice(source, game);
                    }
                } else {
                    Permanent permanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
                    if (permanent != null) {
                        permanent.destroy(source, game, false);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

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