use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class ConsumeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(source.getFirstTarget());
if (player == null || controller == null) {
return false;
}
int greatestPower = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(player.getId())) {
if (permanent != null && permanent.isCreature(game)) {
greatestPower = Math.max(permanent.getPower().getValue(), greatestPower);
}
}
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + greatestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
new SacrificeEffect(filter, 1, "").apply(game, source);
controller.gainLife(greatestPower, game, source);
return true;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class DoOrDieEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (player != null && targetPlayer != null) {
int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
List<Permanent> pile1 = new ArrayList<>();
creatures.setRequired(false);
if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
List<UUID> targets = creatures.getTargets();
for (UUID targetId : targets) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
pile1.add(p);
}
}
}
List<Permanent> pile2 = new ArrayList<>();
for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
if (!pile1.contains(p)) {
pile2.add(p);
}
}
boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to destroy.", pile1, pile2, game);
if (choice) {
destroyPermanents(pile1, game, source);
} else {
destroyPermanents(pile2, game, source);
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class DropOfHoneyStateTriggeredAbility 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 leastPower = Integer.MAX_VALUE;
boolean multipleExist = false;
Permanent permanentToDestroy = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
if (permanent.getPower().getValue() < leastPower) {
permanentToDestroy = permanent;
leastPower = permanent.getPower().getValue();
multipleExist = false;
} else {
if (permanent.getPower().getValue() == leastPower) {
multipleExist = true;
}
}
}
if (multipleExist) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least power");
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, leastPower));
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
if (controller.choose(outcome, target, source.getSourceId(), game)) {
permanentToDestroy = game.getPermanent(target.getFirstTarget());
}
}
}
if (permanentToDestroy != null) {
game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDestroy.getName());
return permanentToDestroy.destroy(source, game, true);
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class DromarTheBanisherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
ChoiceColor choice = new ChoiceColor();
if (player.choose(outcome, choice, game)) {
game.informPlayers(player.getLogName() + " chooses " + choice.getChoice());
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ColorPredicate(choice.getColor()));
new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
return true;
}
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class DroningBureaucratsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int xValue = source.getManaCostsToPay().getX();
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with mana value X");
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
game.addEffect(new CantAttackBlockAllEffect(Duration.EndOfTurn, filter), source);
return true;
}
Aggregations