use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class SelfInflictedWoundEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetOpponent = game.getPlayer(source.getTargets().getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (targetOpponent == null || controller == null) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("a green or white creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
filter.add(Predicates.or(new ColorPredicate(ObjectColor.GREEN), new ColorPredicate(ObjectColor.WHITE)));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), targetOpponent.getId(), game)) {
targetOpponent.chooseTarget(Outcome.Sacrifice, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
if (permanent.sacrifice(source, game)) {
targetOpponent.loseLife(2, game, source, false);
}
}
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class TargetControlledCreatureEachColor method makeFilter.
private static final FilterControlledPermanent makeFilter(String colors) {
List<ObjectColor> objectColors = Arrays.stream(colors.split("")).map(ObjectColor::new).collect(Collectors.toList());
FilterControlledPermanent filter = new FilterControlledCreaturePermanent(CardUtil.concatWithAnd(objectColors.stream().map(ObjectColor::getDescription).map(s -> CardUtil.addArticle(s) + " creature").collect(Collectors.toList())));
filter.add(Predicates.or(objectColors.stream().map(ColorPredicate::new).collect(Collectors.toList())));
return filter;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class ReturnToHandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (targetPlayer == null) {
return false;
}
Target target = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
targetPlayer.chooseTarget(Outcome.ReturnToHand, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class DescentIntoMadnessEffect method selectCards.
private void selectCards(Player player, List<UUID> selectedObjects, int count, Ability source, Game game) {
int amount = Math.min(count, player.getHand().size() + game.getBattlefield().getAllActivePermanents(player.getId()).size());
int cardsFromHand = 0;
while (player.canRespond() && amount > 0) {
Target target;
do {
FilterControlledPermanent filter = new FilterControlledPermanent();
filter.setMessage("permanent you control (" + amount + " left in total)");
List<PermanentIdPredicate> uuidPredicates = new ArrayList<>();
for (UUID uuid : selectedObjects) {
uuidPredicates.add(new PermanentIdPredicate(uuid));
}
filter.add(Predicates.not(Predicates.or(uuidPredicates)));
target = new TargetControlledPermanent(0, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Exile, target, source.getSourceId(), game)) {
for (UUID targetId : target.getTargets()) {
if (!selectedObjects.contains(targetId)) {
Permanent chosen = game.getPermanent(targetId);
if (chosen != null) {
amount--;
game.informPlayers(player.getLogName() + " selects " + chosen.getLogName() + " from battlefield");
selectedObjects.add(targetId);
}
}
}
}
} while (amount > 0 && !target.getTargets().isEmpty() && player.canRespond());
if (amount > 0) {
TargetCard targetInHand;
do {
FilterCard filterInHand = new FilterCard();
filterInHand.setMessage("card from your hand (" + amount + " left in total)");
targetInHand = new TargetCard(0, 1, Zone.HAND, filterInHand);
List<CardIdPredicate> uuidPredicates = new ArrayList<>();
for (UUID uuid : selectedObjects) {
uuidPredicates.add(new CardIdPredicate(uuid));
}
filterInHand.add(Predicates.not(Predicates.or(uuidPredicates)));
if (targetInHand.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Exile, player.getHand(), targetInHand, game)) {
Card card = player.getHand().get(targetInHand.getFirstTarget(), game);
if (card != null) {
selectedObjects.add(targetInHand.getFirstTarget());
amount--;
cardsFromHand++;
}
}
} while (amount > 0 && !targetInHand.getTargets().isEmpty() && player.canRespond());
}
}
if (cardsFromHand > 0) {
game.informPlayers(player.getLogName() + " selects " + cardsFromHand + (cardsFromHand == 1 ? " card" : " cards") + " from their hand");
}
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class CoordinatedBarrageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
if (controller.choose(Outcome.Damage, choice, game)) {
String chosenType = choice.getChoice();
FilterControlledPermanent filter = new FilterControlledPermanent();
filter.add(SubType.byDescription(chosenType).getPredicate());
int damageDealt = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
Permanent permanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (permanent != null) {
permanent.damage(damageDealt, source.getSourceId(), source, game, false, true);
}
return true;
}
}
return false;
}
Aggregations