use of mage.filter.predicate.mageobject.SharesColorPredicate in project mage by magefree.
the class KasminaEnigmaSageSearchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentOrLKI(game);
if (controller == null || permanent == null) {
return false;
}
FilterCard filter = new FilterInstantOrSorceryCard("an instant, or sorcery card which shares a color with " + permanent.getLogName());
filter.add(new SharesColorPredicate(permanent.getColor(game)));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
controller.searchLibrary(target, source, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
}
controller.shuffleLibrary(source, game);
if (card == null || !controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
return true;
}
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 true;
}
use of mage.filter.predicate.mageobject.SharesColorPredicate in project mage by magefree.
the class MournersShieldEffect method init.
@Override
public void init(Ability source, Game game) {
ObjectColor colorsAmongImprinted = new ObjectColor();
Permanent sourceObject = game.getPermanent(source.getSourceId());
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source.getSourceId()));
if (sourceObject == null || sourceObject.getImprinted() == null) {
noneExiled = true;
return;
}
for (UUID imprinted : sourceObject.getImprinted()) {
if (imprinted != null && exileZone.contains(imprinted)) {
Card card = game.getCard(imprinted);
if (card != null) {
colorsAmongImprinted = colorsAmongImprinted.union(card.getColor(game));
}
}
}
FilterObject filterObject = new FilterObject("a source of your choice that shares a color with the exiled card");
filterObject.add(new SharesColorPredicate(colorsAmongImprinted));
this.target = new TargetSource(filterObject);
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
if (target.getFirstTarget() != null) {
mageObjectReference = new MageObjectReference(target.getFirstTarget(), game);
} else {
mageObjectReference = null;
}
}
Aggregations