Search in sources :

Example 1 with EmptyCopyApplier

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

the class CemeteryPucaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent copyToCreature = game.getPermanent(source.getSourceId());
    if (copyToCreature != null) {
        Permanent copyFromCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
        if (copyFromCreature != null) {
            game.copyPermanent(Duration.WhileOnBattlefield, copyFromCreature, copyToCreature.getId(), source, new EmptyCopyApplier());
            ContinuousEffect effect = new GainAbilityTargetEffect(new DiesCreatureTriggeredAbility(new DoIfCostPaid(new CemeteryPucaEffect(), new ManaCostsImpl("{1}")), false, StaticFilters.FILTER_PERMANENT_A_CREATURE, true), Duration.WhileOnBattlefield);
            effect.setTargetPointer(new FixedTarget(copyToCreature.getId(), game));
            game.addEffect(effect, source);
            return true;
        }
    }
    return false;
}
Also used : DiesCreatureTriggeredAbility(mage.abilities.common.DiesCreatureTriggeredAbility) FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 2 with EmptyCopyApplier

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

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

the class BrudicladTelchorEngineerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    CreateTokenEffect effect = new CreateTokenEffect(new BrudicladTelchorMyrToken(), 1);
    if (effect.apply(game, source)) {
        TargetControlledPermanent target = new TargetControlledPermanent(0, 1, filter, true);
        target.setNotTarget(true);
        if (controller.chooseUse(outcome, "Select a token to copy?", source, game) && controller.choose(Outcome.Neutral, target, source.getSourceId(), game)) {
            Permanent toCopyFromPermanent = game.getPermanent(target.getFirstTarget());
            if (toCopyFromPermanent != null) {
                for (Permanent toCopyToPermanent : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
                    if (!toCopyToPermanent.equals(toCopyFromPermanent)) {
                        game.copyPermanent(toCopyFromPermanent, toCopyToPermanent.getId(), source, new EmptyCopyApplier());
                    }
                }
                return true;
            }
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) BrudicladTelchorMyrToken(mage.game.permanent.token.BrudicladTelchorMyrToken)

Example 4 with EmptyCopyApplier

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

the class UnstableShapeshifterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent targetCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (targetCreature != null && permanent != null) {
        Permanent blueprintPermanent = game.copyPermanent(Duration.Custom, targetCreature, permanent.getId(), source, new EmptyCopyApplier());
        blueprintPermanent.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new UnstableShapeshifterEffect(), filterAnotherCreature, false, SetTargetPointer.PERMANENT, ""), source.getSourceId(), game);
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) EntersBattlefieldAllTriggeredAbility(mage.abilities.common.EntersBattlefieldAllTriggeredAbility)

Example 5 with EmptyCopyApplier

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

the class SaheeliSublimeArtificerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent copyTo = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (copyTo != null) {
        Permanent copyFrom = game.getPermanentOrLKIBattlefield(source.getTargets().get(1).getFirstTarget());
        if (copyFrom != null) {
            game.copyPermanent(Duration.EndOfTurn, copyFrom, copyTo.getId(), source, new EmptyCopyApplier());
            ContinuousEffect effect = new AddCardTypeTargetEffect(Duration.EndOfTurn, CardType.ARTIFACT);
            effect.setTargetPointer(new FixedTarget(copyTo, game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCardTypeTargetEffect(mage.abilities.effects.common.continuous.AddCardTypeTargetEffect)

Aggregations

Permanent (mage.game.permanent.Permanent)20 EmptyCopyApplier (mage.util.functions.EmptyCopyApplier)20 TargetPermanent (mage.target.TargetPermanent)9 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)7 Player (mage.players.Player)6 FilterPermanent (mage.filter.FilterPermanent)5 ContinuousEffect (mage.abilities.effects.ContinuousEffect)4 MageObject (mage.MageObject)3 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)3 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 Ability (mage.abilities.Ability)2 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)2 EmptyToken (mage.game.permanent.token.EmptyToken)2 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)2 UUID (java.util.UUID)1 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)1 DiesCreatureTriggeredAbility (mage.abilities.common.DiesCreatureTriggeredAbility)1 EntersBattlefieldAllTriggeredAbility (mage.abilities.common.EntersBattlefieldAllTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1