Search in sources :

Example 1 with Nature

use of pcgen.cdom.enumeration.Nature 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 2 with Nature

use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.

the class CharacterFacadeImpl method getAbilityNature.

/**
	 * @see pcgen.core.facade.CharacterFacade#getAbilityNature(pcgen.core.facade.AbilityFacade)
	 */
@Override
public Nature getAbilityNature(AbilityFacade ability) {
    if (ability == null || !(ability instanceof Ability)) {
        return null;
    }
    /*
		 * TODO This is making a somewhat DRASTIC assumption that ANY Ability
		 * Category is appropriate. Unfortunately, the point at which this
		 * method is called from the UI it is unclear to the untrained eye how
		 * to get the category.
		 */
    List<CNAbility> cnas = theCharacter.getMatchingCNAbilities((Ability) ability);
    Nature nature = null;
    for (CNAbility cna : cnas) {
        nature = Nature.getBestNature(nature, cna.getNature());
    }
    return nature;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) Nature(pcgen.cdom.enumeration.Nature)

Example 3 with Nature

use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.

the class PlayerCharacter method processAbilityList.

private void processAbilityList(CDOMObject cdo, CDOMReference<AbilityList> ref) {
    Collection<CDOMReference<Ability>> mods = cdo.getListMods(ref);
    for (CDOMReference<Ability> objref : mods) {
        Collection<Ability> objs = objref.getContainedObjects();
        Collection<AssociatedPrereqObject> assoc = cdo.getListAssociations(ref, objref);
        for (Ability ab : objs) {
            if (ab == null) {
                Logging.log(Logging.LST_ERROR, "Missing object referenced in the ability list for '" + cdo + "' list is " + ref + ". Source " + cdo.getSourceURI());
                continue;
            }
            for (AssociatedPrereqObject apo : assoc) {
                Nature nature = apo.getAssociation(AssociationKey.NATURE);
                CDOMSingleRef<AbilityCategory> acRef = apo.getAssociation(AssociationKey.CATEGORY);
                AbilityCategory cat = acRef.get();
                if (ab.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
                    List<String> choices = apo.getAssociation(AssociationKey.ASSOC_CHOICES);
                    if (choices == null) {
                        //CHOOSE:NOCHOICE can be unconditionally applied (must be STACK:YES)
                        CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), "");
                        cas.addAllPrerequisites(apo.getPrerequisiteList());
                        applyAbility(cas, cdo);
                    } else {
                        for (final String choice : choices) {
                            CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), choice);
                            cas.addAllPrerequisites(apo.getPrerequisiteList());
                            applyAbility(cas, cdo);
                        }
                    }
                } else {
                    CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab));
                    cas.addAllPrerequisites(apo.getPrerequisiteList());
                    applyAbility(cas, cdo);
                }
            }
        }
    }
    cabFacet.update(id);
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Nature(pcgen.cdom.enumeration.Nature) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 4 with Nature

use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.

the class CNAbilitySelection method getAbilitySelectionFromPersistentFormat.

public static CNAbilitySelection getAbilitySelectionFromPersistentFormat(String persistentFormat) {
    StringTokenizer st = new StringTokenizer(persistentFormat, Constants.PIPE);
    String catString = st.nextToken();
    if (!catString.startsWith("CATEGORY=")) {
        throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must start with CATEGORY=, found: " + persistentFormat);
    }
    String cat = catString.substring(9);
    AbilityCategory ac = SettingsHandler.getGame().getAbilityCategory(cat);
    if (ac == null) {
        throw new IllegalArgumentException("Category in getAbilitySelectionFromPersistentFormat " + "must exist found: " + cat);
    }
    String natureString = st.nextToken();
    if (!natureString.startsWith("NATURE=")) {
        throw new IllegalArgumentException("Second argument in String in getAbilitySelectionFromPersistentFormat " + "must start with NATURE=, found: " + persistentFormat);
    }
    String natString = natureString.substring(7);
    Nature nat = Nature.valueOf(natString);
    String ab = st.nextToken();
    Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, ac, ab);
    if (a == null) {
        throw new IllegalArgumentException("Third argument in String in getAbilitySelectionFromPersistentFormat " + "must be an Ability, but it was not found: " + persistentFormat);
    }
    String sel = null;
    if (st.hasMoreTokens()) {
        /*
			 * No need to check for MULT:YES/NO here, as that is checked
			 * implicitly in the construction of AbilitySelection below
			 */
        sel = st.nextToken();
    } else if (persistentFormat.endsWith(Constants.PIPE)) {
        // Handle the StringTokenizer ignoring blank tokens at the end
        sel = "";
    }
    if (st.hasMoreTokens()) {
        throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must have 3 or 4 arguments, but found more: " + persistentFormat);
    }
    CNAbility cna = CNAbilityFactory.getCNAbility(ac, nat, a);
    return new CNAbilitySelection(cna, sel);
}
Also used : Nature(pcgen.cdom.enumeration.Nature) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) StringTokenizer(java.util.StringTokenizer) AbilityCategory(pcgen.core.AbilityCategory)

Example 5 with Nature

use of pcgen.cdom.enumeration.Nature in project pcgen by PCGen.

the class CharacterAbilities method addCategorisedAbility.

/**
	 * Add the ability to the categorised list held by CharacterAbilities. 
	 * One copy will be added for each choice.
	 * 
	 * @param cat The AbilityCategory that the ability is being added to.
	 * @param ability The ability being added.
	 * @param nature The nature via which the ability is being added.
	 * @param workingAbilityListMap The map to be adjusted.
	 */
private void addCategorisedAbility(CNAbility cna, Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap) {
    Ability ability = cna.getAbility();
    List<CNAbilitySelection> cas = new ArrayList<>();
    Category<Ability> cat = cna.getAbilityCategory();
    Nature nature = cna.getNature();
    if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        List<String> choices = theCharacter.getAssociationList(cna);
        if (choices == null || choices.isEmpty()) {
            Logging.errorPrint("Ignoring Ability: " + ability + " (" + cat + " / " + nature + ") that UI has as added to the PC, but it has no associations");
        } else {
            for (String choice : choices) {
                cas.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ability), choice));
            }
        }
    } else {
        cas.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ability)));
    }
    for (CNAbilitySelection sel : cas) {
        addElement(workingAbilityListMap, sel);
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) Nature(pcgen.cdom.enumeration.Nature) ArrayList(java.util.ArrayList) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Aggregations

Nature (pcgen.cdom.enumeration.Nature)11 Ability (pcgen.core.Ability)10 CNAbility (pcgen.cdom.content.CNAbility)8 ArrayList (java.util.ArrayList)6 AbilityCategory (pcgen.core.AbilityCategory)6 CDOMReference (pcgen.cdom.base.CDOMReference)5 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)5 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)3 ParseResult (pcgen.rules.persistence.token.ParseResult)3 StringTokenizer (java.util.StringTokenizer)2 Formula (pcgen.base.formula.Formula)2 ParsingSeparator (pcgen.base.text.ParsingSeparator)2 ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)2 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)2 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)2 ListKey (pcgen.cdom.enumeration.ListKey)2 AbilitySelector (pcgen.cdom.helper.AbilitySelector)2 AbilityTargetSelector (pcgen.cdom.helper.AbilityTargetSelector)2 AbilityList (pcgen.cdom.list.AbilityList)2