use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class DeityWeaponProfFacetTest 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 DeityWeaponProfFacetTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
Deity cdo1 = new Deity();
cdo1.setName("Deity1");
Deity cdo2 = new Deity();
cdo2.setName("Deity2");
WeaponProf st1 = new WeaponProf();
st1.setName("Prof1");
WeaponProf st2 = new WeaponProf();
st1.setName("Prof2");
cdo1.addToListFor(ListKey.DEITYWEAPON, CDOMDirectSingleRef.getRef(st1));
cdo2.addToListFor(ListKey.DEITYWEAPON, CDOMDirectSingleRef.getRef(st2));
source = new Deity[] { cdo1, cdo2 };
target = new WeaponProf[] { st1, st2 };
}
use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class TypeTokenTest method setUp.
@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
super.setUp();
TokenRegistration.register(TYPE_TOKEN);
Type med = Type.getConstant("Medium");
WeaponProf pls = primaryContext.getReferenceContext().constructCDOMObject(WeaponProf.class, "Longsword");
pls.addToListFor(ListKey.TYPE, med);
WeaponProf sls = secondaryContext.getReferenceContext().constructCDOMObject(WeaponProf.class, "Longsword");
sls.addToListFor(ListKey.TYPE, med);
}
use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class ChangeprofLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<ChangeProf> changes = context.getObjectContext().getListChanges(obj, ListKey.CHANGEPROF);
Collection<ChangeProf> added = changes.getAdded();
if (added == null || added.isEmpty()) {
// Zero indicates no Token
return null;
}
HashMapToList<CDOMGroupRef<WeaponProf>, CDOMReference<WeaponProf>> m = new HashMapToList<>();
for (ChangeProf cp : added) {
CDOMReference<WeaponProf> source = cp.getSource();
CDOMGroupRef<WeaponProf> result = cp.getResult();
m.addToListFor(result, source);
}
SortedSet<CDOMReference<WeaponProf>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
Set<String> returnSet = new TreeSet<>();
for (CDOMGroupRef<WeaponProf> result : m.getKeySet()) {
StringBuilder sb = new StringBuilder();
boolean needComma = false;
set.clear();
set.addAll(m.getListFor(result));
for (CDOMReference<WeaponProf> source : set) {
if (needComma) {
sb.append(Constants.COMMA);
}
needComma = true;
String sourceLst = source.getLSTformat(false);
if (sourceLst.startsWith(Constants.LST_TYPE_EQUAL)) {
sb.append(Constants.LST_TYPE_DOT);
sb.append(sourceLst.substring(5));
} else {
sb.append(sourceLst);
}
}
sb.append(Constants.EQUALS).append(result.getLSTformat(false).substring(5));
returnSet.add(sb.toString());
}
return new String[] { StringUtil.join(returnSet, Constants.PIPE) };
}
use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class ChangeprofLst method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
// value should be of the format:
// Name1,TYPE.type1,Name3=Prof1|Name4,Name5=Prof2
//
// e.g.: TYPE.Hammer,Hand Axe=Simple|Urgosh,Waraxe=Martial
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
List<ChangeProf> list = new ArrayList<>();
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
int equalLoc = tokText.indexOf('=');
if (equalLoc < 0) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": No = found. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
} else if (equalLoc != tokText.lastIndexOf('=')) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": Two = found. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
}
String newType = tokText.substring(equalLoc + 1);
if (newType.isEmpty()) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": Empty Result Type. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
}
if (newType.indexOf(Constants.DOT) != -1) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": Invalid (Compound) Result Type: cannot contain a period (.) " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
}
String[] val = { newType };
CDOMGroupRef<WeaponProf> newTypeProf = context.getReferenceContext().getCDOMTypeReference(WEAPONPROF_CLASS, val);
String profs = tokText.substring(0, equalLoc);
if (profs.isEmpty()) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": Empty Source Prof. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
}
StringTokenizer pTok = new StringTokenizer(profs, Constants.COMMA);
while (pTok.hasMoreTokens()) {
CDOMReference<WeaponProf> wp = TokenUtilities.getTypeOrPrimitive(context, WEAPONPROF_CLASS, pTok.nextToken());
list.add(new ChangeProf(wp, newTypeProf));
}
}
for (ChangeProf cp : list) {
context.getObjectContext().addToList(obj, ListKey.CHANGEPROF, cp);
}
return ParseResult.SUCCESS;
}
Aggregations