diff --git a/src/main/java/electroblob/wizardry/spell/Spell.java b/src/main/java/electroblob/wizardry/spell/Spell.java index 2d1fa98a..8ff98bab 100644 --- a/src/main/java/electroblob/wizardry/spell/Spell.java +++ b/src/main/java/electroblob/wizardry/spell/Spell.java @@ -115,13 +115,18 @@ public abstract class Spell extends IForgeRegistryEntry.Impl implements C public static final String SPLASH_EFFECT_DURATION = "splash_effect_duration"; public static final String SPLASH_EFFECT_STRENGTH = "splash_effect_strength"; - // TODO: Translations for these? public static final String TIER_MATCH_PREFIX = "tier"; public static final String ELEMENT_MATCH_PREFIX = "element"; public static final String TYPE_MATCH_PREFIX = "type"; public static final String DISCOVERED_MATCH_PREFIX = "discovered"; public static final String MODID_MATCH_PREFIX = "modid"; + public static final String TIER_MATCH_ALIAS = "t"; + public static final String ELEMENT_MATCH_ALIAS = "e"; + public static final String TYPE_MATCH_ALIAS = "p"; + public static final String DISCOVERED_MATCH_ALIAS = "d"; + public static final String MODID_MATCH_ALIAS = "m"; + public static final String MATCH_CONDITION_SEPARATOR = ";"; public static final String MATCH_KEY_VALUE_SEPARATOR = "="; public static final String MATCH_VALUE_SEPARATOR = ","; @@ -676,15 +681,28 @@ public abstract class Spell extends IForgeRegistryEntry.Impl implements C } /** - * Returns whether this spell matches the given string. Client-side only! A spell matches a particular string - * if any of the following conditions are true: + * Returns whether this spell matches the given string. Client-side only! Matches are determined as follows: *

- * - The spell's localised name contains the given string
- * - The string starts with "tier:", and the localised name of the spell's tier contains the given string
- * - The string starts with "element:", and the localised name of the spell's element contains the given string
- * - The string starts with "type:", and the localised name of the spell's type contains the given string + * First, attempt to parse the string as one or more conditions separated by semicolons ({@code ;}). Each + * condition has the syntax {@code key=value1,value2,value3,...}, where {@code key} is one of several predefined + * strings (or aliases) pointing to a particular property of the spell, and each {@code value} is a string to match + * to that property. Valid keys are: *

- * Matches are not case-sensitive. + * - {@code tier} (alias {@code t}), specifies the tiers that the spell can match
+ * - {@code element} (alias {@code e}), specifies the elements that the spell can match
+ * - {@code type} (alias {@code p}), specifies the spell types that the spell can match
+ * - {@code modid} (alias {@code m}), specifies the mod IDs that the spell can be from
+ * - {@code discovered} (alias {@code d}), specifies the discovery status ({@code true} or {@code false}) that the + * spell can match
+ *

+ * The spell must match all conditions to count as a match, but only needs to match one of the values for each + * condition. + *

+ * If, at any point, a condition is not of valid syntax (or if the string does not contain {@code ;} or {@code =}), + * the input is instead treated as verbatim, and the spell matches if it has been discovered and its localised name + * contains the given string. + *

+ * Keys are case-sensitive, but everything else is not. * @param text The string to tested * @return True if this spell matches the given string, false otherwise. */ @@ -710,22 +728,27 @@ public abstract class Spell extends IForgeRegistryEntry.Impl implements C switch(key){ case TIER_MATCH_PREFIX: + case TIER_MATCH_ALIAS: // Tier IS known for undiscovered spells so we can match it target = getTier().getDisplayName().toLowerCase(Locale.ROOT); break; case ELEMENT_MATCH_PREFIX: + case ELEMENT_MATCH_ALIAS: if(!discovered) return false; // Element is unknown so doesn't match target = getElement().getDisplayName().toLowerCase(Locale.ROOT); break; case TYPE_MATCH_PREFIX: + case TYPE_MATCH_ALIAS: if(!discovered) return false; // Type is unknown so doesn't match target = getType().getDisplayName().toLowerCase(Locale.ROOT); break; case MODID_MATCH_PREFIX: + case MODID_MATCH_ALIAS: if(!discovered) return false; // Mod ID is unknown so doesn't match target = getRegistryName().getNamespace().toLowerCase(Locale.ROOT); break; case DISCOVERED_MATCH_PREFIX: + case DISCOVERED_MATCH_ALIAS: target = Boolean.toString(discovered); break; default: