use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.
the class AddClassSkillsTest method testGetChoicesListWithClassSkill.
/**
* Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
*/
@Test
public void testGetChoicesListWithClassSkill() {
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
String classPCCText = "CLASS:Cleric HD:8 TYPE:Base.PC ABB:Clr\n" + "CLASS:Cleric STARTSKILLPTS:2 CSKILL:KEY_Knowledge (Dungeoneering)";
PCClass po;
try {
po = parsePCClassText(classPCCText, source);
} catch (PersistenceLayerException e) {
throw new UnreachableError(e);
}
getCharacter().incrementClassLevel(1, po, false);
PCTemplate pct = new PCTemplate();
Skill bluff = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, "KEY_Bluff");
pct.addToListFor(ListKey.CSKILL, CDOMDirectSingleRef.getRef(bluff));
getCharacter().addTemplate(pct);
Globals.getContext().unconditionallyProcess(po, "ADD", "CLASSSKILLS|2|KEY_Bluff,KEY_Listen,KEY_Knowledge (Arcana)");
assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
List<PersistentTransitionChoice<?>> choiceList = po.getListFor(ListKey.ADD);
assertEquals(1, choiceList.size());
TransitionChoice<?> choice = choiceList.get(0);
Collection<?> choiceSet = choice.getChoices().getSet(getCharacter());
assertEquals(3, choiceSet.size());
Set<Object> limitedSet = new HashSet<>();
ClassSkillChoiceActor csca = new ClassSkillChoiceActor(po, 0);
for (Object sc : choiceSet) {
if (csca.allow((Skill) sc, getCharacter(), true)) {
limitedSet.add(sc);
}
}
assertEquals(2, limitedSet.size());
assertEquals(2, choice.getCount().resolve(getCharacter(), ""));
List<String> choiceStrings = new ArrayList<>();
for (Object o : limitedSet) {
choiceStrings.add(o.toString());
}
assertTrue(choiceStrings.contains("Listen"));
assertTrue(choiceStrings.contains("Knowledge (Arcana)"));
}
use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.
the class AddClassSkillsTest method testBasicChoicesList.
/**
* Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
*/
@Test
public void testBasicChoicesList() {
PCClass po = new PCClass();
PlayerCharacter pc = getCharacter();
Globals.getContext().unconditionallyProcess(po, "ADD", "CLASSSKILLS|2|KEY_Bluff,KEY_Listen,KEY_Move Silently");
assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
List<PersistentTransitionChoice<?>> choiceList = po.getListFor(ListKey.ADD);
assertEquals(1, choiceList.size());
TransitionChoice<?> choice = choiceList.get(0);
Collection<?> choiceSet = choice.getChoices().getSet(pc);
assertEquals(3, choiceSet.size());
assertEquals(2, choice.getCount().resolve(pc, ""));
List<String> choiceStrings = new ArrayList<>();
for (Object o : choiceSet) {
choiceStrings.add(o.toString());
}
assertTrue(choiceStrings.contains("Bluff"));
assertTrue(choiceStrings.contains("Listen"));
assertTrue(choiceStrings.contains("Move Silently"));
}
use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.
the class AbilityToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject 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()) && CAT_ABILITY_SELECTION_CLASS.equals(cs.getChoiceClass())) {
AbilityChoiceSet ascs = (AbilityChoiceSet) cs;
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(ascs.getCategory().getLSTformat(false));
sb.append(Constants.PIPE);
sb.append(ascs.getNature());
sb.append(Constants.PIPE);
if (container.allowsStacking()) {
sb.append("STACKS");
Integer stackLimit = container.getStackLimit();
if (stackLimit != null) {
if (stackLimit.intValue() <= 0) {
context.addWriteMessage("Stack Limit in " + getFullName() + " must be > 0");
return null;
}
sb.append(Constants.EQUALS);
sb.append(stackLimit.intValue());
}
sb.append(Constants.COMMA);
}
sb.append(cs.getLSTformat());
addStrings.add(sb.toString());
}
}
return addStrings.toArray(new String[addStrings.size()]);
}
use of pcgen.cdom.base.PersistentTransitionChoice 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.base.PersistentTransitionChoice 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