Search in sources :

Example 66 with AbilityCategory

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

the class ForwardrefTokenTest method testRoundRobinAbilitySpell.

@Test
public void testRoundRobinAbilitySpell() throws PersistenceLayerException {
    primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Lightning Bolt");
    secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Lightning Bolt");
    AbilityCategory newCatp = primaryContext.getReferenceContext().constructCDOMObject(AbilityCategory.class, "NEWCAT");
    AbilityCategory newCats = secondaryContext.getReferenceContext().constructCDOMObject(AbilityCategory.class, "NEWCAT");
    Ability a = primaryContext.getReferenceContext().constructCDOMObject(Ability.class, "Abil3");
    primaryContext.getReferenceContext().reassociateCategory(newCatp, a);
    Ability b = secondaryContext.getReferenceContext().constructCDOMObject(Ability.class, "Abil3");
    secondaryContext.getReferenceContext().reassociateCategory(newCats, b);
    runRoundRobin("ABILITY=NEWCAT|Abil3", "SPELL|Lightning Bolt");
}
Also used : Ability(pcgen.core.Ability) AbilityCategory(pcgen.core.AbilityCategory) Test(org.junit.Test)

Example 67 with AbilityCategory

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

the class PCGVer2Parser method getBonusFromName.

/*
	 * Given a Source string and Target string,
	 * return a List of BonusObj's
	 */
private Map<BonusObj, TempBonusInfo> getBonusFromName(String sName, String tName) {
    //sName = NAME=Haste
    //tName = PC
    String sourceStr = sName.substring(IOConstants.TAG_TEMPBONUS.length() + 1);
    String targetStr = tName.substring(IOConstants.TAG_TEMPBONUSTARGET.length() + 1);
    Object oSource = null;
    if (sourceStr.startsWith(IOConstants.TAG_FEAT + '=')) {
        sourceStr = sourceStr.substring(5);
        oSource = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, sourceStr);
        oSource = thePC.getAbilityKeyed(AbilityCategory.FEAT, sourceStr);
        if (oSource == null) {
            for (final AbilityCategory cat : SettingsHandler.getGame().getAllAbilityCategories()) {
                Ability abilSourceObj = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, cat, sourceStr);
                if (abilSourceObj != null) {
                    oSource = abilSourceObj;
                }
            }
        }
    } else if (sourceStr.startsWith(IOConstants.TAG_SPELL + '=')) {
        sourceStr = sourceStr.substring(6);
        //oSource = aPC.getSpellNamed(sourceStr);
        oSource = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, sourceStr);
    } else if (sourceStr.startsWith(IOConstants.TAG_EQUIPMENT + '=')) {
        sourceStr = sourceStr.substring(10);
        oSource = thePC.getEquipmentNamed(sourceStr);
    } else if (sourceStr.startsWith(IOConstants.TAG_CLASS + '=')) {
        sourceStr = sourceStr.substring(6);
        oSource = thePC.getClassKeyed(sourceStr);
    } else if (sourceStr.startsWith(IOConstants.TAG_TEMPLATE + '=')) {
        sourceStr = sourceStr.substring(9);
        oSource = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, sourceStr);
    } else if (sourceStr.startsWith(IOConstants.TAG_SKILL + '=')) {
        sourceStr = sourceStr.substring(6);
        Skill aSkill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, sourceStr);
        if (thePC.hasSkill(aSkill)) {
            oSource = aSkill;
        } else {
        // TODO Error message
        }
    } else {
    // TODO Error message
    // Hmm, not a supported type
    }
    if (oSource != null) {
        sourceStr = ((CDOMObject) oSource).getKeyName();
    }
    if (targetStr.equals(IOConstants.TAG_PC)) {
        targetStr = thePC.getName();
    } else {
        Object oTarget = thePC.getEquipmentNamed(targetStr);
        targetStr = ((CDOMObject) oTarget).getDisplayName();
    }
    return thePC.getTempBonusMap(sourceStr, targetStr);
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) Skill(pcgen.core.Skill) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory)

Example 68 with AbilityCategory

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

the class PCGVer2Parser method parseAbilityLine.

/*
	 * ###############################################################
	 * Character Ability methods
	 * ###############################################################
	 */
private void parseAbilityLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalAbility", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    AbilityCategory category = null;
    Nature nature = Nature.NORMAL;
    String abilityCat = null;
    Ability ability = null;
    String missingCat = null;
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the AbilityCategory key name
    if (it.hasNext()) {
        final PCGElement element = it.next();
        final String categoryKey = EntityEncoder.decode(element.getText());
        category = SettingsHandler.getGame().getAbilityCategory(categoryKey);
        if (category == null) {
            missingCat = categoryKey;
        }
    }
    // The next element will be the nature
    if (it.hasNext()) {
        final PCGElement element = it.next();
        final String natureKey = EntityEncoder.decode(element.getText());
        nature = Nature.valueOf(natureKey);
    }
    // The next element will be the ability's innate category
    if (it.hasNext()) {
        final PCGElement element = it.next();
        abilityCat = EntityEncoder.decode(element.getText());
    }
    // The next element will be the ability key
    if (it.hasNext()) {
        final PCGElement element = it.next();
        String abilityKey = EntityEncoder.decode(element.getText());
        // Check for an ability that has been updated.
        CategorisedKey categorisedKey = AbilityMigration.getNewAbilityKey(abilityCat, abilityKey, pcgenVersion, SettingsHandler.getGame().getName());
        abilityCat = categorisedKey.getCategory();
        abilityKey = categorisedKey.getKey();
        AbilityCategory innateCategory = SettingsHandler.getGame().getAbilityCategory(abilityCat);
        if (innateCategory == null) {
            missingCat = abilityCat;
        }
        if (innateCategory == null || category == null) {
            final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
            "Warnings.PCGenParser.AbilityCategoryNotFound", abilityKey, missingCat);
            warnings.add(msg);
            return;
        }
        ability = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, innateCategory, abilityKey);
        if (ability == null) {
            warnings.add("Unable to Find Ability: " + abilityKey);
            return;
        }
    }
    List<String> associations = new ArrayList<>();
    List<BonusObj> bonuses = new ArrayList<>();
    while (it.hasNext()) {
        final PCGElement element = it.next();
        final String tag = element.getName();
        if (tag.equals(IOConstants.TAG_APPLIEDTO)) {
            associations.add(EntityEncoder.decode(element.getText()));
        } else if (IOConstants.TAG_SAVE.equals(tag)) {
            final String saveKey = EntityEncoder.decode(element.getText());
            // TODO - This never gets written to the file
            if (saveKey.startsWith(IOConstants.TAG_BONUS) && (saveKey.length() > 6)) {
                final BonusObj aBonus = Bonus.newBonus(Globals.getContext(), saveKey.substring(6));
                if (aBonus != null) {
                    bonuses.add(aBonus);
                }
            } else {
                if (Logging.isDebugMode()) {
                    Logging.debugPrint("Ignoring SAVE:" + saveKey);
                }
            }
        }
    }
    if (ability != null && category != null && nature != null) {
        CNAbility cna = null;
        boolean needError = true;
        if (nature == Nature.NORMAL) {
            // lines, save the feat now.
            if (!featsPresent || category != AbilityCategory.FEAT) {
                try {
                    cna = CNAbilityFactory.getCNAbility(category, nature, ability);
                } catch (IllegalArgumentException e) {
                    Logging.log(Logging.INFO, "Unabe to parse ability line: " + e.getMessage());
                }
            } else {
                needError = false;
            }
        } else if (nature == Nature.VIRTUAL) {
            cna = CNAbilityFactory.getCNAbility(category, nature, ability);
        }
        if (cna == null) {
            if (needError) {
                warnings.add("Unable to build Ability: " + ability);
            }
        } else {
            if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
                for (String appliedToKey : associations) {
                    String[] assoc = appliedToKey.split(Constants.COMMA, -1);
                    for (String string : assoc) {
                        CNAbilitySelection cnas = new CNAbilitySelection(cna, string);
                        try {
                            if (nature == Nature.VIRTUAL) {
                                thePC.addSavedAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
                            } else {
                                thePC.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
                            }
                        } catch (IllegalArgumentException e) {
                            Logging.errorPrint("PCGVer2Parser.parseAbilityLine failed", e);
                            warnings.add(cna + " with selection: " + string + " is no longer valid.");
                        }
                    }
                }
            } else {
                if (associations != null && !associations.isEmpty()) {
                    warnings.add(cna + " found with selections: " + associations + " but is MULT:NO in the data");
                }
                CNAbilitySelection cnas = new CNAbilitySelection(cna);
                if (nature == Nature.VIRTUAL) {
                    thePC.addSavedAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
                } else {
                    thePC.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
                }
            }
            for (BonusObj b : bonuses) {
                thePC.addSaveableBonus(b, cna.getAbility());
            }
        }
    }
}
Also used : Nature(pcgen.cdom.enumeration.Nature) CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) CategorisedKey(pcgen.io.migration.AbilityMigration.CategorisedKey) CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) AbilityCategory(pcgen.core.AbilityCategory)

Example 69 with AbilityCategory

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

the class ChooserUtilities method modifyAvailChoicesForAbilityCategory.

/**
	 * Restrict the available choices to what is allowed by the ability
	 * category.
	 * 
	 * @param availableList
	 *            The list of available choices, will be modified.
	 * @param category
	 *            The ability category
	 * @param ability
	 *            The ability the choices are for.
	 */
private static void modifyAvailChoicesForAbilityCategory(List availableList, AbilityCategory category, Ability ability) {
    AbilityCategory cat;
    if (category == null) {
        cat = SettingsHandler.getGame().getAbilityCategory(ability.getCategory());
    } else {
        cat = category;
    }
    if (!cat.hasDirectReferences()) {
        // Do nothing if there aren't any restrictions
        return;
    }
    Set<String> allowedSet = new HashSet<>();
    for (CDOMSingleRef<Ability> ref : cat.getAbilityRefs()) {
        if (ref.contains(ability)) {
            List<String> choices = new ArrayList<>();
            AbilityUtilities.getUndecoratedName(ref.getLSTformat(false), choices);
            allowedSet.addAll(choices);
        }
    }
    if (allowedSet.isEmpty()) {
        // Do nothing if there aren't any restrictions
        return;
    }
    // Remove any non allowed choices from the list
    for (Iterator iterator = availableList.iterator(); iterator.hasNext(); ) {
        Object obj = iterator.next();
        String key;
        if (obj instanceof CDOMObject) {
            key = ((CDOMObject) obj).getKeyName();
        } else {
            key = obj.toString();
        }
        if (!allowedSet.contains(key)) {
            iterator.remove();
        }
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CDOMObject(pcgen.cdom.base.CDOMObject) AbilityCategory(pcgen.core.AbilityCategory) HashSet(java.util.HashSet)

Example 70 with AbilityCategory

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

the class AbilityAutoListToken method getAbilityList.

/**
	 * @see pcgen.io.exporttoken.AbilityListToken#getAbilityList(pcgen.core.PlayerCharacter, pcgen.core.AbilityCategory)
	 */
@Override
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
    final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
    Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
    for (AbilityCategory aCat : allCats) {
        if (AbilityCategory.ANY.equals(aCategory) || aCat.getParentCategory().equals(aCategory)) {
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.AUTOMATIC)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
        }
    }
    return listOfAbilities;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

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