Search in sources :

Example 46 with WeaponProf

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

the class WeaponProfToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String weaponProfs;
    // 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.
        weaponProfs = value;
        StringTokenizer tok = new StringTokenizer(weaponProfs, 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;
                weaponProfs = value.substring(0, preStart);
                isPre = true;
                ParseResult fail = checkForLoopPrereqs(prereq, context);
                if (fail != null) {
                    return fail;
                }
            }
        }
    } else {
        return new ParseResult.Fail("Use of [] for Prerequisites has been removed. " + "Please use | based standard", context);
    }
    ParseResult pr = checkForIllegalSeparator('|', weaponProfs);
    if (!pr.passed()) {
        return pr;
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(weaponProfs, Constants.PIPE);
    WeaponProfProvider wpp = new WeaponProfProvider();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (Constants.LST_PERCENT_LIST.equals(token)) {
            foundOther = true;
            ChooseSelectionActor<WeaponProf> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<WeaponProf> cca = new ConditionalSelectionActor<>(this);
                cca.addPrerequisite(prereq);
                cra = cca;
            }
            context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
        } else if ("DEITYWEAPONS".equals(token)) {
            foundOther = true;
            context.getObjectContext().put(obj, ObjectKey.HAS_DEITY_WEAPONPROF, new QualifiedObject<>(Boolean.TRUE, prereq));
        } else {
            if (Constants.LST_ALL.equalsIgnoreCase(token)) {
                foundAny = true;
                CDOMGroupRef<WeaponProf> allRef = context.getReferenceContext().getCDOMAllReference(WEAPONPROF_CLASS);
                wpp.addWeaponProfAll(allRef);
            } else {
                foundOther = true;
                if (token.startsWith(Constants.LST_TYPE_DOT) || token.startsWith(Constants.LST_TYPE_EQUAL)) {
                    CDOMGroupRef<WeaponProf> rr = TokenUtilities.getTypeReference(context, WEAPONPROF_CLASS, token.substring(5));
                    if (rr == null) {
                        return ParseResult.INTERNAL_ERROR;
                    }
                    wpp.addWeaponProfType(rr);
                } else {
                    CDOMSingleRef<WeaponProf> ref = context.getReferenceContext().getCDOMReference(WEAPONPROF_CLASS, token);
                    wpp.addWeaponProf(ref);
                }
            }
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    if (!wpp.isEmpty()) {
        if (prereq != null) {
            wpp.addPrerequisite(prereq);
        }
        context.getObjectContext().addToList(obj, ListKey.WEAPONPROF, wpp);
    }
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) WeaponProf(pcgen.core.WeaponProf) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) StringTokenizer(java.util.StringTokenizer) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) QualifiedObject(pcgen.core.QualifiedObject) CDOMGroupRef(pcgen.cdom.reference.CDOMGroupRef) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 47 with WeaponProf

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

the class WeaponProfTokenTest method loadTypeProf.

@Override
protected void loadTypeProf(String... types) {
    WeaponProfProvider wpp = new WeaponProfProvider();
    CDOMGroupRef<WeaponProf> ref = primaryContext.getReferenceContext().getCDOMTypeReference(WeaponProf.class, types);
    wpp.addWeaponProfType(ref);
    primaryProf.addToListFor(ListKey.WEAPONPROF, wpp);
}
Also used : WeaponProf(pcgen.core.WeaponProf) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider)

Example 48 with WeaponProf

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

the class DeityWeapTokenTest method testUnparseMultiple.

@Test
public void testUnparseMultiple() throws PersistenceLayerException {
    WeaponProf wp1 = construct(primaryContext, getLegalValue());
    primaryProf.addToListFor(ListKey.DEITYWEAPON, CDOMDirectSingleRef.getRef(wp1));
    WeaponProf wp2 = construct(primaryContext, getAlternateLegalValue());
    primaryProf.addToListFor(ListKey.DEITYWEAPON, CDOMDirectSingleRef.getRef(wp2));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getLegalValue() + getJoinCharacter() + getAlternateLegalValue());
}
Also used : WeaponProf(pcgen.core.WeaponProf) Test(org.junit.Test)

Example 49 with WeaponProf

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

the class PCGVer2Parser method getWeaponProf.

private WeaponProf getWeaponProf(final String aString) {
    WeaponProf wp = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WeaponProf.class, EntityEncoder.decode(aString));
    if (wp == null) {
        if (Logging.isDebugMode()) {
            final String message = "Unable to find Weapon Proficiency in Rules Data:" + aString;
            Logging.debugPrint(message);
        }
    }
    return wp;
}
Also used : WeaponProf(pcgen.core.WeaponProf)

Example 50 with WeaponProf

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

the class PCGVer2Creator method appendDeityLine.

/*
	 * ###############################################################
	 * Character Deity/Domain methods
	 * ###############################################################
	 */
private void appendDeityLine(StringBuilder buffer) {
    if (charDisplay.getDeity() != null) {
        final Deity aDeity = charDisplay.getDeity();
        buffer.append(IOConstants.TAG_DEITY).append(':');
        buffer.append(EntityEncoder.encode(aDeity.getKeyName()));
        /*
			 * currently unused information
			 *
			 * author: Thomas Behr 09-09-02
			 */
        buffer.append('|');
        buffer.append(IOConstants.TAG_DEITYDOMAINS).append(':');
        buffer.append('[');
        String del = Constants.EMPTY_STRING;
        for (CDOMReference<Domain> ref : aDeity.getSafeListMods(Deity.DOMAINLIST)) {
            for (Domain d : ref.getContainedObjects()) {
                buffer.append(del);
                buffer.append(IOConstants.TAG_DOMAIN).append(':');
                buffer.append(EntityEncoder.encode(d.getKeyName()));
                //$NON-NLS-1$
                del = "|";
            }
        }
        buffer.append(']');
        buffer.append('|');
        buffer.append(IOConstants.TAG_ALIGNALLOW).append(':');
        //TODO Need to clean this up?
        for (final Description desc : aDeity.getSafeListFor(ListKey.DESCRIPTION)) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_DESC).append(':');
            buffer.append(desc.getPCCText());
        }
        buffer.append('|');
        buffer.append(IOConstants.TAG_DEITYFAVWEAP).append(':');
        buffer.append('[');
        List<CDOMReference<WeaponProf>> dwp = aDeity.getListFor(ListKey.DEITYWEAPON);
        if (dwp != null) {
            del = Constants.EMPTY_STRING;
            for (CDOMReference<WeaponProf> ref : dwp) {
                buffer.append(del);
                buffer.append(IOConstants.TAG_WEAPON).append(':');
                buffer.append(EntityEncoder.encode(ref.getLSTformat(false)));
                //$NON-NLS-1$
                del = "|";
            }
        }
        buffer.append(']');
        buffer.append('|');
        buffer.append(IOConstants.TAG_DEITYALIGN).append(':');
        CDOMSingleRef<PCAlignment> al = aDeity.get(ObjectKey.ALIGNMENT);
        if (al != null) {
            buffer.append(al.getLSTformat(false));
        }
        buffer.append(IOConstants.LINE_SEP);
    }
}
Also used : Deity(pcgen.core.Deity) PCAlignment(pcgen.core.PCAlignment) Description(pcgen.core.Description) WeaponProf(pcgen.core.WeaponProf) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference)

Aggregations

WeaponProf (pcgen.core.WeaponProf)56 StringTokenizer (java.util.StringTokenizer)10 Test (org.junit.Test)10 Equipment (pcgen.core.Equipment)10 CDOMReference (pcgen.cdom.base.CDOMReference)6 ArrayList (java.util.ArrayList)5 CDOMObject (pcgen.cdom.base.CDOMObject)5 Deity (pcgen.core.Deity)5 ArmorProf (pcgen.core.ArmorProf)4 PCTemplate (pcgen.core.PCTemplate)4 ShieldProf (pcgen.core.ShieldProf)4 HashSet (java.util.HashSet)3 ChangeProf (pcgen.cdom.content.ChangeProf)3 WeaponProfProvider (pcgen.cdom.helper.WeaponProfProvider)3 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)3 PCClass (pcgen.core.PCClass)3 Race (pcgen.core.Race)3 Type (pcgen.cdom.enumeration.Type)2 EquipmentHead (pcgen.cdom.inst.EquipmentHead)2 CDOMGroupRef (pcgen.cdom.reference.CDOMGroupRef)2