use of mage.ApprovingObject in project mage by magefree.
the class HazoretsUndyingFuryEffect 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) {
controller.shuffleLibrary(source, game);
// move cards from library to exile
controller.moveCardsToExile(controller.getLibrary().getTopCards(game, 4), source, game, true, source.getSourceId(), sourceObject.getIdName());
// cast the possible cards without paying the mana
ExileZone hazoretsUndyingFuryExileZone = game.getExile().getExileZone(source.getSourceId());
Cards cardsToCast = new CardsImpl();
if (hazoretsUndyingFuryExileZone == null) {
return true;
}
cardsToCast.addAll(hazoretsUndyingFuryExileZone.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("nonland 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);
cardsToCast.remove(card);
if (!cardWasCast) {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
}
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class MemoryPlunderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD && controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying cost?", source, game)) {
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);
return cardWasCast;
}
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class CardCanBeCastPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.getLibrary().hasCards()) {
/**
* 10/1/2005 Any card you find must be legally cast-able (for
* example, you have to be able to choose a legal target for
* it). If you can't find a cast-able card (or choose not to),
* nothing happens and you shuffle your library.
*/
FilterCard filter = new FilterCard("red or white instant card with mana value 4 or less");
TargetCardInLibrary target = new TargetCardInLibrary(filter);
filter.add(Predicates.or(new ColorPredicate(ObjectColor.RED), new ColorPredicate(ObjectColor.WHITE)));
filter.add(CardType.INSTANT.getPredicate());
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 5));
filter.add(new CardCanBeCastPredicate(source.getControllerId()));
if (controller.searchLibrary(target, source, game, controller.getId())) {
UUID targetId = target.getFirstTarget();
Card card = game.getCard(targetId);
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);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class PlayTargetWithoutPayingManaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card target = (Card) game.getObject(source.getFirstTarget());
if (controller != null && target != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + target.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(target, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + target.getId(), null);
return cardWasCast;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class ReboundCastSpellFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ExileZone zone = game.getExile().getExileZone(source.getSourceId());
if (zone == null || zone.isEmpty()) {
return false;
}
Card reboundCard = zone.get(source.getSourceId(), game);
Player player = game.getPlayer(source.getControllerId());
if (player != null && reboundCard != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + reboundCard.getId(), Boolean.TRUE);
Boolean cardWasCast = player.cast(player.chooseAbilityForCast(reboundCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + reboundCard.getId(), null);
return cardWasCast;
}
return false;
}
Aggregations