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();
}
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());
}
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;
}
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;
}
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;
}
Aggregations