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