use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class ElementalAppealEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
CreateTokenEffect effect = new CreateTokenEffect(new RedElementalWithTrampleAndHaste());
if (effect.apply(game, source)) {
effect.exileTokensCreatedAtNextEndStep(game, source);
if (KickedCondition.instance.apply(game, source)) {
List<Predicate<MageObject>> predList = new ArrayList<>();
for (UUID tokenId : effect.getLastAddedTokenIds()) {
predList.add(new CardIdPredicate(tokenId));
}
if (!predList.isEmpty()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(predList));
game.addEffect(new BoostAllEffect(7, 0, Duration.EndOfTurn, filter, false), source);
}
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class DomriChaosBringerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getSourceId().equals(spellId)) {
return false;
}
if (game.getTurnNum() != turnNumber) {
return false;
}
MageObject mo = game.getObject(event.getTargetId());
if (mo == null || !mo.isCreature(game)) {
return false;
}
StackObject stackObject = game.getStack().getStackObject(event.getTargetId());
if (stackObject == null) {
return false;
}
this.getEffects().clear();
FilterCard filter = new FilterCard();
filter.add(new CardIdPredicate(stackObject.getSourceId()));
this.addEffect(new GainAbilityControlledSpellsEffect(new RiotAbility(), filter));
return true;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class ShroudedLoreEffect 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("{B}");
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("Shrouded Lore: " + opponent.getLogName() + " has chosen " + card.getLogName());
}
} else {
done = true;
}
if (!done) {
done = true;
if (cost.canPay(source, source, you.getId(), game) && you.chooseUse(Outcome.Benefit, "Pay {B} to choose a different card ?", source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, you.getId(), false, null)) {
done = false;
}
}
}
} 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 AmplifyEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent sourceCreature = ((EntersTheBattlefieldEvent) event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || sourceCreature == null) {
return false;
}
FilterCreatureCard filter = new FilterCreatureCard("creatures cards to reveal");
filter.add(new AmplifyPredicate(sourceCreature));
// You can’t reveal this card or any other cards that are entering the battlefield at the same time as this card.
filter.add(Predicates.not(new CardIdPredicate(source.getSourceId())));
for (Permanent enteringPermanent : game.getPermanentsEntering().values()) {
filter.add(Predicates.not(new CardIdPredicate(enteringPermanent.getId())));
}
if (controller.getHand().count(filter, source.getSourceId(), source.getControllerId(), game) <= 0) {
return false;
}
if (!controller.chooseUse(outcome, "Reveal cards to Amplify?", source, game)) {
return false;
}
TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
if (controller.chooseTarget(outcome, target, source, game) && !target.getTargets().isEmpty()) {
Cards cards = new CardsImpl();
cards.addAll(target.getTargets());
int amountCounters = cards.size() * amplifyFactor.getFactor();
sourceCreature.addCounters(CounterType.P1P1.createInstance(amountCounters), source.getControllerId(), source, game);
controller.revealCards(sourceCreature.getIdName(), cards, game);
}
return false;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class BrunaLightOfAlabasterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID bruna = source.getSourceId();
Player controller = game.getPlayer(source.getControllerId());
FilterPermanent filterAura = new FilterPermanent("Aura");
FilterCard filterAuraCard = new FilterCard("Aura card");
filterAura.add(CardType.ENCHANTMENT.getPredicate());
filterAura.add(SubType.AURA.getPredicate());
filterAura.add(new AuraPermanentCanAttachToPermanentId(bruna));
filterAuraCard.add(CardType.ENCHANTMENT.getPredicate());
filterAuraCard.add(SubType.AURA.getPredicate());
filterAuraCard.add(new AuraCardCanAttachToPermanentId(bruna));
if (controller == null) {
return false;
}
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent == null) {
return false;
}
List<Permanent> fromBattlefield = new ArrayList<>();
List<Card> fromHandGraveyard = new ArrayList<>();
int countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
while (controller.canRespond() && countBattlefield > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", source, game)) {
Target targetAura = new TargetPermanent(filterAura);
targetAura.setNotTarget(true);
if (controller.choose(Outcome.Benefit, targetAura, source.getSourceId(), game)) {
Permanent aura = game.getPermanent(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null) {
fromBattlefield.add(aura);
filterAura.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
}
int countHand = controller.getHand().count(filterAuraCard, game);
while (controller.canRespond() && countHand > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from your hand?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.HAND, filterAuraCard);
if (controller.choose(Outcome.Benefit, controller.getHand(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null) {
fromHandGraveyard.add(aura);
filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countHand = controller.getHand().count(filterAuraCard, game);
}
int countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
while (controller.canRespond() && countGraveyard > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from your graveyard?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.GRAVEYARD, filterAuraCard);
if (controller.choose(Outcome.Benefit, controller.getGraveyard(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null) {
fromHandGraveyard.add(aura);
filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
}
// Move permanents
for (Permanent aura : fromBattlefield) {
Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
if (attachedTo != null) {
attachedTo.removeAttachment(aura.getId(), source, game);
}
sourcePermanent.addAttachment(aura.getId(), source, game);
}
// Move cards
for (Card aura : fromHandGraveyard) {
if (aura != null) {
game.getState().setValue("attachTo:" + aura.getId(), sourcePermanent);
controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
sourcePermanent.addAttachment(aura.getId(), source, game);
}
}
return true;
}
Aggregations