Search in sources :

Example 61 with Target

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

the class WoodElementalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card sourceCard = game.getCard(source.getSourceId());
    if (controller != null && sourceCard != null) {
        Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true);
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.chooseTarget(Outcome.Detriment, target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                int sacrificedForests = target.getTargets().size();
                game.informPlayers(controller.getLogName() + " sacrifices " + sacrificedForests + " untapped Forests for " + sourceCard.getLogName());
                for (UUID targetId : target.getTargets()) {
                    Permanent targetPermanent = game.getPermanent(targetId);
                    if (targetPermanent != null) {
                        targetPermanent.sacrifice(source, game);
                    }
                }
                game.addEffect(new SetPowerToughnessSourceEffect(sacrificedForests, sacrificedForests, Duration.Custom, SubLayer.SetPT_7b), source);
                return true;
            }
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) Player(mage.players.Player) Target(mage.target.Target) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) Card(mage.cards.Card)

Example 62 with Target

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

the class LicidSpecialActionEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game);
    if (licid != null) {
        switch(layer) {
            case TypeChangingEffects_4:
                licid.removeAllCardTypes(game);
                licid.addCardType(game, CardType.ENCHANTMENT);
                licid.removeAllSubTypes(game);
                licid.addSubType(game, SubType.AURA);
                break;
            case AbilityAddingRemovingEffects_6:
                List<Ability> toRemove = new ArrayList<>();
                for (Ability ability : licid.getAbilities(game)) {
                    for (Effect effect : ability.getEffects()) {
                        if (effect instanceof LicidEffect) {
                            toRemove.add(ability);
                            break;
                        }
                    }
                }
                licid.removeAbilities(toRemove, source.getSourceId(), game);
                Ability ability = new EnchantAbility("creature");
                ability.setRuleAtTheTop(true);
                licid.addAbility(ability, source.getSourceId(), game);
                licid.getSpellAbility().getTargets().clear();
                Target target = new TargetCreaturePermanent();
                target.addTarget(this.getTargetPointer().getFirst(game, source), source, game);
                licid.getSpellAbility().getTargets().add(target);
        }
        return true;
    }
    discard();
    return false;
}
Also used : EnchantAbility(mage.abilities.keyword.EnchantAbility) Ability(mage.abilities.Ability) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ArrayList(java.util.ArrayList) OneShotEffect(mage.abilities.effects.OneShotEffect) RemoveSpecialActionEffect(mage.abilities.effects.common.RemoveSpecialActionEffect) Effect(mage.abilities.effects.Effect) CreateSpecialActionEffect(mage.abilities.effects.common.CreateSpecialActionEffect) AttachEffect(mage.abilities.effects.common.AttachEffect) EnchantAbility(mage.abilities.keyword.EnchantAbility)

Example 63 with Target

use of mage.target.Target 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)

Example 64 with Target

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

the class BecomeBlockedTargetEffect method getText.

@Override
public String getText(Mode mode) {
    if (staticText != null && !staticText.isEmpty()) {
        return staticText;
    }
    StringBuilder sb = new StringBuilder();
    if (mode.getTargets().isEmpty()) {
        return "that creature becomes blocked";
    }
    Target target = mode.getTargets().get(0);
    if (target.getNumberOfTargets() == 1) {
        String targetName = target.getTargetName();
        sb.append("target ").append(targetName).append(" becomes blocked");
        return sb.toString();
    }
    if (target.getMaxNumberOfTargets() != target.getMinNumberOfTargets()) {
        sb.append("up to ");
    }
    sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets()));
    sb.append(" target ").append(target.getTargetName()).append(" become blocked");
    return sb.toString();
}
Also used : Target(mage.target.Target)

Example 65 with Target

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

the class DamageMultiEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    this.damagedSet.clear();
    if (source.getTargets().isEmpty()) {
        return true;
    }
    Target multiTarget = source.getTargets().get(0);
    for (UUID target : multiTarget.getTargets()) {
        Permanent permanent = game.getPermanent(target);
        if (permanent != null) {
            if (permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game, false, true) > 0) {
                damagedSet.add(new MageObjectReference(permanent, game));
            }
        } else {
            Player player = game.getPlayer(target);
            if (player != null) {
                player.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game);
            }
        }
    }
    return true;
}
Also used : Target(mage.target.Target) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

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