use of mage.filter.predicate.mageobject.ToughnessPredicate in project mage by magefree.
the class ScourgeOfFleetsEffect 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(TargetController.OPPONENT.getControllerPredicate());
creatureFilter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, islands + 1));
Cards cardsToHand = new CardsImpl();
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 BolsterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (amount.calculate(game, source, this) <= 0) {
return true;
}
int leastToughness = Integer.MAX_VALUE;
Permanent selectedCreature = null;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
if (leastToughness > permanent.getToughness().getValue()) {
leastToughness = permanent.getToughness().getValue();
selectedCreature = permanent;
} else if (leastToughness == permanent.getToughness().getValue()) {
leastToughness = permanent.getToughness().getValue();
selectedCreature = null;
}
}
if (leastToughness != Integer.MAX_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterControlledCreaturePermanent("creature you control with toughness " + leastToughness);
filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
Target target = new TargetPermanent(1, 1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());
}
}
if (selectedCreature != null) {
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(amount.calculate(game, source, this)));
effect.setTargetPointer(new FixedTarget(selectedCreature, game));
return effect.apply(game, source);
}
}
return true;
}
return false;
}
Aggregations