Search in sources :

Example 1 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class JourneyToTheOracleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    controller.revealCards(source, new CardsImpl(card), game);
    if (card.isLand(game)) {
        // note that MDFC land cards are handled differently: they can't be moved
        return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    // query player
    if (!controller.chooseUse(outcome, "Cast " + card.getName() + " by paying {1}?", source, game)) {
        return false;
    }
    // handle split-cards
    if (card instanceof SplitCard) {
        SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
        SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
        // get additional cost if any
        Costs additionalCostsLeft = leftHalfCard.getSpellAbility().getCosts();
        Costs additionalCostsRight = rightHalfCard.getSpellAbility().getCosts();
        // set alternative cost and any additional cost
        controller.setCastSourceIdWithAlternateMana(leftHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsLeft);
        controller.setCastSourceIdWithAlternateMana(rightHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsRight);
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), Boolean.TRUE);
    }
    // handle MDFC
    if (card instanceof ModalDoubleFacesCard) {
        ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
        ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
        // some MDFC cards are lands.  IE: sea gate restoration
        if (!leftHalfCard.isLand(game)) {
            // get additional cost if any
            Costs additionalCostsMDFCLeft = leftHalfCard.getSpellAbility().getCosts();
            // set alternative cost and any additional cost
            controller.setCastSourceIdWithAlternateMana(leftHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsMDFCLeft);
        }
        if (!rightHalfCard.isLand(game)) {
            // get additional cost if any
            Costs additionalCostsMDFCRight = rightHalfCard.getSpellAbility().getCosts();
            // set alternative cost and any additional cost
            controller.setCastSourceIdWithAlternateMana(rightHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsMDFCRight);
        }
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), Boolean.TRUE);
    }
    // handle adventure cards
    if (card instanceof AdventureCard) {
        Card creatureCard = card.getMainCard();
        Card spellCard = ((AdventureCard) card).getSpellCard();
        // get additional cost if any
        Costs additionalCostsCreature = creatureCard.getSpellAbility().getCosts();
        Costs additionalCostsSpellCard = spellCard.getSpellAbility().getCosts();
        // set alternative cost and any additional cost
        controller.setCastSourceIdWithAlternateMana(creatureCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsCreature);
        controller.setCastSourceIdWithAlternateMana(spellCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsSpellCard);
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + creatureCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + spellCard.getId(), Boolean.TRUE);
    }
    // normal card
    if (!(card instanceof SplitCard) || !(card instanceof ModalDoubleFacesCard) || !(card instanceof AdventureCard)) {
        // get additional cost if any
        Costs additionalCostsNormalCard = card.getSpellAbility().getCosts();
        controller.setCastSourceIdWithAlternateMana(card.getMainCard().getId(), new ManaCostsImpl<>("{1}"), additionalCostsNormalCard);
    }
    // cast it
    controller.cast(controller.chooseAbilityForCast(card.getMainCard(), game, false), game, false, new ApprovingObject(source, game));
    // turn off effect after cast on every possible card-face
    if (card instanceof SplitCard) {
        SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
        SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), null);
    }
    if (card instanceof ModalDoubleFacesCard) {
        ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
        ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), null);
    }
    if (card instanceof AdventureCard) {
        Card creatureCard = card.getMainCard();
        Card spellCard = ((AdventureCard) card).getSpellCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + creatureCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + spellCard.getId(), null);
    }
    // turn off effect on a normal card
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    return true;
}
Also used : Player(mage.players.Player) Costs(mage.abilities.costs.Costs) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) ApprovingObject(mage.ApprovingObject) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) SplitCardHalf(mage.cards.SplitCardHalf) CardsImpl(mage.cards.CardsImpl) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard)

Example 2 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class BoosterGenerationTest method testKaldheim_SnowLandAndMDFC.

@Test
public void testKaldheim_SnowLandAndMDFC() {
    boolean foundVale = false;
    boolean foundMDFC = false;
    boolean foundNoMDFC = false;
    for (int i = 1; i <= 100; i++) {
        List<Card> booster = Kaldheim.getInstance().createBooster();
        assertEquals("Booster does not have 15 cards", 15, booster.size());
        assertTrue("Booster contains cards from another set", booster.stream().map(Card::getExpansionSetCode).allMatch("KHM"::equals));
        assertFalse("Booster cannot contain non-snow basic lands", booster.stream().anyMatch(card -> card.isBasic() && !card.isSnow()));
        assertEquals("Booster must contain exactly 1 rare or mythic", 1, booster.stream().map(Card::getRarity).filter(rarity -> rarity == Rarity.RARE || rarity == Rarity.MYTHIC).count());
        assertEquals("Booster must contain exactly 3 uncommons", 3, booster.stream().map(Card::getRarity).filter(Rarity.UNCOMMON::equals).count());
        List<Card> snowLands = booster.stream().filter(card -> card.isSnow() && card.isLand(currentGame)).collect(Collectors.toList());
        switch(snowLands.size()) {
            case 0:
                fail("Booster must have snow lands");
            case 1:
                Card snowLand = snowLands.get(0);
                assertTrue("Only one snow land, must be basic or common", snowLand.isBasic() || snowLand.getRarity() == Rarity.COMMON);
                assertNotEquals("Only one snow land, can't be Shimmerdrift Vale", "Shimmerdrift Vale", snowLand.getName());
                assertNotEquals("Only one snow land, can't be Faceless Haven", "Faceless Haven", snowLand.getName());
                break;
            case 2:
                assertEquals("Booster can't have two snow lands unless one is Shimmerdrift Vale or Faceless Haven", 1, snowLands.stream().filter(card -> card.getName().equals("Shimmerdrift Vale") || card.getName().equals("Faceless Haven")).count());
                assertEquals("Booster can't have two snow lands unless one is not Shimmerdrift Vale or Faceless Haven", 1, snowLands.stream().filter(card -> !card.getName().equals("Shimmerdrift Vale") && !card.getName().equals("Faceless Haven")).count());
                break;
            case 3:
                assertEquals("Booster can't have three snow lands unless one is Shimmerdrift Vale", 1, snowLands.stream().filter(card -> card.getName().equals("Shimmerdrift Vale")).count());
                assertEquals("Booster can't have three snow lands unless one is Faceless Haven", 1, snowLands.stream().filter(card -> card.getName().equals("Faceless Haven")).count());
                assertEquals("Booster can't have three snow lands unless one is not Shimmerdrift Vale or Faceless Haven", 1, snowLands.stream().filter(card -> !card.getName().equals("Shimmerdrift Vale") && !card.getName().equals("Faceless Haven")).count());
                break;
            default:
                fail("Booster can't have more than three snow lands");
        }
        long mdfcCount = booster.stream().filter(card -> card instanceof ModalDoubleFacesCard).count();
        assertTrue("Booster can't have more than one MDFC", mdfcCount < 2);
        foundMDFC |= mdfcCount > 0;
        foundNoMDFC |= mdfcCount == 0;
        foundVale |= booster.stream().map(MageObject::getName).anyMatch("Shimmerdrift Vale"::equals);
        if (foundVale && foundMDFC && foundNoMDFC && i > 20) {
            break;
        }
    }
    assertTrue("No booster contained Shimmerdrift Vale", foundVale);
    assertTrue("No booster contained an MDFC", foundMDFC);
    assertTrue("Every booster contained an MDFC", foundNoMDFC);
}
Also used : MageTestBase(org.mage.test.serverside.base.MageTestBase) java.util(java.util) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) mage.sets(mage.sets) CardScanner(mage.cards.repository.CardScanner) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility) Test(org.junit.Test) SubType(mage.constants.SubType) Collectors(java.util.stream.Collectors) ExpansionSet(mage.cards.ExpansionSet) Ignore(org.junit.Ignore) CardInfo(mage.cards.repository.CardInfo) CardType(mage.constants.CardType) MageObject(mage.MageObject) Rarity(mage.constants.Rarity) Card(mage.cards.Card) Assert(org.junit.Assert) Ability(mage.abilities.Ability) Before(org.junit.Before) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) MageObject(mage.MageObject) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) Card(mage.cards.Card) Test(org.junit.Test)

Example 3 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class ModalDoubleFacesCardsTest method test_Zones_AfterExile.

@Test
public void test_Zones_AfterExile() {
    // {2}, {tap}: Exile target permanent you control.
    addCard(Zone.BATTLEFIELD, playerA, "Synod Sanctum");
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
    // 
    // 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);
    // exile
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{2}, ", "Akoum Warrior");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    checkPermanentCount("exile", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Akoum Warrior", 0);
    checkExileCount("exile", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Akoum Warrior", 1);
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.END_TURN);
    execute();
    assertAllCommandsUsed();
    Card card = currentGame.getState().getExile().getAllCards(currentGame).stream().filter(p -> CardUtil.haveSameNames(p, "Akoum Warrior", currentGame)).findFirst().orElse(null);
    Assert.assertNotNull(card);
    Assert.assertTrue("must be mdf card", card instanceof ModalDoubleFacesCard);
    ModalDoubleFacesCard mdfCard = (ModalDoubleFacesCard) card;
    Assert.assertEquals("card must be on exile", Zone.EXILED, currentGame.getState().getZone(mdfCard.getId()));
    Assert.assertEquals("left part must be on exile", Zone.EXILED, currentGame.getState().getZone(mdfCard.getLeftHalfCard().getId()));
    Assert.assertEquals("right part must be on exile", Zone.EXILED, currentGame.getState().getZone(mdfCard.getRightHalfCard().getId()));
}
Also used : ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) Test(org.junit.Test)

Example 4 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class CopySpellTest method test_SimpleCopy_MDFC.

@Test
public void test_SimpleCopy_MDFC() {
    ModalDoubleFacesCard sourceCard = (ModalDoubleFacesCard) CardRepository.instance.findCard("Agadeem's Awakening").getCard();
    ModalDoubleFacesCard originalCard = (ModalDoubleFacesCard) CardRepository.instance.findCard("Agadeem's Awakening").getCard();
    prepareZoneAndZCC(originalCard);
    ModalDoubleFacesCard copiedCard = (ModalDoubleFacesCard) currentGame.copyCard(originalCard, null, playerA.getId());
    // main
    Assert.assertNotEquals("main - id must be different", originalCard.getId(), copiedCard.getId());
    Assert.assertEquals("main - rules must be same", originalCard.getRules(), copiedCard.getRules());
    abilitySourceMustBeSame(sourceCard, "main source");
    abilitySourceMustBeSame(originalCard, "main original");
    abilitySourceMustBeSame(copiedCard, "main copied");
    // cardsMustHaveSameZoneAndZCC(originalCard, copiedCard, "main");
    // left
    Assert.assertNotEquals("left - id must be different", originalCard.getLeftHalfCard().getId(), copiedCard.getLeftHalfCard().getId());
    Assert.assertEquals("left - rules must be same", originalCard.getLeftHalfCard().getRules(), copiedCard.getLeftHalfCard().getRules());
    Assert.assertEquals("left - parent ref", copiedCard.getLeftHalfCard().getParentCard().getId(), copiedCard.getId());
    abilitySourceMustBeSame(originalCard.getLeftHalfCard(), "left original");
    abilitySourceMustBeSame(copiedCard.getLeftHalfCard(), "left copied");
    // cardsMustHaveSameZoneAndZCC(originalCard.getLeftHalfCard(), copiedCard.getLeftHalfCard(), "left");
    // right
    Assert.assertNotEquals("right - id must be different", originalCard.getRightHalfCard().getId(), copiedCard.getRightHalfCard().getId());
    Assert.assertEquals("right - rules must be same", originalCard.getRightHalfCard().getRules(), copiedCard.getRightHalfCard().getRules());
    Assert.assertEquals("right - parent ref", copiedCard.getRightHalfCard().getParentCard().getId(), copiedCard.getId());
    abilitySourceMustBeSame(originalCard.getRightHalfCard(), "right original");
    abilitySourceMustBeSame(copiedCard.getRightHalfCard(), "right copied");
// cardsMustHaveSameZoneAndZCC(originalCard.getRightHalfCard(), copiedCard.getRightHalfCard(), "right");
}
Also used : ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) Test(org.junit.Test)

Example 5 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class FlashbackReplacementEffect method getSpellAbilityToResolve.

@Override
public SpellAbility getSpellAbilityToResolve(Game game) {
    Card card = game.getCard(getSourceId());
    if (card != null) {
        if (spellAbilityToResolve == null) {
            SpellAbility spellAbilityCopy = null;
            if (card instanceof SplitCard) {
                if (((SplitCard) card).getLeftHalfCard().getName().equals(abilityName)) {
                    spellAbilityCopy = ((SplitCard) card).getLeftHalfCard().getSpellAbility().copy();
                } else if (((SplitCard) card).getRightHalfCard().getName().equals(abilityName)) {
                    spellAbilityCopy = ((SplitCard) card).getRightHalfCard().getSpellAbility().copy();
                }
            } else if (card instanceof ModalDoubleFacesCard) {
                if (((ModalDoubleFacesCard) card).getLeftHalfCard().getName().equals(abilityName)) {
                    spellAbilityCopy = ((ModalDoubleFacesCard) card).getLeftHalfCard().getSpellAbility().copy();
                } else if (((ModalDoubleFacesCard) card).getRightHalfCard().getName().equals(abilityName)) {
                    spellAbilityCopy = ((ModalDoubleFacesCard) card).getRightHalfCard().getSpellAbility().copy();
                }
            } else {
                spellAbilityCopy = card.getSpellAbility().copy();
            }
            if (spellAbilityCopy == null) {
                return null;
            }
            spellAbilityCopy.setId(this.getId());
            spellAbilityCopy.getManaCosts().clear();
            spellAbilityCopy.getManaCostsToPay().clear();
            spellAbilityCopy.getCosts().addAll(this.getCosts().copy());
            spellAbilityCopy.addCost(this.getManaCosts().copy());
            spellAbilityCopy.setSpellAbilityCastMode(this.getSpellAbilityCastMode());
            spellAbilityToResolve = spellAbilityCopy;
            ContinuousEffect effect = new FlashbackReplacementEffect();
            effect.setTargetPointer(new FixedTarget(getSourceId(), game.getState().getZoneChangeCounter(getSourceId())));
            game.addEffect(effect, this);
        }
    }
    return spellAbilityToResolve;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SpellAbility(mage.abilities.SpellAbility) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SplitCard(mage.cards.SplitCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card)

Aggregations

ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)10 Card (mage.cards.Card)7 SplitCard (mage.cards.SplitCard)7 AdventureCard (mage.cards.AdventureCard)5 Player (mage.players.Player)4 Ability (mage.abilities.Ability)3 ModalDoubleFacesCardHalf (mage.cards.ModalDoubleFacesCardHalf)3 Test (org.junit.Test)3 UUID (java.util.UUID)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 SplitCardHalf (mage.cards.SplitCardHalf)2 SubType (mage.constants.SubType)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 ApprovingObject (mage.ApprovingObject)1 MageObject (mage.MageObject)1 MageObjectReference (mage.MageObjectReference)1 SpellAbility (mage.abilities.SpellAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 Costs (mage.abilities.costs.Costs)1