use of pcgen.core.Language in project pcgen by PCGen.
the class AutoLangListTest method testFromTemplate.
@Test
public void testFromTemplate() throws PersistenceLayerException {
PCTemplate source = create(PCTemplate.class, "Source");
Language granted = createGrantedObject();
processToken(source);
assertEquals(0, getCount());
templateInputFacet.directAdd(id, source, getAssoc());
assertTrue(containsExpected(granted));
assertEquals(1, getCount());
templateInputFacet.remove(id, source);
assertEquals(0, getCount());
assertTrue(cleanedSideEffects());
}
use of pcgen.core.Language in project pcgen by PCGen.
the class AutoLangListTest method testFromRace.
@Test
public void testFromRace() throws PersistenceLayerException {
Race source = create(Race.class, "Source");
Language granted = createGrantedObject();
processToken(source);
assertEquals(0, getCount());
raceFacet.directSet(id, source, getAssoc());
assertTrue(containsExpected(granted));
assertEquals(1, getCount());
raceFacet.remove(id);
assertEquals(0, getCount());
assertTrue(cleanedSideEffects());
}
use of pcgen.core.Language in project pcgen by PCGen.
the class PCClassLangbonusTest method testSimple.
@Test
public void testSimple() throws PersistenceLayerException {
PCClass source = create(PCClass.class, "Source");
Language granted = create(Language.class, "Granted");
ParseResult result = token.parseToken(context, source, "Granted");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
finishLoad();
assertEquals(0, startingLanguageFacet.getCount(id));
classFacet.addClass(id, source);
assertTrue(startingLanguageFacet.contains(id, granted));
assertEquals(1, startingLanguageFacet.getCount(id));
classFacet.removeClass(id, source);
assertEquals(0, startingLanguageFacet.getCount(id));
}
use of pcgen.core.Language in project pcgen by PCGen.
the class LanguageChooserFacadeImpl method commit.
/**
* @see pcgen.core.facade.LanguageChooserFacade#commit()
*/
@Override
@SuppressWarnings("unchecked")
public void commit() {
ChoiceManagerList<Language> choiceManager = ChooserUtilities.getChoiceManager(source, theCharacter);
List<Language> selected = new ArrayList<>(selectedList.getSize());
for (LanguageFacade langFacade : selectedList) {
selected.add((Language) langFacade);
}
choiceManager.applyChoices(theCharacter, selected);
// Update list on character facade
pcFacade.refreshLanguageList();
}
use of pcgen.core.Language in project pcgen by PCGen.
the class KitSkill method addRanks.
private KitSkillAdd addRanks(PlayerCharacter pc, PCClass pcClass, Skill aSkill, double ranksLeftToAdd, boolean isFree, List<String> warnings) {
if (!isFree && pcClass.getSkillPool(pc) == 0) {
return null;
}
double curRank = 0.0;
if (pc.hasSkill(aSkill)) {
curRank = pc.getRank(aSkill).doubleValue();
}
double ranksToAdd = ranksLeftToAdd;
if (!Globals.checkRule(RuleConstants.SKILLMAX) && (ranksToAdd > 0.0)) {
ranksToAdd = Math.min(pc.getMaxRank(aSkill, pcClass).doubleValue(), curRank + ranksLeftToAdd);
ranksToAdd -= curRank;
if (!CoreUtility.doublesEqual(ranksToAdd, ranksLeftToAdd)) {
warnings.add("SKILL: Could not add " + (ranksLeftToAdd - ranksToAdd) + " to " + aSkill.getDisplayName() + ". Exceeds MAXRANK of " + pc.getMaxRank(aSkill, pcClass) + ".");
}
}
int ptsToSpend = 0;
int[] points = new int[pc.getLevelInfoSize()];
if (!isFree) {
double ranksAdded = 0.0;
int skillCost = pc.getSkillCostForClass(aSkill, pcClass).getCost();
ptsToSpend = (int) (ranksToAdd * skillCost);
for (int i = 0; i < pc.getLevelInfoSize(); i++) {
PCLevelInfo info = pc.getLevelInfo(i);
if (info.getClassKeyName().equals(pcClass.getKeyName())) {
// We are spending this class' points.
points[i] = info.getSkillPointsRemaining();
} else {
points[i] = -1;
}
}
for (int i = 0; i < points.length; i++) {
int remaining = points[i];
if (remaining <= 0) {
continue;
}
int left = remaining - Math.min(remaining, ptsToSpend);
points[i] = left;
int spent = (remaining - left);
ptsToSpend -= spent;
ranksAdded += ((double) spent / (double) skillCost);
if (ranksAdded == ranksToAdd || ptsToSpend <= 0) {
break;
}
}
ranksToAdd = ranksAdded;
ptsToSpend = (int) (ranksToAdd * skillCost);
}
String ret = SkillRankControl.modRanks(ranksToAdd, pcClass, false, pc, aSkill);
if (!ret.isEmpty()) {
if (isFree && ret.indexOf("You do not have enough skill points.") != -1) {
SkillRankControl.modRanks(ranksToAdd, pcClass, true, pc, aSkill);
} else {
warnings.add(ret);
return null;
}
}
if (!isFree) {
for (int i = 0; i < pc.getLevelInfoSize(); i++) {
PCLevelInfo info = pc.getLevelInfo(i);
if (points[i] >= 0) {
info.setSkillPointsRemaining(points[i]);
}
}
}
List<Language> langList = new ArrayList<>();
if (ChooseActivation.hasNewChooseToken(aSkill) && !selection.isEmpty()) {
ChoiceManagerList<Language> controller = ChooserUtilities.getConfiguredController(aSkill, pc, null, new ArrayList<>());
int limit = (int) ranksToAdd;
for (CDOMSingleRef<Language> ref : selection) {
Language lang = ref.get();
if (controller.conditionallyApply(pc, lang)) {
langList.add(lang);
limit--;
}
if (limit <= 0) {
break;
}
}
}
return new KitSkillAdd(aSkill, ranksToAdd, ptsToSpend, langList, pcClass);
}
Aggregations