Card: add AllNonLegendaryCreatureNames for SpyKit

This commit is contained in:
Hanmac
2016-09-02 09:01:14 +00:00
parent 911bc42698
commit 31aa59ce9d

View File

@@ -1460,6 +1460,8 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} else if (keyword.equals("Unblockable")) { } else if (keyword.equals("Unblockable")) {
sbLong.append(getName()).append(" can't be blocked.\r\n"); sbLong.append(getName()).append(" can't be blocked.\r\n");
} else if (keyword.equals("AllNonLegendaryCreatureNames")) {
sbLong.append(getName()).append(" has all names of nonlegendary creature cards.\r\n");
} }
else { else {
if ((i != 0) && (sb.length() != 0)) { if ((i != 0) && (sb.length() != 0)) {
@@ -1716,6 +1718,10 @@ public class Card extends GameEntity implements Comparable<Card> {
sb.insert(sb.indexOf(".) ") + 3, "\r\n"); sb.insert(sb.indexOf(".) ") + 3, "\r\n");
} }
if (isGoaded()) {
sb.append("is goaded by: " + Lang.joinHomogenous(getGoaded()));
sb.append("\r\n");
}
// replace triple line feeds with double line feeds // replace triple line feeds with double line feeds
int start; int start;
final String s = "\r\n\r\n\r\n"; final String s = "\r\n\r\n\r\n";
@@ -3669,19 +3675,19 @@ public class Card extends GameEntity implements Comparable<Card> {
// by name can also have color names, so needs to happen before colors. // by name can also have color names, so needs to happen before colors.
if (property.startsWith("named")) { if (property.startsWith("named")) {
String name = property.substring(5).replace(";", ","); // for some legendary cards String name = property.substring(5).replace(";", ","); // for some legendary cards
if (!getName().equals(name)) { if (!sharesNameWith(name)) {
return false; return false;
} }
} else if (property.startsWith("notnamed")) { } else if (property.startsWith("notnamed")) {
if (getName().equals(property.substring(8))) { if (sharesNameWith(property.substring(8))) {
return false; return false;
} }
} else if (property.startsWith("sameName")) { } else if (property.startsWith("sameName")) {
if (getName().equals("") || !sharesNameWith(source)) { if (!sharesNameWith(source)) {
return false; return false;
} }
} else if (property.equals("NamedCard")) { } else if (property.equals("NamedCard")) {
if (getName().equals("") || !sharesNameWith(source.getNamedCard())) { if (!sharesNameWith(source.getNamedCard())) {
return false; return false;
} }
} else if (property.equals("NamedByRememberedPlayer")) { } else if (property.equals("NamedByRememberedPlayer")) {
@@ -3689,7 +3695,7 @@ public class Card extends GameEntity implements Comparable<Card> {
final Card newCard = game.getCardState(source); final Card newCard = game.getCardState(source);
for (final Object o : newCard.getRemembered()) { for (final Object o : newCard.getRemembered()) {
if (o instanceof Player) { if (o instanceof Player) {
if (!getName().equals(((Player) o).getNamedCard())) { if (!sharesNameWith(((Player) o).getNamedCard())) {
return false; return false;
} }
} }
@@ -3697,7 +3703,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
for (final Object o : source.getRemembered()) { for (final Object o : source.getRemembered()) {
if (o instanceof Player) { if (o instanceof Player) {
if (!getName().equals(((Player) o).getNamedCard())) { if (!sharesNameWith(((Player) o).getNamedCard())) {
return false; return false;
} }
} }
@@ -5364,18 +5370,63 @@ public class Card extends GameEntity implements Comparable<Card> {
public final boolean isColorless() { return CardUtil.getColors(this).isColorless(); } public final boolean isColorless() { return CardUtil.getColors(this).isColorless(); }
public final boolean sharesNameWith(final Card c1) { public final boolean sharesNameWith(final Card c1) {
// in a corner case where c1 is null, there is no name to share with.
if (c1 == null) {
return false;
}
// Special Logic for SpyKit
if (c1.hasKeyword("AllNonLegendaryCreatureNames")) {
if (hasKeyword("AllNonLegendaryCreatureNames")) {
// with both does have this, then they share any name
return true;
} else if (getName().isEmpty()) {
// if this does not have a name, then there is no name to share
return false;
} else {
// check if this card has a name from a face
// in general token creatures does not have this
final ICardFace face = StaticData.instance().getCommonCards().getFaceByName(getName());
if (face == null) {
return false;
}
// TODO add check if face is legal in the format of the game
// name does need to be a non-legendary creature
final CardType type = face.getType();
if (type != null && type.isCreature() && !type.isLegendary())
return true;
}
}
return sharesNameWith(c1.getName()); return sharesNameWith(c1.getName());
} }
public final boolean sharesNameWith(final String name) { public final boolean sharesNameWith(final String name) {
boolean shares; // the name is null or empty
shares = getName().equals(name); if (name == null || name.isEmpty()) {
return false;
}
boolean shares = getName().equals(name);
// Split cards has extra logic to check if it does share a name with
if (isSplitCard()) { if (isSplitCard()) {
shares |= name.equals(getState(CardStateName.LeftSplit).getName()); shares |= name.equals(getState(CardStateName.LeftSplit).getName());
shares |= name.equals(getState(CardStateName.RightSplit).getName()); shares |= name.equals(getState(CardStateName.RightSplit).getName());
} }
if (!shares && hasKeyword("AllNonLegendaryCreatureNames")) {
// check if the name is from a face
// in general token creatures does not have this
final ICardFace face = StaticData.instance().getCommonCards().getFaceByName(name);
if (face == null) {
return false;
}
// TODO add check if face is legal in the format of the game
// name does need to be a non-legendary creature
final CardType type = face.getType();
if (type.isCreature() && !type.isLegendary())
return true;
}
return shares; return shares;
} }