use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsTokenTest method testUnparseNonExclusive.
@Test
public void testUnparseNonExclusive() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("NONEXCLUSIVE", Skill.class, getAllRef(), ObjectKey.EXCLUSIVE, Boolean.FALSE);
omr.returnIncludesNulls(true);
refs.add(omr);
ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
primaryProf.addToListFor(ListKey.ADD, tc);
tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "NONEXCLUSIVE");
}
use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsTokenTest method testUnparseTrained.
@Test
public void testUnparseTrained() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("TRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, Boolean.FALSE);
omr.returnIncludesNulls(true);
refs.add(omr);
ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
primaryProf.addToListFor(ListKey.ADD, tc);
tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "TRAINED");
}
use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsTokenTest method testUnparseSingleRanked.
@Test
public void testUnparseSingleRanked() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
addSingleRef(refs, "TestWP1");
ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
primaryProf.addToListFor(ListKey.ADD, tc);
tc.setChoiceActor(new ClassSkillChoiceActor(fighter, 3));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "TestWP1,AUTORANK=3");
}
use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsLevelToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClassLevel obj) {
Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.ADD);
Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
if (addedItems == null || addedItems.isEmpty()) {
// Zero indicates no Token
return null;
}
List<String> addStrings = new ArrayList<>();
for (TransitionChoice<?> container : addedItems) {
SelectableSet<?> cs = container.getChoices();
if (getTokenName().equals(cs.getName()) && SKILL_CLASS.equals(cs.getChoiceClass())) {
Formula f = container.getCount();
if (f == null) {
context.addWriteMessage("Unable to find " + getFullName() + " Count");
return null;
}
if (f.isStatic() && f.resolveStatic().doubleValue() <= 0) {
context.addWriteMessage("Count in " + getFullName() + " must be > 0");
return null;
}
if (!cs.getGroupingState().isValid()) {
context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + cs.getLSTformat());
return null;
}
StringBuilder sb = new StringBuilder();
if (!FormulaFactory.ONE.equals(f)) {
sb.append(f).append(Constants.PIPE);
}
sb.append(cs.getLSTformat());
ClassSkillChoiceActor actor = (ClassSkillChoiceActor) container.getChoiceActor();
Integer rank = actor.getApplyRank();
if (rank != null) {
sb.append(Constants.COMMA).append("AUTORANK=" + rank);
}
addStrings.add(sb.toString());
}
}
return addStrings.toArray(new String[addStrings.size()]);
}
use of pcgen.cdom.helper.ClassSkillChoiceActor in project pcgen by PCGen.
the class ClassSkillsToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClass obj) {
Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.ADD);
Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
if (addedItems == null || addedItems.isEmpty()) {
// Zero indicates no Token
return null;
}
List<String> addStrings = new ArrayList<>();
for (TransitionChoice<?> container : addedItems) {
SelectableSet<?> cs = container.getChoices();
if (getTokenName().equals(cs.getName()) && SKILL_CLASS.equals(cs.getChoiceClass())) {
Formula f = container.getCount();
if (f == null) {
context.addWriteMessage("Unable to find " + getFullName() + " Count");
return null;
}
if (f.isStatic() && f.resolveStatic().doubleValue() <= 0) {
context.addWriteMessage("Count in " + getFullName() + " must be > 0");
return null;
}
if (!cs.getGroupingState().isValid()) {
context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + cs.getLSTformat());
return null;
}
StringBuilder sb = new StringBuilder();
if (!FormulaFactory.ONE.equals(f)) {
sb.append(f).append(Constants.PIPE);
}
sb.append(cs.getLSTformat());
ClassSkillChoiceActor actor = (ClassSkillChoiceActor) container.getChoiceActor();
Integer rank = actor.getApplyRank();
if (rank != null) {
sb.append(Constants.COMMA).append("AUTORANK=" + rank);
}
addStrings.add(sb.toString());
}
}
return addStrings.toArray(new String[addStrings.size()]);
}
Aggregations