use of mage.filter.FilterObject in project mage by magefree.
the class RunedHaloSetProtectionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (controller != null && cardName != null && !cardName.isEmpty()) {
FilterObject filter = new FilterObject("the card name [" + cardName + ']');
filter.add(new NamePredicate(cardName));
ContinuousEffect effect = new GainAbilityControllerEffect(new ProtectionAbility(filter), Duration.Custom);
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.filter.FilterObject in project mage by magefree.
the class EmptyShrineKannushiProtectionAbility method canTarget.
@Override
public boolean canTarget(MageObject source, Game game) {
ObjectColor color = new ObjectColor();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controllerId)) {
ObjectColor permanentColor = permanent.getColor(game);
if (permanentColor.isColorless()) {
continue;
}
if (permanentColor.isBlack()) {
color.setBlack(true);
}
if (permanentColor.isBlue()) {
color.setBlue(true);
}
if (permanentColor.isGreen()) {
color.setGreen(true);
}
if (permanentColor.isRed()) {
color.setRed(true);
}
if (permanentColor.isWhite()) {
color.setWhite(true);
}
}
List<Predicate<MageObject>> colorPredicates = new ArrayList<>();
if (color.isBlack()) {
colorPredicates.add(new ColorPredicate(ObjectColor.BLACK));
}
if (color.isBlue()) {
colorPredicates.add(new ColorPredicate(ObjectColor.BLUE));
}
if (color.isGreen()) {
colorPredicates.add(new ColorPredicate(ObjectColor.GREEN));
}
if (color.isRed()) {
colorPredicates.add(new ColorPredicate(ObjectColor.RED));
}
if (color.isWhite()) {
colorPredicates.add(new ColorPredicate(ObjectColor.WHITE));
}
Filter protectionFilter = new FilterObject("the colors of permanents you control");
protectionFilter.add(Predicates.or(colorPredicates));
this.filter = protectionFilter;
return super.canTarget(source, game);
}
use of mage.filter.FilterObject 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