Search in sources :

Example 1 with SplitCard

use of mage.cards.SplitCard 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 SplitCard

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

the class CopySpellTest method test_SimpleCopy_SplitCard.

@Test
public void test_SimpleCopy_SplitCard() {
    SplitCard sourceCard = (SplitCard) CardRepository.instance.findCard("Alive // Well").getCard();
    SplitCard originalCard = (SplitCard) CardRepository.instance.findCard("Alive // Well").getCard();
    prepareZoneAndZCC(originalCard);
    SplitCard copiedCard = (SplitCard) 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 : SplitCard(mage.cards.SplitCard) Test(org.junit.Test)

Example 3 with SplitCard

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

the class SpellAbility method canActivate.

@Override
public ActivationStatus canActivate(UUID playerId, Game game) {
    if (this.spellCanBeActivatedRegularlyNow(playerId, game)) {
        if (spellAbilityType == SpellAbilityType.SPLIT || spellAbilityType == SpellAbilityType.SPLIT_AFTERMATH) {
            return ActivationStatus.getFalse();
        }
        // play from not own hand
        ApprovingObject approvingObject = game.getContinuousEffects().asThough(getSourceId(), AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, this, playerId, game);
        if (approvingObject == null) {
            Card card = game.getCard(sourceId);
            if (!(card != null && card.isOwnedBy(playerId))) {
                return ActivationStatus.getFalse();
            }
        }
        // Check if rule modifying events prevent to cast the spell in check playable mode
        if (game.inCheckPlayableState()) {
            Card card = game.getCard(sourceId);
            GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, this.getId(), this, playerId);
            castEvent.setZone(card == null ? null : game.getState().getZone(card.getMainCard().getId()));
            if (game.getContinuousEffects().preventedByRuleModification(castEvent, this, game, true)) {
                return ActivationStatus.getFalse();
            }
        }
        // Alternate spell abilities (Flashback, Overload) can't be cast with no mana to pay option
        if (getSpellAbilityType() == SpellAbilityType.BASE_ALTERNATE) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.getCastSourceIdWithAlternateMana().contains(getSourceId())) {
                return ActivationStatus.getFalse();
            }
        }
        // can pay all costs and choose targets
        if (costs.canPay(this, this, playerId, game)) {
            if (getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
                SplitCard splitCard = (SplitCard) game.getCard(getSourceId());
                if (splitCard != null) {
                    // see https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/251926-snapcaster-mage-and-fuse
                    if (game.getState().getZone(splitCard.getId()) == Zone.HAND) {
                        return new ActivationStatus(splitCard.getLeftHalfCard().getSpellAbility().canChooseTarget(game, playerId) && splitCard.getRightHalfCard().getSpellAbility().canChooseTarget(game, playerId), null);
                    }
                }
                return ActivationStatus.getFalse();
            } else {
                return new ActivationStatus(canChooseTarget(game, playerId), approvingObject);
            }
        }
    }
    return ActivationStatus.getFalse();
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) GameEvent(mage.game.events.GameEvent) SplitCard(mage.cards.SplitCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card)

Example 4 with SplitCard

use of mage.cards.SplitCard 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)

Example 5 with SplitCard

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

the class AsThoughEffectImpl method allowCardToPlayWithoutMana.

/**
 * Internal method to do the necessary to allow the card from objectId to be
 * cast or played (if it's a land) without paying any mana. Additional costs
 * (like sacrificing or discarding) have still to be payed. Checks if the
 * card is of the correct type or in the correct zone have to be done
 * before.
 *
 * @param objectId sourceId of the card to play
 * @param source source ability that allows this effect
 * @param affectedControllerId player allowed to play the card
 * @param game
 * @return
 */
protected boolean allowCardToPlayWithoutMana(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    Player player = game.getPlayer(affectedControllerId);
    Card card = game.getCard(objectId);
    if (card == null || player == null) {
        return false;
    }
    if (!card.isLand(game)) {
        if (card instanceof SplitCard) {
            Card leftCard = ((SplitCard) card).getLeftHalfCard();
            player.setCastSourceIdWithAlternateMana(leftCard.getId(), null, leftCard.getSpellAbility().getCosts());
            Card rightCard = ((SplitCard) card).getRightHalfCard();
            player.setCastSourceIdWithAlternateMana(rightCard.getId(), null, rightCard.getSpellAbility().getCosts());
        } else if (card instanceof ModalDoubleFacesCard) {
            Card leftCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
            Card rightCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
            // some MDFC's are land.  IE: sea gate restoration
            if (!leftCard.isLand(game)) {
                player.setCastSourceIdWithAlternateMana(leftCard.getId(), null, leftCard.getSpellAbility().getCosts());
            }
            if (!rightCard.isLand(game)) {
                player.setCastSourceIdWithAlternateMana(rightCard.getId(), null, rightCard.getSpellAbility().getCosts());
            }
        } else if (card instanceof AdventureCard) {
            Card creatureCard = card.getMainCard();
            Card spellCard = ((AdventureCard) card).getSpellCard();
            player.setCastSourceIdWithAlternateMana(creatureCard.getId(), null, creatureCard.getSpellAbility().getCosts());
            player.setCastSourceIdWithAlternateMana(spellCard.getId(), null, spellCard.getSpellAbility().getCosts());
        }
        player.setCastSourceIdWithAlternateMana(objectId, null, card.getSpellAbility().getCosts());
    }
    return true;
}
Also used : Player(mage.players.Player) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) Card(mage.cards.Card)

Aggregations

SplitCard (mage.cards.SplitCard)9 ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)7 Card (mage.cards.Card)6 AdventureCard (mage.cards.AdventureCard)5 Player (mage.players.Player)5 ModalDoubleFacesCardHalf (mage.cards.ModalDoubleFacesCardHalf)3 UUID (java.util.UUID)2 ApprovingObject (mage.ApprovingObject)2 Ability (mage.abilities.Ability)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 SplitCardHalf (mage.cards.SplitCardHalf)2 MageObjectReference (mage.MageObjectReference)1 SpellAbility (mage.abilities.SpellAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 Costs (mage.abilities.costs.Costs)1 FlyingAbility (mage.abilities.keyword.FlyingAbility)1 ForetellAbility (mage.abilities.keyword.ForetellAbility)1 RetraceAbility (mage.abilities.keyword.RetraceAbility)1 CardsImpl (mage.cards.CardsImpl)1 MockCard (mage.cards.mock.MockCard)1