use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class TargetCreatureWithLessPowerPermanent method canChoose.
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
// get the most powerful controlled creature that can be targeted
int maxPower = Integer.MIN_VALUE;
Card sourceCard = game.getCard(sourceId);
if (sourceCard == null) {
return false;
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, sourceControllerId, game)) {
if (permanent.getPower().getValue() > maxPower && permanent.canBeTargetedBy(sourceCard, sourceControllerId, game)) {
maxPower = permanent.getPower().getValue();
}
}
// now check, if another creature has less power and can be targeted
FilterCreaturePermanent checkFilter = new FilterCreaturePermanent();
checkFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, maxPower));
for (Permanent permanent : game.getBattlefield().getActivePermanents(checkFilter, sourceControllerId, sourceId, game)) {
if (permanent.canBeTargetedBy(sourceCard, sourceControllerId, game)) {
return true;
}
}
return false;
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class NightmareUnmakingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
FilterPermanent filter = new FilterCreaturePermanent();
filter.add(new PowerPredicate(comparisonType, player.getHand().size()));
return new ExileAllEffect(filter).apply(game, source);
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class RumblingRuinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int counter = 1;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
if (permanent == null || !permanent.isCreature(game)) {
continue;
}
counter += permanent.getCounters(game).getCount(CounterType.P1P1);
}
FilterCreaturePermanent filter = new FilterOpponentsCreaturePermanent();
filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, counter));
game.addEffect(new CantBlockAllEffect(filter, Duration.EndOfTurn), source);
return true;
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class FallOfTheImpostorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller != null && opponent != null) {
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game);
Integer maxPower = null;
for (Permanent permanent : permanents) {
if (permanent != null) {
int power = permanent.getPower().getValue();
if (maxPower == null || power > maxPower) {
maxPower = power;
}
}
}
if (maxPower != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(opponent.getId()));
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
TargetCreaturePermanent target = new TargetCreaturePermanent(1, 1, filter, true);
controller.chooseTarget(outcome, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
controller.moveCardsToExile(permanent, source, game, true, null, null);
return true;
}
}
}
return false;
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class TargetCreatureWithLessPowerPermanent method possibleTargets.
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Spell spell = game.getStack().getSpell(sourceId);
if (spell != null) {
Permanent firstTarget = getPermanentFromFirstTarget(spell.getSpellAbility(), game);
if (firstTarget != null) {
int power = firstTarget.getPower().getValue();
// overwrite the filter with the power predicate
filter = new FilterCreaturePermanent("creature with power less than " + power);
filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, power));
}
}
return super.possibleTargets(sourceId, sourceControllerId, game);
}
Aggregations