use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class Aspect method printAspect.
public static String printAspect(PlayerCharacter pc, AspectName key, List<CNAbility> abilities, boolean printName) {
if (abilities.isEmpty()) {
return "";
}
Ability sampleAbilityObject = abilities.get(0).getAbility();
StringBuilder buff = new StringBuilder(50);
List<Aspect> aspects = sampleAbilityObject.get(MapKey.ASPECT, key);
Aspect aspect = lastPassingAspect(aspects, pc, sampleAbilityObject);
if (aspect != null) {
if (printName) {
buff.append(aspect.getName()).append(": ");
}
buff.append(aspect.getAspectText(pc, abilities));
}
return buff.toString();
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class CNAbilitySelectionUtilities method canCoExist.
public static boolean canCoExist(CNAbilitySelection cnas1, CNAbilitySelection cnas2) {
CNAbility cna = cnas1.getCNAbility();
Ability a = cna.getAbility();
CNAbility ocna = cnas2.getCNAbility();
if (!ocna.getAbilityCategory().getParentCategory().equals(cna.getAbilityCategory().getParentCategory())) {
//This test is only required because Ability only checks key :/
return true;
}
if (!ocna.getAbility().equals(a)) {
//Different abilities, so doesn't matter...
return true;
}
//Same ability here
if (!a.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
//If MULT:NO, then can't coexist...
return false;
}
//MULT:YES here
if (a.getSafe(ObjectKey.STACKS)) {
//Allows stacking, so always true (give or take NUMCHOICES?)
return true;
}
//STACK:NO here
if (cnas1.getSelection().equals(cnas2.getSelection())) {
//enforce STACK:NO
return false;
}
return true;
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class GrantedAbilityFacet method getPoolAbilities.
public Collection<CNAbility> getPoolAbilities(CharID id, Category<Ability> cat) {
List<List<SourcedCNAS>> list = getList(id);
List<CNAbility> returnList = new ArrayList<>();
if (list != null) {
for (List<SourcedCNAS> array : list) {
CNAbility cna = array.get(0).cnas.getCNAbility();
if (cna.getAbilityCategory().equals(cat)) {
returnList.add(cna);
}
}
}
return returnList;
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class PCGVer2Parser method parseVFeatLine.
private void parseVFeatLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String message = "Illegal VFeat line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
warnings.add(message);
return;
}
final Iterator<PCGElement> it = tokens.getElements().iterator();
// the first element defines the Feat key name
if (it.hasNext()) {
final PCGElement element = it.next();
final String abilityKey = EntityEncoder.decode(element.getText());
Ability anAbility = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, abilityKey);
if (anAbility == null) {
final String message = "Could not add vfeat: " + abilityKey;
warnings.add(message);
return;
}
CNAbility cna = CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.VIRTUAL, anAbility);
parseFeatsHandleAppliedToAndSaveTags(it, cna);
thePC.setDirty(true);
}
}
use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.
the class PCGVer2Creator method appendAbilityLines.
/*
* ###############################################################
* Character Ability methods
* ###############################################################
*/
private void appendAbilityLines(StringBuilder buffer) {
ArrayList<AbilityCategory> categories = new ArrayList<>(getGameMode().getAllAbilityCategories());
categories.add(AbilityCategory.LANGBONUS);
Collection<CNAbilitySelection> virtSave = thePC.getSaveAbilities();
categories.sort(new Comparator<AbilityCategory>() {
@Override
public int compare(AbilityCategory a, AbilityCategory b) {
return a.getKeyName().compareTo(b.getKeyName());
}
});
for (final AbilityCategory cat : categories) {
final List<CNAbility> normalAbilitiesToSave = new ArrayList<>(thePC.getPoolAbilities(cat, Nature.NORMAL));
// ABILITY:FEAT|NORMAL|Feat Key|APPLIEDTO:xxx|TYPE:xxx|SAVE:xxx|DESC:xxx
Collections.sort(normalAbilitiesToSave);
for (final CNAbility ability : normalAbilitiesToSave) {
writeAbilityToBuffer(buffer, ability);
}
boolean hasVirt = false;
for (final CNAbilitySelection ability : virtSave) {
CNAbility cnAbility = ability.getCNAbility();
if (cnAbility.getAbilityCategory().equals(cat)) {
//TODO Need to write each CNAbility only once :/
writeAbilityToBuffer(buffer, cnAbility);
hasVirt = true;
}
}
if (!normalAbilitiesToSave.isEmpty() || hasVirt || thePC.getUserPoolBonus(cat) != 0.0) {
buffer.append(IOConstants.TAG_USERPOOL).append(IOConstants.TAG_END);
buffer.append(EntityEncoder.encode(cat.getKeyName())).append(IOConstants.TAG_SEPARATOR);
buffer.append(IOConstants.TAG_POOLPOINTS).append(IOConstants.TAG_END);
buffer.append(thePC.getUserPoolBonus(cat));
buffer.append(IOConstants.LINE_SEP);
}
}
}
Aggregations