use of pcgen.core.Ability in project pcgen by PCGen.
the class AbilityLoader method includeObject.
/**
* This method should be called by finishObject implementations in
* order to check if the parsed object is affected by an INCLUDE or
* EXCLUDE request.
*
* @param cdo PObject to determine whether to include in
* Globals etc.
* @return boolean true if the object should be included, else false
* to exclude it
*/
@Override
protected final boolean includeObject(SourceEntry source, CDOMObject cdo) {
// Null check; never add nulls or objects without a name/key name
if ((cdo == null) || (cdo.getDisplayName() == null) || (cdo.getDisplayName().trim().isEmpty()) || (cdo.getKeyName() == null) || (cdo.getKeyName().trim().isEmpty())) {
return false;
}
Ability ability = (Ability) cdo;
// If includes were present, check includes for given object
List<String> includeItems = source.getIncludeItems();
if (!includeItems.isEmpty()) {
if (includeItems.contains(ability.getCategory() + "," + ability.getKeyName())) {
return true;
}
if (includeItems.contains(ability.getKeyName())) {
Logging.deprecationPrint("Deprecated INCLUDE value when loading " + source.getURI() + " . Abilities (including feats) must always have " + "categories (e.g. " + "INCLUDE:CATEGORY=cat1,key1,key2|CATEGORY=cat2,key3 ).");
return true;
}
return false;
}
// If excludes were present, check excludes for given object
List<String> excludeItems = source.getExcludeItems();
if (!excludeItems.isEmpty()) {
if (excludeItems.contains(ability.getCategory() + "," + ability.getKeyName())) {
return false;
}
if (excludeItems.contains(ability.getKeyName())) {
Logging.deprecationPrint("Deprecated EXCLUDE value when loading " + source.getURI() + " . Abilities (including feats) must always have " + "categories (e.g. " + "EXCLUDE:CATEGORY=cat1,key1,key2|CATEGORY=cat2,key3 ).");
return false;
}
return true;
}
return true;
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class Aspect method getAspectText.
/**
* Gets the name string after having substituting all variables.
*
* @param aPC The PlayerCharacter used to evaluate formulas.
* @param abilities the abilities for which the Aspect text should be compiled
*
* @return The fully substituted description string.
*/
public String getAspectText(final PlayerCharacter aPC, List<CNAbility> abilities) {
final StringBuilder buf = new StringBuilder(50);
if ((abilities == null) || (abilities.isEmpty())) {
return "";
}
Ability sampleAbilityObject = abilities.get(0).getAbility();
if (!qualifies(aPC, sampleAbilityObject)) {
return "";
}
for (final String comp : theComponents) {
if (comp.startsWith(VAR_MARKER)) {
final int ind = Integer.parseInt(comp.substring(VAR_MARKER.length()));
if (theVariables == null || ind > theVariables.size()) {
buf.append(Constants.EMPTY_STRING);
continue;
}
final String var = theVariables.get(ind - 1);
if (var.equals(VAR_NAME)) {
buf.append(sampleAbilityObject.getOutputName());
} else if (var.equals(VAR_LIST)) {
List<String> assocList = new ArrayList<>();
for (CNAbility cna : abilities) {
assocList.addAll(aPC.getAssociationList(cna));
}
String joinString;
if (assocList.size() == 2) {
joinString = " and ";
} else {
joinString = ", ";
}
Collections.sort(assocList);
buf.append(StringUtil.joinToStringBuilder(assocList, joinString));
} else if (//$NON-NLS-1$
var.startsWith("\"")) {
buf.append(var.substring(1, var.length() - 1));
} else {
//$NON-NLS-1$
buf.append(aPC.getVariableValue(var, "Aspect").intValue());
}
} else {
buf.append(comp);
}
}
return buf.toString();
}
use of pcgen.core.Ability 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.core.Ability 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.core.Ability in project pcgen by PCGen.
the class AbilityTargetSelector method applyChoice.
@Override
public void applyChoice(ChooseDriver obj, T choice, PlayerCharacter pc) {
Ability ab = ability.get();
ChooseInformation ci = ab.get(ObjectKey.CHOOSE_INFO);
detailedApply(obj, ci, choice, pc);
}
Aggregations