Search in sources :

Example 71 with Equipment

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

use of pcgen.core.Equipment 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)

Example 73 with Equipment

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

the class ShieldProfToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String shieldProf;
    // 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.
        shieldProf = value;
        StringTokenizer tok = new StringTokenizer(shieldProf, 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;
                shieldProf = 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 = checkForIllegalSeparator('|', shieldProf);
    if (!pr.passed()) {
        return pr;
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE);
    List<CDOMReference<ShieldProf>> shieldProfs = 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<ShieldProf> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<ShieldProf> 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;
            shieldProfs.add(context.getReferenceContext().getCDOMAllReference(SHIELDPROF_CLASS));
        } else if (aProf.startsWith("SHIELDTYPE.") || aProf.startsWith("SHIELDTYPE=")) {
            foundOther = true;
            CDOMReference<Equipment> ref = TokenUtilities.getTypeReference(context, EQUIPMENT_CLASS, "SHIELD." + aProf.substring(11));
            if (ref == null) {
                return ParseResult.INTERNAL_ERROR;
            }
            equipTypes.add(ref);
        } else {
            foundOther = true;
            shieldProfs.add(context.getReferenceContext().getCDOMReference(SHIELDPROF_CLASS, aProf));
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    if (!shieldProfs.isEmpty() || !equipTypes.isEmpty()) {
        ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
        if (prereq != null) {
            pp.addPrerequisite(prereq);
        }
        context.getObjectContext().addToList(obj, ListKey.AUTO_SHIELDPROF, pp);
    }
    return ParseResult.SUCCESS;
}
Also used : ShieldProf(pcgen.core.ShieldProf) ParseResult(pcgen.rules.persistence.token.ParseResult) ArrayList(java.util.ArrayList) StringTokenizer(java.util.StringTokenizer) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) Equipment(pcgen.core.Equipment) ShieldProfProvider(pcgen.cdom.helper.ShieldProfProvider) CDOMReference(pcgen.cdom.base.CDOMReference) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 74 with Equipment

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

the class EquipToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
        count = FormulaFactory.ONE;
    } else {
        count = FormulaFactory.getFormulaFor(activeValue);
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
            return new ParseResult.Fail("Count in " + getFullName() + " must be > 0", context);
        }
        activeValue = sep.next();
    }
    if (sep.hasNext()) {
        return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value, context);
    }
    ParseResult pr = checkSeparatorsAndNonEmpty(',', activeValue);
    if (!pr.passed()) {
        return pr;
    }
    List<CDOMReference<Equipment>> refs = new ArrayList<>();
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        CDOMReference<Equipment> lang = TokenUtilities.getTypeOrPrimitive(context, EQUIPMENT_CLASS, tokText);
        if (lang == null) {
            return new ParseResult.Fail("  Error was encountered while parsing " + getFullName() + ": " + value + " had an invalid reference: " + tokText, context);
        }
        refs.add(lang);
    }
    ReferenceChoiceSet<Equipment> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Equipment> cs = new ChoiceSet<>(getTokenName(), new QualifiedDecorator<>(rcs));
    cs.setTitle("Equipment Choice");
    PersistentTransitionChoice<Equipment> tc = new ConcretePersistentTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) ParsingSeparator(pcgen.base.text.ParsingSeparator) Equipment(pcgen.core.Equipment) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 75 with Equipment

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

the class EquipToken method applyChoice.

@Override
public void applyChoice(CDOMObject owner, Equipment choice, PlayerCharacter pc) {
    Equipment bEquipment = choice.clone();
    bEquipment.setQty(1);
    pc.addEquipment(bEquipment);
}
Also used : Equipment(pcgen.core.Equipment)

Aggregations

Equipment (pcgen.core.Equipment)166 PlayerCharacter (pcgen.core.PlayerCharacter)41 ArrayList (java.util.ArrayList)28 StringTokenizer (java.util.StringTokenizer)25 EquipSet (pcgen.core.character.EquipSet)22 CDOMObject (pcgen.cdom.base.CDOMObject)20 LoadContext (pcgen.rules.context.LoadContext)15 SizeAdjustment (pcgen.core.SizeAdjustment)11 EquipmentHead (pcgen.cdom.inst.EquipmentHead)10 WeaponProf (pcgen.core.WeaponProf)10 CharID (pcgen.cdom.enumeration.CharID)9 WieldCategory (pcgen.core.character.WieldCategory)9 CDOMReference (pcgen.cdom.base.CDOMReference)8 ArmorProf (pcgen.core.ArmorProf)8 EquipmentModifier (pcgen.core.EquipmentModifier)8 Race (pcgen.core.Race)8 ShieldProf (pcgen.core.ShieldProf)8 BonusObj (pcgen.core.bonus.BonusObj)8 Test (org.junit.Test)7 ScopeInstance (pcgen.base.formula.base.ScopeInstance)7