use of pcgen.core.AbilityCategory 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);
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class CharacterFacadeImpl method refreshAvailableTempBonuses.
void refreshAvailableTempBonuses() {
List<TempBonusFacadeImpl> tempBonuses = new ArrayList<>();
// first objects on the PC
for (CDOMObject cdo : theCharacter.getCDOMObjectList()) {
scanForTempBonuses(tempBonuses, cdo);
}
//
// next do all abilities to get TEMPBONUS:ANYPC only
GameMode game = (GameMode) dataSet.getGameMode();
for (AbilityCategory cat : game.getAllAbilityCategories()) {
if (cat.getParentCategory() == cat) {
for (Ability aFeat : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, cat).getAllObjects()) {
scanForAnyPcTempBonuses(tempBonuses, aFeat);
}
}
}
// Do all the PC's spells
for (Spell aSpell : theCharacter.aggregateSpellList("", "", "", 0, 9)) {
scanForTempBonuses(tempBonuses, aSpell);
}
// Do all the pc's innate spells.
Collection<CharacterSpell> innateSpells = theCharacter.getCharacterSpells(charDisplay.getRace(), Constants.INNATE_SPELL_BOOK_NAME);
for (CharacterSpell aCharacterSpell : innateSpells) {
if (aCharacterSpell == null) {
continue;
}
scanForTempBonuses(tempBonuses, aCharacterSpell.getSpell());
}
// Next do all spells to get TEMPBONUS:ANYPC or TEMPBONUS:EQUIP
for (Spell spell : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Spell.class)) {
scanForNonPcTempBonuses(tempBonuses, spell);
}
// do all Templates to get TEMPBONUS:ANYPC or TEMPBONUS:EQUIP
for (PCTemplate aTemp : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(PCTemplate.class)) {
scanForNonPcTempBonuses(tempBonuses, aTemp);
}
Collections.sort(tempBonuses);
availTempBonuses.updateContents(tempBonuses);
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class CharacterAbilities method rebuildAbilityLists.
/**
* Rebuild the ability lists for the character to include the character's
* current abilities.
*/
synchronized void rebuildAbilityLists() {
Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap = new LinkedHashMap<>();
DefaultListFacade<AbilityCategoryFacade> workingActiveCategories = new DefaultListFacade<>();
for (AbilityCategoryFacade category : dataSetFacade.getAbilities().getKeys()) {
AbilityCategory cat = (AbilityCategory) category;
for (CNAbility cna : theCharacter.getPoolAbilities(cat)) {
addCategorisedAbility(cna, workingAbilityListMap);
}
// deal with visibility
boolean visible = cat.isVisibleTo(theCharacter, View.VISIBLE_DISPLAY);
if (visible && !workingActiveCategories.containsElement(cat)) {
int index = getCatIndex(cat, workingActiveCategories);
workingActiveCategories.addElement(index, cat);
}
if (!visible && workingActiveCategories.containsElement(cat)) {
workingActiveCategories.removeElement(cat);
// updateAbilityCategoryTodo(cat);
}
if (visible) {
adviseSelectionChangeLater(cat);
}
}
// Update map contents
for (AbilityCategoryFacade category : workingAbilityListMap.keySet()) {
DefaultListFacade<AbilityFacade> workingListFacade = workingAbilityListMap.get(category);
DefaultListFacade<AbilityFacade> masterListFacade = abilityListMap.get(category);
if (masterListFacade == null) {
abilityListMap.put(category, workingListFacade);
} else {
masterListFacade.updateContentsNoOrder(workingListFacade.getContents());
}
updateAbilityCategoryTodo((AbilityCategory) category);
}
Set<AbilityCategoryFacade> origCats = new HashSet<>(abilityListMap.keySet());
for (AbilityCategoryFacade category : origCats) {
if (!workingAbilityListMap.containsKey(category)) {
if (workingActiveCategories.containsElement(category)) {
abilityListMap.get(category).clearContents();
} else {
abilityListMap.remove(category);
}
updateAbilityCategoryTodo((AbilityCategory) category);
}
}
activeCategories.updateContents(workingActiveCategories.getContents());
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class CharacterAbilities method addAbility.
/**
* Process a request by the user to add an ability. The user will be informed
* if the request cannot be allowed. Updates to the displayed lists are
* handled by events (see initForCharacter).
*
* @param categoryFacade The category in which the ability s bing added.
* @param abilityFacade The ability to be added.
*/
public void addAbility(AbilityCategoryFacade categoryFacade, AbilityFacade abilityFacade) {
if (abilityFacade == null || !(abilityFacade instanceof Ability) || categoryFacade == null || !(categoryFacade instanceof AbilityCategory)) {
return;
}
Ability ability = (Ability) abilityFacade;
AbilityCategory category = (AbilityCategory) categoryFacade;
if (!checkAbilityQualify(ability, category)) {
return;
}
// we can only be here if the PC can add the ability
try {
theCharacter.setDirty(true);
theCharacter.getSpellList();
CNAbility cna = CNAbilityFactory.getCNAbility(category, Nature.NORMAL, ability);
AbilityUtilities.driveChooseAndAdd(cna, theCharacter, true);
} catch (Exception exc) {
Logging.errorPrint("Failed to add ability due to ", exc);
ShowMessageDelegate.showMessageDialog(LanguageBundle.getFormattedString("in_iayAddAbility", //$NON-NLS-1$
exc.getMessage()), Constants.APPLICATION_NAME, MessageType.ERROR);
}
// Recalc the innate spell list
theCharacter.getSpellList();
theCharacter.calcActiveBonuses();
// update the ability info
rebuildAbilityLists();
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class CharacterAbilities method setRemainingSelection.
/**
* Set the number of selections that are remaining for this category.
* @param categoryFacade The ability category to be set.
* @param remaining The number of choices left.
*/
public void setRemainingSelection(AbilityCategoryFacade categoryFacade, int remaining) {
if (categoryFacade == null || !(categoryFacade instanceof AbilityCategory)) {
return;
}
AbilityCategory category = (AbilityCategory) categoryFacade;
BigDecimal pool = theCharacter.getAvailableAbilityPool(category);
final BigDecimal newRemain = new BigDecimal(remaining);
if (pool.equals(newRemain)) {
return;
}
theCharacter.adjustAbilities(category, newRemain.subtract(pool));
}
Aggregations