use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class ForgottenLoreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (you != null && opponent != null) {
FilterCard filter = new FilterCard();
filter.add(new OwnerIdPredicate(you.getId()));
Cost cost = new ManaCostsImpl("{G}");
TargetCardInGraveyard chosenCard;
Card card = null;
boolean done = false;
do {
chosenCard = new TargetCardInGraveyard(filter);
chosenCard.setNotTarget(true);
if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
card = game.getCard(chosenCard.getFirstTarget());
if (card != null) {
filter.add(Predicates.not(new CardIdPredicate(card.getId())));
game.informPlayers("Forgotten Lore: " + opponent.getLogName() + " has chosen " + card.getLogName());
}
} else {
done = true;
}
if (!done) {
if (cost.canPay(source, source, you.getId(), game) && you.chooseUse(Outcome.Benefit, "Pay {G} to choose a different card ?", source, game)) {
cost.clearPaid();
if (!cost.pay(source, game, source, you.getId(), false, null)) {
done = true;
}
} else {
done = true;
}
}
} while (!done);
if (card != null) {
Cards cardsToHand = new CardsImpl();
cardsToHand.add(card);
you.moveCards(cardsToHand, Zone.HAND, source, game);
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.CardIdPredicate 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.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class MarkForDeathEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent target = game.getPermanent(source.getFirstTarget());
if (target == null) {
return false;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(target.getControllerId()));
filter.add(Predicates.not(new CardIdPredicate(target.getId())));
ContinuousEffect effect = new BlocksIfAbleTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(target.getId()));
game.addEffect(effect, source);
target.untap(game);
ContinuousEffect effect2 = new CantBlockAllEffect(filter, Duration.EndOfTurn);
game.addEffect(effect2, source);
return true;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class SigilOfValorCount method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Permanent equipment = game.getPermanent(sourceAbility.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
FilterPermanent filterPermanent = new FilterControlledCreaturePermanent();
filterPermanent.add(Predicates.not(new CardIdPredicate(equipment.getAttachedTo())));
return game.getBattlefield().count(filterPermanent, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
}
return 0;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class TheMimeoplasmEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (controller != null && permanent != null) {
if (new CardsInAllGraveyardsCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this) >= 2) {
if (controller.chooseUse(Outcome.Benefit, "Do you want to exile two creature cards from graveyards?", source, game)) {
TargetCardInGraveyard targetCopy = new TargetCardInGraveyard(new FilterCreatureCard("creature card to become a copy of"));
targetCopy.setNotTarget(true);
if (controller.choose(Outcome.Copy, targetCopy, source.getSourceId(), game)) {
Card cardToCopy = game.getCard(targetCopy.getFirstTarget());
if (cardToCopy != null) {
FilterCreatureCard filter = new FilterCreatureCard("creature card to determine amount of additional +1/+1 counters");
filter.add(Predicates.not(new CardIdPredicate(cardToCopy.getId())));
TargetCardInGraveyard targetCounters = new TargetCardInGraveyard(filter);
targetCounters.setNotTarget(true);
if (controller.choose(Outcome.Copy, targetCounters, source.getSourceId(), game)) {
Card cardForCounters = game.getCard(targetCounters.getFirstTarget());
if (cardForCounters != null) {
Cards cardsToExile = new CardsImpl();
cardsToExile.add(cardToCopy);
cardsToExile.add(cardForCounters);
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
CopyEffect copyEffect = new CopyEffect(Duration.Custom, cardToCopy, source.getSourceId());
game.addEffect(copyEffect, source);
permanent.addCounters(CounterType.P1P1.createInstance(cardForCounters.getPower().getValue()), source.getControllerId(), source, game);
}
}
}
}
}
}
return true;
}
return false;
}
Aggregations