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());
}
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;
}
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();
}
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;
}
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();
}
Aggregations