if (planeswalkers.size() > 1) { //don't bother checking if less than 2 planeswalkers in play
for (Permanent planeswalker: planeswalkers) {
for (String planeswalkertype: planeswalker.getSubtype()) {
FilterPlaneswalkerPermanent filterPlaneswalker = new FilterPlaneswalkerPermanent();
filterPlaneswalker.add(new SubtypePredicate(planeswalkertype));
filterPlaneswalker.add(new ControllerIdPredicate(planeswalker.getControllerId()));
if (getBattlefield().contains(filterPlaneswalker, planeswalker.getControllerId(), this, 2)) {
Player controller = this.getPlayer(planeswalker.getControllerId());
if (controller != null) {
Target targetPlaneswalkerToKeep = new TargetPermanent(filterPlaneswalker);
targetPlaneswalkerToKeep.setTargetName(new StringBuilder(planeswalker.getName()).append(" to keep?").toString());
controller.chooseTarget(Outcome.Benefit, targetPlaneswalkerToKeep, null, this);
for (Permanent dupPlaneswalker: this.getBattlefield().getActivePermanents(filterPlaneswalker, planeswalker.getControllerId(), this)) {
if (!targetPlaneswalkerToKeep.getTargets().contains(dupPlaneswalker.getId())) {
movePermanentToGraveyardWithInfo(dupPlaneswalker);
}
}
}
return true;
}
}
}
}
//201300713 - 704.5k
// If a player controls two or more legendary permanents with the same name, that player
// chooses one of them, and the rest are put into their owners' graveyards.
// This is called the "legend rule."
if (legendary.size() > 1) { //don't bother checking if less than 2 legends in play
for (Permanent legend: legendary) {
FilterPermanent filterLegendName = new FilterPermanent();
filterLegendName.add(new SupertypePredicate("Legendary"));
filterLegendName.add(new NamePredicate(legend.getName()));
filterLegendName.add(new ControllerIdPredicate(legend.getControllerId()));
if (getBattlefield().contains(filterLegendName, legend.getControllerId(), this, 2)) {
Player controller = this.getPlayer(legend.getControllerId());
if (controller != null) {
Target targetLegendaryToKeep = new TargetPermanent(filterLegendName);
targetLegendaryToKeep.setTargetName(new StringBuilder(legend.getName()).append(" to keep (Legendary Rule)?").toString());