use of pcgen.cdom.reference.Qualifier in project pcgen by PCGen.
the class LoadValidator method buildCategoryMap.
private void buildCategoryMap() {
categoryMap = new DoubleKeyMapToList<>();
for (Campaign c : campaignList) {
for (Qualifier q : c.getSafeListFor(ListKey.FORWARDREF)) {
Class<? extends Loadable> qcl = q.getQualifiedClass();
if (CATEGORIZED_CLASS.isAssignableFrom(qcl)) {
CDOMSingleRef<?> ref = q.getQualifiedReference();
String cat = ((CDOMTransparentCategorizedSingleRef<?>) ref).getLSTCategory();
categoryMap.addToListFor(qcl, cat, ref.getLSTformat(false));
}
}
}
}
use of pcgen.cdom.reference.Qualifier in project pcgen by PCGen.
the class QualifyToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<Qualifier> changes = context.getObjectContext().getListChanges(obj, ListKey.QUALIFY);
if (changes == null || changes.isEmpty()) {
return null;
}
Collection<Qualifier> quals = changes.getAdded();
HashMapToList<String, CDOMSingleRef<?>> map = new HashMapToList<>();
for (Qualifier qual : quals) {
Class<? extends Loadable> cl = qual.getQualifiedClass();
String s = StringPClassUtil.getStringFor(cl);
CDOMSingleRef<?> ref = qual.getQualifiedReference();
String key = s;
if (ref instanceof CategorizedCDOMReference) {
Category<?> cat = ((CategorizedCDOMReference<?>) ref).getCDOMCategory();
key += '=' + cat.getKeyName();
}
map.addToListFor(key, ref);
}
Set<CDOMSingleRef<?>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
Set<String> returnSet = new TreeSet<>();
for (String key : map.getKeySet()) {
set.clear();
set.addAll(map.getListFor(key));
StringBuilder sb = new StringBuilder();
sb.append(key).append(Constants.PIPE).append(ReferenceUtilities.joinLstFormat(set, Constants.PIPE));
returnSet.add(sb.toString());
}
return returnSet.toArray(new String[returnSet.size()]);
}
use of pcgen.cdom.reference.Qualifier in project pcgen by PCGen.
the class ForwardRefToken method unparse.
@Override
public String[] unparse(LoadContext context, Campaign obj) {
Changes<Qualifier> changes = context.getObjectContext().getListChanges(obj, ListKey.FORWARDREF);
if (changes == null || changes.isEmpty()) {
return null;
}
Collection<Qualifier> quals = changes.getAdded();
HashMapToList<String, CDOMSingleRef<?>> map = new HashMapToList<>();
for (Qualifier qual : quals) {
Class<? extends Loadable> cl = qual.getQualifiedClass();
String s = StringPClassUtil.getStringFor(cl);
CDOMSingleRef<?> ref = qual.getQualifiedReference();
String key = s;
if (ref instanceof CategorizedCDOMReference) {
String cat = ((CategorizedCDOMReference<?>) ref).getLSTCategory();
if (Constants.FEAT_CATEGORY.equals(cat)) {
key = Constants.FEAT_CATEGORY;
} else {
key += '=' + cat;
}
}
map.addToListFor(key, ref);
}
Set<CDOMSingleRef<?>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
Set<String> returnSet = new TreeSet<>();
for (String key : map.getKeySet()) {
set.clear();
set.addAll(map.getListFor(key));
StringBuilder sb = new StringBuilder();
sb.append(key).append(Constants.PIPE).append(ReferenceUtilities.joinLstFormat(set, Constants.COMMA));
returnSet.add(sb.toString());
}
return returnSet.toArray(new String[returnSet.size()]);
}
use of pcgen.cdom.reference.Qualifier in project pcgen by PCGen.
the class ForwardRefToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Campaign obj, String value) {
int pipeLoc = value.indexOf('|');
if (pipeLoc == -1) {
return new ParseResult.Fail(getTokenName() + " requires at least two arguments, " + "ReferenceType and Key: " + value, context);
}
if (value.lastIndexOf('|') != pipeLoc) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage(getTokenName() + " requires at only two pipe separated arguments, " + "ReferenceType and Keys: " + value);
cpr.addErrorMessage(" keys are comma separated");
return cpr;
}
String firstToken = value.substring(0, pipeLoc);
ReferenceManufacturer<? extends Loadable> rm = context.getManufacturer(firstToken);
if (rm == null) {
return new ParseResult.Fail(getTokenName() + " unable to generate manufacturer for type: " + value, context);
}
String rest = value.substring(pipeLoc + 1);
if (hasIllegalSeparator(',', rest)) {
return new ParseResult.Fail(getTokenName() + " keys are comma separated", context);
}
StringTokenizer st = new StringTokenizer(rest, Constants.COMMA);
while (st.hasMoreTokens()) {
CDOMSingleRef<? extends Loadable> ref = rm.getReference(st.nextToken());
context.getObjectContext().addToList(obj, ListKey.FORWARDREF, new Qualifier(rm.getReferenceClass(), ref));
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.reference.Qualifier in project pcgen by PCGen.
the class PCClassTest method testBypassClassPrereqs.
/**
* Test the interaction of prerequisites on PCClasses and bonuses and the
* Bypass Class Prereqs flag.
* @throws Exception
*/
public void testBypassClassPrereqs() throws Exception {
LoadContext context = Globals.getContext();
// Setup class with prereqs and var based abilities with prereqs.
final PreVariableParser parser = new PreVariableParser();
final Prerequisite aPrereq = parser.parse("VARGTEQ", "Foo,1", false, false);
final GameMode gameMode = SettingsHandler.getGame();
RuleCheck aClassPreRule = gameMode.getModeContext().getReferenceContext().silentlyGetConstructedCDOMObject(RuleCheck.class, "CLASSPRE");
if (aClassPreRule == null) {
aClassPreRule = new RuleCheck();
aClassPreRule.setName("CLASSPRE");
gameMode.getModeContext().getReferenceContext().importObject(aClassPreRule);
}
aClassPreRule.setDefault(false);
final PCClass aPrClass = new PCClass();
aPrClass.setName("PreReqClass");
aPrClass.put(StringKey.KEY_NAME, "KEY_PreReqClass");
final BonusObj aBonus = Bonus.newBonus(context, "MISC|SR|10|PREVARGTEQ:Foo,2");
if (aBonus != null) {
aPrClass.addToListFor(ListKey.BONUS, aBonus);
}
aPrClass.addPrerequisite(aPrereq);
final PCClass aQClass = new PCClass();
aQClass.setName("QualClass");
aQClass.put(StringKey.KEY_NAME, "KEY_QualClass");
CDOMDirectSingleRef<PCClass> ref = CDOMDirectSingleRef.getRef(aPrClass);
aQClass.addToListFor(ListKey.QUALIFY, new Qualifier(PCClass.class, ref));
//aQClass.setQualifyString("KEY_PreReqClass|PreReqVar");
final PCClass aNqClass = new PCClass();
aNqClass.setName("NonQualClass");
aNqClass.put(StringKey.KEY_NAME, "KEY_NonQualClass");
aNqClass.put(VariableKey.getConstant("Foo"), FormulaFactory.ONE);
aNqClass.getOriginalClassLevel(2).put(VariableKey.getConstant("Foo"), FormulaFactory.getFormulaFor(2));
// Setup character without prereqs
final PlayerCharacter character = getCharacter();
// Test no prereqs and no bypass fails class and var
assertFalse("PC with no prereqs should fail class qual test.", aPrClass.qualifies(character, aPrClass));
assertEquals("PC with no prereqs should fail var qual test.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
// Test no prereqs and bypass passes class and fails var
aClassPreRule.setDefault(true);
assertTrue("PC with no prereqs should pass class qual test when bypassing prereqs is on.", aPrClass.qualifies(character, aPrClass));
assertEquals("PC with no prereqs should fail var qual test when bypass prereqs is on.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
// Test prereqs and bypass pass class and var
character.incrementClassLevel(1, aNqClass);
assertTrue("PC with prereqs and bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
character.incrementClassLevel(1, aNqClass);
assertEquals("PC with prereqs and bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
// Test prereqs and no bypass passes class and var
aClassPreRule.setDefault(false);
assertTrue("PC with prereqs and no bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
assertEquals("PC with prereqs and no bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
}
Aggregations