Search in sources :

Example 6 with SpecialAbility

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);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) SpecialAbility(pcgen.core.SpecialAbility)

Example 7 with SpecialAbility

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()]);
}
Also used : SpecialAbility(pcgen.core.SpecialAbility) ArrayList(java.util.ArrayList)

Example 8 with SpecialAbility

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();
}
Also used : Race(pcgen.core.Race) ArrayList(java.util.ArrayList) SpecialAbility(pcgen.core.SpecialAbility)

Example 9 with SpecialAbility

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;
}
Also used : ArrayList(java.util.ArrayList) SpecialAbility(pcgen.core.SpecialAbility) SAProcessor(pcgen.cdom.helper.SAProcessor)

Example 10 with SpecialAbility

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());
}
Also used : ChooseDriver(pcgen.cdom.base.ChooseDriver) SpecialAbility(pcgen.core.SpecialAbility)

Aggregations

SpecialAbility (pcgen.core.SpecialAbility)15 ArrayList (java.util.ArrayList)8 PCClassLevel (pcgen.cdom.inst.PCClassLevel)4 PCClass (pcgen.core.PCClass)4 StringTokenizer (java.util.StringTokenizer)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 SAProcessor (pcgen.cdom.helper.SAProcessor)2 Campaign (pcgen.core.Campaign)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 CharacterDisplay (pcgen.core.display.CharacterDisplay)2 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)2 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)2 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)2 PCClassLoader (pcgen.persistence.lst.PCClassLoader)2 LoadContext (pcgen.rules.context.LoadContext)2 TreeSet (java.util.TreeSet)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 ChooseDriver (pcgen.cdom.base.ChooseDriver)1 Ungranted (pcgen.cdom.base.Ungranted)1