Search in sources :

Example 1 with CopyApplier

use of mage.util.functions.CopyApplier 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 2 with CopyApplier

use of mage.util.functions.CopyApplier 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 3 with CopyApplier

use of mage.util.functions.CopyApplier in project mage by magefree.

the class CreateTokenCopyTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID targetId;
    if (getTargetPointer() instanceof FixedTarget) {
        targetId = ((FixedTarget) getTargetPointer()).getTarget();
    } else {
        targetId = getTargetPointer().getFirst(game, source);
    }
    Permanent permanent;
    if (savedPermanent != null) {
        permanent = savedPermanent;
    } else if (useLKI) {
        permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    } else {
        permanent = game.getPermanentOrLKIBattlefield(targetId);
    }
    // can target card or permanent
    Card copyFrom;
    CopyApplier applier = new EmptyCopyApplier();
    if (permanent != null) {
        // handle copies of copies
        Permanent copyFromPermanent = permanent;
        for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
            if (effect instanceof CopyEffect) {
                CopyEffect copyEffect = (CopyEffect) effect;
                // there is another copy effect that our targetPermanent copies stats from
                if (copyEffect.getSourceId().equals(permanent.getId())) {
                    MageObject object = ((CopyEffect) effect).getTarget();
                    if (object instanceof Permanent) {
                        copyFromPermanent = (Permanent) object;
                        if (copyEffect.getApplier() != null) {
                            applier = copyEffect.getApplier();
                        }
                    }
                }
            }
        }
        copyFrom = copyFromPermanent;
    } else {
        copyFrom = game.getCard(getTargetPointer().getFirst(game, source));
    }
    if (copyFrom == null) {
        return false;
    }
    // create token and modify all attributes permanently (without game usage)
    EmptyToken token = new EmptyToken();
    // needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
    CardUtil.copyTo(token).from(copyFrom, game);
    applier.apply(game, token, source, targetId);
    if (becomesArtifact) {
        token.addCardType(CardType.ARTIFACT);
    }
    if (isntLegendary) {
        token.getSuperType().remove(SuperType.LEGENDARY);
    }
    if (startingLoyalty != -1) {
        token.setStartingLoyalty(startingLoyalty);
    }
    if (additionalCardType != null) {
        token.addCardType(additionalCardType);
    }
    if (hasHaste) {
        token.addAbility(HasteAbility.getInstance());
    }
    if (gainsFlying) {
        token.addAbility(FlyingAbility.getInstance());
    }
    if (tokenPower != Integer.MIN_VALUE) {
        token.removePTCDA();
        token.getPower().modifyBaseValue(tokenPower);
    }
    if (tokenToughness != Integer.MIN_VALUE) {
        token.removePTCDA();
        token.getToughness().modifyBaseValue(tokenToughness);
    }
    if (onlySubType != null) {
        token.removeAllCreatureTypes();
        token.addSubType(onlySubType);
    }
    if (additionalSubType != null) {
        token.addSubType(additionalSubType);
    }
    if (color != null) {
        token.getColor().setColor(color);
    }
    additionalAbilities.stream().forEach(token::addAbility);
    if (!this.abilityClazzesToRemove.isEmpty()) {
        List<Ability> abilitiesToRemoveTmp = new ArrayList<>();
        // Find the ones to remove
        for (Ability ability : token.getAbilities()) {
            if (this.abilityClazzesToRemove.contains(ability.getClass())) {
                abilitiesToRemoveTmp.add(ability);
            }
        }
        // Remove them
        for (Ability ability : abilitiesToRemoveTmp) {
            // Remove subabilities
            token.removeAbilities(ability.getSubAbilities());
            // Remove the ability
            token.removeAbility(ability);
        }
    }
    token.putOntoBattlefield(number, game, source, playerId == null ? source.getControllerId() : playerId, tapped, attacking, attackedPlayer);
    for (UUID tokenId : token.getLastAddedTokenIds()) {
        // by cards like Doubling Season multiple tokens can be added to the battlefield
        Permanent tokenPermanent = game.getPermanent(tokenId);
        if (tokenPermanent != null) {
            addedTokenPermanents.add(tokenPermanent);
            // add counters if necessary ie Ochre Jelly
            if (counter != null && numberOfCounters > 0) {
                tokenPermanent.addCounters(counter.createInstance(numberOfCounters), source.getControllerId(), source, game);
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) HasteAbility(mage.abilities.keyword.HasteAbility) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Ability(mage.abilities.Ability) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Card(mage.cards.Card) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) CopyApplier(mage.util.functions.CopyApplier) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) ContinuousEffect(mage.abilities.effects.ContinuousEffect) EmptyToken(mage.game.permanent.token.EmptyToken)

Example 4 with CopyApplier

use of mage.util.functions.CopyApplier in project mage by magefree.

the class CryptoplasmEffect method apply.

@Override
public boolean apply(Game game, final Ability source) {
    Permanent creatureToCopy = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (creatureToCopy != null) {
        CopyApplier applier = new CopyApplier() {

            @Override
            public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
                Ability upkeepAbility = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmEffect(), TargetController.YOU, true);
                upkeepAbility.addTarget(new TargetCreaturePermanent());
                blueprint.getAbilities().add(upkeepAbility);
                return true;
            }
        };
        game.copyPermanent(creatureToCopy, source.getSourceId(), source, applier);
    }
    return true;
}
Also used : BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Ability(mage.abilities.Ability) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Game(mage.game.Game) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CopyApplier(mage.util.functions.CopyApplier) MageObject(mage.MageObject) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) UUID(java.util.UUID)

Example 5 with CopyApplier

use of mage.util.functions.CopyApplier in project mage by magefree.

the class OlagLudevicsHubrisCopyApplier method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Cards cards = new CardsImpl(game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)));
    cards.removeIf(uuid -> !game.getCard(uuid).isCreature(game));
    if (cards.isEmpty()) {
        return false;
    }
    Card copyFromCard = getCard(cards, source, game);
    if (copyFromCard == null) {
        return false;
    }
    Permanent newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game);
    newBluePrint.assignNewId();
    CopyApplier applier = new OlagLudevicsHubrisCopyApplier();
    applier.apply(game, newBluePrint, source, source.getSourceId());
    CopyEffect copyEffect = new CopyEffect(Duration.Custom, newBluePrint, source.getSourceId());
    copyEffect.newId();
    copyEffect.setApplier(applier);
    Ability newAbility = source.copy();
    copyEffect.init(newAbility, game);
    game.addEffect(copyEffect, newAbility);
    return false;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) CopyApplier(mage.util.functions.CopyApplier) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Aggregations

Permanent (mage.game.permanent.Permanent)11 CopyApplier (mage.util.functions.CopyApplier)11 Ability (mage.abilities.Ability)10 CopyEffect (mage.abilities.effects.common.CopyEffect)7 Player (mage.players.Player)7 PermanentCard (mage.game.permanent.PermanentCard)6 MageObject (mage.MageObject)5 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 UUID (java.util.UUID)4 Card (mage.cards.Card)4 TargetPermanent (mage.target.TargetPermanent)4 BeginningOfUpkeepTriggeredAbility (mage.abilities.common.BeginningOfUpkeepTriggeredAbility)3 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 FilterCreatureCard (mage.filter.common.FilterCreatureCard)3 Game (mage.game.Game)3 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 FilterPermanent (mage.filter.FilterPermanent)2 EmptyToken (mage.game.permanent.token.EmptyToken)2 Target (mage.target.Target)2