Search in sources :

Example 11 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class PCClass method clone.

@Override
public PCClass clone() {
    PCClass aClass = null;
    try {
        aClass = (PCClass) super.clone();
        List<KnownSpellIdentifier> ksl = getListFor(ListKey.KNOWN_SPELLS);
        if (ksl != null) {
            aClass.removeListFor(ListKey.KNOWN_SPELLS);
            for (KnownSpellIdentifier ksi : ksl) {
                aClass.addToListFor(ListKey.KNOWN_SPELLS, ksi);
            }
        }
        Map<AttackType, Integer> acmap = getMapFor(MapKey.ATTACK_CYCLE);
        if (acmap != null && !acmap.isEmpty()) {
            aClass.removeMapFor(MapKey.ATTACK_CYCLE);
            for (Map.Entry<AttackType, Integer> me : acmap.entrySet()) {
                aClass.addToMapFor(MapKey.ATTACK_CYCLE, me.getKey(), me.getValue());
            }
        }
        aClass.levelMap = new TreeMap<>();
        for (Map.Entry<Integer, PCClassLevel> me : levelMap.entrySet()) {
            aClass.levelMap.put(me.getKey(), me.getValue().clone());
        }
    } catch (CloneNotSupportedException exc) {
        ShowMessageDelegate.showMessageDialog(exc.getMessage(), Constants.APPLICATION_NAME, MessageType.ERROR);
    }
    return aClass;
}
Also used : KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) AttackType(pcgen.util.enumeration.AttackType) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 12 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class CharacterFacadeImpl method buildAvailableDomainsList.

/**
	 * This method returns all available domains, without filtering.
	 */
private void buildAvailableDomainsList() {
    List<DomainFacadeImpl> availDomainList = new ArrayList<>();
    List<DomainFacadeImpl> selDomainList = new ArrayList<>();
    Deity pcDeity = charDisplay.getDeity();
    if (pcDeity != null) {
        for (CDOMReference<Domain> domainRef : pcDeity.getSafeListMods(Deity.DOMAINLIST)) {
            Collection<AssociatedPrereqObject> assoc = pcDeity.getListAssociations(Deity.DOMAINLIST, domainRef);
            for (AssociatedPrereqObject apo : assoc) {
                for (Domain d : domainRef.getContainedObjects()) {
                    if (!isDomainInList(availDomainList, d)) {
                        availDomainList.add(new DomainFacadeImpl(d, apo.getPrerequisiteList()));
                    }
                }
            }
        }
    }
    // Loop through the available prestige domains
    for (PCClass aClass : charDisplay.getClassList()) {
        /*
			 * Need to do for the class, for compatibility, since level 0 is
			 * loaded into the class itself
			 */
        processDomainList(aClass, availDomainList);
        processAddDomains(aClass, availDomainList);
        for (int lvl = 0; lvl <= charDisplay.getLevel(aClass); lvl++) {
            PCClassLevel cl = charDisplay.getActiveClassLevel(aClass, lvl);
            processAddDomains(cl, availDomainList);
            processDomainList(cl, availDomainList);
        }
    }
    // Loop through the character's selected domains
    for (Domain d : charDisplay.getDomainSet()) {
        DomainFacadeImpl domainFI = new DomainFacadeImpl(d);
        boolean found = false;
        for (DomainFacadeImpl row : availDomainList) {
            if (d.equals(row.getRawObject())) {
                domainFI = row;
                found = true;
                break;
            }
        }
        if (!found) {
            availDomainList.add(domainFI);
        }
        if (!isDomainInList(selDomainList, d)) {
            selDomainList.add(domainFI);
        }
    }
    availDomains.updateContents(availDomainList);
    domains.updateContents(selDomainList);
    maxDomains.set(theCharacter.getMaxCharacterDomains());
    remainingDomains.set(theCharacter.getMaxCharacterDomains() - charDisplay.getDomainCount());
    updateDomainTodo();
}
Also used : Deity(pcgen.core.Deity) ArrayList(java.util.ArrayList) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 13 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class PCClassLoader method parseClassLevelLine.

public void parseClassLevelLine(LoadContext context, PCClass pcClass, int lvl, SourceEntry source, String restOfLine) throws PersistenceLayerException {
    if (restOfLine == null) {
        return;
    }
    PCClassLevel classlevel = pcClass.getOriginalClassLevel(lvl);
    final StringTokenizer colToken = new StringTokenizer(restOfLine, SystemLoader.TAB_DELIM);
    // loop through all the tokens and parse them
    while (colToken.hasMoreTokens()) {
        String token = colToken.nextToken().trim();
        int colonLoc = token.indexOf(':');
        if (colonLoc == -1) {
            Logging.errorPrint("Invalid Token - does not contain a colon: '" + token + "' in Class " + pcClass.getDisplayName() + " of " + source);
            continue;
        } else if (colonLoc == 0) {
            Logging.errorPrint("Invalid Token - starts with a colon: '" + token + "' in Class " + pcClass.getDisplayName() + " of " + source);
            continue;
        }
        String key = token.substring(0, colonLoc);
        String value = (colonLoc == token.length() - 1) ? null : token.substring(colonLoc + 1);
        if (context.processToken(classlevel, key.intern(), value.intern())) {
            context.commit();
        } else {
            context.rollback();
            Logging.replayParsedMessages();
        }
        Logging.clearParseMessages();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 14 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class ClassSkillChoiceActor method applyChoice.

/**
	 * Applies the given Skill choice to the given PlayerCharacter. The given
	 * Skill is added as a class skill for the PCClass provided during
	 * construction of this ClassSkillChoiceActor. If the number of ranks
	 * provided during construction of this ClassSkillChoiceActor was not null
	 * or zero, then ranks are also applied to the given skill.
	 * 
	 * @param owner
	 *            The owning object for this choice.
	 * @param choice
	 *            The Skill which should be added as a Class Skill for the
	 *            PCClass provided during construction of this
	 *            ClassSkillChoiceActor
	 * @param pc
	 *            The PlayerCharacter to which the changes driven by this
	 *            ClassSkillChoiceActor should be applied.
	 */
@Override
public void applyChoice(CDOMObject owner, Skill choice, PlayerCharacter pc) {
    PCClass pcc = getSourceClass(pc);
    if (pcc == null) {
        Logging.errorPrint("Unable to find the pc's class " + source + " to apply skill choices to.");
        return;
    }
    pc.addLocalCost(pcc, choice, SkillCost.CLASS, owner);
    if (applyRank != null) {
        if (owner instanceof PCClassLevel) {
            // Ensure that the skill points for this level are already calculated.
            PCClassLevel classLevel = (PCClassLevel) owner;
            PCClass pcClass = (PCClass) classLevel.getSafe(ObjectKey.PARENT);
            int levelIndex = 1;
            for (PCLevelInfo lvlInfo : pc.getLevelInfo()) {
                if (lvlInfo.getClassKeyName() == pcClass.getKeyName() && lvlInfo.getClassLevel() == classLevel.getSafe(IntegerKey.LEVEL)) {
                    pc.checkSkillModChangeForLevel(pcClass, lvlInfo, classLevel, levelIndex++);
                    break;
                }
            }
        }
        String result = SkillRankControl.modRanks(applyRank, pcc, false, pc, choice);
        if (StringUtils.isNotEmpty(result)) {
            Logging.errorPrint("Unable to apply {0} ranks of {1}. Error: {2}", applyRank, choice, result);
        }
    }
}
Also used : PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 15 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class ClassToken method getClassSpecialAbilityList.

/**
	 * Get the list of Special Abilities for a class that the PC is eligible
	 * for.
	 * 
	 * @param pcclass
	 *            The class to get the special abilities for
	 * @param aPC
	 *            The PC
	 * @return List of special abilities
	 */
public static List<String> getClassSpecialAbilityList(PCClass pcclass, final PlayerCharacter aPC) {
    CharacterDisplay display = aPC.getDisplay();
    final List<String> formattedList = new ArrayList<>();
    final List<SpecialAbility> saList = new ArrayList<>();
    saList.addAll(display.getResolvedUserSpecialAbilities(pcclass));
    saList.addAll(display.getResolvedSpecialAbilities(pcclass));
    for (int i = 1; i <= display.getLevel(pcclass); i++) {
        PCClassLevel pcl = display.getActiveClassLevel(pcclass, i);
        saList.addAll(display.getResolvedUserSpecialAbilities(pcl));
        saList.addAll(display.getResolvedSpecialAbilities(pcl));
    }
    if (saList.isEmpty()) {
        return formattedList;
    }
    Collections.sort(saList);
    // to include all of the variables
    for (SpecialAbility sa : saList) {
        String str = sa.getDisplayName();
        if (str == null || str.isEmpty()) {
            continue;
        }
        StringTokenizer varTok = new StringTokenizer(str, Constants.PIPE);
        final String aString = varTok.nextToken();
        int[] varValue = null;
        int varCount = varTok.countTokens();
        if (varCount != 0) {
            varValue = new int[varCount];
            for (int j = 0; j < varCount; ++j) {
                // Get the value for each variable
                final String vString = varTok.nextToken();
                varValue[j] = aPC.getVariable(vString, true).intValue();
            }
        }
        final StringBuilder newAbility = new StringBuilder();
        varTok = new StringTokenizer(aString, "%", true);
        varCount = 0;
        boolean isZero = false;
        // Fill in each % with the value of the appropriate token
        while (varTok.hasMoreTokens()) {
            final String nextTok = varTok.nextToken();
            if ("%".equals(nextTok)) {
                if (varCount == 0) {
                    // If this is the first token, then set the count of
                    // successful token replacements to 0
                    isZero = true;
                }
                if ((varValue != null) && (varCount < varValue.length)) {
                    final int thisVar = varValue[varCount++];
                    // Update isZero if this token has a value of anything
                    // other than 0
                    isZero &= (thisVar == 0);
                    newAbility.append(thisVar);
                } else {
                    newAbility.append('%');
                }
            } else {
                newAbility.append(nextTok);
            }
        }
        if (!isZero) {
            // If all of the tokens for this ability were 0 then we do not
            // show it,
            // otherwise we add it to the return list.
            formattedList.add(newAbility.toString());
        }
    }
    return formattedList;
}
Also used : StringTokenizer(java.util.StringTokenizer) CharacterDisplay(pcgen.core.display.CharacterDisplay) ArrayList(java.util.ArrayList) SpecialAbility(pcgen.core.SpecialAbility) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Aggregations

PCClassLevel (pcgen.cdom.inst.PCClassLevel)69 PCClass (pcgen.core.PCClass)26 Test (org.junit.Test)25 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)9 CDOMObject (pcgen.cdom.base.CDOMObject)8 ArrayList (java.util.ArrayList)5 CharID (pcgen.cdom.enumeration.CharID)5 ParseResult (pcgen.rules.persistence.token.ParseResult)5 CDOMReference (pcgen.cdom.base.CDOMReference)4 SpecialAbility (pcgen.core.SpecialAbility)4 LoadContext (pcgen.rules.context.LoadContext)4 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)4 StringTokenizer (java.util.StringTokenizer)3 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)3 Domain (pcgen.core.Domain)3 Skill (pcgen.core.Skill)3 TestContext (plugin.lsttokens.editcontext.testsupport.TestContext)3 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2