Search in sources :

Example 6 with SpellProhibitor

use of pcgen.core.SpellProhibitor 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 7 with SpellProhibitor

use of pcgen.core.SpellProhibitor 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 8 with SpellProhibitor

use of pcgen.core.SpellProhibitor in project pcgen by PCGen.

the class ProhibitspellToken method typeSafeParse.

private SpellProhibitor typeSafeParse(ProhibitedSpellType type, String args) {
    SpellProhibitor spellProb = new SpellProhibitor();
    spellProb.setType(type);
    if (args.isEmpty()) {
        Logging.errorPrint(getTokenName() + ' ' + type + " has no arguments");
        return null;
    }
    String joinChar = getJoinChar(type, new LinkedList<>());
    if (args.indexOf(joinChar) == 0) {
        Logging.errorPrint(getTokenName() + " arguments may not start with " + joinChar);
        return null;
    }
    if (args.lastIndexOf(joinChar) == args.length() - 1) {
        Logging.errorPrint(getTokenName() + " arguments may not end with " + joinChar);
        return null;
    }
    if (args.indexOf(joinChar + joinChar) != -1) {
        Logging.errorPrint(getTokenName() + " arguments uses double separator " + joinChar + joinChar);
        return null;
    }
    StringTokenizer elements = new StringTokenizer(args, joinChar);
    while (elements.hasMoreTokens()) {
        String aValue = elements.nextToken();
        if (type.equals(ProhibitedSpellType.ALIGNMENT) && (!aValue.equalsIgnoreCase("GOOD")) && (!aValue.equalsIgnoreCase("EVIL")) && (!aValue.equalsIgnoreCase("LAWFUL")) && (!aValue.equalsIgnoreCase("CHAOTIC"))) {
            Logging.errorPrint("Illegal PROHIBITSPELL:ALIGNMENT subtag '" + aValue + '\'');
            return null;
        } else {
            spellProb.addValue(aValue);
        }
    }
    return spellProb;
}
Also used : StringTokenizer(java.util.StringTokenizer) SpellProhibitor(pcgen.core.SpellProhibitor)

Example 9 with SpellProhibitor

use of pcgen.core.SpellProhibitor 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 10 with SpellProhibitor

use of pcgen.core.SpellProhibitor 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)22 TreeSet (java.util.TreeSet)6 Test (org.junit.Test)6 PCClass (pcgen.core.PCClass)6 StringTokenizer (java.util.StringTokenizer)4 ProhibitedSpellType (pcgen.util.enumeration.ProhibitedSpellType)4 ArrayList (java.util.ArrayList)2 SubClass (pcgen.core.SubClass)2 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)2 CharID (pcgen.cdom.enumeration.CharID)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 Domain (pcgen.core.Domain)1 SpecialAbility (pcgen.core.SpecialAbility)1 SpellSupportForPCClass (pcgen.core.SpellSupportForPCClass)1 BonusObj (pcgen.core.bonus.BonusObj)1 CDOMChooserFacadeImpl (pcgen.core.chooser.CDOMChooserFacadeImpl)1 PCLevelInfoStat (pcgen.core.pclevelinfo.PCLevelInfoStat)1 Prerequisite (pcgen.core.prereq.Prerequisite)1 Gui2InfoFactory (pcgen.gui2.facade.Gui2InfoFactory)1 HtmlInfoBuilder (pcgen.gui2.util.HtmlInfoBuilder)1