use of mage.ApprovingObject in project mage by magefree.
the class SpellweaverVoluteEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null && sourcePermanent.getAttachedTo() != null) {
Card enchantedCard = game.getCard(sourcePermanent.getAttachedTo());
if (enchantedCard != null && game.getState().getZone(enchantedCard.getId()) == Zone.GRAVEYARD) {
Player ownerEnchanted = game.getPlayer(enchantedCard.getOwnerId());
if (ownerEnchanted != null && controller.chooseUse(Outcome.Copy, "Create a copy of " + enchantedCard.getName() + '?', source, game)) {
Card copiedCard = game.copyCard(enchantedCard, source, source.getControllerId());
if (copiedCard != null) {
controller.getGraveyard().add(copiedCard);
game.getState().setZone(copiedCard.getId(), Zone.GRAVEYARD);
if (controller.chooseUse(Outcome.PlayForFree, "Cast the copied card without paying mana cost?", source, game)) {
if (copiedCard.getSpellAbility() != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
}
if (controller.moveCards(enchantedCard, Zone.EXILED, source, game)) {
FilterCard filter = new FilterCard("instant card in a graveyard");
filter.add(CardType.INSTANT.getPredicate());
TargetCardInGraveyard auraTarget = new TargetCardInGraveyard(filter);
if (auraTarget.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Benefit, auraTarget, source.getSourceId(), game);
Card newAuraTarget = game.getCard(auraTarget.getFirstTarget());
if (newAuraTarget != null) {
if (enchantedCard.getId().equals(newAuraTarget.getId())) {
} else if (newAuraTarget.addAttachment(sourcePermanent.getId(), source, game)) {
game.informPlayers(sourcePermanent.getLogName() + " was attached to " + newAuraTarget.getLogName());
}
}
}
}
}
}
}
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class SpellweaverHelixCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent != null) {
boolean foundSpellWithSameName = false;
for (UUID imprintId : sourcePermanent.getImprinted()) {
Card card = game.getCard(imprintId);
if (card != null) {
if (!foundSpellWithSameName && card.getName().equals(spellName)) {
foundSpellWithSameName = true;
} else {
if (controller.chooseUse(Outcome.Copy, "Copy " + card.getIdName(), source, game)) {
Card copy = game.copyCard(card, source, source.getControllerId());
if (controller.chooseUse(Outcome.PlayForFree, "Cast " + copy.getIdName() + " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + copy.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(copy, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copy.getId(), null);
}
}
}
}
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class SpellbinderCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent spellbinder = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (spellbinder != null && spellbinder.getImprinted() != null && !spellbinder.getImprinted().isEmpty()) {
Card imprintedInstant = game.getCard(spellbinder.getImprinted().get(0));
if (imprintedInstant != null && game.getState().getZone(imprintedInstant.getId()) == Zone.EXILED) {
if (controller.chooseUse(outcome, "Create a copy of " + imprintedInstant.getName() + '?', source, game)) {
Card copiedCard = game.copyCard(imprintedInstant, source, source.getControllerId());
if (copiedCard != null) {
game.getExile().add(source.getSourceId(), "", copiedCard);
game.getState().setZone(copiedCard.getId(), Zone.EXILED);
if (controller.chooseUse(outcome, "Cast the copied card without paying mana cost?", source, game)) {
if (copiedCard.getSpellAbility() != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
} else {
Logger.getLogger(SpellbinderCopyEffect.class).error("Spellbinder: spell ability == null " + copiedCard.getName());
}
}
}
}
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class SurgeToVictoryCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card card = mor.getCard(game);
if (player == null || card == null) {
return false;
}
Card copiedCard = game.copyCard(card, source, player.getId());
if (copiedCard == null) {
return false;
}
player.moveCards(copiedCard, Zone.EXILED, source, game);
if (!player.chooseUse(outcome, "Cast the copy of the exiled card?", source, game)) {
return false;
}
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class TalentOfTheTelepathEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Cards cardsToCast = new CardsImpl();
Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (targetOpponent != null && sourceObject != null) {
Set<Card> allCards = targetOpponent.getLibrary().getTopCards(game, 7);
Cards cards = new CardsImpl(allCards);
targetOpponent.revealCards(sourceObject.getIdName() + " - " + targetOpponent.getName() + "'s top library cards", cards, game);
for (Card card : allCards) {
if (filter.match(card, game)) {
cardsToCast.add(card);
}
}
// cast an instant or sorcery for free
if (!cardsToCast.isEmpty()) {
int numberOfSpells = 1;
if (SpellMasteryCondition.instance.apply(game, source)) {
numberOfSpells++;
}
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// zone should be ignored here
TargetCard target = new TargetCard(Zone.LIBRARY, filter);
target.setNotTarget(true);
while (controller.canRespond() && numberOfSpells > 0 && !cardsToCast.isEmpty() && controller.chooseUse(outcome, "Cast an instant or sorcery card " + "from among them for free?", source, game) && controller.choose(Outcome.PlayForFree, cardsToCast, target, game)) {
Card card = cardsToCast.get(target.getFirstTarget(), game);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
cardsToCast.remove(card);
if (cardWasCast) {
numberOfSpells--;
allCards.remove(card);
}
} else {
break;
}
if (!controller.canRespond()) {
return false;
}
target.clearChosen();
}
}
}
targetOpponent.moveCards(allCards, Zone.GRAVEYARD, source, game);
return true;
}
return false;
}
Aggregations