Search in sources :

Example 36 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ArmorProfTokenTest method loadAllReference.

@Override
protected void loadAllReference() {
    List<CDOMReference<ArmorProf>> armorProfs = new ArrayList<>();
    List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
    armorProfs.add(primaryContext.getReferenceContext().getCDOMAllReference(ArmorProf.class));
    ArmorProfProvider pp = new ArmorProfProvider(armorProfs, equipTypes);
    primaryProf.addToListFor(ListKey.AUTO_ARMORPROF, pp);
}
Also used : ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) ArrayList(java.util.ArrayList) ArmorProf(pcgen.core.ArmorProf) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 37 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ArmorProfTokenTest method loadProf.

@Override
protected void loadProf(CDOMSingleRef<ArmorProf> ref) {
    List<CDOMReference<ArmorProf>> armorProfs = new ArrayList<>();
    List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
    armorProfs.add(ref);
    ArmorProfProvider pp = new ArmorProfProvider(armorProfs, equipTypes);
    primaryProf.addToListFor(ListKey.AUTO_ARMORPROF, pp);
}
Also used : ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) ArrayList(java.util.ArrayList) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 38 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ArmorProfTokenTest method loadTypeProf.

@Override
protected void loadTypeProf(String... types) {
    CDOMGroupRef<Equipment> ref = primaryContext.getReferenceContext().getCDOMTypeReference(Equipment.class, types);
    List<CDOMReference<ArmorProf>> armorProfs = new ArrayList<>();
    List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
    equipTypes.add(ref);
    ArmorProfProvider pp = new ArmorProfProvider(armorProfs, equipTypes);
    primaryProf.addToListFor(ListKey.AUTO_ARMORPROF, pp);
}
Also used : ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) Equipment(pcgen.core.Equipment) ArrayList(java.util.ArrayList) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 39 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ShieldProfTokenTest method loadTypeProf.

@Override
protected void loadTypeProf(String... types) {
    CDOMGroupRef<Equipment> ref = primaryContext.getReferenceContext().getCDOMTypeReference(Equipment.class, types);
    List<CDOMReference<ShieldProf>> shieldProfs = new ArrayList<>();
    List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
    equipTypes.add(ref);
    ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
    primaryProf.addToListFor(ListKey.AUTO_SHIELDPROF, pp);
}
Also used : Equipment(pcgen.core.Equipment) ArrayList(java.util.ArrayList) ShieldProfProvider(pcgen.cdom.helper.ShieldProfProvider) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 40 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ArmorProfToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String armorProf;
    // Do not initialize, null is significant!
    Prerequisite prereq = null;
    boolean isPre = false;
    if (value.indexOf("[") == -1) {
        // Supported version of PRExxx using |.  Needs to be at the front of the
        // Parsing code because many objects expect the pre to have been determined
        // Ahead of time.  Until deprecated code is removed, it will have to stay
        // like this.
        armorProf = value;
        StringTokenizer tok = new StringTokenizer(armorProf, Constants.PIPE);
        while (tok.hasMoreTokens()) {
            String token = tok.nextToken();
            if (PreParserFactory.isPreReqString(token)) {
                if (isPre) {
                    String errorText = "Invalid " + getTokenName() + ": " + value + "  PRExxx must be at the END of the Token";
                    Logging.errorPrint(errorText);
                    return new ParseResult.Fail(errorText, context);
                }
                prereq = getPrerequisite(token);
                if (prereq == null) {
                    return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
                }
                int preStart = value.indexOf(token) - 1;
                armorProf = value.substring(0, preStart);
                isPre = true;
            }
        }
    } else {
        return new ParseResult.Fail("Use of [] for Prerequisites has been removed. " + "Please use | based standard", context);
    }
    ParseResult pr = checkSeparatorsAndNonEmpty('|', armorProf);
    if (!pr.passed()) {
        return pr;
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(armorProf, Constants.PIPE);
    List<CDOMReference<ArmorProf>> armorProfs = new ArrayList<>();
    List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String aProf = tok.nextToken();
        if (Constants.LST_PERCENT_LIST.equals(aProf)) {
            foundOther = true;
            ChooseSelectionActor<ArmorProf> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<ArmorProf> cca = new ConditionalSelectionActor<>(this);
                cca.addPrerequisite(prereq);
                cra = cca;
            }
            context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
        } else if (Constants.LST_ALL.equalsIgnoreCase(aProf)) {
            foundAny = true;
            armorProfs.add(context.getReferenceContext().getCDOMAllReference(ARMORPROF_CLASS));
        } else if (aProf.startsWith("ARMORTYPE.") || aProf.startsWith("ARMORTYPE=")) {
            foundOther = true;
            CDOMReference<Equipment> ref = TokenUtilities.getTypeReference(context, EQUIPMENT_CLASS, "ARMOR." + aProf.substring(10));
            if (ref == null) {
                return ParseResult.INTERNAL_ERROR;
            }
            equipTypes.add(ref);
        } else {
            foundOther = true;
            armorProfs.add(context.getReferenceContext().getCDOMReference(ARMORPROF_CLASS, aProf));
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    if (!armorProfs.isEmpty() || !equipTypes.isEmpty()) {
        ArmorProfProvider pp = new ArmorProfProvider(armorProfs, equipTypes);
        if (prereq != null) {
            pp.addPrerequisite(prereq);
        }
        context.getObjectContext().addToList(obj, ListKey.AUTO_ARMORPROF, pp);
    }
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ArrayList(java.util.ArrayList) StringTokenizer(java.util.StringTokenizer) ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) Equipment(pcgen.core.Equipment) ArmorProf(pcgen.core.ArmorProf) CDOMReference(pcgen.cdom.base.CDOMReference) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

CDOMReference (pcgen.cdom.base.CDOMReference)125 ArrayList (java.util.ArrayList)57 StringTokenizer (java.util.StringTokenizer)40 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)35 ParseResult (pcgen.rules.persistence.token.ParseResult)30 Skill (pcgen.core.Skill)24 ChoiceSet (pcgen.cdom.base.ChoiceSet)22 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)21 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)19 Prerequisite (pcgen.core.prereq.Prerequisite)18 Formula (pcgen.base.formula.Formula)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 Spell (pcgen.core.spell.Spell)15 TreeSet (java.util.TreeSet)14 Test (org.junit.Test)14 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)12 CharID (pcgen.cdom.enumeration.CharID)11 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)11 ParsingSeparator (pcgen.base.text.ParsingSeparator)10 CDOMList (pcgen.cdom.base.CDOMList)10