Search in sources :

Example 21 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class ShadowKinApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            cards.addAll(player.millCards(3, source, game));
        }
    }
    if (cards.isEmpty()) {
        return false;
    }
    TargetCardInGraveyard target = new TargetCardInGraveyard(0, 1, StaticFilters.FILTER_CARD_CREATURE);
    target.setNotTarget(true);
    controller.choose(outcome, cards, target, game);
    Card card = game.getCard(target.getFirstTarget());
    Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
    if (card == null || sourcePermanent == null) {
        return true;
    }
    controller.moveCards(card, Zone.EXILED, source, game);
    Permanent blueprint = new PermanentCard(card, source.getControllerId(), game);
    blueprint.assignNewId();
    CopyApplier applier = new ShadowKinApplier();
    applier.apply(game, blueprint, source, sourcePermanent.getId());
    CopyEffect copyEffect = new CopyEffect(Duration.Custom, blueprint, sourcePermanent.getId());
    copyEffect.newId();
    copyEffect.setApplier(applier);
    Ability newAbility = source.copy();
    copyEffect.init(newAbility, game);
    game.addEffect(copyEffect, newAbility);
    return true;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) FlashAbility(mage.abilities.keyword.FlashAbility) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Permanent(mage.game.permanent.Permanent) CopyApplier(mage.util.functions.CopyApplier) UUID(java.util.UUID) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 22 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class TamiyoCompleatedSageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getFirstTarget());
    if (player == null || card == null) {
        return false;
    }
    player.moveCards(card, Zone.EXILED, source, game);
    return new CreateTokenCopyTargetEffect().setSavedPermanent(new PermanentCard(card, source.getControllerId(), game)).apply(game, source);
}
Also used : Player(mage.players.Player) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) PermanentCard(mage.game.permanent.PermanentCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 23 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class VolrathTheShapestealerCopyApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent volrathTheShapestealer = game.getPermanent(source.getSourceId());
    Permanent newBluePrint = null;
    if (controller == null || volrathTheShapestealer == null) {
        return false;
    }
    Card copyFromCard = game.getPermanent(source.getFirstTarget());
    if (copyFromCard == null) {
        return true;
    }
    newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game);
    newBluePrint.assignNewId();
    CopyApplier applier = new VolrathTheShapestealerCopyApplier();
    applier.apply(game, newBluePrint, source, volrathTheShapestealer.getId());
    CopyEffect copyEffect = new CopyEffect(Duration.UntilYourNextTurn, newBluePrint, volrathTheShapestealer.getId());
    copyEffect.newId();
    copyEffect.setApplier(applier);
    Ability newAbility = source.copy();
    copyEffect.init(newAbility, game);
    game.addEffect(copyEffect, newAbility);
    return true;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) CopyApplier(mage.util.functions.CopyApplier) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 24 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class ModalDoubleFacesCardsTest method test_Zones_AfterCast_1.

@Test
public void test_Zones_AfterCast_1() {
    // Akoum Warrior {5}{R} - creature
    // Akoum Teeth - land
    addCard(Zone.HAND, playerA, "Akoum Warrior");
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
    // prepare mdf permanent
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Akoum Warrior");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    checkPermanentCount("prepare", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Akoum Warrior", 1);
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.END_TURN);
    execute();
    assertAllCommandsUsed();
    Card card = currentGame.getState().getBattlefield().getAllPermanents().stream().filter(p -> CardUtil.haveSameNames(p, "Akoum Warrior", currentGame)).findFirst().orElse(null);
    Assert.assertNotNull(card);
    Assert.assertEquals("permanent card must be on battlefield", Zone.BATTLEFIELD, currentGame.getState().getZone(card.getId()));
    Assert.assertEquals("main permanent card must be on battlefield", Zone.BATTLEFIELD, currentGame.getState().getZone(card.getMainCard().getId()));
    Assert.assertEquals("half card must be on battlefield", Zone.BATTLEFIELD, currentGame.getState().getZone(((PermanentCard) card).getCard().getId()));
    Assert.assertEquals("main card must be on battlefield", Zone.BATTLEFIELD, currentGame.getState().getZone(((PermanentCard) card).getCard().getMainCard().getId()));
}
Also used : ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) Test(org.junit.Test)

Example 25 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class RevealAndShuffleIntoLibrarySourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
    Player controller = game.getPlayer(source.getControllerId());
    if (sourceObject != null && controller != null) {
        Player owner = null;
        Cards cards = new CardsImpl();
        Permanent permanent = null;
        if (sourceObject instanceof Spell) {
            sourceObject = ((Spell) sourceObject).getCard();
        }
        if (sourceObject instanceof Permanent) {
            permanent = (Permanent) sourceObject;
            owner = game.getPlayer(permanent.getOwnerId());
            if (sourceObject instanceof PermanentCard) {
                cards.add(permanent);
            }
        } else if (sourceObject instanceof Card) {
            owner = game.getPlayer(((Card) sourceObject).getOwnerId());
            cards.add((Card) sourceObject);
        }
        if (owner != null) {
            Zone fromZone = game.getState().getZone(sourceObject.getId());
            if (!cards.isEmpty()) {
                controller.revealCards(sourceObject.getName(), cards, game);
            }
            if (permanent != null) {
                controller.moveCardToLibraryWithInfo(permanent, source, game, fromZone, true, true);
            } else {
                controller.moveCardToLibraryWithInfo((Card) sourceObject, source, game, fromZone, true, true);
            }
            if (!cards.isEmpty()) {
                controller.shuffleLibrary(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Zone(mage.constants.Zone) MageObject(mage.MageObject) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Spell(mage.game.stack.Spell) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card)

Aggregations

PermanentCard (mage.game.permanent.PermanentCard)42 Card (mage.cards.Card)22 Permanent (mage.game.permanent.Permanent)16 Player (mage.players.Player)16 Ability (mage.abilities.Ability)11 MageObject (mage.MageObject)9 CardInfo (mage.cards.repository.CardInfo)9 CopyEffect (mage.abilities.effects.common.CopyEffect)8 FilterCard (mage.filter.FilterCard)6 CopyApplier (mage.util.functions.CopyApplier)6 UUID (java.util.UUID)5 PermanentMeld (mage.game.permanent.PermanentMeld)4 Test (org.junit.Test)4 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)3 FilterCreatureCard (mage.filter.common.FilterCreatureCard)3 PermanentToken (mage.game.permanent.PermanentToken)3 TargetCard (mage.target.TargetCard)3 Matcher (java.util.regex.Matcher)2