use of mage.filter.predicate.mageobject.CardIdPredicate 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.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class ArmoryAutomatonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
// dynamic filter (can't selects own attaches and can't selects twice)
FilterPermanent currentFilter = new FilterEquipmentPermanent();
FilterPermanent filterSourceId = new FilterPermanent();
filterSourceId.add(new CardIdPredicate(source.getSourceId()));
currentFilter.add(Predicates.not(new AttachedToPredicate(filterSourceId)));
int countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Select and attach a target Equipment?", source, game)) {
Target targetEquipment = new TargetPermanent(currentFilter);
targetEquipment.setRequired(false);
if (player.choose(Outcome.Benefit, targetEquipment, source.getSourceId(), game) && targetEquipment.getFirstTarget() != null) {
// exclude selected for next time
currentFilter.add(Predicates.not(new PermanentIdPredicate(targetEquipment.getFirstTarget())));
Permanent aura = game.getPermanent(targetEquipment.getFirstTarget());
if (aura != null) {
Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
if (attachedTo != null) {
attachedTo.removeAttachment(aura.getId(), source, game);
}
sourcePermanent.addAttachment(aura.getId(), source, game);
}
} else {
break;
}
countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.CardIdPredicate in project mage by magefree.
the class DanseMacabreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int toughness = 0;
Cards cards = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) < 1) {
continue;
}
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
continue;
}
if (source.isControlledBy(playerId)) {
toughness += permanent.getToughness().getValue();
}
cards.add(permanent);
permanent.sacrifice(source, game);
}
int result = controller.rollDice(outcome, source, game, 20) + toughness;
cards.retainZone(Zone.GRAVEYARD, game);
if (cards.isEmpty()) {
return true;
}
FilterCard filterCard = new FilterCard("card put into a graveyard this way");
filterCard.add(Predicates.or(cards.stream().map(cardId -> new CardIdPredicate(cardId)).collect(Collectors.toSet())));
TargetCardInGraveyard target;
if (result >= 15) {
target = new TargetCardInGraveyard(0, 2, filterCard);
} else if (result > 0) {
target = new TargetCardInGraveyard(filterCard);
} else {
return true;
}
target.setNotTarget(true);
controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game);
controller.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game);
return true;
}
Aggregations