Cleanup code for plural type names (like Clerics), and fix them for type changing effects.

This commit is contained in:
elcnesh
2014-08-18 12:52:45 +00:00
parent 12b0aa8e40
commit fca084c44e
3 changed files with 69 additions and 33 deletions

View File

@@ -2399,8 +2399,9 @@ public class Card extends GameEntity implements Comparable<Card> {
for (final Entry<String, String> e : Sets.union(this.changedTextColors.toMap().entrySet(),
this.changedTextTypes.toMap().entrySet())) {
// only the upper case ones, to avoid duplicity
if (Character.isUpperCase(e.getKey().charAt(0))) {
// ignore lower case and plural form keys, to avoid duplicity
if (Character.isUpperCase(e.getKey().charAt(0)) &&
!CardUtil.singularTypes.containsKey(e.getKey())) {
sb.append("Text changed: all instances of ");
if (e.getKey().equals("Any")) {
if (this.changedTextColors.toMap().containsKey(e.getKey())) {
@@ -8472,30 +8473,15 @@ public class Card extends GameEntity implements Comparable<Card> {
if (source.isSpell() && !source.isColorless()) {
return true;
}
} else if (kw.equals("Protection from Dragons")) {
if (source.isType("Dragon")) {
return true;
}
} else if (kw.equals("Protection from Demons")) {
if (source.isType("Demon")) {
return true;
}
} else if (kw.equals("Protection from Goblins")) {
if (source.isType("Goblin")) {
return true;
}
} else if (kw.equals("Protection from Clerics")) {
if (source.isType("Cleric")) {
return true;
}
} else if (kw.equals("Protection from Gorgons")) {
if (source.isType("Gorgon")) {
return true;
}
} else if (kw.equals("Protection from the chosen player")) {
if (source.getController().equals(this.chosenPlayer)) {
return true;
}
} else if (kw.startsWith("Protection from ")) {
final String protectType = CardUtil.getSingularType(kw.substring("Protection from ".length()));
if (source.isType(protectType)) {
return true;
}
}
}
}

View File

@@ -61,6 +61,12 @@ public final class CardChangedWords {
// the actual change (b->c)
resultCache.put(ccw.getOriginalWord(), ccw.getNewWord());
// possible plural form
final String singular = CardUtil.getPluralType(ccw.getOriginalWord());
if (!singular.equals(ccw.getOriginalWord())) {
resultCache.put(singular, ccw.getNewWord());
}
}
for (final String key : ImmutableList.copyOf(resultCache.keySet())) {

View File

@@ -17,6 +17,14 @@
*/
package forge.game.card;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import forge.ImageKeys;
import forge.card.CardCharacteristicName;
import forge.card.ColorSet;
@@ -30,13 +38,6 @@ import forge.game.spellability.AbilitySub;
import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.google.common.collect.Lists;
public final class CardUtil {
// disable instantiation
private CardUtil() { }
@@ -46,17 +47,34 @@ public final class CardUtil {
/** List of all keywords that could be modified by text changes.
* Mostly this is caused by them having a variable, like a cost.
*/
public static final List<String> modifiableKeywords = Lists.newArrayList(
public static final ImmutableList<String> modifiableKeywords = ImmutableList.<String>builder().add(
"Enchant", "Protection", "Cumulative upkeep", "Equip", "Buyback",
"Cycling", "Echo", "Kicker", "Flashback", "Madness", "Morph",
"Affinity", "Entwine", "Splice", "Ninjutsu",
"Transute", "Replicate", "Recover", "Suspend", "Aura swap",
"Fortify", "Transfigure", "Champion", "Evoke", "Prowl",
"Reinforce", "Unearth", "Level up", "Miracle", "Overload",
"Scavenge", "Bestow");
"Scavenge", "Bestow").build();
/** List of keyword endings of keywords that could be modified by text changes. */
public static final List<String> modifiableKeywordEndings = Lists.newArrayList("walk", "cycling",
"offering");
public static final ImmutableList<String> modifiableKeywordEndings = ImmutableList.<String>builder().add(
"walk", "cycling", "offering").build();
/**
* Map of plural type names to the corresponding singular form.
* So Clerics maps to Cleric, Demons to Demon, etc.
*/
public static final ImmutableBiMap<String, String> singularTypes = ImmutableBiMap.<String, String>builder()
.put("Clerics", "Cleric")
.put("Demons", "Demon")
.put("Dragons", "Dragon")
.put("Goblins", "Goblin")
.put("Gorgons", "Gorgon")
.build();
/**
* Map of singular type names to the corresponding plural form.
* So Cleric maps to Clerics, Demon to Demons, etc.
*/
public static final ImmutableBiMap<String, String> pluralTypes = singularTypes.inverse();
public static final boolean isKeywordModifiable(final String kw) {
for (final String modKw : modifiableKeywords) {
@@ -72,6 +90,32 @@ public final class CardUtil {
return false;
}
/**
* If the input is a plural type, return the corresponding singular form.
* Otherwise, simply return the input.
* @param type a String.
* @return the corresponding type.
*/
public static final String getSingularType(final String type) {
if (singularTypes.containsKey(type)) {
return singularTypes.get(type);
}
return type;
}
/**
* If the input is a singular type, return the corresponding plural form.
* Otherwise, simply return the input.
* @param type a String.
* @return the corresponding type.
*/
public static final String getPluralType(final String type) {
if (pluralTypes.containsKey(type)) {
return pluralTypes.get(type);
}
return type;
}
public static ColorSet getColors(final Card c) {
return c.determineColor();
}