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

Method rollHP

code/src/java/pcgen/cdom/facet/HitPointFacet.java:71–99  ·  view source on GitHub ↗

Roll the hitpoints for a single level. @param min the minimum number on the die @param max the maximum number on the die @param totalLevel the level the hitpoints are being rolled for (used in maths) @return the hitpoints for the given level.

(final int min, final int max, final int totalLevel)

Source from the content-addressed store, hash-verified

69 * @return the hitpoints for the given level.
70 */
71 private static int rollHP(final int min, final int max, final int totalLevel)
72 {
73 int roll;
74
75 switch (SettingsHandler.getHPRollMethod())
76 {
77 case Constants.HP_USER_ROLLED -> roll = 1;
78 case Constants.HP_AVERAGE -> {
79 roll = max - min;
80
81 // (n+1)/2
82 // average roll on a die with an odd # of sides works out exactly
83 // average roll on a die with an even # of sides will have an extra 0.5
84
85 if (((totalLevel & 0x01) == 0) && ((roll & 0x01) != 0))
86 {
87 ++roll;
88 }
89 roll = min + (roll / 2);
90 }
91 case Constants.HP_AUTO_MAX -> roll = max;
92 case Constants.HP_PERCENTAGE -> roll = (min - 1) + (int) ((SettingsHandler.getHPPercent() * ((max - min) + 1)) / 100.0);
93 case Constants.HP_AVERAGE_ROUNDED_UP -> roll = (int) Math.ceil((min + max) / 2.0);
94 case Constants.HP_STANDARD -> roll = Math.abs(RandomUtil.getRandomInt((max - min) + 1)) + min;
95 default -> roll = Math.abs(RandomUtil.getRandomInt((max - min) + 1)) + min;
96 }
97
98 return roll;
99 }
100
101 /**
102 * Watches for new PCClassLevel objects to be granted to the Player

Callers 1

dataAddedMethod · 0.95

Calls 13

getHPRollMethodMethod · 0.95
getHPPercentMethod · 0.95
getRandomIntMethod · 0.95
getLevelHitDieMethod · 0.95
getDieMethod · 0.95
isImportingMethod · 0.95
getKeyNameMethod · 0.65
getClassLevelMethod · 0.65
setMethod · 0.65
getBonusMethod · 0.45
getPCMethod · 0.45

Tested by

no test coverage detected