use of mage.filter.FilterPermanent in project mage by magefree.
the class TurnaboutEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || game.getPlayer(source.getFirstTarget()) == null) {
return true;
}
Choice choiceImpl = new ChoiceImpl(true);
choiceImpl.setMessage("Choose card type to tap or untap");
choiceImpl.setChoices(choice);
if (!controller.choose(Outcome.Neutral, choiceImpl, game)) {
return false;
}
FilterPermanent filter;
switch(choiceImpl.getChoice()) {
case "Artifact":
filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT;
break;
case "Land":
filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND;
break;
case "Creature":
filter = StaticFilters.FILTER_CONTROLLED_CREATURE;
break;
default:
throw new IllegalArgumentException("Choice is required");
}
boolean tap = controller.chooseUse(Outcome.Neutral, "Tap or untap?", null, "Tap", "Untap", source, game);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getFirstTarget(), source.getSourceId(), game)) {
if (tap) {
permanent.tap(source, game);
} else {
permanent.untap(game);
}
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class WildMammothEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
Player newController = null;
int maxCreatures = 0;
boolean tie = false;
FilterPermanent filter = new FilterPermanent();
filter.add(CardType.CREATURE.getPredicate());
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int value = game.getBattlefield().countAll(filter, playerId, game);
if (value > maxCreatures) {
maxCreatures = value;
}
}
}
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int value = game.getBattlefield().countAll(filter, playerId, game);
if (value == maxCreatures) {
if (newController == null) {
newController = player;
} else {
tie = true;
break;
}
}
}
}
if (!controller.equals(newController) && !tie && newController != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newController.getId());
effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class OpponentControlsPermanentCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean conditionApplies = false;
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
FilterPermanent localFilter = filter.copy();
localFilter.add(new ControllerIdPredicate(opponentId));
if (ComparisonType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, this.count)) {
conditionApplies = true;
break;
}
}
return conditionApplies;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class EmberGaleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(targetPlayer.getId()));
RestrictionEffect effect = new CantBlockAllEffect(filter, Duration.EndOfTurn);
game.addEffect(effect, source);
FilterPermanent filter2 = new FilterPermanent();
filter2.add(new ControllerIdPredicate(targetPlayer.getId()));
filter2.add(Predicates.or(new ColorPredicate(ObjectColor.WHITE), new ColorPredicate(ObjectColor.BLUE)));
filter2.add(CardType.CREATURE.getPredicate());
for (Permanent creature : game.getBattlefield().getAllActivePermanents(filter2, targetPlayer.getId(), game)) {
creature.damage(1, source.getSourceId(), source, game, false, true);
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class EquipoiseEffect method phaseOutCardType.
private void phaseOutCardType(Player controller, Player targetPlayer, CardType cardType, Ability source, Game game) {
FilterPermanent filter = new FilterControlledPermanent();
filter.add(cardType.getPredicate());
int numberController = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
int numberTargetPlayer = game.getBattlefield().count(filter, source.getSourceId(), targetPlayer.getId(), game);
int excess = numberTargetPlayer - numberController;
if (excess > 0) {
FilterPermanent filterChoose = new FilterPermanent(cardType.toString().toLowerCase(Locale.ENGLISH) + (excess > 1 ? "s" : "") + " of target player");
filterChoose.add(new ControllerIdPredicate(targetPlayer.getId()));
filterChoose.add(cardType.getPredicate());
Target target = new TargetPermanent(excess, excess, filterChoose, true);
controller.chooseTarget(outcome, target, source, game);
new PhaseOutAllEffect(target.getTargets()).apply(game, source);
}
}
Aggregations