use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class PreSpecialAbilityTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) throws PrerequisiteException {
int runningTotal = 0;
int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException exceptn) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreSpecialAbility.error.bad_operand", //$NON-NLS-1$
prereq.toString()));
}
final String aString = prereq.getKey().toUpperCase();
for (SpecialAbility sa : character.getSpecialAbilityList()) {
if (sa.getKeyName().toUpperCase().startsWith(aString)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class SabLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<SpecialAbility> changes = context.getObjectContext().getListChanges(obj, ListKey.SAB);
Collection<SpecialAbility> added = changes.getAdded();
List<String> list = new ArrayList<>();
if (changes.includesGlobalClear()) {
list.add(Constants.LST_DOT_CLEAR);
} else if (added == null || added.isEmpty()) {
// Zero indicates no Token (and no global clear, so nothing to do)
return null;
}
if (added != null) {
for (SpecialAbility ab : added) {
StringBuilder sb = new StringBuilder();
sb.append(ab.getLSTformat());
if (ab.hasPrerequisites()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, ab.getPrerequisiteList()));
}
list.add(sb.toString());
}
}
return list.toArray(new String[list.size()]);
}
use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class RaceToken method getSubToken.
private static String getSubToken(final String subToken, CharacterDisplay display) {
if (!subToken.equals(SUBTOKENLIST[0])) {
return Constants.EMPTY_STRING;
}
final List<SpecialAbility> saList = new ArrayList<>();
Race race = display.getRace();
saList.addAll(display.getResolvedUserSpecialAbilities(race));
saList.addAll(display.getResolvedSpecialAbilities(race));
if (saList.isEmpty()) {
return Constants.EMPTY_STRING;
}
StringBuilder returnString = new StringBuilder();
boolean firstLine = true;
for (SpecialAbility sa : saList) {
if (!firstLine) {
//$NON-NLS-1$
returnString.append(", ");
}
firstLine = false;
returnString.append(sa.getDisplayName());
}
return returnString.toString();
}
use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class UserSpecialAbilityFacet method getResolved.
/**
* Returns a non-null copy of the List of resolved SpecialAbility objects
* for the given source CDOMObject and the Player Character represented by
* the given CharID. The Player Character must qualify for the Special
* Ability (if it has prerequisites) in order for the resolved
* SpecialAbility to be returned by this method. This method returns an
* empty List if no SpecialAbility objects are in this
* UserSpecialAbilityFacet for the given source CDOMObject and the Player
* Character identified by the given CharID.
*
* This method is value-semantic in that ownership of the returned List is
* transferred to the class calling this method. Modification of the
* returned List will not modify this UserSpecialAbilityFacet and
* modification of this UserSpecialAbilityFacet will not modify the returned
* List. Modifications to the returned List will also not modify any future
* or previous objects returned by this (or other) methods on
* UserSpecialAbilityFacet. If you wish to modify the information stored in
* this UserSpecialAbilityFacet, you must use the add*() and remove*()
* methods of UserSpecialAbilityFacet.
*
* @param id
* The CharID representing the Player Character for which a copy
* of the resolved items in this UserSpecialAbilityFacet should
* be returned
* @param source
* The source of the SpecialAbility objects for this
* UserSpecialAbilityFacet to be used for the resolution of the
* SpecialAbility objects in the Player Character
* @return A non-null List of resolved SpecialAbility objects from this
* UserSpecialAbilityFacet for the Player Character represented by
* the given CharID
*/
public List<SpecialAbility> getResolved(CharID id, Object source) {
List<SpecialAbility> returnList = new ArrayList<>();
SAProcessor proc = new SAProcessor(trackingFacet.getPC(id));
for (SpecialAbility sa : getQualifiedSet(id, source)) {
returnList.add(proc.act(sa, source));
}
return returnList;
}
use of pcgen.core.SpecialAbility in project pcgen by PCGen.
the class SAProcessor method act.
@Override
public SpecialAbility act(SpecialAbility sa, Object source) {
final String key = sa.getKeyName();
final int idx = key.indexOf("%CHOICE");
if (idx == -1) {
return sa;
}
StringBuilder sb = new StringBuilder(100);
sb.append(key.substring(0, idx));
if (source instanceof ChooseDriver) {
ChooseDriver object = (ChooseDriver) source;
if (pc.hasAssociations(object)) {
List<String> associationList = pc.getAssociationList(object);
Collections.sort(associationList);
sb.append(StringUtil.joinToStringBuilder(associationList, ", "));
}
} else {
Logging.errorPrint("In SpecialAbility resolution, " + "Error using object of type: " + source.getClass().getName() + " because " + "%CHOICE" + " was requested but the object does not support CHOOSE");
sb.append("<undefined>");
}
sb.append(key.substring(idx + 7));
return new SpecialAbility(sb.toString(), sa.getSADesc());
}
Aggregations