use of mage.filter.predicate.mageobject.ToughnessPredicate in project mage by magefree.
the class PurgingScytheEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
int leastToughness = Integer.MAX_VALUE;
boolean multipleExist = false;
Permanent permanentToDamage = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
if (permanent.getToughness().getValue() < leastToughness) {
permanentToDamage = permanent;
leastToughness = permanent.getToughness().getValue();
multipleExist = false;
} else {
if (permanent.getToughness().getValue() == leastToughness) {
multipleExist = true;
}
}
}
if (multipleExist) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least toughness");
filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
if (controller.choose(outcome, target, source.getSourceId(), game)) {
permanentToDamage = game.getPermanent(target.getFirstTarget());
}
}
}
if (permanentToDamage != null) {
game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDamage.getName());
return permanentToDamage.damage(2, source.getSourceId(), source, game, false, true) > 0;
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ToughnessPredicate in project mage by magefree.
the class SkymarkRocAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.getSourceId())) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls with toughness 2 or less");
UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
filter.add(new ControllerIdPredicate(defenderId));
filter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, 3));
this.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
this.addTarget(target);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ToughnessPredicate in project mage by magefree.
the class ColfenorTheLastYewTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!super.checkTrigger(event, game)) {
return false;
}
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
Permanent permanent = zEvent.getTarget();
if (permanent == null) {
return false;
}
FilterCard filterCard = new FilterCreatureCard("creature card with toughness less than " + permanent.getToughness().getValue());
filterCard.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, permanent.getToughness().getValue()));
filterCard.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(permanent, game))));
this.getTargets().clear();
this.addTarget(new TargetCardInYourGraveyard(0, 1, filterCard));
return true;
}
use of mage.filter.predicate.mageobject.ToughnessPredicate in project mage by magefree.
the class EngulfTheShoreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int islands = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
FilterPermanent creatureFilter = new FilterCreaturePermanent();
creatureFilter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, islands + 1));
Set<Card> cardsToHand = new HashSet<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(creatureFilter, source.getControllerId(), source.getSourceId(), game)) {
cardsToHand.add(permanent);
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ToughnessPredicate in project mage by magefree.
the class ProfanerOfTheDeadReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent exploitedCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (controller != null && exploitedCreature != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(TargetController.OPPONENT.getControllerPredicate());
filter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, exploitedCreature.getToughness().getValue()));
Cards cardsToHand = new CardsImpl();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
cardsToHand.add(permanent);
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
return true;
}
return false;
}
Aggregations