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);
}
}
}
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);
}
}
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;
}
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();
}
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);
}
}
Aggregations