use of mage.ApprovingObject in project mage by magefree.
the class EpicExperimentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
// move cards from library to exile
controller.moveCardsToExile(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()), source, game, true, source.getSourceId(), sourceObject.getIdName());
// cast the possible cards without paying the mana
ExileZone epicExperimentExileZone = game.getExile().getExileZone(source.getSourceId());
FilterCard filter = new FilterInstantOrSorceryCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
filter.setMessage("instant and sorcery cards with mana value " + source.getManaCostsToPay().getX() + " or less");
Cards cardsToCast = new CardsImpl();
if (epicExperimentExileZone == null) {
return true;
}
cardsToCast.addAll(epicExperimentExileZone.getCards(filter, source.getSourceId(), source.getControllerId(), game));
while (controller.canRespond() && !cardsToCast.isEmpty()) {
if (!controller.chooseUse(Outcome.PlayForFree, "Cast (another) a card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
break;
}
TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("instant or sorcery card to cast for free"));
if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
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);
if (!cardWasCast) {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
cardsToCast.remove(card);
} else {
break;
}
} else {
break;
}
}
// move cards not cast to graveyard
ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
if (exileZone != null) {
controller.moveCards(exileZone.getCards(game), Zone.GRAVEYARD, source, game);
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class GalvanothEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
controller.lookAtCards(source, null, new CardsImpl(card), game);
if (card.isInstantOrSorcery(game)) {
if (controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class GuileReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
Player controller = game.getPlayer(source.getControllerId());
if (spell != null && controller != null) {
controller.moveCards(spell, Zone.EXILED, source, game);
if (!spell.isCopy()) {
// copies doesn't exists in exile zone
Card spellCard = spell.getCard();
if (spellCard != null && controller.chooseUse(Outcome.PlayForFree, "Play " + spellCard.getIdName() + " for free?", source, game)) {
controller.playCard(spellCard, game, true, new ApprovingObject(source, game));
}
return true;
}
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class KahoMinamoHistorianCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCard filter = new FilterCard();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
TargetCardInExile target = new TargetCardInExile(filter, CardUtil.getCardExileZoneId(game, source));
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
if (cards != null && !cards.isEmpty() && controller.choose(Outcome.PlayForFree, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class MindsDilationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && sourceObject != null && opponent != null) {
if (opponent.getLibrary().hasCards()) {
Card card = opponent.getLibrary().getFromTop(game);
if (card != null && opponent.moveCards(card, Zone.EXILED, source, game)) {
if (!card.isLand(game)) {
if (controller.chooseUse(outcome, "Cast " + card.getLogName() + " without paying its mana cost from exile?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
}
return true;
}
return false;
}
Aggregations