Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. package com.bbg.tb.utility;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.bbg.tb.mobile.Mobile;
  6.  
  7. public class Formula {
  8.  
  9. public static Random random = new Random();
  10.  
  11. public static void seed(long s) {
  12. random.setSeed(s);
  13. }
  14.  
  15. public static int d20() {
  16. return random.nextInt(20);
  17. }
  18.  
  19. public static int getSavingThrow(Mobile m, String stat) {
  20. try {
  21. return d20() + abilityCheck(m, stat) + proficiencyCheck(m, stat + "_save");
  22. } catch (Exception e) {
  23. e.printStackTrace();
  24. }
  25. return 0;
  26. }
  27.  
  28. public static int dexSave(Mobile m) {
  29. return getSavingThrow(m, "dexterity");
  30. }
  31.  
  32. public static int intSave(Mobile m) {
  33. return getSavingThrow(m, "intelligence");
  34. }
  35.  
  36. public static int strSave(Mobile m) {
  37. return getSavingThrow(m, "strength");
  38. }
  39.  
  40. public static int conSave(Mobile m) {
  41. return getSavingThrow(m, "constitution");
  42. }
  43.  
  44. public static int wisSave(Mobile m) {
  45. return getSavingThrow(m, "wisdom");
  46. }
  47.  
  48. public static int chaSave(Mobile m) {
  49. return getSavingThrow(m, "charisma");
  50. }
  51.  
  52. public static float initiativeCheck(Mobile m) {
  53. try {
  54. float check = d20() + dexCheck(m) + ((boolean) m.fields.get("alert") ? 0 : 5)
  55. + (int) m.fields.get("initiative_bonus");
  56. check += ((float) m.fields.get("dexterity") / 100f);
  57. return check;
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. }
  61. return 0;
  62. }
  63.  
  64. public static int skillCheck(Mobile m, String skill) {
  65. int check = d20();
  66. switch (skill.toLowerCase()) {
  67. case "athletics":
  68. check += strCheck(m);
  69. break;
  70. case "acrobatics":
  71. case "sleight_of_hand":
  72. case "stealth":
  73. check += dexCheck(m);
  74. break;
  75. case "arcana":
  76. case "history":
  77. case "investigation":
  78. case "nature":
  79. case "religion":
  80. check += intCheck(m);
  81. break;
  82. case "animal_handling":
  83. case "insight":
  84. case "medicine":
  85. case "perception":
  86. case "survival":
  87. check += wisCheck(m);
  88. break;
  89. case "deception":
  90. case "intimidation":
  91. case "performance":
  92. case "persuasion":
  93. check += chaCheck(m);
  94. break;
  95. default:
  96. return 0;
  97. }
  98. return check + proficiencyCheck(m, skill);
  99. }
  100.  
  101. public static int proficiencyCheck(Mobile m, String skill) {
  102. try {
  103. return (boolean) m.fields.get(skill) ? getProficiencyBonus(m) : 0;
  104. } catch (Exception e) {
  105. e.printStackTrace();
  106. }
  107. return 0;
  108. }
  109.  
  110. public static int abilityCheck(Mobile m, String stat) {
  111. try {
  112. return ((int) m.fields.get(stat) / 2) - 5;
  113. } catch (Exception e) {
  114. e.printStackTrace();
  115. }
  116. return 0;
  117. }
  118.  
  119. public static int dexCheck(Mobile m) {
  120. return abilityCheck(m, "dexterity");
  121. }
  122.  
  123. public static int intCheck(Mobile m) {
  124. return abilityCheck(m, "intelligence");
  125. }
  126.  
  127. public static int strCheck(Mobile m) {
  128. return abilityCheck(m, "strength");
  129. }
  130.  
  131. public static int conCheck(Mobile m) {
  132. return abilityCheck(m, "constitution");
  133. }
  134.  
  135. public static int wisCheck(Mobile m) {
  136. return abilityCheck(m, "wisdom");
  137. }
  138.  
  139. public static int chaCheck(Mobile m) {
  140. return abilityCheck(m, "charisma");
  141. }
  142.  
  143. public static int getProficiencyBonus(Mobile m) {
  144. try {
  145. return (((int) m.fields.get("level") - 1) / 4) + 2;
  146. } catch (Exception e) {
  147. e.printStackTrace();
  148. }
  149. return 2;
  150. }
  151.  
  152. public static int roll(String dice) {
  153. try {
  154. dice = dice.replace(" ", "");
  155. String[] split = dice.split("d");
  156. int numDice = Integer.parseInt(split[0]);
  157. int numSides = 0;
  158. int bonus = 0;
  159. if (split[1].indexOf("+") < 0) {
  160. numSides = Integer.parseInt(split[1]);
  161. } else {
  162. split = split[1].split("+");
  163. numSides = Integer.parseInt(split[0]);
  164. bonus = Integer.parseInt(split[1]);
  165. }
  166. int roll = 0;
  167. for (int i = 0; i < numDice; i++) {
  168. roll += random.nextInt(numSides);
  169. }
  170. return roll + bonus;
  171. } catch (Exception e) {
  172. e.printStackTrace();
  173. }
  174. return 0;
  175. }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement