Search in sources :

Example 46 with PCClass

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

the class AbstractContentTokenTest method testFromClass.

@Test
public void testFromClass() throws PersistenceLayerException {
    PCClass source = create(PCClass.class, "Source");
    processToken(source);
    assertEquals(baseCount(), targetFacetCount());
    classFacet.addClass(id, source);
    assertTrue(containsExpected());
    assertEquals(baseCount() + 1, targetFacetCount());
    classFacet.removeClass(id, source);
    assertEquals(baseCount(), targetFacetCount());
}
Also used : PCClass(pcgen.core.PCClass) Test(org.junit.Test) AbstractTokenModelTest(tokenmodel.testsupport.AbstractTokenModelTest)

Example 47 with PCClass

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

the class CharacterFacadeImpl method validateAlignmentChange.

/**
	 * Validate the new alignment matches those allowed for the character's 
	 * classes. If not offer the user a choice of backing out or making the 
	 * classes into ex-classes.
	 * 
	 * @param newAlign The alignment to be set
	 */
private boolean validateAlignmentChange(AlignmentFacade newAlign) {
    AlignmentFacade oldAlign = this.alignment.get();
    if (oldAlign == null || newAlign.equals(oldAlign)) {
        return true;
    }
    // We can't do any validation if the new alignment isn't a known class
    if (!(newAlign instanceof PCAlignment)) {
        return true;
    }
    //
    // Get a list of classes that will become unqualified (and have an ex-class)
    //
    StringBuilder unqualified = new StringBuilder(100);
    List<PCClass> classList = charDisplay.getClassList();
    List<PCClass> exclassList = new ArrayList<>();
    PCAlignment savedAlignmnet = charDisplay.getPCAlignment();
    for (PCClass aClass : classList) {
        theCharacter.setAlignment((PCAlignment) newAlign);
        {
            if (!theCharacter.isQualified(aClass)) {
                if (aClass.containsKey(ObjectKey.EX_CLASS)) {
                    if (unqualified.length() > 0) {
                        //$NON-NLS-1$
                        unqualified.append(", ");
                    }
                    unqualified.append(aClass.getKeyName());
                    exclassList.add(aClass);
                }
            }
        }
    }
    //
    if (unqualified.length() > 0) {
        if (!delegate.showWarningConfirm(Constants.APPLICATION_NAME, LanguageBundle.getString("in_sumExClassesWarning") + Constants.LINE_SEPARATOR + unqualified)) {
            theCharacter.setAlignment(savedAlignmnet);
            return false;
        }
    }
    //
    for (PCClass aClass : exclassList) {
        theCharacter.makeIntoExClass(aClass);
    }
    // Update the facade and UI
    refreshClassLevelModel();
    return true;
}
Also used : PCAlignment(pcgen.core.PCAlignment) ArrayList(java.util.ArrayList) AlignmentFacade(pcgen.facade.core.AlignmentFacade) PCClass(pcgen.core.PCClass)

Example 48 with PCClass

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

the class CharacterFacadeImpl method refreshClassLevelModel.

void refreshClassLevelModel() {
    List<CharacterLevelFacade> newlevels = new ArrayList<>();
    List<PCClass> newClasses = charDisplay.getClassList();
    Collection<PCLevelInfo> levelInfo = charDisplay.getLevelInfo();
    Map<String, PCClass> classMap = new HashMap<>();
    for (PCClass pcClass : newClasses) {
        classMap.put(pcClass.getKeyName(), pcClass);
    }
    for (PCLevelInfo lvlInfo : levelInfo) {
        final String classKeyName = lvlInfo.getClassKeyName();
        PCClass currClass = classMap.get(classKeyName);
        if (currClass == null) {
            Logging.errorPrint("No PCClass found for '" + classKeyName + "' in character's class list: " + newClasses);
            return;
        }
        CharacterLevelFacadeImpl cl = new CharacterLevelFacadeImpl(currClass, newlevels.size() + 1);
        newlevels.add(cl);
    }
    pcClasses.clear();
    pcClasses.addAll(newClasses);
    pcClassLevels.updateContents(newlevels);
    // Now get the CharacterLevelsFacadeImpl to do a refresh too.
    charLevelsFacade.classListRefreshRequired();
}
Also used : CharacterLevelFacade(pcgen.facade.core.CharacterLevelFacade) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass)

Example 49 with PCClass

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

the class CharacterFacadeImpl method validateAddLevel.

private boolean validateAddLevel(PCClass theClass) {
    int levels = 1;
    if (theClass == null) {
        return false;
    }
    if (!theCharacter.isQualified(theClass)) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString("in_clYouAreNotQualifiedToTakeTheClass"));
        return false;
    }
    if (!theCharacter.canLevelUp()) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString("in_Enforce_rejectLevelUp"));
        return false;
    }
    final PCClass aClass = theCharacter.getClassKeyed(theClass.getKeyName());
    // Check if the subclass (if any) is qualified for
    if (aClass != null) {
        String subClassKey = charDisplay.getSubClassName(aClass);
        if (subClassKey != null) {
            final PCClass subClass = aClass.getSubClassKeyed(subClassKey);
            if (subClass != null && !theCharacter.isQualified(subClass)) {
                delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString(//$NON-NLS-1$
                "in_sumYouAreNotQualifiedToTakeTheClass", aClass.getDisplayName() + "/" + //$NON-NLS-1$
                subClass.getDisplayName()));
                return false;
            }
        }
    }
    if (!Globals.checkRule(RuleConstants.LEVELCAP) && theClass.hasMaxLevel() && ((levels > theClass.getSafe(IntegerKey.LEVEL_LIMIT)) || ((aClass != null) && ((charDisplay.getLevel(aClass) + levels) > aClass.getSafe(IntegerKey.LEVEL_LIMIT))))) {
        delegate.showInfoMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
        LanguageBundle.getFormattedString(//$NON-NLS-1$
        "in_sumMaximumLevelIs", String.valueOf(theClass.getSafe(IntegerKey.LEVEL_LIMIT))));
        return false;
    }
    // Check with the user on their first level up
    if (charDisplay.getTotalLevels() == 0) {
        if (SettingsHandler.getGame().isPurchaseStatMode() && (theCharacter.getPointBuyPoints() > getUsedStatPool())) {
            if (!//$NON-NLS-1$
            delegate.showWarningConfirm(//$NON-NLS-1$
            LanguageBundle.getString("in_sumLevelWarnTitle"), //$NON-NLS-1$
            LanguageBundle.getString("in_sumPoolWarning"))) {
                return false;
            }
        } else if (allAbilitiesAreZero()) {
            if (!delegate.showWarningConfirm(LanguageBundle.getString("in_sumLevelWarnTitle"), LanguageBundle.getString("in_sumAbilitiesZeroWarning"))) {
                return false;
            }
        } else {
            Boolean proceed = delegate.maybeShowWarningConfirm(LanguageBundle.getString("in_sumLevelWarnTitle"), LanguageBundle.getString("in_sumAbilitiesWarning"), LanguageBundle.getString("in_sumAbilitiesWarningCheckBox"), PCGenSettings.OPTIONS_CONTEXT, PCGenSettings.OPTION_SHOW_WARNING_AT_FIRST_LEVEL_UP);
            if (Boolean.FALSE.equals(proceed)) {
                return false;
            }
        }
    }
    return true;
}
Also used : PCClass(pcgen.core.PCClass)

Example 50 with PCClass

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

the class CharacterFacadeImpl method removeCharacterLevels.

/**
	 * @see pcgen.core.facade.CharacterFacade#removeCharacterLevels(int)
	 */
@Override
public void removeCharacterLevels(int levels) {
    for (int i = levels; i > 0 && !pcClassLevels.isEmpty(); i--) {
        ClassFacade classFacade = charLevelsFacade.getClassTaken(pcClassLevels.getElementAt(pcClassLevels.getSize() - 1));
        pcClassLevels.removeElement(pcClassLevels.getSize() - 1);
        if (classFacade instanceof PCClass) {
            Logging.log(Logging.INFO, charDisplay.getName() + ": Removing level " + //$NON-NLS-1$
            (pcClassLevels.getSize() + 1) + " in class " + //$NON-NLS-1$
            classFacade);
            theCharacter.incrementClassLevel(-1, (PCClass) classFacade);
        }
        charLevelsFacade.removeLastLevel();
    }
    // Clean up the class list 
    for (Iterator<ClassFacade> iterator = pcClasses.iterator(); iterator.hasNext(); ) {
        ClassFacade classFacade = iterator.next();
        boolean stillPresent = false;
        for (CharacterLevelFacade charLevel : pcClassLevels) {
            if (charLevelsFacade.getClassTaken(charLevel) == classFacade) {
                stillPresent = true;
                break;
            }
        }
        if (!stillPresent) {
            iterator.remove();
        }
    }
    postLevellingUpdates();
}
Also used : CharacterLevelFacade(pcgen.facade.core.CharacterLevelFacade) ClassFacade(pcgen.facade.core.ClassFacade) 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