Search in sources :

Example 1 with CopyEffect

use of mage.abilities.effects.common.CopyEffect in project mage by magefree.

the class BodyDoubleCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Target target = new TargetCardInGraveyard(new FilterCreatureCard("creature card in a graveyard"));
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            player.choose(outcome, target, source.getSourceId(), game);
            Card copyFromCard = game.getCard(target.getFirstTarget());
            if (copyFromCard != null) {
                CopyEffect copyEffect = new CopyEffect(Duration.Custom, copyFromCard, source.getSourceId());
                game.addEffect(copyEffect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) Player(mage.players.Player) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 2 with CopyEffect

use of mage.abilities.effects.common.CopyEffect 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)

Example 3 with CopyEffect

use of mage.abilities.effects.common.CopyEffect in project mage by magefree.

the class LazavDimirMastermindCopyApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent lazavDimirMastermind = game.getPermanent(source.getSourceId());
    Permanent newBluePrint = null;
    if (controller != null && lazavDimirMastermind != null) {
        Card copyFromCard = game.getCard(((FixedTarget) getTargetPointer()).getTarget());
        if (copyFromCard != null) {
            newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game);
            newBluePrint.assignNewId();
            CopyApplier applier = new LazavDimirMastermindCopyApplier();
            applier.apply(game, newBluePrint, source, lazavDimirMastermind.getId());
            CopyEffect copyEffect = new CopyEffect(Duration.Custom, newBluePrint, lazavDimirMastermind.getId());
            copyEffect.newId();
            copyEffect.setApplier(applier);
            Ability newAbility = source.copy();
            copyEffect.init(newAbility, game);
            game.addEffect(copyEffect, newAbility);
        }
        return true;
    }
    return false;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) PutCardIntoGraveFromAnywhereAllTriggeredAbility(mage.abilities.common.PutCardIntoGraveFromAnywhereAllTriggeredAbility) HexproofAbility(mage.abilities.keyword.HexproofAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) CopyApplier(mage.util.functions.CopyApplier) FilterCreatureCard(mage.filter.common.FilterCreatureCard) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard)

Example 4 with CopyEffect

use of mage.abilities.effects.common.CopyEffect in project mage by magefree.

the class ZamWesselEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (targetPlayer != null) {
            TargetCard targetCard = new TargetCard(0, 1, Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
            controller.choose(outcome, targetPlayer.getHand(), targetCard, game);
            Card copyFromCard = game.getCard(targetCard.getFirstTarget());
            if (copyFromCard != null) {
                game.informPlayers(controller.getLogName() + " chooses to copy " + copyFromCard.getName());
                CopyEffect copyEffect = new CopyEffect(Duration.Custom, copyFromCard, source.getSourceId());
                game.addEffect(copyEffect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 5 with CopyEffect

use of mage.abilities.effects.common.CopyEffect in project mage by magefree.

the class GameImpl method copyPermanent.

@Override
public Permanent copyPermanent(Duration duration, Permanent copyFromPermanent, UUID copyToPermanentId, Ability source, CopyApplier applier) {
    Permanent newBluePrint = null;
    // handle copies of copies
    for (Effect effect : getState().getContinuousEffects().getLayeredEffects(this)) {
        if (effect instanceof CopyEffect) {
            CopyEffect copyEffect = (CopyEffect) effect;
            // there is another copy effect that our targetPermanent copies stats from
            if (copyEffect.getSourceId().equals(copyFromPermanent.getId())) {
                MageObject oldBluePrint = ((CopyEffect) effect).getTarget();
                if (oldBluePrint instanceof Permanent) {
                    // copy it and apply the applier if any
                    newBluePrint = ((Permanent) oldBluePrint).copy();
                }
            }
        }
    }
    // if it was no copy of copy take the target itself
    if (newBluePrint == null) {
        newBluePrint = copyFromPermanent.copy();
        newBluePrint.reset(this);
        // getState().addCard(permanent);
        if (copyFromPermanent.isMorphed() || copyFromPermanent.isManifested() || copyFromPermanent.isFaceDown(this)) {
            MorphAbility.setPermanentToFaceDownCreature(newBluePrint, this);
        }
        newBluePrint.assignNewId();
        if (copyFromPermanent.isTransformed()) {
            TransformAbility.transformPermanent(newBluePrint, newBluePrint.getSecondCardFace(), this, source);
        }
    }
    if (applier != null) {
        applier.apply(this, newBluePrint, source, copyToPermanentId);
    }
    // save original copy link (handle copy of copies too)
    newBluePrint.setCopy(true, (copyFromPermanent.getCopyFrom() != null ? copyFromPermanent.getCopyFrom() : copyFromPermanent));
    CopyEffect newEffect = new CopyEffect(duration, newBluePrint, copyToPermanentId);
    newEffect.newId();
    newEffect.setApplier(applier);
    Ability newAbility = source.copy();
    newEffect.init(newAbility, this);
    // If there are already copy effects with duration = Custom to the same object, remove the existing effects because they no longer have any effect
    if (duration == Duration.Custom) {
        for (Effect effect : getState().getContinuousEffects().getLayeredEffects(this)) {
            if (effect instanceof CopyEffect) {
                CopyEffect copyEffect = (CopyEffect) effect;
                // there is another copy effect that copies to the same permanent
                if (copyEffect.getSourceId().equals(copyToPermanentId) && copyEffect.getDuration() == Duration.Custom) {
                    copyEffect.discard();
                }
            }
        }
    }
    state.addEffect(newEffect, newAbility);
    return newBluePrint;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) SagaAbility(mage.abilities.common.SagaAbility) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) AttachableToRestrictedAbility(mage.abilities.common.AttachableToRestrictedAbility) TriggeredManaAbility(mage.abilities.mana.TriggeredManaAbility) DelayedTriggeredManaAbility(mage.abilities.mana.DelayedTriggeredManaAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) CantHaveMoreThanAmountCountersSourceAbility(mage.abilities.common.CantHaveMoreThanAmountCountersSourceAbility) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Effect(mage.abilities.effects.Effect) InfoEffect(mage.abilities.effects.common.InfoEffect) CopyEffect(mage.abilities.effects.common.CopyEffect)

Aggregations

CopyEffect (mage.abilities.effects.common.CopyEffect)15 Permanent (mage.game.permanent.Permanent)13 Player (mage.players.Player)11 PermanentCard (mage.game.permanent.PermanentCard)8 Ability (mage.abilities.Ability)7 Card (mage.cards.Card)7 CopyApplier (mage.util.functions.CopyApplier)7 FilterCreatureCard (mage.filter.common.FilterCreatureCard)5 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)4 UUID (java.util.UUID)3 MageObject (mage.MageObject)3 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 FilterPermanent (mage.filter.FilterPermanent)3 TargetPermanent (mage.target.TargetPermanent)3 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)3 BeginningOfCombatTriggeredAbility (mage.abilities.common.BeginningOfCombatTriggeredAbility)2 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)2 Effect (mage.abilities.effects.Effect)2 FilterCard (mage.filter.FilterCard)2