use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class JandorsRingWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
JandorsRingWatcher watcher = game.getState().getWatcher(JandorsRingWatcher.class);
if (watcher != null) {
UUID cardId = watcher.getLastDrewCard(source.getControllerId());
Card card = game.getCard(cardId);
if (card != null) {
FilterCard filter = new FilterCard(card.getName());
filter.add(new CardIdPredicate(card.getId()));
DiscardCardYouChooseTargetEffect effect = new DiscardCardYouChooseTargetEffect(filter, TargetController.YOU);
if (effect.apply(game, source)) {
// Conditional was already checked, card should be in hand, but if for some weird reason it fails, the card won't be drawn, although the cost will already be paid
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.drawCards(1, source, game);
}
}
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class NecromanticSelectionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl();
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), source.getSourceId(), game)) {
permanent.destroy(source, game, false);
// Meren of the Clan Nel Toth bug #8515
game.checkStateAndTriggered();
if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) {
cards.add(permanent);
}
}
FilterCard filter = new FilterCreatureCard("creature card put into a graveyard with " + sourceObject.getLogName());
List<Predicate<MageObject>> cardIdPredicates = new ArrayList<>();
for (UUID cardId : cards) {
cardIdPredicates.add(new CardIdPredicate(cardId));
}
filter.add(Predicates.or(cardIdPredicates));
Target target = new TargetCardInGraveyard(filter);
target.setNotTarget(true);
if (controller.chooseTarget(Outcome.Benefit, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
ContinuousEffect effect = new BecomesBlackZombieAdditionEffect();
effect.setText("It's a black Zombie in addition to its other colors and types");
effect.setTargetPointer(new FixedTarget(card.getId(), game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class ContinuousEffects method applySpliceEffects.
/**
* Checks all available splice effects to be applied.
*
* @param abilityToModify
* @param game
*/
public void applySpliceEffects(Ability abilityToModify, Game game) {
// splice spell - spell can't be spliced again
if (CardUtil.isSpliceAbility(abilityToModify, game)) {
return;
}
// fused spell - can be spliced only to main fused ability, not to parts
if (CardUtil.isFusedPartAbility(abilityToModify, game)) {
return;
}
List<SpliceCardEffect> spliceEffects = getApplicableSpliceCardEffects(game, abilityToModify.getControllerId());
// get the applyable splice abilities
List<Ability> spliceAbilities = new ArrayList<>();
for (SpliceCardEffect effect : spliceEffects) {
Set<Ability> abilities = spliceCardEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
if (effect.applies(abilityToModify, ability, game)) {
spliceAbilities.add(ability);
}
}
}
if (!spliceAbilities.isEmpty()) {
Player controller = game.getPlayer(abilityToModify.getControllerId());
if (controller.chooseUse(Outcome.Benefit, "Splice a card?", abilityToModify, game)) {
Cards cardsToReveal = new CardsImpl();
do {
FilterCard filter = new FilterCard("a card to splice");
List<Predicate<MageObject>> idPredicates = new ArrayList<>();
for (Ability ability : spliceAbilities) {
idPredicates.add(new CardIdPredicate((ability.getSourceId())));
}
filter.add(Predicates.or(idPredicates));
TargetCardInHand target = new TargetCardInHand(filter);
controller.chooseTarget(Outcome.Benefit, target, abilityToModify, game);
UUID cardId = target.getFirstTarget();
if (cardId != null) {
Ability selectedAbility = null;
for (Ability ability : spliceAbilities) {
if (ability.getSourceId().equals(cardId)) {
selectedAbility = ability;
break;
}
}
if (selectedAbility != null) {
SpliceCardEffect spliceEffect = (SpliceCardEffect) selectedAbility.getEffects().get(0);
spliceEffect.apply(game, selectedAbility, abilityToModify);
cardsToReveal.add(game.getCard(cardId));
spliceAbilities.remove(selectedAbility);
}
}
} while (!spliceAbilities.isEmpty() && controller.chooseUse(Outcome.Benefit, "Splice another card?", abilityToModify, game));
controller.revealCards("Spliced cards", cardsToReveal, game);
}
}
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class GuardianProjectEffect method checkCondition.
// This is needed as checkInterveningIfClause can't access trigger event information
static boolean checkCondition(Permanent permanent, UUID controllerId, Game game) {
Player player = game.getPlayer(controllerId);
if (player == null) {
return false;
}
if (!permanent.getName().isEmpty()) {
FilterCard filterCard = new FilterCard();
filterCard.add(new NamePredicate(permanent.getName()));
filterCard.add(new OwnerIdPredicate(controllerId));
if (player.getGraveyard().count(filterCard, game) > 0) {
return false;
}
}
FilterPermanent filterPermanent = new FilterCreaturePermanent();
filterPermanent.add(new NamePredicate(permanent.getName()));
filterPermanent.add(Predicates.not(new CardIdPredicate(permanent.getId())));
filterPermanent.add(new ControllerIdPredicate(controllerId));
if (!game.getBattlefield().getActivePermanents(filterPermanent, controllerId, game).isEmpty()) {
return false;
}
return true;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class LilianaDreadhordeGeneralEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent keepFilter = new FilterPermanent();
keepFilter.add(TargetController.OPPONENT.getControllerPredicate());
for (UUID opponentId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player opponent = game.getPlayer(opponentId);
if (opponent == null || !opponent.hasOpponent(source.getControllerId(), game)) {
continue;
}
for (CardType cardType : CardType.values()) {
if (!cardType.isPermanentType()) {
continue;
}
FilterControlledPermanent filter = new FilterControlledPermanent("a " + cardType.toString() + " you control " + "(everything you don't choose will be sacrificed)");
filter.add(cardType.getPredicate());
Target target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (opponent.choose(outcome, target, source.getSourceId(), game)) {
keepFilter.add(Predicates.not(new CardIdPredicate(target.getFirstTarget())));
}
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
if (keepFilter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
permanent.sacrifice(source, game);
}
}
return true;
}
Aggregations