use of pcgen.core.Language in project pcgen by PCGen.
the class KitSkill method updatePCSkills.
/**
* Needs documentation.
*
* @param pc update skills for this PC
* @param aSkill Skill to update
* @param aRank Number of ranks to add
* @param aCost Cost of added ranks
* @param langList Languages to be selected for a language skill
* @param pcClass skills apply to this class
*
* @return {@code true} for success
* TODO What about throwing on failure?
*/
private boolean updatePCSkills(final PlayerCharacter pc, final Skill aSkill, final int aRank, final double aCost, List<Language> langList, final PCClass pcClass) {
boolean oldImporting = pc.isImporting();
pc.setImporting(true);
final String aString = SkillRankControl.modRanks(aRank, pcClass, true, pc, aSkill);
pc.setImporting(oldImporting);
if (!aString.isEmpty()) {
Logging.errorPrint("SKILL: " + aString);
return false;
}
// Add any supplied languages
ChoiceManagerList<Language> controller = ChooserUtilities.getConfiguredController(aSkill, pc, null, new ArrayList<>());
for (Language lang : langList) {
if (!controller.conditionallyApply(pc, lang)) {
Logging.errorPrint("Failed to apply Language into Skill: " + lang.getLSTformat());
}
}
//
// Fix up the skill pools to reflect what we just spent.
//
double ptsToSpend = aCost;
if (ptsToSpend >= 0.0) {
for (PCLevelInfo info : pc.getLevelInfo()) {
if (info.getClassKeyName().equals(pcClass.getKeyName())) {
// We are spending this class' points.
int remaining = info.getSkillPointsRemaining();
if (remaining == 0) {
continue;
}
int left = remaining - (int) Math.min(remaining, ptsToSpend);
info.setSkillPointsRemaining(left);
ptsToSpend -= (remaining - left);
if (ptsToSpend <= 0) {
break;
}
}
}
}
return true;
}
use of pcgen.core.Language in project pcgen by PCGen.
the class LanguagesToken method getToken.
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
@Override
public String getToken(String tokenSource, CharacterDisplay display, ExportHandler eh) {
StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
aTok.nextToken();
int languageIndex = 0;
int startIndex = 0;
List<Language> languageList = new ArrayList<>(display.getSortedLanguageSet());
if (aTok.hasMoreTokens()) {
try {
startIndex = Integer.parseInt(aTok.nextToken());
languageIndex = startIndex + 1;
/*
* PERFORMANCE This can actually shortcut the subList below, as
* it really is only grabbling one language
*/
} catch (NumberFormatException e) {
//TODO: Should this really be ignored?
}
} else {
languageIndex = languageList.size();
}
if (languageList.isEmpty()) {
return "";
}
List<Language> subList = languageList.subList(Math.max(startIndex, 0), Math.min(languageIndex, languageList.size()));
return StringUtil.join(subList, ", ");
}
use of pcgen.core.Language in project pcgen by PCGen.
the class StartingLanguageFacetTest method getObject.
@Override
protected Language getObject() {
Language wp = new Language();
wp.setName("WP" + n++);
return wp;
}
use of pcgen.core.Language in project pcgen by PCGen.
the class LangToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
Changes<QualifiedObject<CDOMReference<Language>>> changes = context.getObjectContext().getListChanges(obj, ListKey.AUTO_LANGUAGE);
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
Collection<QualifiedObject<CDOMReference<Language>>> added = changes.getAdded();
StringBuilder sb = new StringBuilder();
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
boolean foundAny = false;
boolean foundOther = false;
if (changes.includesGlobalClear()) {
sb.append(Constants.LST_DOT_CLEAR);
}
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> cra : listAdded) {
if (cra.getSource().equals(getTokenName())) {
try {
if (sb.length() > 0) {
sb.append('|');
}
sb.append(cra.getLstFormat());
foundOther = true;
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
}
}
}
if (added != null) {
boolean needPipe = sb.length() > 0;
Prerequisite prereq = null;
for (QualifiedObject<CDOMReference<Language>> spp : added) {
CDOMReference<Language> lang = spp.getRawObject();
List<Prerequisite> prereqs = spp.getPrerequisiteList();
String ab = lang.getLSTformat(false);
boolean isUnconditionalAll = Constants.LST_ALL.equals(ab);
foundAny |= isUnconditionalAll;
foundOther |= !isUnconditionalAll;
if (needPipe) {
sb.append('|');
}
needPipe = true;
if (prereqs != null && !prereqs.isEmpty()) {
if (prereqs.size() > 1) {
context.addWriteMessage("Error: " + obj.getClass().getSimpleName() + " had more than one Prerequisite for " + getFullName());
return null;
}
Prerequisite p = prereqs.get(0);
if (prereq != null && !p.equals(prereq)) {
context.addWriteMessage("Error: " + obj.getClass().getSimpleName() + " had differing Prerequisites for " + getFullName());
return null;
}
prereq = p;
}
sb.append(ab);
}
if (prereq != null) {
StringWriter swriter = new StringWriter();
try {
prereqWriter.write(swriter, prereq);
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
sb.append('|').append(swriter.toString());
}
}
if (foundAny && foundOther) {
context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + sb);
return null;
}
if (sb.length() == 0) {
// okay
return null;
}
return new String[] { sb.toString() };
}
use of pcgen.core.Language in project pcgen by PCGen.
the class PreLanguageTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
final String requiredLang = prereq.getKey();
final int requiredNumber = Integer.parseInt(prereq.getOperand());
int runningTotal = 0;
if (prereq.getKey().equalsIgnoreCase("ANY")) {
//$NON-NLS-1$
runningTotal = display.getLanguageCount();
} else {
final Language aLang = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Language.class, requiredLang);
if (aLang != null) {
if (display.hasLanguage(aLang)) {
runningTotal = 1;
}
} else if (//$NON-NLS-1$
!requiredLang.equals("ANY")) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreLanguage.error.no_such_language", //$NON-NLS-1$
requiredLang));
}
}
runningTotal = prereq.getOperator().compare(runningTotal, requiredNumber);
return countedTotal(prereq, runningTotal);
}
Aggregations