Search in sources :

Example 41 with TargetPermanent

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

the class ThroatSlitterTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((DamagedPlayerEvent) event).isCombatDamage() && event.getSourceId().equals(sourceId)) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("nonblack creature that player controls");
        filter.add(new ControllerIdPredicate(event.getPlayerId()));
        filter.add(Predicates.not(new ColorPredicate(ObjectColor.BLACK)));
        filter.setMessage("nonblack creature controlled by " + game.getPlayer(event.getTargetId()).getLogName());
        this.getTargets().clear();
        this.addTarget(new TargetPermanent(filter));
        return true;
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent)

Example 42 with TargetPermanent

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

the class VesuvanDoppelgangerCopyEffect 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) {
        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)) {
            controller.choose(Outcome.Copy, target, source.getSourceId(), game);
            Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
            if (copyFromPermanent != null) {
                game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {

                    @Override
                    public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
                        blueprint.getColor().setColor(sourcePermanent.getColor(game));
                        blueprint.getAbilities().add(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new VesuvanDoppelgangerCopyEffect(), TargetController.YOU, true, false, rule2));
                        return true;
                    }
                });
                return true;
            }
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) MageObject(mage.MageObject) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Game(mage.game.Game) CopyApplier(mage.util.functions.CopyApplier) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 43 with TargetPermanent

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

the class WaywardGuideBeastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, source.getSourceId(), source.getControllerId(), game) == 0) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(1, 1, StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, true);
    player.choose(outcome, target, source.getSourceId(), game);
    player.moveCards(game.getCard(target.getFirstTarget()), Zone.HAND, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetPermanent(mage.target.TargetPermanent)

Example 44 with TargetPermanent

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

the class WorldQuellerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourceCreature = game.getPermanent(source.getSourceId());
    if (player != null && sourceCreature != null) {
        Choice choiceImpl = new ChoiceImpl();
        choiceImpl.setChoices(choice);
        if (!player.choose(Outcome.Neutral, choiceImpl, game)) {
            return false;
        }
        CardType type = null;
        String choosenType = choiceImpl.getChoice();
        if (choosenType.equals(CardType.ARTIFACT.toString())) {
            type = CardType.ARTIFACT;
        } else if (choosenType.equals(CardType.LAND.toString())) {
            type = CardType.LAND;
        } else if (choosenType.equals(CardType.CREATURE.toString())) {
            type = CardType.CREATURE;
        } else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
            type = CardType.ENCHANTMENT;
        } else if (choosenType.equals(CardType.INSTANT.toString())) {
            type = CardType.INSTANT;
        } else if (choosenType.equals(CardType.SORCERY.toString())) {
            type = CardType.SORCERY;
        } else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
            type = CardType.PLANESWALKER;
        } else if (choosenType.equals(CardType.TRIBAL.toString())) {
            type = CardType.TRIBAL;
        }
        if (type != null) {
            FilterControlledPermanent filter = new FilterControlledPermanent("permanent you control of type " + type.toString());
            filter.add(type.getPredicate());
            TargetPermanent target = new TargetControlledPermanent(1, 1, filter, false);
            target.setNotTarget(true);
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player2 = game.getPlayer(playerId);
                if (player2 != null && target.canChoose(source.getSourceId(), playerId, game)) {
                    while (player2.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), playerId, game)) {
                        player2.chooseTarget(Outcome.Sacrifice, target, source, game);
                    }
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        chosen.add(permanent);
                    }
                    target.clearChosen();
                }
            }
            // all chosen permanents are sacrificed together
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
                if (chosen.contains(permanent)) {
                    permanent.sacrifice(source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Card(mage.cards.Card) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CardType(mage.constants.CardType) ChoiceImpl(mage.choices.ChoiceImpl) TargetPermanent(mage.target.TargetPermanent)

Example 45 with TargetPermanent

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

the class CopyPermanentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourcePermanent = game.getPermanentEntering(source.getSourceId());
    if (sourcePermanent == null) {
        sourcePermanent = game.getObject(source.getSourceId());
    }
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    Permanent copyFromPermanent = null;
    if (useTargetOfAbility) {
        copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    } else {
        Target target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            controller.choose(Outcome.Copy, target, source.getSourceId(), game);
            copyFromPermanent = game.getPermanent(target.getFirstTarget());
        }
    }
    if (copyFromPermanent == null) {
        return true;
    }
    bluePrintPermanent = game.copyPermanent(duration, copyFromPermanent, sourcePermanent.getId(), source, applier);
    if (bluePrintPermanent == null) {
        return false;
    }
    // if object is a copy of an aura, it needs to attach again for new target
    if (!bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
        return true;
    }
    // copied from mage.cards.c.CopyEnchantment.java
    // permanent can be attached (Estrid's Mask) or enchant (Utopia Sprawl)
    // TODO: fix Animate Dead -- it's can't be copied (can't retarget)
    Outcome auraOutcome = Outcome.BoostCreature;
    Target auraTarget = null;
    // attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
    for (Ability ability : bluePrintPermanent.getAbilities()) {
        if (!(ability instanceof SpellAbility)) {
            continue;
        }
        auraOutcome = ability.getEffects().getOutcome(ability);
        for (Effect effect : ability.getEffects()) {
            if (!(effect instanceof AttachEffect)) {
                continue;
            }
            if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
                auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
            }
        }
    }
    // enchant - search in all abilities (example: cast Estrid's Invocation on enchanted creature by Estrid, the Masked second ability, cast Estrid's Invocation on it)
    if (auraTarget == null) {
        for (Ability ability : bluePrintPermanent.getAbilities()) {
            if (!(ability instanceof EnchantAbility)) {
                continue;
            }
            auraOutcome = ability.getEffects().getOutcome(ability);
            if (ability.getTargets().size() > 0) {
                // Animate Dead don't have targets
                auraTarget = ability.getTargets().get(0);
            }
        }
    }
    /* if this is a copy of a copy, the copy's target has been
         * copied and needs to be cleared
         */
    if (auraTarget == null) {
        return true;
    }
    // clear selected target
    if (auraTarget.getFirstTarget() != null) {
        auraTarget.remove(auraTarget.getFirstTarget());
    }
    // select new target
    auraTarget.setNotTarget(true);
    if (!controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
        return true;
    }
    UUID targetId = auraTarget.getFirstTarget();
    Permanent targetPermanent = game.getPermanent(targetId);
    Player targetPlayer = game.getPlayer(targetId);
    if (targetPermanent != null) {
        targetPermanent.addAttachment(sourcePermanent.getId(), source, game);
    } else if (targetPlayer != null) {
        targetPlayer.addAttachment(sourcePermanent.getId(), source, game);
    } else {
        return false;
    }
    return true;
}
Also used : EnchantAbility(mage.abilities.keyword.EnchantAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Outcome(mage.constants.Outcome) MageObject(mage.MageObject) SpellAbility(mage.abilities.SpellAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetPermanent(mage.target.TargetPermanent) EnchantAbility(mage.abilities.keyword.EnchantAbility) 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