Search in sources :

Example 1 with ProhibitedSpellType

use of pcgen.util.enumeration.ProhibitedSpellType in project pcgen by PCGen.

the class ProhibitspellToken method subParse.

public SpellProhibitor subParse(String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    String token = tok.nextToken();
    int dotLoc = token.indexOf(Constants.DOT);
    if (dotLoc == -1) {
        Logging.errorPrint(getTokenName() + " has no . separator for arguments: " + value);
        return null;
    }
    String pstString = token.substring(0, dotLoc);
    ProhibitedSpellType type;
    try {
        type = ProhibitedSpellType.valueOf(pstString);
    } catch (IllegalArgumentException e) {
        Logging.errorPrint(getTokenName() + " encountered an invalid Prohibited Spell Type: " + value);
        Logging.errorPrint("  Legal values are: " + StringUtil.join(Arrays.asList(ProhibitedSpellType.values()), ", "));
        return null;
    }
    SpellProhibitor spellProb = typeSafeParse(type, token.substring(dotLoc + 1));
    if (spellProb == null) {
        Logging.errorPrint("  entire token value was: " + value);
        return null;
    }
    if (!tok.hasMoreTokens()) {
        // No prereqs, so we're done
        return spellProb;
    }
    token = tok.nextToken();
    while (true) {
        Prerequisite prereq = getPrerequisite(token);
        if (prereq == null) {
            Logging.errorPrint("   (Did you put more than one limit, or items after the " + "PRExxx tags in " + getTokenName() + ":?)");
            return null;
        }
        spellProb.addPrerequisite(prereq);
        if (!tok.hasMoreTokens()) {
            break;
        }
        token = tok.nextToken();
    }
    return spellProb;
}
Also used : StringTokenizer(java.util.StringTokenizer) ProhibitedSpellType(pcgen.util.enumeration.ProhibitedSpellType) SpellProhibitor(pcgen.core.SpellProhibitor) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 2 with ProhibitedSpellType

use of pcgen.util.enumeration.ProhibitedSpellType in project pcgen by PCGen.

the class ProhibitspellToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass pcc) {
    Changes<SpellProhibitor> changes = context.getObjectContext().getListChanges(pcc, ListKey.SPELL_PROHIBITOR);
    Collection<SpellProhibitor> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token present
        return null;
    }
    List<String> list = new ArrayList<>();
    for (SpellProhibitor sp : added) {
        StringBuilder sb = new StringBuilder();
        ProhibitedSpellType pst = sp.getType();
        sb.append(pst.toString().toUpperCase());
        sb.append('.');
        Collection<String> valueSet = sp.getValueList();
        String joinChar = getJoinChar(pst, valueSet);
        sb.append(StringUtil.join(new TreeSet<>(valueSet), joinChar));
        if (sp.hasPrerequisites()) {
            sb.append(Constants.PIPE);
            sb.append(getPrerequisiteString(context, sp.getPrerequisiteList()));
        }
        list.add(sb.toString());
    }
    return list.toArray(new String[list.size()]);
}
Also used : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ProhibitedSpellType(pcgen.util.enumeration.ProhibitedSpellType) SpellProhibitor(pcgen.core.SpellProhibitor)

Example 3 with ProhibitedSpellType

use of pcgen.util.enumeration.ProhibitedSpellType in project pcgen by PCGen.

the class ChoiceToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, SubClass sc, String value) {
    int pipeLoc = value.indexOf('|');
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " has no | separator for arguments: " + value, context);
    }
    if (value.lastIndexOf('|') != pipeLoc) {
        return new ParseResult.Fail(getTokenName() + " has more than two | separated arguments: " + value, context);
    }
    String pstString = value.substring(0, pipeLoc);
    ProhibitedSpellType type;
    try {
        type = ProhibitedSpellType.valueOf(pstString);
    } catch (IllegalArgumentException e) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(getTokenName() + " encountered an invalid Prohibited Spell Type: " + value);
        cpr.addErrorMessage("  Legal values are: " + StringUtil.join(Arrays.asList(ProhibitedSpellType.values()), ", "));
        return cpr;
    }
    if (type.equals(ProhibitedSpellType.SCHOOL) || type.equals(ProhibitedSpellType.SUBSCHOOL) || type.equals(ProhibitedSpellType.DESCRIPTOR)) {
        SpellProhibitor sp = new SpellProhibitor();
        sp.setType(type);
        sp.addValue(value.substring(pipeLoc + 1));
        context.getObjectContext().put(sc, ObjectKey.CHOICE, sp);
        return ParseResult.SUCCESS;
    }
    return new ParseResult.Fail("Invalid TYPE in " + getTokenName() + ": " + pstString, context);
}
Also used : ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ProhibitedSpellType(pcgen.util.enumeration.ProhibitedSpellType) SpellProhibitor(pcgen.core.SpellProhibitor)

Example 4 with ProhibitedSpellType

use of pcgen.util.enumeration.ProhibitedSpellType in project pcgen by PCGen.

the class ChoiceToken method unparse.

@Override
public String[] unparse(LoadContext context, SubClass pcc) {
    SpellProhibitor sp = context.getObjectContext().getObject(pcc, ObjectKey.CHOICE);
    if (sp == null) {
        // Zero indicates no Token present
        return null;
    }
    StringBuilder sb = new StringBuilder();
    ProhibitedSpellType pst = sp.getType();
    sb.append(pst.toString().toUpperCase());
    sb.append('|');
    Collection<String> valueSet = sp.getValueList();
    sb.append(StringUtil.join(new TreeSet<>(valueSet), Constants.PIPE));
    return new String[] { sb.toString() };
}
Also used : TreeSet(java.util.TreeSet) ProhibitedSpellType(pcgen.util.enumeration.ProhibitedSpellType) SpellProhibitor(pcgen.core.SpellProhibitor)

Aggregations

SpellProhibitor (pcgen.core.SpellProhibitor)4 ProhibitedSpellType (pcgen.util.enumeration.ProhibitedSpellType)4 TreeSet (java.util.TreeSet)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Prerequisite (pcgen.core.prereq.Prerequisite)1 ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)1