use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangelevelToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClass pcc) {
LevelExchange le = context.getObjectContext().getObject(pcc, ObjectKey.EXCHANGE_LEVEL);
if (le == null) {
return null;
}
StringBuilder sb = new StringBuilder();
sb.append(le.getExchangeClass().getLSTformat(false)).append(Constants.PIPE);
sb.append(le.getMinDonatingLevel()).append(Constants.PIPE);
sb.append(le.getMaxDonatedLevels()).append(Constants.PIPE);
sb.append(le.getDonatingLowerLevelBound());
return new String[] { sb.toString() };
}
use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangeLevelTokenTest method testUnparseBadRemainMathLevel.
@Test
public void testUnparseBadRemainMathLevel() throws PersistenceLayerException {
try {
PCClass fighter = primaryContext.getReferenceContext().constructCDOMObject(PCClass.class, "Fighter");
LevelExchange le = new LevelExchange(CDOMDirectSingleRef.getRef(fighter), 4, 2, 1);
primaryProf.put(ObjectKey.EXCHANGE_LEVEL, le);
assertBadUnparse();
} catch (IllegalArgumentException e) {
// Good here too :)
}
}
use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangeLevelTokenTest method testUnparseNegativeMaxLevel.
@Test
public void testUnparseNegativeMaxLevel() throws PersistenceLayerException {
try {
PCClass fighter = primaryContext.getReferenceContext().constructCDOMObject(PCClass.class, "Fighter");
LevelExchange le = new LevelExchange(CDOMDirectSingleRef.getRef(fighter), 4, -12, 2);
primaryProf.put(ObjectKey.EXCHANGE_LEVEL, le);
assertBadUnparse();
} catch (IllegalArgumentException e) {
// Good here too :)
}
}
use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangeLevelApplication method exchangeLevels.
public static void exchangeLevels(final PlayerCharacter aPC, PCClass newcl) {
LevelExchange le = newcl.get(ObjectKey.EXCHANGE_LEVEL);
try {
PCClass cl = le.getExchangeClass().get();
int iMinLevel = le.getMinDonatingLevel();
int iMaxDonation = le.getMaxDonatedLevels();
int iLowest = le.getDonatingLowerLevelBound();
final PCClass aClass = aPC.getClassKeyed(cl.getKeyName());
if (aClass != null) {
final int iNumOrigClassLevel = aPC.getLevel(aClass);
if (iNumOrigClassLevel >= iMinLevel) {
iMaxDonation = Math.min(iMaxDonation, iNumOrigClassLevel - iLowest + 1);
if (newcl.hasMaxLevel()) {
iMaxDonation = Math.min(iMaxDonation, newcl.getSafe(IntegerKey.LEVEL_LIMIT) - aPC.getLevel(newcl));
}
if (iMaxDonation > 0) {
//
// Build the choice list
//
final List<Integer> choiceNames = new ArrayList<>();
for (int i = 0; i <= iMaxDonation; ++i) {
choiceNames.add(i);
}
//
// Get number of levels to exchange for this class
//
String title = LanguageBundle.getFormattedString("in_exchangeLevelsChoice", aClass.getDisplayName(), newcl.getDisplayName());
CDOMChooserFacadeImpl<Integer> chooserFacade = new CDOMChooserFacadeImpl<>(title, choiceNames, new ArrayList<>(), 1);
chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
final List<Integer> selectedList = chooserFacade.getFinalSelected();
int iLevels = 0;
if (!selectedList.isEmpty()) {
iLevels = selectedList.get(0);
}
if (iLevels > 0) {
aPC.giveClassesAway(newcl, aClass, iLevels);
}
}
}
}
} catch (NumberFormatException exc) {
ShowMessageDelegate.showMessageDialog("levelExchange:" + Constants.LINE_SEPARATOR + exc.getMessage(), Constants.APPLICATION_NAME, MessageType.ERROR);
}
}
Aggregations