use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class HatcherySpiderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int xValue = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this);
FilterCard filter = new FilterPermanentCard("green permanent card with mana value " + xValue + " or less");
filter.add(new ColorPredicate(ObjectColor.GREEN));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard target = new TargetCardInLibrary(filter);
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) && player.choose(outcome, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
cards.remove(card);
}
}
while (!cards.isEmpty()) {
Card card = cards.getRandom(game);
player.getLibrary().putOnBottom(card, game);
cards.remove(card);
}
return true;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class MausoleumSecretsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int critterCount = player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game);
FilterCard filter = new FilterCard("a black card with mana value less than or equal to " + critterCount);
filter.add(new ColorPredicate(ObjectColor.BLACK));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, critterCount + 1));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true).apply(game, source);
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class SehtsTigerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
ChoiceColor choice = new ChoiceColor();
if (controller != null && mageObject != null && controller.choose(Outcome.Protect, choice, game)) {
game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
FilterCard filter = new FilterCard();
filter.add(new ColorPredicate(choice.getColor()));
filter.setMessage(choice.getChoice());
Ability ability = new ProtectionAbility(filter);
game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class CardCanBeCastPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.getLibrary().hasCards()) {
/**
* 10/1/2005 Any card you find must be legally cast-able (for
* example, you have to be able to choose a legal target for
* it). If you can't find a cast-able card (or choose not to),
* nothing happens and you shuffle your library.
*/
FilterCard filter = new FilterCard("red or white instant card with mana value 4 or less");
TargetCardInLibrary target = new TargetCardInLibrary(filter);
filter.add(Predicates.or(new ColorPredicate(ObjectColor.RED), new ColorPredicate(ObjectColor.WHITE)));
filter.add(CardType.INSTANT.getPredicate());
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 5));
filter.add(new CardCanBeCastPredicate(source.getControllerId()));
if (controller.searchLibrary(target, source, game, controller.getId())) {
UUID targetId = target.getFirstTarget();
Card card = game.getCard(targetId);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class MostCommonColorCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent[] colorFilters = new FilterPermanent[6];
int i = 0;
for (ObjectColor color : ObjectColor.getAllColors()) {
colorFilters[i] = new FilterPermanent();
colorFilters[i].add(new ColorPredicate(color));
if (predicate != null) {
colorFilters[i].add(predicate);
}
i++;
}
int[] colorCounts = new int[6];
i = 0;
for (ObjectColor color : ObjectColor.getAllColors()) {
colorFilters[i].add(new ColorPredicate(color));
colorCounts[i] = game.getBattlefield().count(colorFilters[i], source.getId(), source.getControllerId(), game);
i++;
}
int max = 0;
for (i = 0; i < 5; i++) {
if (colorCounts[i] > max) {
max = colorCounts[i] * 1;
}
}
i = 0;
ObjectColor commonest = new ObjectColor();
for (ObjectColor color : ObjectColor.getAllColors()) {
if (colorCounts[i] == max) {
commonest.addColor(color);
}
i++;
}
if (compareColor.shares(commonest)) {
if (isMono) {
return !commonest.isMulticolored();
} else {
return true;
}
}
return false;
}
Aggregations