Search in sources :

Example 56 with PCClass

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

the class SpellBuilderFacadeImpl method recalcCasterLevelDetails.

private void recalcCasterLevelDetails() {
    // Metamagic
    int levelAdjust = 0;
    for (AbilityFacade feat : selMetamagicFeats) {
        levelAdjust += ((Ability) feat).getSafe(IntegerKey.ADD_SPELL_LEVEL);
    }
    // Limit Caster level
    int minClassLevel = 1;
    int maxClassLevel = 20;
    PCClass aClass;
    InfoFacade castingClass = pcClass.get();
    if (castingClass instanceof PCClass) {
        aClass = (PCClass) castingClass;
    } else if (castingClass instanceof Domain) {
        // TODO We should not be hardcoding the link between cleric and domains
        aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, "Cleric");
    } else {
        Logging.errorPrint("Found Casting Class in recalc that was not a Class or Domain: " + castingClass.getClass());
        return;
    }
    if (aClass != null) {
        minClassLevel = character.getSpellSupport(aClass).getMinLevelForSpellLevel(spellLevel.get() + levelAdjust, true);
        minClassLevel = Math.max(1, minClassLevel);
        if (aClass.hasMaxLevel()) {
            maxClassLevel = aClass.getSafe(IntegerKey.LEVEL_LIMIT);
        }
    }
    updateAvailCasterLevels(minClassLevel, maxClassLevel);
    int currCasterLevel = casterLevel.get() == null ? 0 : casterLevel.get();
    if (currCasterLevel < minClassLevel) {
        casterLevel.set(minClassLevel);
    } else if (currCasterLevel > maxClassLevel) {
        casterLevel.set(maxClassLevel);
    }
}
Also used : InfoFacade(pcgen.facade.core.InfoFacade) AbilityFacade(pcgen.facade.core.AbilityFacade) PCClass(pcgen.core.PCClass) Domain(pcgen.core.Domain)

Example 57 with PCClass

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

the class KitSkill method testApply.

@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
    skillsToAdd = new ArrayList<>();
    List<Skill> skillChoices = getSkillChoices(aPC);
    if (skillChoices == null || skillChoices.isEmpty()) {
        // They didn't make a choice so don't add any ranks.
        return false;
    }
    for (Skill skill : skillChoices) {
        BigDecimal ranksLeftToAdd = getRank();
        if (ranksLeftToAdd == null) {
            ranksLeftToAdd = BigDecimal.ONE;
        }
        double ranksLeft = ranksLeftToAdd.doubleValue();
        List<PCClass> classList = new ArrayList<>();
        if (className != null) {
            String classKey = className.get().getKeyName();
            // Make sure if they specified a class to add from we try that
            // class first.
            PCClass pcClass = aPC.getClassKeyed(classKey);
            if (pcClass != null) {
                classList.add(pcClass);
            } else {
                warnings.add("SKILL: Could not find specified class " + classKey + " in PC to add ranks from.");
            }
        }
        for (PCClass pcClass : aPC.getClassSet()) {
            if (!classList.contains(pcClass)) {
                classList.add(pcClass);
            }
        }
        // Try and find a class we can add them from.
        boolean oldImporting = aPC.isImporting();
        aPC.setImporting(true);
        for (PCClass pcClass : classList) {
            final KitSkillAdd sta = addRanks(aPC, pcClass, skill, ranksLeft, isFree(), warnings);
            if (sta != null) {
                skillsToAdd.add(sta);
                ranksLeft -= sta.getRanks();
                if (ranksLeft <= 0.0) {
                    break;
                }
            }
        }
        aPC.setImporting(oldImporting);
        if (ranksLeft > 0.0) {
            warnings.add("SKILL: Could not add " + ranksLeft + " ranks to " + skill.getKeyName() + ". Not enough points.");
        }
    }
    return true;
}
Also used : Skill(pcgen.core.Skill) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) BigDecimal(java.math.BigDecimal)

Example 58 with PCClass

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

the class KitSpells method testApply.

@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
    theSpells = null;
    PCClass aClass = findDefaultSpellClass(castingClass, aPC);
    if (aClass == null) {
        warnings.add("SPELLS: Character does not have " + castingClass + " spellcasting class.");
        return false;
    }
    String workingBook = spellBook == null ? Globals.getDefaultSpellBook() : spellBook;
    List<KitSpellBookEntry> aSpellList = new ArrayList<>();
    if (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS) && !workingBook.equals(Globals.getDefaultSpellBook())) {
        warnings.add("SPELLS: " + aClass.getDisplayName() + " can only add to " + Globals.getDefaultSpellBook());
        return false;
    }
    for (KnownSpellIdentifier ksi : spells.getKeySet()) {
        Collection<Spell> allSpells = ksi.getContainedSpells(aPC, Collections.singletonList(aClass.get(ObjectKey.CLASS_SPELLLIST)));
        Set<List<CDOMSingleRef<Ability>>> feats = spells.getSecondaryKeySet(ksi);
        for (Spell sp : allSpells) {
            for (List<CDOMSingleRef<Ability>> list : feats) {
                Integer count = spells.get(ksi, list);
                aSpellList.add(new KitSpellBookEntry(spellBook, sp, list, count));
            }
        }
    }
    final Formula choiceFormula = getCount();
    int numberOfChoices;
    if (choiceFormula == null) {
        numberOfChoices = aSpellList.size();
    } else {
        numberOfChoices = choiceFormula.resolve(aPC, "").intValue();
    }
    //
    if (numberOfChoices > aSpellList.size()) {
        numberOfChoices = aSpellList.size();
    }
    if (numberOfChoices == 0) {
        return false;
    }
    List<KitSpellBookEntry> xs;
    if (numberOfChoices == aSpellList.size()) {
        xs = aSpellList;
    } else {
        //
        while (true) {
            xs = Globals.getChoiceFromList("Choose " + aClass.getKeyName() + " spell(s) for " + workingBook, aSpellList, new ArrayList<>(), numberOfChoices, aPC);
            if (!xs.isEmpty()) {
                break;
            }
        }
    }
    //
    for (KitSpellBookEntry obj : xs) {
        if (obj != null) {
            obj.setPCClass(aClass);
            if (theSpells == null) {
                theSpells = new ArrayList<>();
            }
            theSpells.add(obj);
        } else {
            warnings.add("SPELLS: Non-existant spell chosen");
        }
    }
    if (theSpells != null && !theSpells.isEmpty()) {
        return true;
    }
    return false;
}
Also used : Ability(pcgen.core.Ability) KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) Formula(pcgen.base.formula.Formula) CDOMList(pcgen.cdom.base.CDOMList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 59 with PCClass

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

the class ClassDataHandler method startElement.

/**
	 * @throws SAXException
	 * @throws IllegalArgumentException if the file being processed is not the
	 * same GameMode as requested.
	 *  
	 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
	 */
@Override
public void startElement(final String uri, final String localName, final String aName, final Attributes anAttrs) throws SAXException {
    if (//$NON-NLS-1$
    theState == ParserState.INIT && "class_data".equals(aName)) {
        if (anAttrs != null) {
            //$NON-NLS-1$
            final String gm = anAttrs.getValue("game_mode");
            if (!SystemCollections.getGameModeNamed(gm).equals(theGameMode)) {
                //$NON-NLS-1$
                throw new IllegalArgumentException("Incorrect game mode");
            }
            theValidFlag = true;
        }
        return;
    }
    if (!theValidFlag) {
        //$NON-NLS-1$
        throw new SAXException("NPCGen.Options.InvalidFileFormat");
    }
    if (theState == ParserState.INIT) {
        if (//$NON-NLS-1$
        "class".equals(aName)) {
            if (anAttrs != null) {
                //$NON-NLS-1$
                final String classKey = anAttrs.getValue("key");
                final PCClass pcClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKey);
                if (pcClass == null) {
                    //$NON-NLS-1$
                    Logging.errorPrintLocalised("Exceptions.PCGenParser.ClassNotFound", classKey);
                } else {
                    theCurrentData = new ClassData(pcClass);
                    theState = ParserState.CLASSDATA;
                }
            }
        }
    } else if (theState == ParserState.CLASSDATA) {
        if (//$NON-NLS-1$
        "stats".equals(aName)) {
            theState = ParserState.STATDATA;
        } else if (//$NON-NLS-1$
        "skills".equals(aName)) {
            theState = ParserState.SKILLDATA;
        } else if (//$NON-NLS-1$
        "abilities".equals(aName)) {
            theState = ParserState.ABILITYDATA;
            theCurrentCategory = AbilityCategory.FEAT;
            if (anAttrs != null) {
                //$NON-NLS-1$
                final String catName = anAttrs.getValue("category");
                if (catName != null) {
                    theCurrentCategory = SettingsHandler.getGame().getAbilityCategory(catName);
                }
            }
        } else if (//$NON-NLS-1$
        "spells".equals(aName)) {
            theState = ParserState.SPELLDATA;
            theCurrentSpellType = SpellType.KNOWN;
            if (anAttrs != null) {
                //$NON-NLS-1$
                final String bookName = anAttrs.getValue("type");
                if (bookName != null) {
                    if (//$NON-NLS-1$
                    "Prepared Spells".equals(bookName)) {
                        theCurrentSpellType = SpellType.PREPARED;
                    }
                }
            }
        } else if (//$NON-NLS-1$
        "subclasses".equals(aName)) {
            theState = ParserState.SUBCLASSDATA;
        }
    } else if (theState == ParserState.STATDATA) {
        if (//$NON-NLS-1$
        "stat".equals(aName)) {
            if (anAttrs != null) {
                final int weight = getWeight(anAttrs);
                //$NON-NLS-1$
                final String statAbbr = anAttrs.getValue("value");
                if (statAbbr != null) {
                    PCStat stat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCStat.class, statAbbr);
                    theCurrentData.addStat(stat, weight);
                }
            }
        }
    } else if (theState == ParserState.SKILLDATA) {
        if (//$NON-NLS-1$
        "skill".equals(aName)) {
            if (anAttrs != null) {
                final int weight = getWeight(anAttrs);
                //$NON-NLS-1$
                final String key = anAttrs.getValue("value");
                if (key != null) {
                    if (//$NON-NLS-1$
                    "*".equals(key)) {
                        remainingWeight = weight;
                    } else if (//$NON-NLS-1$
                    key.startsWith("TYPE")) {
                        final List<Skill> skillsOfType = Globals.getPObjectsOfType(Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Skill.class), key.substring(5));
                        if (skillsOfType.isEmpty()) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            Logging.debugPrint("NPCGenerator: No skills of type found (" + key + ")");
                        }
                    } else {
                        final Skill skill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, key);
                        if (skill == null) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            Logging.debugPrint("NPCGenerator: Skill not found (" + key + ")");
                        }
                    }
                    if (//$NON-NLS-1$
                    weight > 0 && !key.equals("*")) {
                        theCurrentData.addSkill(key, weight);
                    } else {
                        removeList.add(key);
                    }
                }
            }
        }
    } else if (theState == ParserState.ABILITYDATA) {
        if (//$NON-NLS-1$
        "ability".equals(aName)) {
            if (anAttrs != null) {
                final int weight = getWeight(anAttrs);
                //$NON-NLS-1$
                final String key = anAttrs.getValue("value");
                if (key != null) {
                    if (//$NON-NLS-1$
                    "*".equals(key)) {
                        remainingWeight = weight;
                    } else if (//$NON-NLS-1$
                    key.startsWith("TYPE")) {
                        Type type = Type.getConstant(key.substring(5));
                        for (final Ability ability : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, theCurrentCategory).getAllObjects()) {
                            if (!ability.containsInList(ListKey.TYPE, type)) {
                                continue;
                            }
                            if (ability.getSafe(ObjectKey.VISIBILITY) == Visibility.DEFAULT) {
                                if (weight > 0) {
                                    theCurrentData.addAbility(theCurrentCategory, ability, weight);
                                } else {
                                    // We have to remove any feats of this
                                    // type.
                                    // TODO - This is a little goofy.  We
                                    // already have the feat but we will 
                                    // store the key and reretrieve it.
                                    removeList.add(ability.getKeyName());
                                }
                            }
                        }
                    } else {
                        final Ability ability = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, theCurrentCategory, key);
                        if (ability == null) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            Logging.debugPrint("Ability (" + key + ") not found");
                        } else if (weight > 0) {
                            theCurrentData.addAbility(theCurrentCategory, ability, weight);
                        } else {
                            // We have to remove any feats of this
                            // type.
                            // TODO - This is a little goofy.  We
                            // already have the feat but we will 
                            // store the key and reretrieve it.
                            removeList.add(ability.getKeyName());
                        }
                    }
                }
            }
        }
    } else if (theState == ParserState.SPELLDATA) {
        if (//$NON-NLS-1$
        "level".equals(aName) && anAttrs != null) {
            //$NON-NLS-1$
            final String lvlStr = anAttrs.getValue("id");
            if (lvlStr != null) {
                theCurrentLevel = Integer.parseInt(lvlStr);
                theState = ParserState.SPELLLEVELDATA;
            }
        }
    } else if (theState == ParserState.SPELLLEVELDATA) {
        if (//$NON-NLS-1$
        "spell".equals(aName) && anAttrs != null) {
            final int weight = getWeight(anAttrs);
            //$NON-NLS-1$
            final String key = anAttrs.getValue("name");
            if (key != null) {
                if (//$NON-NLS-1$
                "*".equals(key)) {
                    remainingWeight = weight;
                } else if (//$NON-NLS-1$
                key.startsWith("SCHOOL")) {
                // Not sure how to do this yet
                } else {
                    final Spell spell = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, key);
                    if (spell != null) {
                        if (theCurrentSpellType == SpellType.KNOWN) {
                            theCurrentData.addKnownSpell(theCurrentLevel, spell, weight);
                        } else if (theCurrentSpellType == SpellType.PREPARED) {
                            theCurrentData.addPreparedSpell(theCurrentLevel, spell, weight);
                        }
                    } else {
                        Logging.errorPrint("Spell \"" + key + "\" not found.");
                    }
                }
            }
        }
    } else if (theState == ParserState.SUBCLASSDATA) {
        if (//$NON-NLS-1$
        "subclass".equals(aName) && anAttrs != null) {
            final int weight = getWeight(anAttrs);
            //$NON-NLS-1$
            final String key = anAttrs.getValue("value");
            theCurrentData.addSubClass(key, weight);
        }
    }
}
Also used : Ability(pcgen.core.Ability) Skill(pcgen.core.Skill) Type(pcgen.cdom.enumeration.Type) PCClass(pcgen.core.PCClass) PCStat(pcgen.core.PCStat) Spell(pcgen.core.spell.Spell) SAXException(org.xml.sax.SAXException)

Example 60 with PCClass

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

the class Configuration method getClassOptions.

public List<ClassGeneratorOption> getClassOptions() {
    final List<ClassGeneratorOption> ret = new ArrayList<>();
    for (final GeneratorOption opt : theGeneratorOptions) {
        if (opt instanceof ClassGeneratorOption) {
            ret.add((ClassGeneratorOption) opt);
        }
    }
    for (final PCClass pcClass : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(PCClass.class)) {
        final ClassGeneratorOption opt = new ClassGeneratorOption();
        opt.setName(pcClass.getDisplayName());
        opt.addChoice(1, pcClass.getKeyName());
        ret.add(opt);
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass)

Aggregations

PCClass (pcgen.core.PCClass)359 Test (org.junit.Test)96 PlayerCharacter (pcgen.core.PlayerCharacter)61 Skill (pcgen.core.Skill)55 ArrayList (java.util.ArrayList)35 Domain (pcgen.core.Domain)30 LoadContext (pcgen.rules.context.LoadContext)28 PCClassLevel (pcgen.cdom.inst.PCClassLevel)26 CDOMObject (pcgen.cdom.base.CDOMObject)23 CharacterSpell (pcgen.core.character.CharacterSpell)20 Spell (pcgen.core.spell.Spell)20 StringTokenizer (java.util.StringTokenizer)19 CharID (pcgen.cdom.enumeration.CharID)19 ClassSource (pcgen.cdom.helper.ClassSource)19 PreClassTester (plugin.pretokens.test.PreClassTester)16 SkillCost (pcgen.cdom.enumeration.SkillCost)15 ParseResult (pcgen.rules.persistence.token.ParseResult)15 Ability (pcgen.core.Ability)14 Race (pcgen.core.Race)14 BonusObj (pcgen.core.bonus.BonusObj)14