Search in sources :

Example 16 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class MonskillToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCClass pcc, String value) {
    BonusObj bon = Bonus.newBonus(context, "MONSKILLPTS|NUMBER|" + value);
    if (bon == null) {
        return new ParseResult.Fail(getTokenName() + " was given invalid bonus value: " + value, context);
    }
    Prerequisite prereq = getPrerequisite("PRELEVELMAX:1");
    if (prereq == null) {
        return new ParseResult.Fail("Internal Error: " + getTokenName() + " had invalid prerequisite", context);
    }
    bon.addPrerequisite(prereq);
    bon.setTokenSource(getTokenName());
    context.getObjectContext().addToList(pcc, ListKey.BONUS, bon);
    return ParseResult.SUCCESS;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 17 with Prerequisite

use of pcgen.core.prereq.Prerequisite 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 18 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class DomainToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
    boolean first = true;
    String tok = pipeTok.nextToken();
    if (looksLikeAPrerequisite(tok)) {
        return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName() + ": " + value, context);
    }
    List<QualifiedObject<CDOMSingleRef<Domain>>> toAdd = new ArrayList<>();
    boolean foundClear = false;
    while (true) {
        if (Constants.LST_DOT_CLEAR.equals(tok)) {
            if (!first) {
                return new ParseResult.Fail("  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
            }
            context.getObjectContext().removeList(pcc, ListKey.DOMAIN);
            foundClear = true;
        } else {
            CDOMSingleRef<Domain> domain = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, tok);
            QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(domain);
            toAdd.add(qo);
            context.getObjectContext().addToList(pcc, ListKey.DOMAIN, qo);
        }
        first = false;
        if (!pipeTok.hasMoreTokens()) {
            // No prereqs, so we're done
            return ParseResult.SUCCESS;
        }
        tok = pipeTok.nextToken();
        if (looksLikeAPrerequisite(tok)) {
            break;
        }
    }
    if (foundClear) {
        return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR in " + getTokenName(), context);
    }
    while (true) {
        Prerequisite prereq = getPrerequisite(tok);
        if (prereq == null) {
            return new ParseResult.Fail("   (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
        }
        for (PrereqObject pro : toAdd) {
            pro.addPrerequisite(prereq);
        }
        if (!pipeTok.hasMoreTokens()) {
            break;
        }
        tok = pipeTok.nextToken();
    }
    return ParseResult.SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) PrereqObject(pcgen.cdom.base.PrereqObject) StringTokenizer(java.util.StringTokenizer) QualifiedObject(pcgen.core.QualifiedObject) Domain(pcgen.core.Domain) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 19 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class AdddomainsToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass pcc) {
    AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), pcc, PCClass.ALLOWED_DOMAINS);
    Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
        context.addWriteMessage(getTokenName() + " does not support .CLEAR");
        return null;
    }
    MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
    if (mtl == null || mtl.isEmpty()) {
        return null;
    }
    PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
    Set<String> set = new TreeSet<>();
    Set<String> noPrereqSet = new TreeSet<>();
    for (CDOMReference<Domain> domain : mtl.getKeySet()) {
        for (AssociatedPrereqObject assoc : mtl.getListFor(domain)) {
            StringBuilder sb = new StringBuilder(domain.getLSTformat(false));
            List<Prerequisite> prereqs = assoc.getPrerequisiteList();
            if (prereqs == null || prereqs.isEmpty()) {
                noPrereqSet.add(sb.toString());
                continue;
            }
            for (Prerequisite prereq : prereqs) {
                sb.append(Constants.PIPE);
                StringWriter swriter = new StringWriter();
                try {
                    prereqWriter.write(swriter, prereq);
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
                sb.append(swriter.toString());
            }
            set.add(sb.toString());
        }
    }
    if (!noPrereqSet.isEmpty()) {
        set.add(StringUtil.join(noPrereqSet, Constants.PIPE));
    }
    return set.toArray(new String[set.size()]);
}
Also used : PrerequisiteWriter(pcgen.persistence.lst.output.prereq.PrerequisiteWriter) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringWriter(java.io.StringWriter) TreeSet(java.util.TreeSet) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 20 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class EquipBuyToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String activeValue = sep.next();
    if (looksLikeAPrerequisite(activeValue)) {
        return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
    }
    Formula f = FormulaFactory.getFormulaFor(activeValue);
    if (!f.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
    }
    List<Prerequisite> prereqs = new ArrayList<>();
    while (sep.hasNext()) {
        activeValue = sep.next();
        Prerequisite prereq = getPrerequisite(activeValue);
        if (prereq == null) {
            return new ParseResult.Fail("   (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
        }
        prereqs.add(prereq);
    }
    kit.put(ObjectKey.EQUIP_BUY, new QualifiedObject<>(f, prereqs));
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

Prerequisite (pcgen.core.prereq.Prerequisite)267 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)62 Test (org.junit.Test)61 PrerequisiteOperator (pcgen.core.prereq.PrerequisiteOperator)50 StringTokenizer (java.util.StringTokenizer)36 ArrayList (java.util.ArrayList)35 StringWriter (java.io.StringWriter)19 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)19 CDOMReference (pcgen.cdom.base.CDOMReference)18 ParseResult (pcgen.rules.persistence.token.ParseResult)18 BonusObj (pcgen.core.bonus.BonusObj)13 TreeSet (java.util.TreeSet)12 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)12 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10 Domain (pcgen.core.Domain)10 QualifiedObject (pcgen.core.QualifiedObject)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 PrerequisiteWriter (pcgen.persistence.lst.output.prereq.PrerequisiteWriter)9 Ungranted (pcgen.cdom.base.Ungranted)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8