Search in sources :

Example 31 with Target

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

the class TragicArroganceffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Permanent> choosenPermanent = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterArtifactPermanent filterArtifactPermanent = new FilterArtifactPermanent("an artifact of " + player.getName());
                filterArtifactPermanent.add(new ControllerIdPredicate(playerId));
                Target target1 = new TargetArtifactPermanent(1, 1, filterArtifactPermanent, true);
                FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent("a creature of " + player.getName());
                filterCreaturePermanent.add(new ControllerIdPredicate(playerId));
                Target target2 = new TargetPermanent(1, 1, filterCreaturePermanent, true);
                FilterEnchantmentPermanent filterEnchantmentPermanent = new FilterEnchantmentPermanent("an enchantment of " + player.getName());
                filterEnchantmentPermanent.add(new ControllerIdPredicate(playerId));
                Target target3 = new TargetPermanent(1, 1, filterEnchantmentPermanent, true);
                FilterPlaneswalkerPermanent filterPlaneswalkerPermanent = new FilterPlaneswalkerPermanent("a planeswalker of " + player.getName());
                filterPlaneswalkerPermanent.add(new ControllerIdPredicate(playerId));
                Target target4 = new TargetPermanent(1, 1, filterPlaneswalkerPermanent, true);
                if (target1.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target1, source, game);
                    Permanent artifact = game.getPermanent(target1.getFirstTarget());
                    if (artifact != null) {
                        choosenPermanent.add(artifact);
                    }
                    target1.clearChosen();
                }
                if (target2.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target2, source, game);
                    Permanent creature = game.getPermanent(target2.getFirstTarget());
                    if (creature != null) {
                        choosenPermanent.add(creature);
                    }
                    target2.clearChosen();
                }
                if (target3.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target3, source, game);
                    Permanent enchantment = game.getPermanent(target3.getFirstTarget());
                    if (enchantment != null) {
                        choosenPermanent.add(enchantment);
                    }
                    target3.clearChosen();
                }
                if (target4.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target4, source, game);
                    Permanent planeswalker = game.getPermanent(target4.getFirstTarget());
                    if (planeswalker != null) {
                        choosenPermanent.add(planeswalker);
                    }
                    target4.clearChosen();
                }
            }
        }
        // Then each player sacrifices all other nonland permanents they control
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENTS_NON_LAND, playerId, game)) {
                    if (!choosenPermanent.contains(permanent)) {
                        permanent.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 32 with Target

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

the class VaevictisAsmadiTheDireEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Player> playersToFlip = new ArrayList<>();
    for (Target target : source.getTargets()) {
        for (UUID permId : target.getTargets()) {
            Permanent permanent = game.getPermanent(permId);
            if (permanent == null || !permanent.sacrifice(source, game)) {
                continue;
            }
            Player player = game.getPlayer(permanent.getControllerId());
            if (player != null) {
                playersToFlip.add(player);
            }
        }
    }
    for (Player player : playersToFlip) {
        if (player == null) {
            return false;
        }
        Card card = player.getLibrary().getFromTop(game);
        if (card == null) {
            continue;
        }
        player.revealCards(source, new CardsImpl(card), game);
        if (card.isPermanent(game)) {
            player.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 33 with Target

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

the class WallOfStolenIdentityCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        permanent = game.getPermanentEntering(source.getSourceId());
    }
    final Permanent sourcePermanent = permanent;
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
    target.setRequired(true);
    if (source instanceof SimpleStaticAbility) {
        target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
        target.setRequired(false);
        target.setNotTarget(true);
    }
    if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
        return false;
    }
    controller.choose(Outcome.Copy, target, source.getSourceId(), game);
    Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
    if (copyFromPermanent == null) {
        return false;
    }
    game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {

        @Override
        public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
            blueprint.addSubType(SubType.WALL);
            blueprint.getAbilities().add(DefenderAbility.getInstance());
            return true;
        }
    });
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new TapTargetEffect(), false, "tap the copied creature " + "and it doesn't untap during its controller's untap step for as long as you control {this}");
    ability.addEffect(new DontUntapInControllersUntapStepTargetEffect(Duration.WhileControlled));
    ability.getEffects().setTargetPointer(new FixedTarget(copyFromPermanent, game));
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DefenderAbility(mage.abilities.keyword.DefenderAbility) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) MageObject(mage.MageObject) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Game(mage.game.Game) CopyApplier(mage.util.functions.CopyApplier) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TapTargetEffect(mage.abilities.effects.common.TapTargetEffect) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) DontUntapInControllersUntapStepTargetEffect(mage.abilities.effects.common.DontUntapInControllersUntapStepTargetEffect)

Example 34 with Target

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

the class SourceTargetsPermanentCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
    if (sourceSpell == null) {
        return false;
    }
    Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
    while (targets.hasNext()) {
        Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
        if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
            return true;
        }
    }
    return false;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) StackObject(mage.game.stack.StackObject)

Example 35 with Target

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

the class ReturnToHandTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<UUID> copyIds = new ArrayList<>();
    Set<Card> cards = new LinkedHashSet<>();
    if (multitargetHandling) {
        for (Target target : source.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                MageObject mageObject = game.getObject(targetId);
                if (mageObject instanceof Spell && mageObject.isCopy()) {
                    copyIds.add(targetId);
                } else if (mageObject instanceof Card) {
                    cards.add((Card) mageObject);
                }
            }
        }
    } else {
        for (UUID targetId : targetPointer.getTargets(game, source)) {
            MageObject mageObject = game.getObject(targetId);
            if (mageObject != null) {
                if (mageObject instanceof Spell && mageObject.isCopy()) {
                    copyIds.add(targetId);
                } else if (mageObject instanceof Card) {
                    cards.add((Card) mageObject);
                }
            }
        }
    }
    for (UUID copyId : copyIds) {
        game.getStack().remove(game.getSpell(copyId), game);
    }
    return controller.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Aggregations

Target (mage.target.Target)385 Player (mage.players.Player)291 Permanent (mage.game.permanent.Permanent)223 UUID (java.util.UUID)155 Card (mage.cards.Card)86 TargetPermanent (mage.target.TargetPermanent)80 FilterCard (mage.filter.FilterCard)62 FilterPermanent (mage.filter.FilterPermanent)56 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)54 FixedTarget (mage.target.targetpointer.FixedTarget)49 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)45 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)45 MageObject (mage.MageObject)43 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)42 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 TargetOpponent (mage.target.common.TargetOpponent)35 CardsImpl (mage.cards.CardsImpl)32 ArrayList (java.util.ArrayList)31 ContinuousEffect (mage.abilities.effects.ContinuousEffect)31 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)30