use of mage.cards.ModalDoubleFacesCardHalf 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;
}
use of mage.cards.ModalDoubleFacesCardHalf in project mage by magefree.
the class EtherealValkyrieEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.drawCards(1, source, game);
TargetCardInHand targetCard = new TargetCardInHand(new FilterCard("card to exile face down. It becomes foretold."));
if (controller.chooseTarget(Outcome.Benefit, targetCard, source, game)) {
Card exileCard = game.getCard(targetCard.getFirstTarget());
if (exileCard == null) {
return false;
}
// process Split, MDFC, and Adventure cards first
// note that 'Foretell Cost' refers to the main card (left) and 'Foretell Split Cost' refers to the (right) card if it exists
ForetellAbility foretellAbility = null;
if (exileCard instanceof SplitCard) {
String leftHalfCost = CardUtil.reduceCost(((SplitCard) exileCard).getLeftHalfCard().getManaCost(), 2).getText();
String rightHalfCost = CardUtil.reduceCost(((SplitCard) exileCard).getRightHalfCard().getManaCost(), 2).getText();
game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", leftHalfCost);
game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", rightHalfCost);
foretellAbility = new ForetellAbility(exileCard, leftHalfCost, rightHalfCost);
} else if (exileCard instanceof ModalDoubleFacesCard) {
ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) exileCard).getLeftHalfCard();
if (!leftHalfCard.isLand(game)) {
String leftHalfCost = CardUtil.reduceCost(leftHalfCard.getManaCost(), 2).getText();
game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", leftHalfCost);
ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) exileCard).getRightHalfCard();
if (rightHalfCard.isLand(game)) {
foretellAbility = new ForetellAbility(exileCard, leftHalfCost);
} else {
String rightHalfCost = CardUtil.reduceCost(rightHalfCard.getManaCost(), 2).getText();
game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", rightHalfCost);
foretellAbility = new ForetellAbility(exileCard, leftHalfCost, rightHalfCost);
}
}
} else if (exileCard instanceof AdventureCard) {
String creatureCost = CardUtil.reduceCost(exileCard.getMainCard().getManaCost(), 2).getText();
String spellCost = CardUtil.reduceCost(((AdventureCard) exileCard).getSpellCard().getManaCost(), 2).getText();
game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", creatureCost);
game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", spellCost);
foretellAbility = new ForetellAbility(exileCard, creatureCost, spellCost);
} else {
// normal card
String costText = CardUtil.reduceCost(exileCard.getManaCost(), 2).getText();
game.getState().setValue(exileCard.getId().toString() + "Foretell Cost", costText);
foretellAbility = new ForetellAbility(exileCard, costText);
}
// note that the card is not foretell'd into exile, it is put into exile and made foretold
if (foretellAbility != null) {
// copy source and use it for the foretold effect on the exiled card
// bug #8673
Ability copiedSource = source.copy();
copiedSource.newId();
copiedSource.setSourceId(exileCard.getId());
game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Turn Number", game.getTurnNum());
UUID exileId = CardUtil.getExileZoneId(exileCard.getMainCard().getId().toString() + "foretellAbility", game);
controller.moveCardsToExile(exileCard, source, game, true, exileId, " Foretell Turn Number: " + game.getTurnNum());
exileCard.setFaceDown(true, game);
foretellAbility.setSourceId(exileCard.getId());
foretellAbility.setControllerId(exileCard.getOwnerId());
game.getState().addOtherAbility(exileCard, foretellAbility);
foretellAbility.activate(game, true);
ContinuousEffect effect = foretellAbility.new ForetellAddCostEffect(new MageObjectReference(exileCard, game));
game.addEffect(effect, copiedSource);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.FORETOLD, exileCard.getId(), null, null));
return true;
}
}
}
return false;
}
use of mage.cards.ModalDoubleFacesCardHalf in project mage by magefree.
the class AftermathExileAsResolvesFromGraveyard method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getFromZone() == Zone.STACK && zEvent.getToZone() != Zone.EXILED) {
// Moving something from stack to somewhere else
// Get the source id, getting the whole split card's ID, because
// that's the card that is changing zones in the event, but
// source.getSourceId is only the split card half.
// If branch so that we also support putting Aftermath on
// non-split cards for... whatever reason, in case somebody
// wants to do that in the future.
UUID sourceId = source.getSourceId();
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard instanceof SplitCardHalf) {
sourceCard = ((SplitCardHalf) sourceCard).getParentCard();
sourceId = sourceCard.getId();
}
if (sourceCard instanceof ModalDoubleFacesCardHalf) {
sourceCard = ((ModalDoubleFacesCardHalf) sourceCard).getParentCard();
sourceId = sourceCard.getId();
}
if (zEvent.getTargetId().equals(sourceId)) {
// Moving this spell from stack to yard
Spell spell = game.getStack().getSpell(source.getSourceId());
// And this spell was cast from the graveyard, so we need to exile it
return spell != null && spell.getFromZone() == Zone.GRAVEYARD;
}
}
return false;
}
use of mage.cards.ModalDoubleFacesCardHalf in project mage by magefree.
the class WrennAndSixEmblemEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card == null) {
continue;
}
if (card instanceof SplitCard) {
SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
if (leftHalfCard.isInstantOrSorcery(game)) {
Ability ability = new RetraceAbility(leftHalfCard);
ability.setSourceId(cardId);
ability.setControllerId(leftHalfCard.getOwnerId());
game.getState().addOtherAbility(leftHalfCard, ability);
}
if (rightHalfCard.isInstantOrSorcery(game)) {
Ability ability = new RetraceAbility(rightHalfCard);
ability.setSourceId(cardId);
ability.setControllerId(rightHalfCard.getOwnerId());
game.getState().addOtherAbility(rightHalfCard, ability);
}
}
if (card instanceof ModalDoubleFacesCard) {
ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
if (leftHalfCard.isInstantOrSorcery(game)) {
Ability ability = new RetraceAbility(leftHalfCard);
ability.setSourceId(cardId);
ability.setControllerId(leftHalfCard.getOwnerId());
game.getState().addOtherAbility(leftHalfCard, ability);
}
if (rightHalfCard.isInstantOrSorcery(game)) {
Ability ability = new RetraceAbility(rightHalfCard);
ability.setSourceId(cardId);
ability.setControllerId(rightHalfCard.getOwnerId());
game.getState().addOtherAbility(rightHalfCard, ability);
}
}
if (card instanceof AdventureCard) {
// Adventure cards are castable per https://twitter.com/elishffrn/status/1179047911729946624
card = ((AdventureCard) card).getSpellCard();
}
if (!card.isInstantOrSorcery(game)) {
continue;
}
Ability ability = new RetraceAbility(card);
ability.setSourceId(cardId);
ability.setControllerId(card.getOwnerId());
game.getState().addOtherAbility(card, ability);
}
return true;
}
Aggregations