use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.
the class PCGVer2Creator method writeAbilityToBuffer.
private void writeAbilityToBuffer(StringBuilder buffer, CNAbility cna) {
Category<Ability> cat = cna.getAbilityCategory();
Nature nature = cna.getNature();
Ability ability = cna.getAbility();
buffer.append(IOConstants.TAG_ABILITY).append(IOConstants.TAG_END);
buffer.append(EntityEncoder.encode(cat.getKeyName())).append(IOConstants.TAG_SEPARATOR);
buffer.append(IOConstants.TAG_TYPE).append(IOConstants.TAG_END);
buffer.append(EntityEncoder.encode(nature.toString())).append(IOConstants.TAG_SEPARATOR);
buffer.append(IOConstants.TAG_CATEGORY).append(IOConstants.TAG_END);
buffer.append(EntityEncoder.encode(ability.getCategory())).append(IOConstants.TAG_SEPARATOR);
buffer.append(IOConstants.TAG_MAPKEY).append(IOConstants.TAG_END);
buffer.append(EntityEncoder.encode(ability.getKeyName())).append(IOConstants.TAG_SEPARATOR);
if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
buffer.append(IOConstants.TAG_APPLIEDTO).append(IOConstants.TAG_END);
List<String> assocList = thePC.getAssociationList(cna);
boolean first = true;
for (String assoc : assocList) {
if (!first) {
buffer.append(Constants.COMMA);
}
first = false;
buffer.append(EntityEncoder.encode(assoc));
}
buffer.append(IOConstants.TAG_SEPARATOR);
}
buffer.append(IOConstants.TAG_TYPE).append(IOConstants.TAG_END);
buffer.append(EntityEncoder.encode(ability.getType()));
for (final BonusObj save : thePC.getSaveableBonusList(ability)) {
buffer.append('|');
buffer.append(IOConstants.TAG_SAVE).append(':');
buffer.append(EntityEncoder.encode("BONUS|" + save));
}
for (final Description desc : ability.getSafeListFor(ListKey.DESCRIPTION)) {
buffer.append(Constants.PIPE);
buffer.append(IOConstants.TAG_DESC).append(':');
buffer.append(EntityEncoder.encode(desc.getPCCText()));
}
buffer.append(IOConstants.LINE_SEP);
}
use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.
the class CharacterFacadeImpl method getAbilityNature.
/**
* @see pcgen.core.facade.CharacterFacade#getAbilityNature(pcgen.core.facade.AbilityFacade)
*/
@Override
public Nature getAbilityNature(AbilityFacade ability) {
if (ability == null || !(ability instanceof Ability)) {
return null;
}
/*
* TODO This is making a somewhat DRASTIC assumption that ANY Ability
* Category is appropriate. Unfortunately, the point at which this
* method is called from the UI it is unclear to the untrained eye how
* to get the category.
*/
List<CNAbility> cnas = theCharacter.getMatchingCNAbilities((Ability) ability);
Nature nature = null;
for (CNAbility cna : cnas) {
nature = Nature.getBestNature(nature, cna.getNature());
}
return nature;
}
use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.
the class PlayerCharacter method processAbilityList.
private void processAbilityList(CDOMObject cdo, CDOMReference<AbilityList> ref) {
Collection<CDOMReference<Ability>> mods = cdo.getListMods(ref);
for (CDOMReference<Ability> objref : mods) {
Collection<Ability> objs = objref.getContainedObjects();
Collection<AssociatedPrereqObject> assoc = cdo.getListAssociations(ref, objref);
for (Ability ab : objs) {
if (ab == null) {
Logging.log(Logging.LST_ERROR, "Missing object referenced in the ability list for '" + cdo + "' list is " + ref + ". Source " + cdo.getSourceURI());
continue;
}
for (AssociatedPrereqObject apo : assoc) {
Nature nature = apo.getAssociation(AssociationKey.NATURE);
CDOMSingleRef<AbilityCategory> acRef = apo.getAssociation(AssociationKey.CATEGORY);
AbilityCategory cat = acRef.get();
if (ab.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
List<String> choices = apo.getAssociation(AssociationKey.ASSOC_CHOICES);
if (choices == null) {
//CHOOSE:NOCHOICE can be unconditionally applied (must be STACK:YES)
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), "");
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
} else {
for (final String choice : choices) {
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), choice);
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
}
}
} else {
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab));
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
}
}
}
}
cabFacet.update(id);
}
use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.
the class CNAbilitySelection method getAbilitySelectionFromPersistentFormat.
public static CNAbilitySelection getAbilitySelectionFromPersistentFormat(String persistentFormat) {
StringTokenizer st = new StringTokenizer(persistentFormat, Constants.PIPE);
String catString = st.nextToken();
if (!catString.startsWith("CATEGORY=")) {
throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must start with CATEGORY=, found: " + persistentFormat);
}
String cat = catString.substring(9);
AbilityCategory ac = SettingsHandler.getGame().getAbilityCategory(cat);
if (ac == null) {
throw new IllegalArgumentException("Category in getAbilitySelectionFromPersistentFormat " + "must exist found: " + cat);
}
String natureString = st.nextToken();
if (!natureString.startsWith("NATURE=")) {
throw new IllegalArgumentException("Second argument in String in getAbilitySelectionFromPersistentFormat " + "must start with NATURE=, found: " + persistentFormat);
}
String natString = natureString.substring(7);
Nature nat = Nature.valueOf(natString);
String ab = st.nextToken();
Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, ac, ab);
if (a == null) {
throw new IllegalArgumentException("Third argument in String in getAbilitySelectionFromPersistentFormat " + "must be an Ability, but it was not found: " + persistentFormat);
}
String sel = null;
if (st.hasMoreTokens()) {
/*
* No need to check for MULT:YES/NO here, as that is checked
* implicitly in the construction of AbilitySelection below
*/
sel = st.nextToken();
} else if (persistentFormat.endsWith(Constants.PIPE)) {
// Handle the StringTokenizer ignoring blank tokens at the end
sel = "";
}
if (st.hasMoreTokens()) {
throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must have 3 or 4 arguments, but found more: " + persistentFormat);
}
CNAbility cna = CNAbilityFactory.getCNAbility(ac, nat, a);
return new CNAbilitySelection(cna, sel);
}
use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.
the class CharacterAbilities method addCategorisedAbility.
/**
* Add the ability to the categorised list held by CharacterAbilities.
* One copy will be added for each choice.
*
* @param cat The AbilityCategory that the ability is being added to.
* @param ability The ability being added.
* @param nature The nature via which the ability is being added.
* @param workingAbilityListMap The map to be adjusted.
*/
private void addCategorisedAbility(CNAbility cna, Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap) {
Ability ability = cna.getAbility();
List<CNAbilitySelection> cas = new ArrayList<>();
Category<Ability> cat = cna.getAbilityCategory();
Nature nature = cna.getNature();
if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
List<String> choices = theCharacter.getAssociationList(cna);
if (choices == null || choices.isEmpty()) {
Logging.errorPrint("Ignoring Ability: " + ability + " (" + cat + " / " + nature + ") that UI has as added to the PC, but it has no associations");
} else {
for (String choice : choices) {
cas.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ability), choice));
}
}
} else {
cas.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ability)));
}
for (CNAbilitySelection sel : cas) {
addElement(workingAbilityListMap, sel);
}
}
Aggregations