use of mage.ApprovingObject in project mage by magefree.
the class KnowledgeExploitationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller == null || opponent == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
controller.searchLibrary(target, source, game, opponent.getId());
Card card = opponent.getLibrary().getCard(target.getFirstTarget(), game);
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);
}
opponent.shuffleLibrary(source, game);
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class MindclawShamanEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetOpponent = game.getPlayer(source.getFirstTarget());
MageObject sourceObject = source.getSourceObject(game);
if (targetOpponent != null && sourceObject != null) {
if (!targetOpponent.getHand().isEmpty()) {
targetOpponent.revealCards(sourceObject.getName(), targetOpponent.getHand(), game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetCard target = new TargetCard(Zone.HAND, filter);
target.setNotTarget(true);
if (controller.choose(Outcome.PlayForFree, targetOpponent.getHand(), target, game)) {
Card chosenCard = targetOpponent.getHand().get(target.getFirstTarget(), game);
if (chosenCard != null) {
if (controller.chooseUse(Outcome.PlayForFree, "Cast the chosen card without " + "paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(chosenCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), null);
} else {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " canceled casting the card.");
}
}
}
return true;
}
}
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class OmnispellAdeptEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterCard realFilter = filter.copy();
Target target = new TargetCardInHand(realFilter);
// choose one card until it possible to cast
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery " + "card from your hand without paying its mana cost?", source, game)) {
Card cardToCast;
while (controller.canRespond() && controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
cardToCast = game.getCard(target.getFirstTarget());
if (cardToCast == null) {
break;
}
// remove card from choose dialog (infinite fix)
realFilter.add(Predicates.not(new CardIdPredicate(cardToCast.getId())));
if (!cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
continue;
}
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
if (cardWasCast) {
break;
} else {
game.informPlayer(controller, "You're not able to cast " + cardToCast.getIdName() + " or you canceled the casting.");
}
}
}
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class OmenMachineEffect2 method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
Card card = player.getLibrary().getFromTop(game);
if (card != null) {
player.moveCards(card, Zone.EXILED, source, game);
if (card.isLand(game)) {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
} else {
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;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class PanopticMirrorCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent PanopticMirror = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (PanopticMirror == null) {
PanopticMirror = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (PanopticMirror != null && PanopticMirror.getImprinted() != null && !PanopticMirror.getImprinted().isEmpty() && controller != null) {
CardsImpl cards = new CardsImpl();
for (UUID uuid : PanopticMirror.getImprinted()) {
Card card = game.getCard(uuid);
if (card != null) {
if (card instanceof SplitCard) {
cards.add(((SplitCard) card).getLeftHalfCard());
cards.add(((SplitCard) card).getRightHalfCard());
} else if (card instanceof ModalDoubleFacesCard) {
cards.add(((ModalDoubleFacesCard) card).getLeftHalfCard());
cards.add(((ModalDoubleFacesCard) card).getRightHalfCard());
} else {
cards.add(card);
}
}
}
Card cardToCopy;
if (cards.size() == 1) {
cardToCopy = cards.getCards(game).iterator().next();
} else {
TargetCard target = new TargetCard(1, Zone.EXILED, new FilterCard("card to copy"));
controller.choose(Outcome.Copy, cards, target, game);
cardToCopy = cards.get(target.getFirstTarget(), game);
}
if (cardToCopy != null) {
Card copy = game.copyCard(cardToCopy, source, source.getControllerId());
if (controller.chooseUse(Outcome.PlayForFree, "Cast the copied card without paying 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;
}
Aggregations