use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.
the class PCGVer2Parser method parseWeaponProficienciesLine.
/*
* ###############################################################
* Character Weapon proficiencies methods
* ###############################################################
*/
private void parseWeaponProficienciesLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String message = "Illegal Weapon proficiencies line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
warnings.add(message);
return;
}
CDOMObject source = null;
boolean hadSource = false;
for (PCGElement element : tokens.getElements()) {
if (IOConstants.TAG_SOURCE.equals(element.getName())) {
hadSource = true;
String type = Constants.EMPTY_STRING;
String key = Constants.EMPTY_STRING;
for (final PCGElement child : element.getChildren()) {
final String tag = child.getName();
if (IOConstants.TAG_TYPE.equals(tag)) {
type = child.getText().toUpperCase();
} else if (IOConstants.TAG_NAME.equals(tag)) {
key = child.getText();
}
}
if (Constants.EMPTY_STRING.equals(type) || Constants.EMPTY_STRING.equals(key)) {
final String message = "Illegal Weapon proficiencies line ignored: " + line;
warnings.add(message);
return;
}
if (IOConstants.TAG_RACE.equals(type)) {
source = thePC.getRace();
} else if (TAG_PCTEMPLATE.equals(type)) {
PCTemplate template = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, key);
if (thePC.hasTemplate(template)) {
source = template;
} else {
warnings.add("PC does not have Template: " + key);
}
} else if (IOConstants.TAG_PCCLASS.equals(type)) {
source = thePC.getClassKeyed(key);
}
if (source == null) {
final String message = "Invalid source specification: " + line;
warnings.add(message);
}
break;
}
}
final PCGElement element = tokens.getElements().get(0);
boolean processed = false;
if (source != null) {
List<PersistentTransitionChoice<?>> adds = source.getListFor(ListKey.ADD);
if (adds != null) {
for (PersistentTransitionChoice<?> ptc : adds) {
if (ptc.getChoiceClass().equals(WeaponProf.class)) {
for (PCGElement child : element.getChildren()) {
WeaponProf wp = getWeaponProf(child.getText());
Set c = Collections.singleton(wp);
ptc.act(c, source, thePC);
}
processed = true;
break;
}
}
}
}
if (hadSource && !processed) {
final String message = "Unable to apply WeaponProfs: " + line;
warnings.add(message);
}
}
use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.
the class KitLevelAbility method doApplication.
private boolean doApplication(PlayerCharacter aPC) {
PCClass theClass = theClassName.get();
PCClass classKeyed = aPC.getClassKeyed(theClass.getKeyName());
if (classKeyed == null) {
//Error?
}
//Look for ADD in class
List<PersistentTransitionChoice<?>> adds = theClass.getListFor(ListKey.ADD);
if (adds == null) {
//Error?
}
for (PersistentTransitionChoice<?> ch : adds) {
if (add.equals(ch)) {
process(aPC, classKeyed, ch);
return true;
}
}
return false;
}
use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.
the class TemplateToken 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 (PCTEMPLATE_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;
}
StringBuilder sb = new StringBuilder();
if (!FormulaFactory.ONE.equals(f)) {
sb.append(f).append(Constants.PIPE);
}
sb.append(cs.getLSTformat());
addStrings.add(sb.toString());
// assoc.getAssociation(AssociationKey.CHOICE_MAXCOUNT);
}
}
return addStrings.toArray(new String[addStrings.size()]);
}
use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.
the class LanguageToken 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 (cs.getName().equals(getTokenName()) && LANGUAGE_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());
addStrings.add(sb.toString());
// assoc.getAssociation(AssociationKey.CHOICE_MAXCOUNT);
}
}
return addStrings.toArray(new String[addStrings.size()]);
}
use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.
the class AddClassSkillsTest method testGetChoicesListWithParens.
/**
* Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
*/
@Test
public void testGetChoicesListWithParens() {
PCClass po = new PCClass();
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());
assertEquals(2, choice.getCount().resolve(getCharacter(), ""));
List<String> choiceStrings = new ArrayList<>();
for (Object o : choiceSet) {
choiceStrings.add(o.toString());
}
assertTrue(choiceStrings.contains("Bluff"));
assertTrue(choiceStrings.contains("Listen"));
assertTrue(choiceStrings.contains("Knowledge (Arcana)"));
}
Aggregations