mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Merge pull request #9386 from weirddan455/braids
[DMU] Implemented Braids, Arisen Nightmare
This commit is contained in:
commit
c140b073ad
7 changed files with 206 additions and 75 deletions
|
|
@ -0,0 +1,60 @@
|
|||
package mage.filter.predicate.mageobject;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.constants.CardType;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author weirddan455
|
||||
*/
|
||||
public class SharesCardTypePredicate implements Predicate<MageObject> {
|
||||
|
||||
private final LinkedHashSet<CardType> cardTypes;
|
||||
|
||||
public SharesCardTypePredicate(Collection<CardType> cardTypes) {
|
||||
this.cardTypes = new LinkedHashSet<>(cardTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(MageObject input, Game game) {
|
||||
for (CardType type : input.getCardType(game)) {
|
||||
if (cardTypes.contains(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
Iterator<CardType> it = cardTypes.iterator();
|
||||
switch(cardTypes.size()) {
|
||||
case 0:
|
||||
return "";
|
||||
case 1:
|
||||
return it.next().toString().toLowerCase(Locale.ENGLISH);
|
||||
case 2:
|
||||
return it.next().toString().toLowerCase(Locale.ENGLISH) + " or " + it.next().toString().toLowerCase(Locale.ENGLISH);
|
||||
default: {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(it.next().toString().toLowerCase(Locale.ENGLISH));
|
||||
while (it.hasNext()) {
|
||||
CardType type = it.next();
|
||||
sb.append(", ");
|
||||
if (!it.hasNext()) {
|
||||
sb.append("or ");
|
||||
}
|
||||
sb.append(type.toString().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue