Search in sources :

Example 46 with AbilityCategory

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);
}
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 47 with AbilityCategory

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);
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) GameMode(pcgen.core.GameMode) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 48 with AbilityCategory

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());
}
Also used : AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) LinkedHashMap(java.util.LinkedHashMap) CNAbility(pcgen.cdom.content.CNAbility) AbilityFacade(pcgen.facade.core.AbilityFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade) AbilityCategory(pcgen.core.AbilityCategory) HashSet(java.util.HashSet)

Example 49 with AbilityCategory

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();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) AbilityCategory(pcgen.core.AbilityCategory)

Example 50 with AbilityCategory

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));
}
Also used : AbilityCategory(pcgen.core.AbilityCategory) BigDecimal(java.math.BigDecimal)

Aggregations

AbilityCategory (pcgen.core.AbilityCategory)72 Ability (pcgen.core.Ability)60 CNAbility (pcgen.cdom.content.CNAbility)34 HashMapToList (pcgen.base.util.HashMapToList)14 ArrayList (java.util.ArrayList)10 PlayerCharacter (pcgen.core.PlayerCharacter)10 StringTokenizer (java.util.StringTokenizer)9 Test (org.junit.Test)9 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)7 Nature (pcgen.cdom.enumeration.Nature)6 BigDecimal (java.math.BigDecimal)5 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 CDOMReference (pcgen.cdom.base.CDOMReference)4 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)4 PCTemplate (pcgen.core.PCTemplate)3 SpecialAbility (pcgen.core.SpecialAbility)3 BonusObj (pcgen.core.bonus.BonusObj)3 ParseResult (pcgen.rules.persistence.token.ParseResult)3 HashSet (java.util.HashSet)2