Search in sources :

Example 51 with Ability

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

the class AbilitySelectionApplication method dataAdded.

@Override
public void dataAdded(DataFacetChangeEvent<CharID, CNAbilitySelection> dfce) {
    CharID id = dfce.getCharID();
    PlayerCharacter pc = pcFacet.getPC(id);
    CNAbilitySelection cnas = dfce.getCDOMObject();
    CNAbility cna = cnas.getCNAbility();
    Ability ability = cna.getAbility();
    String selection = cnas.getSelection();
    if (selection != null) {
        ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
        if (chooseInfo != null) {
            applySelection(pc, chooseInfo, cna, selection);
        }
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) CharID(pcgen.cdom.enumeration.CharID)

Example 52 with Ability

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

the class AbilitySelectionApplication method applySelection.

private <T> void applySelection(PlayerCharacter pc, ChooseInformation<T> chooseInfo, CNAbility cna, String selection) {
    Ability ability = cna.getAbility();
    T obj = chooseInfo.decodeChoice(Globals.getContext(), selection);
    if (obj == null) {
        Logging.errorPrint("Unable to apply Selection: '" + selection + "' to Ability " + ability + " (" + ability.getCDOMCategory() + ") because the given selection does not exist in the loaded data");
    } else {
        chooseInfo.getChoiceActor().applyChoice(cna, obj, pc);
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 53 with Ability

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

the class ModifyChoiceDecorator method getSet.

/**
	 * Returns a Set containing the Objects which this ModifyChoiceDecorator
	 * contains and which are also possessed by the PlayerCharacter.
	 * 
	 * It is intended that classes which implement ModifyChoiceDecorator will
	 * make this method value-semantic, meaning that ownership of the Set
	 * returned by this method will be transferred to the calling object.
	 * Modification of the returned Set will not result in modifying the
	 * ModifyChoiceDecorator (and vice versa since the ModifyChoiceDecorator is
	 * near immutable)
	 * 
	 * @param pc
	 *            The PlayerCharacter for which the choices in this
	 *            ModifyChoiceDecorator should be returned.
	 * @return A Set containing the Objects which this ModifyChoiceDecorator
	 *         contains and which are also possessed by the PlayerCharacter.
	 */
@Override
public Set<CNAbility> getSet(PlayerCharacter pc) {
    Collection<? extends Ability> collection = pcs.getSet(pc);
    List<CNAbility> pcfeats = pc.getPoolAbilities(AbilityCategory.FEAT);
    Set<CNAbility> returnSet = new HashSet<>();
    for (CNAbility cna : pcfeats) {
        Ability a = cna.getAbility();
        if (a.getSafe(ObjectKey.MULTIPLE_ALLOWED).booleanValue() && collection.contains(a)) {
            returnSet.add(cna);
        }
    }
    return returnSet;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) HashSet(java.util.HashSet)

Example 54 with Ability

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

the class AbilitySelection method getPersistentFormat.

/**
	 * Encodes the AbilitySelection into a String sufficient to uniquely
	 * identify the AbilitySelection. This may not sufficiently encode to be
	 * stored into a file or format which restricts certain characters (such as
	 * URLs), it simply encodes into an identifying String. There is no
	 * guarantee that this encoding is human readable, simply that the encoding
	 * is uniquely identifying such that the
	 * getAbilitySelectionFromPersistentFormat method of AbilitySelection is
	 * capable of decoding the String into an AbilitySelection.
	 * 
	 * @return A String sufficient to uniquely identify the AbilitySelection.
	 */
public String getPersistentFormat() {
    Ability ability = getObject();
    StringBuilder sb = new StringBuilder();
    sb.append("CATEGORY=");
    sb.append(ability.getCDOMCategory().getKeyName());
    sb.append('|');
    sb.append(ability.getKeyName());
    String selection = getSelection();
    if (selection != null) {
        sb.append('|');
        sb.append(selection);
    }
    return sb.toString();
}
Also used : Ability(pcgen.core.Ability)

Example 55 with Ability

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

the class AbilitySelection method decodeFeatSelectionChoice.

/**
	 * Decode a legacy feat selection format. This may come from a character 
	 * saved when an ability was coded with a FEATSELECTION but is loaded with 
	 * the same tag migrated to an ABILITYSELECTION.
	 *   
	 * @param context
	 *            The data loading context in use. 
	 * @param persistentFormat
	 *            The String which should be decoded to provide an
	 *            AbilitySelection.
	 * 
	 * @return An AbilitySelection that was encoded in the given String.
	 */
private static AbilitySelection decodeFeatSelectionChoice(LoadContext context, String persistentFormat) {
    Ability ability = context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, persistentFormat);
    if (ability == null) {
        List<String> choices = new ArrayList<>();
        String baseKey = AbilityUtilities.getUndecoratedName(persistentFormat, choices);
        ability = context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, baseKey);
        if (ability == null) {
            throw new IllegalArgumentException("String in decodeChoice " + "must be a Feat Key " + "(or Feat Key with Selection if appropriate), was: " + persistentFormat);
        }
        return new AbilitySelection(ability, choices.get(0));
    } else if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        /*
			 * MULT:YES, CHOOSE:NOCHOICE can land here
			 * 
			 * TODO There needs to be better validation at some point that this
			 * is proper (meaning it is actually CHOOSE:NOCHOICE!)
			 */
        return new AbilitySelection(ability, "");
    } else {
        return new AbilitySelection(ability, null);
    }
}
Also used : Ability(pcgen.core.Ability) ArrayList(java.util.ArrayList)

Aggregations

Ability (pcgen.core.Ability)279 CNAbility (pcgen.cdom.content.CNAbility)128 AbilityCategory (pcgen.core.AbilityCategory)60 PlayerCharacter (pcgen.core.PlayerCharacter)54 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)43 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)25 ParseResult (pcgen.rules.persistence.token.ParseResult)21 HashMapToList (pcgen.base.util.HashMapToList)15 PCClass (pcgen.core.PCClass)15 Spell (pcgen.core.spell.Spell)15 StringTokenizer (java.util.StringTokenizer)14 TestContext (plugin.lsttokens.editcontext.testsupport.TestContext)13 LoadContext (pcgen.rules.context.LoadContext)12 SpecialAbility (pcgen.core.SpecialAbility)11 CharacterSpell (pcgen.core.character.CharacterSpell)11 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)11 List (java.util.List)10 CDOMObject (pcgen.cdom.base.CDOMObject)10 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10