Search in sources :

Example 1 with SpecialAbility

use of pcgen.core.SpecialAbility in project pcgen by PCGen.

the class PCGVer2Creator method appendClassLines.

/*
	 * ###############################################################
	 * Character Class(es) methods
	 * ###############################################################
	 */
private void appendClassLines(StringBuilder buffer) {
    Cache specials = new Cache();
    for (PCClass pcClass : charDisplay.getClassSet()) {
        int classLevel = charDisplay.getLevel(pcClass);
        buffer.append(IOConstants.TAG_CLASS).append(':');
        buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
        final String subClassKey = charDisplay.getSubClassName(pcClass);
        if (subClassKey != null && !Constants.EMPTY_STRING.equals(subClassKey)) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_SUBCLASS).append(':');
            buffer.append(EntityEncoder.encode(subClassKey));
        }
        buffer.append('|');
        buffer.append(IOConstants.TAG_LEVEL).append(':');
        buffer.append(classLevel);
        buffer.append('|');
        buffer.append(IOConstants.TAG_SKILLPOOL).append(':');
        Integer currentPool = thePC.getSkillPool(pcClass);
        buffer.append(currentPool == null ? 0 : currentPool);
        // determine if this class can cast spells
        boolean isCaster = false;
        if (!thePC.getSpellSupport(pcClass).canCastSpells(thePC)) {
            isCaster = true;
        }
        boolean isPsionic = thePC.getSpellSupport(pcClass).hasKnownList() && !isCaster;
        if (isCaster || isPsionic) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_SPELLBASE).append(':');
            buffer.append(EntityEncoder.encode(pcClass.getSpellBaseStat()));
            buffer.append('|');
            buffer.append(IOConstants.TAG_CANCASTPERDAY).append(':');
            buffer.append(StringUtil.join(thePC.getSpellSupport(pcClass).getCastListForLevel(classLevel), ","));
        }
        Collection<? extends SpellProhibitor> prohib = charDisplay.getProhibitedSchools(pcClass);
        if (prohib != null) {
            Set<String> set = new TreeSet<>();
            for (SpellProhibitor sp : prohib) {
                set.addAll(sp.getValueList());
            }
            if (!set.isEmpty()) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_PROHIBITED).append(':');
                buffer.append(EntityEncoder.encode(StringUtil.join(set, ",")));
            }
        }
        appendAddTokenInfo(buffer, pcClass);
        buffer.append(IOConstants.LINE_SEP);
        String spec = thePC.getAssoc(pcClass, AssociationKey.SPECIALTY);
        if (spec != null) {
            specials.put(pcClass.getKeyName() + IOConstants.TAG_SPECIALTY + '0', spec);
        }
        String key;
        key = pcClass.getKeyName() + IOConstants.TAG_SAVE + '0';
        List<? extends SpecialAbility> salist = charDisplay.getUserSpecialAbilityList(pcClass);
        if (salist != null && !salist.isEmpty()) {
            SpecialAbility sa = salist.get(0);
            specials.put(pcClass.getKeyName() + IOConstants.TAG_SA + 0, sa.getKeyName());
        }
        for (BonusObj save : thePC.getSaveableBonusList(pcClass)) {
            specials.put(key, "BONUS|" + save);
        }
        for (int i = 1; i <= charDisplay.getLevel(pcClass); i++) {
            key = pcClass.getKeyName() + IOConstants.TAG_SAVE + (i - 1);
            PCClassLevel pcl = charDisplay.getActiveClassLevel(pcClass, i);
            for (BonusObj save : thePC.getSaveableBonusList(pcl)) {
                specials.put(key, "BONUS|" + save);
            }
        }
    }
    //
    for (PCLevelInfo pcl : charDisplay.getLevelInfo()) {
        final String classKeyName = pcl.getClassKeyName();
        int lvl = pcl.getClassLevel() - 1;
        PCClass pcClass = thePC.getClassKeyed(classKeyName);
        buffer.append(IOConstants.TAG_CLASSABILITIESLEVEL).append(':');
        if (pcClass == null) {
            pcClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKeyName);
            if (pcClass != null) {
                pcClass = thePC.getClassKeyed(pcClass.get(ObjectKey.EX_CLASS).get().getKeyName());
            }
        }
        if (pcClass != null) {
            buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
        } else {
            //$NON-NLS-1$
            buffer.append(EntityEncoder.encode("???"));
        }
        buffer.append('=').append(lvl + 1);
        if (pcClass != null) {
            String aKey = charDisplay.getSubstitutionClassName(charDisplay.getActiveClassLevel(pcClass, lvl + 1));
            if (aKey != null) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_SUBSTITUTIONLEVEL).append(':');
                buffer.append(aKey);
            }
            buffer.append('|');
            buffer.append(IOConstants.TAG_HITPOINTS).append(':');
            PCClassLevel classLevel = charDisplay.getActiveClassLevel(pcClass, lvl);
            Integer hp = charDisplay.getHP(classLevel);
            buffer.append(hp == null ? 0 : hp);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SAVE + lvl), IOConstants.TAG_SAVES, IOConstants.TAG_SAVE, lvl);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SPECIALTY + lvl), IOConstants.TAG_SPECIALTIES, IOConstants.TAG_SPECIALTY, lvl);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SA + lvl), IOConstants.TAG_SPECIALABILITIES, IOConstants.TAG_SA, lvl);
            if (lvl == 0) {
                appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SA + (lvl - 1)), IOConstants.TAG_SPECIALABILITIES, IOConstants.TAG_SA, -1);
            }
            //
            // Remember what choices were made for each of the ADD: tags
            //
            appendAddTokenInfo(buffer, charDisplay.getActiveClassLevel(pcClass, lvl + 1));
        }
        List<PCLevelInfoStat> statList = pcl.getModifiedStats(true);
        if (statList != null) {
            for (PCLevelInfoStat stat : statList) {
                buffer.append('|').append(IOConstants.TAG_PRESTAT).append(':').append(stat.toString());
            }
        }
        statList = pcl.getModifiedStats(false);
        if (statList != null) {
            for (PCLevelInfoStat stat : statList) {
                buffer.append('|').append(IOConstants.TAG_PRESTAT).append(':').append(stat.toString());
            }
        }
        int sp = pcl.getSkillPointsGained(thePC);
        //if (sp != 0)
        {
            buffer.append('|').append(IOConstants.TAG_SKILLPOINTSGAINED).append(':').append(sp);
        }
        sp = pcl.getSkillPointsRemaining();
        //if (sp != 0)
        {
            buffer.append('|').append(IOConstants.TAG_SKILLPOINTSREMAINING).append(':').append(sp);
        }
        buffer.append(IOConstants.LINE_SEP);
    }
}
Also used : PCLevelInfoStat(pcgen.core.pclevelinfo.PCLevelInfoStat) BonusObj(pcgen.core.bonus.BonusObj) SpecialAbility(pcgen.core.SpecialAbility) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor) PCClassLevel(pcgen.cdom.inst.PCClassLevel) TreeSet(java.util.TreeSet) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 2 with SpecialAbility

use of pcgen.core.SpecialAbility in project pcgen by PCGen.

the class SpecialAbilityFacet 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 SpecialAbilityFacet
	 * 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 SpecialAbilityFacet and modification
	 * of this SpecialAbilityFacet 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
	 * SpecialAbilityFacet. If you wish to modify the information stored in this
	 * SpecialAbilityFacet, you must use the add*() and remove*() methods of
	 * SpecialAbilityFacet.
	 * 
	 * @param id
	 *            The CharID representing the Player Character for which a copy
	 *            of the resolved items in this SpecialAbilityFacet should be
	 *            returned
	 * @param source
	 *            The source of the SpecialAbility objects for this
	 *            SpecialAbilityFacet 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
	 *         SpecialAbilityFacet 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 3 with SpecialAbility

use of pcgen.core.SpecialAbility in project pcgen by PCGen.

the class ClassToken method getClassSpecialAbilityList.

/**
	 * Get the list of Special Abilities for a class that the PC is eligible
	 * for.
	 * 
	 * @param pcclass
	 *            The class to get the special abilities for
	 * @param aPC
	 *            The PC
	 * @return List of special abilities
	 */
public static List<String> getClassSpecialAbilityList(PCClass pcclass, final PlayerCharacter aPC) {
    CharacterDisplay display = aPC.getDisplay();
    final List<String> formattedList = new ArrayList<>();
    final List<SpecialAbility> saList = new ArrayList<>();
    saList.addAll(display.getResolvedUserSpecialAbilities(pcclass));
    saList.addAll(display.getResolvedSpecialAbilities(pcclass));
    for (int i = 1; i <= display.getLevel(pcclass); i++) {
        PCClassLevel pcl = display.getActiveClassLevel(pcclass, i);
        saList.addAll(display.getResolvedUserSpecialAbilities(pcl));
        saList.addAll(display.getResolvedSpecialAbilities(pcl));
    }
    if (saList.isEmpty()) {
        return formattedList;
    }
    Collections.sort(saList);
    // to include all of the variables
    for (SpecialAbility sa : saList) {
        String str = sa.getDisplayName();
        if (str == null || str.isEmpty()) {
            continue;
        }
        StringTokenizer varTok = new StringTokenizer(str, Constants.PIPE);
        final String aString = varTok.nextToken();
        int[] varValue = null;
        int varCount = varTok.countTokens();
        if (varCount != 0) {
            varValue = new int[varCount];
            for (int j = 0; j < varCount; ++j) {
                // Get the value for each variable
                final String vString = varTok.nextToken();
                varValue[j] = aPC.getVariable(vString, true).intValue();
            }
        }
        final StringBuilder newAbility = new StringBuilder();
        varTok = new StringTokenizer(aString, "%", true);
        varCount = 0;
        boolean isZero = false;
        // Fill in each % with the value of the appropriate token
        while (varTok.hasMoreTokens()) {
            final String nextTok = varTok.nextToken();
            if ("%".equals(nextTok)) {
                if (varCount == 0) {
                    // If this is the first token, then set the count of
                    // successful token replacements to 0
                    isZero = true;
                }
                if ((varValue != null) && (varCount < varValue.length)) {
                    final int thisVar = varValue[varCount++];
                    // Update isZero if this token has a value of anything
                    // other than 0
                    isZero &= (thisVar == 0);
                    newAbility.append(thisVar);
                } else {
                    newAbility.append('%');
                }
            } else {
                newAbility.append(nextTok);
            }
        }
        if (!isZero) {
            // If all of the tokens for this ability were 0 then we do not
            // show it,
            // otherwise we add it to the return list.
            formattedList.add(newAbility.toString());
        }
    }
    return formattedList;
}
Also used : StringTokenizer(java.util.StringTokenizer) CharacterDisplay(pcgen.core.display.CharacterDisplay) ArrayList(java.util.ArrayList) SpecialAbility(pcgen.core.SpecialAbility) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 4 with SpecialAbility

use of pcgen.core.SpecialAbility in project pcgen by PCGen.

the class DeityToken method getSAToken.

/**
	 * Get the SA sub token
	 * @param deity
	 * @return the SA sub token
	 */
public static String getSAToken(Deity deity, CharacterDisplay display) {
    final List<SpecialAbility> saList = new ArrayList<>();
    saList.addAll(display.getResolvedUserSpecialAbilities(deity));
    saList.addAll(display.getResolvedSpecialAbilities(deity));
    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 : ArrayList(java.util.ArrayList) SpecialAbility(pcgen.core.SpecialAbility)

Example 5 with SpecialAbility

use of pcgen.core.SpecialAbility in project pcgen by PCGen.

the class TemplateToken method getSAToken.

/**
	 * Get value of SA sub token
	 * @param template
	 * @param pc
	 * @return value of SA sub token
	 */
public static String getSAToken(PCTemplate template, PlayerCharacter pc) {
    CharacterDisplay display = pc.getDisplay();
    List<SpecialAbility> saList = new ArrayList<>();
    saList.addAll(display.getResolvedUserSpecialAbilities(template));
    saList.addAll(display.getResolvedSpecialAbilities(template));
    List<PCTemplate> subList = new ArrayList<>();
    subList.addAll(template.getConditionalTemplates(display.getTotalLevels(), display.totalHitDice()));
    for (PCTemplate subt : subList) {
        saList.addAll(display.getResolvedUserSpecialAbilities(subt));
        saList.addAll(display.getResolvedSpecialAbilities(subt));
    }
    List<String> saDescList = new ArrayList<>();
    for (SpecialAbility sa : saList) {
        if (!sa.qualifies(pc, template)) {
            continue;
        }
        final String saText = sa.getParsedText(pc, pc, template);
        if (saText != null && !saText.equals("")) {
            saDescList.add(saText);
        }
    }
    return StringUtil.join(saDescList, ", ");
}
Also used : CharacterDisplay(pcgen.core.display.CharacterDisplay) ArrayList(java.util.ArrayList) SpecialAbility(pcgen.core.SpecialAbility) PCTemplate(pcgen.core.PCTemplate)

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