use of mage.filter.FilterPermanent in project mage by magefree.
the class ParasiticStrixTriggeredAbility method checkInterveningIfClause.
@Override
public boolean checkInterveningIfClause(Game game) {
FilterPermanent filter = new FilterPermanent();
filter.add(new ColorPredicate(ObjectColor.BLACK));
if (game.getBattlefield().countAll(filter, this.controllerId, game) >= 1) {
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class RidersOfGavonyGainAbilityControlledEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
if (protectionFilter == null) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(permanent.getId(), game);
if (subType != null) {
protectionFilter = new FilterPermanent(subType.getDescription() + 's');
protectionFilter.add(subType.getPredicate());
} else {
discard();
}
}
}
if (protectionFilter != null) {
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
perm.addAbility(new ProtectionAbility(protectionFilter), source.getSourceId(), game);
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class ShowOfDominanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int highestPower = Integer.MIN_VALUE;
Permanent selectedCreature = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
if (highestPower < permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = permanent;
} else if (highestPower == permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = null;
}
}
if (highestPower != Integer.MIN_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + highestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, highestPower));
Target target = new TargetPermanent(1, 1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());
}
}
if (selectedCreature != null) {
FixedTarget target = new FixedTarget(selectedCreature.getId(), game);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(4));
effect.setTargetPointer(target);
effect.apply(game, source);
ContinuousEffect continuousEffect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
continuousEffect.setTargetPointer(target);
game.addEffect(continuousEffect, source);
return true;
}
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class SoullessOneDynamicCount method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
FilterPermanent zombiesBattlefield = new FilterPermanent("Zombies on the battlefield");
FilterCard zombiesInGraveyard = new FilterCard("Zombie cards in all graveyards");
zombiesBattlefield.add(SubType.ZOMBIE.getPredicate());
zombiesInGraveyard.add(SubType.ZOMBIE.getPredicate());
int count = game.getBattlefield().count(zombiesBattlefield, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
for (UUID playerId : game.getState().getPlayersInRange(sourceAbility.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
count += player.getGraveyard().count(zombiesInGraveyard, game);
}
}
return count;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class TrevaTheRenewerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
ChoiceColor choice = new ChoiceColor();
if (controller.choose(outcome, choice, game)) {
game.informPlayers(controller.getLogName() + " chooses " + choice.getColor());
FilterPermanent filter = new FilterPermanent();
filter.add(new ColorPredicate(choice.getColor()));
int cardsWithColor = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
if (cardsWithColor > 0) {
new GainLifeEffect(cardsWithColor).apply(game, source);
}
return true;
}
return false;
}
Aggregations