use of mage.ApprovingObject in project mage by magefree.
the class UnexpectedResultEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card sourceCard = game.getCard(source.getSourceId());
if (controller == null || sourceCard == null) {
return false;
}
if (controller.getLibrary().hasCards()) {
controller.shuffleLibrary(source, game);
Card card = controller.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
controller.revealCards(sourceCard.getName(), new CardsImpl(card), game);
if (card.isLand(game)) {
String message = "Put " + card.getName() + " onto the battlefield?";
if (controller.chooseUse(Outcome.PutLandInPlay, message, source, game)) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
controller.moveCards(sourceCard, Zone.HAND, source, game);
return true;
}
} else {
if (controller.chooseUse(outcome, "Cast " + card.getName() + " without paying its mana 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 true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class WrexialReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card card = game.getCard(source.getFirstTarget());
if (controller == null || card == null) {
return false;
}
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);
game.addEffect(new WrexialReplacementEffect(card.getId()), source);
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class CastCardFromOutsideTheGameEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
while (player.chooseUse(Outcome.Benefit, choiceText, source, game)) {
Cards cards = player.getSideboard();
if (cards.isEmpty()) {
if (!game.isSimulation()) {
game.informPlayer(player, "You have no cards outside the game.");
}
return false;
}
Set<Card> filtered = cards.getCards(filterCard, source.getSourceId(), source.getControllerId(), game);
if (filtered.isEmpty()) {
if (!game.isSimulation()) {
game.informPlayer(player, "You have no " + filterCard.getMessage() + " outside the game.");
}
return false;
}
Cards filteredCards = new CardsImpl();
for (Card card : filtered) {
filteredCards.add(card.getId());
}
TargetCard target = new TargetCard(Zone.OUTSIDE, filterCard);
if (player.choose(Outcome.Benefit, filteredCards, target, game)) {
Card card = player.getSideboard().get(target.getFirstTarget(), game);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class MadnessCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
Player owner = game.getPlayer(card.getOwnerId());
if (owner == null) {
return false;
}
// Replace with the new cost
SpellAbility castByMadness = card.getSpellAbility().copy();
ManaCosts<ManaCost> costRef = castByMadness.getManaCostsToPay();
castByMadness.setSpellAbilityType(SpellAbilityType.BASE_ALTERNATE);
castByMadness.setSpellAbilityCastMode(SpellAbilityCastMode.MADNESS);
castByMadness.getCosts().clear();
castByMadness.addCost(new PayLifeCost(this.lifeCost));
costRef.clear();
costRef.add(madnessCost);
return owner.cast(castByMadness, game, false, new ApprovingObject(source, game));
}
use of mage.ApprovingObject in project mage by magefree.
the class RippleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null) {
if (!player.chooseUse(Outcome.Neutral, "Reveal " + rippleNumber + " cards from the top of your library?", source, game)) {
// fizzle
return true;
}
// reveal top cards from library
Cards cards = new CardsImpl();
cards.addAll(player.getLibrary().getTopCards(game, rippleNumber));
player.revealCards(sourceObject.getIdName(), cards, game);
// determine which card should be rippled
String cardNameToRipple = sourceObject.getName();
FilterCard sameNameFilter = new FilterCard("card(s) with the name: \"" + cardNameToRipple + "\" to cast without paying their mana cost");
sameNameFilter.add(new NamePredicate(cardNameToRipple));
TargetCard target1 = new TargetCard(Zone.LIBRARY, sameNameFilter);
target1.setRequired(false);
// choose cards to play for free
while (player.canRespond() && cards.count(sameNameFilter, game) > 0 && player.choose(Outcome.PlayForFree, cards, target1, game)) {
Card card = cards.get(target1.getFirstTarget(), game);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
cards.remove(card);
}
target1.clearChosen();
}
// move cards that weren't cast to the bottom of the library
player.putCardsOnBottomOfLibrary(cards, game, source, true);
return true;
}
return false;
}
Aggregations