mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
CardType: fixed seting specific SubTypes
This commit is contained in:
@@ -32,19 +32,24 @@ public class CardChangedType {
|
||||
private final boolean removeSuperTypes;
|
||||
private final boolean removeCardTypes;
|
||||
private final boolean removeSubTypes;
|
||||
private final boolean removeLandTypes;
|
||||
private final boolean removeCreatureTypes;
|
||||
private final boolean removeArtifactTypes;
|
||||
private final boolean removeEnchantmentTypes;
|
||||
|
||||
public CardChangedType(final CardType addType0, final CardType removeType0, final boolean removeSuperType0,
|
||||
final boolean removeCardType0, final boolean removeSubType0, final boolean removeCreatureType0,
|
||||
final boolean removeArtifactType0) {
|
||||
final boolean removeCardType0, final boolean removeSubType0, final boolean removeLandType0,
|
||||
final boolean removeCreatureType0, final boolean removeArtifactType0,
|
||||
final boolean removeEnchantmentTypes0) {
|
||||
addType = addType0;
|
||||
removeType = removeType0;
|
||||
removeSuperTypes = removeSuperType0;
|
||||
removeCardTypes = removeCardType0;
|
||||
removeSubTypes = removeSubType0;
|
||||
removeLandTypes = removeLandType0;
|
||||
removeCreatureTypes = removeCreatureType0;
|
||||
removeArtifactTypes = removeArtifactType0;
|
||||
removeEnchantmentTypes = removeEnchantmentTypes0;
|
||||
}
|
||||
|
||||
public final CardType getAddType() {
|
||||
@@ -67,6 +72,10 @@ public class CardChangedType {
|
||||
return removeSubTypes;
|
||||
}
|
||||
|
||||
public final boolean isRemoveLandTypes() {
|
||||
return removeLandTypes;
|
||||
}
|
||||
|
||||
public final boolean isRemoveCreatureTypes() {
|
||||
return removeCreatureTypes;
|
||||
}
|
||||
@@ -74,4 +83,8 @@ public class CardChangedType {
|
||||
public final boolean isRemoveArtifactTypes() {
|
||||
return removeArtifactTypes;
|
||||
}
|
||||
|
||||
public final boolean isRemoveEnchantmentTypes() {
|
||||
return removeEnchantmentTypes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
|
||||
public boolean setCreatureTypes(Collection<String> ctypes) {
|
||||
// if it isn't a creature then this has no effect
|
||||
if (!coreTypes.contains(CoreType.Creature)) {
|
||||
if (!isCreature() && !isTribal()) {
|
||||
return false;
|
||||
}
|
||||
boolean changed = Iterables.removeIf(subtypes, Predicates.IS_CREATURE_TYPE);
|
||||
@@ -236,7 +236,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
final Set<String> landTypes = Sets.newHashSet();
|
||||
if (isLand()) {
|
||||
for (final String t : subtypes) {
|
||||
if (isALandType(t) || isABasicLandType(t)) {
|
||||
if (isALandType(t)) {
|
||||
landTypes.add(t);
|
||||
}
|
||||
}
|
||||
@@ -435,6 +435,9 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
@Override
|
||||
public CardTypeView getTypeWithChanges(final Iterable<CardChangedType> changedCardTypes) {
|
||||
CardType newType = null;
|
||||
if (Iterables.isEmpty(changedCardTypes)) {
|
||||
return this;
|
||||
}
|
||||
// we assume that changes are already correctly ordered (taken from TreeMap.values())
|
||||
for (final CardChangedType ct : changedCardTypes) {
|
||||
if(null == newType)
|
||||
@@ -449,7 +452,10 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
if (ct.isRemoveSubTypes()) {
|
||||
newType.subtypes.clear();
|
||||
}
|
||||
else {
|
||||
else if (!newType.subtypes.isEmpty()) {
|
||||
if (ct.isRemoveLandTypes()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_LAND_TYPE);
|
||||
}
|
||||
if (ct.isRemoveCreatureTypes()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_CREATURE_TYPE);
|
||||
// need to remove AllCreatureTypes too when removing creature Types
|
||||
@@ -458,6 +464,9 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
if (ct.isRemoveArtifactTypes()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_ARTIFACT_TYPE);
|
||||
}
|
||||
if (ct.isRemoveEnchantmentTypes()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_ENCHANTMENT_TYPE);
|
||||
}
|
||||
}
|
||||
if (ct.getRemoveType() != null) {
|
||||
newType.removeAll(ct.getRemoveType());
|
||||
@@ -466,6 +475,28 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
newType.addAll(ct.getAddType());
|
||||
}
|
||||
}
|
||||
// sanisfy subtypes
|
||||
if (newType != null && !newType.subtypes.isEmpty()) {
|
||||
if (!newType.isCreature() && !newType.isTribal()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_CREATURE_TYPE);
|
||||
newType.subtypes.remove("AllCreatureTypes");
|
||||
}
|
||||
if (!newType.isLand()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_LAND_TYPE);
|
||||
}
|
||||
if (!newType.isArtifact()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_ARTIFACT_TYPE);
|
||||
}
|
||||
if (!newType.isEnchantment()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_ENCHANTMENT_TYPE);
|
||||
}
|
||||
if (!newType.isInstant() && !newType.isSorcery()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_SPELL_TYPE);
|
||||
}
|
||||
if (!newType.isPlaneswalker() && !newType.isEmblem()) {
|
||||
Iterables.removeIf(newType.subtypes, Predicates.IS_WALKER_TYPE);
|
||||
}
|
||||
}
|
||||
return newType == null ? this : newType;
|
||||
}
|
||||
|
||||
@@ -574,6 +605,13 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
public static final BiMap<String,String> singularTypes = pluralTypes.inverse();
|
||||
}
|
||||
public static class Predicates {
|
||||
public static Predicate<String> IS_LAND_TYPE = new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
return CardType.isALandType(input);
|
||||
}
|
||||
};
|
||||
|
||||
public static Predicate<String> IS_ARTIFACT_TYPE = new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
@@ -587,6 +625,27 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
return CardType.isACreatureType(input);
|
||||
}
|
||||
};
|
||||
|
||||
public static Predicate<String> IS_ENCHANTMENT_TYPE = new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
return CardType.isAnEnchantmentType(input);
|
||||
}
|
||||
};
|
||||
|
||||
public static Predicate<String> IS_SPELL_TYPE = new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
return CardType.isASpellType(input);
|
||||
}
|
||||
};
|
||||
|
||||
public static Predicate<String> IS_WALKER_TYPE = new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
return CardType.isAPlaneswalkerType(input);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -656,7 +715,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
}
|
||||
|
||||
public static boolean isALandType(final String cardType) {
|
||||
return (Constant.LAND_TYPES.contains(cardType));
|
||||
return Constant.LAND_TYPES.contains(cardType) || isABasicLandType(cardType);
|
||||
}
|
||||
|
||||
public static boolean isAPlaneswalkerType(final String cardType) {
|
||||
@@ -667,6 +726,13 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
return (Constant.BASIC_TYPES.contains(cardType));
|
||||
}
|
||||
|
||||
public static boolean isAnEnchantmentType(final String cardType) {
|
||||
return (Constant.ENCHANTMENT_TYPES.contains(cardType));
|
||||
}
|
||||
|
||||
public static boolean isASpellType(final String cardType) {
|
||||
return (Constant.SPELL_TYPES.contains(cardType));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the input is a plural type, return the corresponding singular form.
|
||||
|
||||
Reference in New Issue
Block a user