Search in sources :

Example 11 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class PCGVer2Creator method writeAbilityToBuffer.

private void writeAbilityToBuffer(StringBuilder buffer, CNAbility cna) {
    Category<Ability> cat = cna.getAbilityCategory();
    Nature nature = cna.getNature();
    Ability ability = cna.getAbility();
    buffer.append(IOConstants.TAG_ABILITY).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(cat.getKeyName())).append(IOConstants.TAG_SEPARATOR);
    buffer.append(IOConstants.TAG_TYPE).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(nature.toString())).append(IOConstants.TAG_SEPARATOR);
    buffer.append(IOConstants.TAG_CATEGORY).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(ability.getCategory())).append(IOConstants.TAG_SEPARATOR);
    buffer.append(IOConstants.TAG_MAPKEY).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(ability.getKeyName())).append(IOConstants.TAG_SEPARATOR);
    if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        buffer.append(IOConstants.TAG_APPLIEDTO).append(IOConstants.TAG_END);
        List<String> assocList = thePC.getAssociationList(cna);
        boolean first = true;
        for (String assoc : assocList) {
            if (!first) {
                buffer.append(Constants.COMMA);
            }
            first = false;
            buffer.append(EntityEncoder.encode(assoc));
        }
        buffer.append(IOConstants.TAG_SEPARATOR);
    }
    buffer.append(IOConstants.TAG_TYPE).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(ability.getType()));
    for (final BonusObj save : thePC.getSaveableBonusList(ability)) {
        buffer.append('|');
        buffer.append(IOConstants.TAG_SAVE).append(':');
        buffer.append(EntityEncoder.encode("BONUS|" + save));
    }
    for (final Description desc : ability.getSafeListFor(ListKey.DESCRIPTION)) {
        buffer.append(Constants.PIPE);
        buffer.append(IOConstants.TAG_DESC).append(':');
        buffer.append(EntityEncoder.encode(desc.getPCCText()));
    }
    buffer.append(IOConstants.LINE_SEP);
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) SpecialAbility(pcgen.core.SpecialAbility) Nature(pcgen.cdom.enumeration.Nature) Description(pcgen.core.Description) BonusObj(pcgen.core.bonus.BonusObj)

Example 12 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class PCGVer2Parser method parseFeatLine.

/*
	 * ###############################################################
	 * Character Feats methods
	 * ###############################################################
	 */
private void parseFeatLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalFeat", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the Ability key name
    if (it.hasNext()) {
        final PCGElement element = it.next();
        final String abilityKey = EntityEncoder.decode(element.getText());
        /* First, check to see if the PC already has this ability. If so,
			 * then we just need to mod it. Otherwise we need to create a new
			 * one and add it using non-aggregate (when using aggregate, we
			 * get clones of the PCs actual feats, which don't get saved or
			 * preserved) */
        Ability anAbility = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, abilityKey);
        if (anAbility == null) {
            final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
            "Warnings.PCGenParser.CouldntAddAbility", abilityKey);
            warnings.add(msg);
            return;
        }
        CNAbility pcAbility = CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, anAbility);
        if (!anAbility.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
            thePC.addAbility(new CNAbilitySelection(pcAbility), UserSelection.getInstance(), UserSelection.getInstance());
        }
        parseFeatsHandleAppliedToAndSaveTags(it, pcAbility);
        featsPresent = true;
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 13 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbilityListToken method getTokenForCategory.

/**
	 * Produce the ABILITY token output for a specific ability 
	 * category.
	 *  
	 * @param pc The character being processed.
	 * @param aTok The tokenised request, already past the category.
	 * @param tokenString The output token requested 
	 * @param aCategory The ability category being output.
	 * @return The token value.
	 */
protected String getTokenForCategory(PlayerCharacter pc, final StringTokenizer aTok, final String tokenString, final AbilityCategory aCategory) {
    if (aCategory == null) {
        return "";
    }
    StringBuilder retString = new StringBuilder();
    // once
    if (lastPC != pc || !aCategory.equals(lastCategory) || lastPCSerial != pc.getSerial() || !tokenString.equals(lastType)) {
        abilityMap = getAbilityList(pc, aCategory);
        lastPC = pc;
        lastCategory = aCategory;
        lastPCSerial = pc.getSerial();
        lastType = tokenString;
    }
    // Default values
    List<String> types = new ArrayList<>();
    List<String> negate = new ArrayList<>();
    String aspect = null;
    while (aTok.hasMoreTokens()) {
        final String typeStr = aTok.nextToken();
        int typeInd = typeStr.indexOf("TYPE=");
        if (typeInd != -1 && typeStr.length() > 5) {
            if (typeInd > 0) {
                negate.add(typeStr.substring(typeInd + 5));
            } else {
                types.add(typeStr.substring(typeInd + 5));
            }
        }
        int aspectInd = typeStr.indexOf("ASPECT=");
        if (aspectInd != -1 && typeStr.length() > 7) {
            aspect = typeStr.substring(aspectInd + 7);
        }
    }
    MapToList<Ability, CNAbility> aList = AbilityToken.buildAbilityList(types, negate, null, View.VISIBLE_EXPORT, aspect, abilityMap);
    boolean needComma = false;
    for (Ability ability : aList.getKeySet()) {
        if (needComma) {
            retString.append(DELIM);
        }
        needComma = true;
        retString.append(QualifiedName.qualifiedName(pc, aList.getListFor(ability)));
    }
    return retString.toString();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) ArrayList(java.util.ArrayList)

Example 14 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbilityToken method getAspectString.

/**
	 * Gets the aspect string.
	 * 
	 * @param pc
	 *            The character being exported.
	 * @param ability
	 *            The ability
	 * 
	 * @return the aspect string
	 */
private String getAspectString(PlayerCharacter pc, List<CNAbility> abilities) {
    if (abilities.isEmpty()) {
        return "";
    }
    Ability sampleAbilityObject = abilities.get(0).getAbility();
    Set<AspectName> aspectKeys = sampleAbilityObject.getKeysFor(MapKey.ASPECT);
    SortedSet<AspectName> sortedKeys = new TreeSet<>(aspectKeys);
    StringBuilder buff = new StringBuilder();
    for (AspectName key : sortedKeys) {
        if (buff.length() > 0) {
            buff.append(", ");
        }
        buff.append(Aspect.printAspect(pc, key, abilities));
    }
    return buff.toString();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AspectName(pcgen.cdom.enumeration.AspectName) TreeSet(java.util.TreeSet)

Example 15 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class AbilityToken method getAbilityList.

/**
	 * Returns the correct list of abilities for the character. This method is
	 * overridden in subclasses if they need to change the list of abilities
	 * looked at.
	 * 
	 * @param pc
	 *            The character who's abilities we are retrieving.
	 * @param aCategory
	 *            The category of ability being reported.
	 * @return List of abilities.
	 */
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
    final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
    Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
    for (AbilityCategory aCat : allCats) {
        if (AbilityCategory.ANY.equals(aCategory) || aCat.getParentCategory().equals(aCategory)) {
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.NORMAL)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
        }
    }
    return listOfAbilities;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Aggregations

CNAbility (pcgen.cdom.content.CNAbility)131 Ability (pcgen.core.Ability)77 ArrayList (java.util.ArrayList)37 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)28 AbilityCategory (pcgen.core.AbilityCategory)26 Test (org.junit.Test)21 HashMapToList (pcgen.base.util.HashMapToList)16 List (java.util.List)15 PlayerCharacter (pcgen.core.PlayerCharacter)9 Language (pcgen.core.Language)7 HashSet (java.util.HashSet)5 Nature (pcgen.cdom.enumeration.Nature)5 SpecialAbility (pcgen.core.SpecialAbility)5 BonusObj (pcgen.core.bonus.BonusObj)5 BigDecimal (java.math.BigDecimal)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 LoadContext (pcgen.rules.context.LoadContext)4 StringTokenizer (java.util.StringTokenizer)3 GenericMapToList (pcgen.base.util.GenericMapToList)3 PCClass (pcgen.core.PCClass)3