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)
| 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 |
no test coverage detected