Search in sources :

Example 21 with WeaponProf

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

the class WeaponProfTokenTest method testUnparseIndivAll.

@Test
public void testUnparseIndivAll() throws PersistenceLayerException {
    WeaponProfProvider wpp = new WeaponProfProvider();
    wpp.addWeaponProfAll(primaryContext.getReferenceContext().getCDOMAllReference(WeaponProf.class));
    WeaponProf wp1 = construct(primaryContext, "TestWP1");
    CDOMSingleRef<WeaponProf> ref = CDOMDirectSingleRef.getRef(wp1);
    wpp.addWeaponProf(ref);
    primaryProf.addToListFor(ListKey.WEAPONPROF, wpp);
    assertBadUnparse();
}
Also used : WeaponProf(pcgen.core.WeaponProf) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) Test(org.junit.Test)

Example 22 with WeaponProf

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

the class DeityWeapTokenTest method testUnparseSingle.

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

Example 23 with WeaponProf

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

the class DeityweapToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Deity deity, String value) {
    boolean first = true;
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<WeaponProf> ref;
        if (Constants.LST_DOT_CLEAR.equals(token)) {
            if (!first) {
                return new ParseResult.Fail("  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
            }
            context.getObjectContext().removeList(deity, ListKey.DEITYWEAPON);
        } else {
            if (Constants.LST_ALL.equalsIgnoreCase(token) || Constants.LST_ANY.equalsIgnoreCase(token)) {
                foundAny = true;
                ref = context.getReferenceContext().getCDOMAllReference(WEAPONPROF_CLASS);
            } else {
                foundOther = true;
                ref = context.getReferenceContext().getCDOMReference(WEAPONPROF_CLASS, token);
            }
            context.getObjectContext().addToList(deity, ListKey.DEITYWEAPON, ref);
        }
        first = false;
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) WeaponProf(pcgen.core.WeaponProf)

Example 24 with WeaponProf

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

the class BonusWeaponProfFacetTest method getObject.

@Override
protected WeaponProf getObject() {
    WeaponProf wp = new WeaponProf();
    wp.setName("WP" + n++);
    return wp;
}
Also used : WeaponProf(pcgen.core.WeaponProf)

Example 25 with WeaponProf

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

the class ProficiencyToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail("Equipment Token PROFICIENCY syntax " + "without a Subtoken is invalid: PROFICIENCY:" + value, context);
    }
    if (pipeLoc != value.lastIndexOf(Constants.PIPE)) {
        return new ParseResult.Fail(getTokenName() + " expecting only one '|', " + "format is: SubToken|ProfName value was: " + value, context);
    }
    String subtoken = value.substring(0, pipeLoc);
    String prof = value.substring(pipeLoc + 1);
    if (prof == null || prof.isEmpty()) {
        return new ParseResult.Fail("PROFICIENCY cannot have " + "empty second argument: " + value, context);
    }
    if (subtoken.equals("WEAPON")) {
        // This can be reactivated if .CLEAR is implemented, to allow .MOD to override the proficiency			
        //			if (context.getObjectContext().getObject(eq, ObjectKey.WEAPON_PROF) != null)
        //			{
        //				return new ParseResult.Fail(
        //					"Only one PROFICIENCY:WEAPON is allowed per item. Token was PROFICIENCY:"
        //						+ value, context);
        //			}
        CDOMSingleRef<WeaponProf> wp = context.getReferenceContext().getCDOMReference(WeaponProf.class, prof);
        context.getObjectContext().put(eq, ObjectKey.WEAPON_PROF, wp);
    } else if (subtoken.equals("ARMOR")) {
        //			if (context.getObjectContext().getObject(eq, ObjectKey.ARMOR_PROF) != null)
        //			{
        //				return new ParseResult.Fail(
        //					"Only one PROFICIENCY:ARMOR is allowed per item. Token was PROFICIENCY:"
        //						+ value, context);
        //			}
        CDOMSingleRef<ArmorProf> wp = context.getReferenceContext().getCDOMReference(ArmorProf.class, prof);
        context.getObjectContext().put(eq, ObjectKey.ARMOR_PROF, wp);
    } else if (subtoken.equals("SHIELD")) {
        //			if (context.getObjectContext().getObject(eq, ObjectKey.SHIELD_PROF) != null)
        //			{
        //				return new ParseResult.Fail(
        //					"Only one PROFICIENCY:SHIELD is allowed per item. Token was PROFICIENCY:"
        //						+ value, context);
        //			}
        CDOMSingleRef<ShieldProf> wp = context.getReferenceContext().getCDOMReference(ShieldProf.class, prof);
        context.getObjectContext().put(eq, ObjectKey.SHIELD_PROF, wp);
    } else {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Unknown Subtoken for PROFICIENCY: " + subtoken);
        cpr.addErrorMessage("  Subtoken must be " + "WEAPON, ARMOR or SHIELD");
        return cpr;
    }
    return ParseResult.SUCCESS;
}
Also used : ShieldProf(pcgen.core.ShieldProf) WeaponProf(pcgen.core.WeaponProf) ArmorProf(pcgen.core.ArmorProf) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

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