MCPcopy Create free account
hub / github.com/PCGen/pcgen / addRanks

Method addRanks

code/src/java/pcgen/core/kit/KitSkill.java:306–418  ·  view source on GitHub ↗
(PlayerCharacter pc, PCClass pcClass, Skill aSkill, double ranksLeftToAdd,
		boolean isFree, List<String> warnings)

Source from the content-addressed store, hash-verified

304 }
305
306 private KitSkillAdd addRanks(PlayerCharacter pc, PCClass pcClass, Skill aSkill, double ranksLeftToAdd,
307 boolean isFree, List<String> warnings)
308 {
309 if (!isFree && pcClass.getSkillPool(pc) == 0)
310 {
311 return null;
312 }
313
314 double curRank = 0.0;
315 if (pc.hasSkill(aSkill))
316 {
317 curRank = pc.getRank(aSkill).doubleValue();
318 }
319 double ranksToAdd = ranksLeftToAdd;
320 if (!Globals.checkRule(RuleConstants.SKILLMAX) && (ranksToAdd > 0.0))
321 {
322 ranksToAdd = Math.min(pc.getMaxRank(aSkill, pcClass).doubleValue(), curRank + ranksLeftToAdd);
323 ranksToAdd -= curRank;
324 if (!CoreUtility.doublesEqual(ranksToAdd, ranksLeftToAdd))
325 {
326 warnings.add("SKILL: Could not add " + (ranksLeftToAdd - ranksToAdd) + " to " + aSkill.getDisplayName()
327 + ". Exceeds MAXRANK of " + pc.getMaxRank(aSkill, pcClass) + ".");
328 }
329 }
330 int ptsToSpend = 0;
331 int[] points = new int[pc.getLevelInfoSize()];
332 if (!isFree)
333 {
334 double ranksAdded = 0.0;
335 int skillCost = pc.getSkillCostForClass(aSkill, pcClass).getCost();
336 ptsToSpend = (int) (ranksToAdd * skillCost);
337 for (int i = 0; i < pc.getLevelInfoSize(); i++)
338 {
339 PCLevelInfo info = pc.getLevelInfo(i);
340 if (info.getClassKeyName().equals(pcClass.getKeyName()))
341 {
342 // We are spending this class' points.
343 points[i] = info.getSkillPointsRemaining();
344 }
345 else
346 {
347 points[i] = -1;
348 }
349 }
350 for (int i = 0; i < points.length; i++)
351 {
352 int remaining = points[i];
353 if (remaining <= 0)
354 {
355 continue;
356 }
357 int left = remaining - Math.min(remaining, ptsToSpend);
358 points[i] = left;
359 int spent = (remaining - left);
360 ptsToSpend -= spent;
361 ranksAdded += ((double) spent / (double) skillCost);
362 if (ranksAdded == ranksToAdd || ptsToSpend <= 0)
363 {

Callers 1

testApplyMethod · 0.95

Calls 15

checkRuleMethod · 0.95
doublesEqualMethod · 0.95
getClassKeyNameMethod · 0.95
modRanksMethod · 0.95
hasNewChooseTokenMethod · 0.95
doubleValueMethod · 0.80
getSkillCostForClassMethod · 0.80
addMethod · 0.65
getDisplayNameMethod · 0.65

Tested by

no test coverage detected