Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. package com.rs.game.player;
  2.  
  3. import com.rs.cache.loaders.ClientScriptMap;
  4. import com.rs.cache.loaders.GeneralRequirementMap;
  5.  
  6. public class PrayerManager {
  7.  
  8. /**
  9. * Enumeration containing the normal prayer structs.
  10. */
  11. private static final ClientScriptMap GR_MAP_ORDER;
  12.  
  13. static {
  14. GR_MAP_ORDER = ClientScriptMap.getMap(6759);
  15. }
  16.  
  17. /**
  18. * Tree Struct Keys
  19. */
  20. private static final int FIRST_TIER_LEVEL = 2963, FIRST_TIER_MAP = 2964, SECOND_TIER_LEVEL = 2965, SECOND_TIER_MAP = 2966, THIRD_TIER_LEVEL = 2967, THIRD_TIER_MAP = 2968;
  21.  
  22. /**
  23. * Branch Struct Keys
  24. */
  25. private static final int LEVEL_REQUIREMENT = 2945, TREE_STRUCT_KEY = 2962, NAME = 2794, DESCRIPTION = 2795, REQUIREMENT_MESSAGE = 2808;
  26.  
  27.  
  28. private transient Player player;
  29.  
  30. /**
  31. * Prayers currently active.
  32. */
  33. private transient boolean[] active;
  34.  
  35. /**
  36. * Whether or not the player is using ancients.
  37. */
  38. private boolean ancient;
  39.  
  40. /**
  41. * The amount of prayer points a player currently has.
  42. */
  43. private int points;
  44.  
  45. private static final int[][] VARBITS = {
  46. {},
  47. {}
  48. };
  49.  
  50. public void setPoints(int points, boolean boost) {
  51. int replaced = boost ? this.points + points : this.points - points;
  52. this.points = replaced = boost ? Math.max(max(), replaced) : Math.min(0, replaced);
  53. if (!player.getVarsManager().sendVarBit(16736, points))
  54. return;
  55. player.updateBuffs();
  56. }
  57.  
  58. public void drain(int points) {
  59. setPoints(points, false);
  60. }
  61.  
  62. public void boost(int points) {
  63. setPoints(points, true);
  64. }
  65.  
  66. public void boost() {
  67. boost(max());
  68. }
  69.  
  70. public int max() {
  71. return player.getSkills().getLevelForXp(Skills.PRAYER) * 10;
  72. }
  73.  
  74. public int getPoints() {
  75. return points;
  76. }
  77.  
  78. public void activate(int slot) {
  79. if (!active[slot]) {
  80. if (getLevelRequirement(slot) > player.getSkills().getLevel(Skills.PRAYER)) {
  81. player.getPackets().sendGameMessage(getRequirementMessage(slot));
  82. return;
  83. }
  84. }
  85. active[slot] = !active[slot];
  86. player.getVarsManager().sendVarBit(VARBITS[ancient ? 1 : 0][slot], active[slot] ? 1 : 0);
  87. }
  88.  
  89. private GeneralRequirementMap getStruct(int slot) {
  90. GeneralRequirementMap tierMap = GeneralRequirementMap.getMap(GR_MAP_ORDER.getIntValue(slot));
  91. int level = player.getSkills().getLevel(Skills.PRAYER);
  92. if (level >= tierMap.getIntValue(THIRD_TIER_LEVEL))
  93. return GeneralRequirementMap.getMap(THIRD_TIER_MAP);
  94. else if (level >= tierMap.getIntValue(SECOND_TIER_LEVEL))
  95. return GeneralRequirementMap.getMap(SECOND_TIER_MAP);
  96. else if (level >= tierMap.getIntValue(FIRST_TIER_LEVEL))
  97. return GeneralRequirementMap.getMap(FIRST_TIER_MAP);
  98. return null;
  99. }
  100.  
  101. private int getLevelRequirement(int slot) {
  102. return getStruct(slot).getIntValue(LEVEL_REQUIREMENT);
  103. }
  104.  
  105. private String getRequirementMessage(int slot) {
  106. return getStruct(slot).getStringValue(REQUIREMENT_MESSAGE);
  107. }
  108.  
  109. public String getDescription(int slot) {
  110. return getStruct(slot).getStringValue(DESCRIPTION);
  111. }
  112.  
  113. public String getName(int slot) {
  114. return getStruct(slot).getStringValue(NAME);
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement