Search in sources :

Example 16 with Target

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

the class GlyphOfReincarnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetWall = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && targetWall != null) {
        BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
        if (watcher != null) {
            Map<UUID, Player> destroyed = new HashMap<>();
            for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                if (!creature.getId().equals(targetWall.getId())) {
                    if (watcher.creatureHasBlockedAttacker(new MageObjectReference(creature, game), new MageObjectReference(targetWall, game), game)) {
                        if (creature.destroy(source, game, true) && game.getState().getZone(creature.getId()) == Zone.GRAVEYARD) {
                            // If a commander is replaced to command zone, the creature does not die
                            Player permController = game.getPlayer(creature.getControllerId());
                            if (permController != null) {
                                destroyed.put(creature.getId(), permController);
                            }
                        }
                    }
                }
            }
            // onto the battlefield under its owner’s control
            for (Map.Entry<UUID, Player> entry : destroyed.entrySet()) {
                Permanent permanent = (Permanent) game.getLastKnownInformation(entry.getKey(), Zone.BATTLEFIELD);
                Player player = entry.getValue();
                if (permanent != null && player != null) {
                    FilterCreatureCard filter = new FilterCreatureCard("a creature card from " + player.getName() + "'s graveyard");
                    filter.add(new OwnerIdPredicate(player.getId()));
                    Target targetCreature = new TargetCardInGraveyard(filter);
                    targetCreature.setNotTarget(true);
                    if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, targetCreature, source, game)) {
                        Card card = game.getCard(targetCreature.getFirstTarget());
                        if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
                            controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HashMap(java.util.HashMap) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) BlockedAttackerWatcher(mage.watchers.common.BlockedAttackerWatcher) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) MageObjectReference(mage.MageObjectReference)

Example 17 with Target

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

the class GlowsporeShamanEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Target target = new TargetCardInYourGraveyard(0, 1, filter, true);
    if (player.chooseUse(outcome, "Put a land card on top of your library?", source, game) && player.choose(outcome, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            return player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) CardsImpl(mage.cards.CardsImpl) FilterLandCard(mage.filter.common.FilterLandCard) Card(mage.cards.Card)

Example 18 with Target

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

the class HeartPiercerManticoreSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Target target = new TargetControlledCreaturePermanent(1, 1, StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, true);
    if (!controller.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Permanent toSacrifice = game.getPermanent(target.getFirstTarget());
    if (toSacrifice == null) {
        return false;
    }
    int power = toSacrifice.getPower().getValue();
    if (!toSacrifice.sacrifice(source, game)) {
        return false;
    }
    ReflexiveTriggeredAbility trigger = new ReflexiveTriggeredAbility(new DamageTargetEffect(power), false, "{this} deals damage equal to that creature's power to any target.");
    trigger.addTarget(new TargetAnyTarget());
    game.fireReflexiveTriggeredAbility(trigger, source);
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetAnyTarget(mage.target.common.TargetAnyTarget) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 19 with Target

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

the class HateMirageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).forEach(uuid -> {
        CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
        effect.setTargetPointer(new FixedTarget(uuid, game));
        effect.apply(game, source);
        effect.exileTokensCreatedAtNextEndStep(game, source);
    });
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect)

Example 20 with Target

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

the class LordOfThePitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent == null) {
        sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    }
    if (player == null || sourcePermanent == null) {
        return false;
    }
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature other than " + sourcePermanent.getName());
    filter.add(AnotherPredicate.instance);
    Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
    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);
            return true;
        }
    } else {
        player.damage(7, source.getSourceId(), source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

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