Advertisement
Guest User

thieving class

a guest
Feb 19th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. package server.content.skills;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import core.util.Misc;
  6. import server.Config;
  7. import server.event.CycleEvent;
  8. import server.event.CycleEventContainer;
  9. import server.event.CycleEventHandler;
  10. import server.game.players.Client;
  11. import server.game.players.Player;
  12.  
  13. public class Thieving {
  14.  
  15. @SuppressWarnings("unused")
  16. private Client c;
  17.  
  18. public Thieving(Client c) {
  19. this.c = c;
  20. }
  21.  
  22. public boolean playerIsStunned = false;
  23. public long lastStunned;
  24. private boolean playerIsPickpocketing = false;
  25. private boolean successfulThief = true;
  26.  
  27. /**
  28. * This enum contains all the items that can
  29. * be pickpocket from each npc. It also contains
  30. * the level required, the xp gained, stun time
  31. * and stun damage.
  32. *
  33. * To implement this, you will first need to check
  34. * if the npc you are trying to pickpocket is an npc
  35. * that can be pickpocketed. Then, you will call the
  36. * actual pickpocket method below.
  37. *
  38. *
  39. *
  40. */
  41.  
  42. public static enum pickpocket {
  43.  
  44. MAN(new int[] {1, 2, 3}, new int[][] {{995, 50}}, 1, 8, 5, 1),
  45. WOMAN(new int[] {4, 5, 6}, new int[][] {{995, 50}}, 1, 8, 5, 1),
  46. FARMER(new int[] {7, 1757, 1758, 1759, 1760, 1761}, new int[][] {{995, 150}, {5318, 1}}, 10, 14.5, 5, 1),
  47. FEMALE_HAM_MEMBER(new int[] {1715}, new int[][] {{882, 20}, {1351, 1}, {1265, 1}, {1349, 1}, {1267, 1}, {886, 20}, {1353, 1}, {1207, 1}, {1129, 1}, {4170, 1}, {4302, 1}, {4298, 1}, {4300, 1}, {4304, 1}, {4306, 1}, {4308, 1}, {4310, 1}, {995, 200}, {319, 1}, {2138, 1}, {668, 1}, {453, 1}, {440, 1}, {1739, 1}, {314, 5}, {1734, 6}, {1733, 1}, {1511, 1}, {686, 1}, {697, 1}, {1625, 1}, {1627, 1}, {1617, 1}, {199, 1}, {201, 1}, {203, 1}}, 15, 18.5, 4, 3),
  48. MALE_HAM_MEMBER(new int[] {1714}, new int[][] {{882, 20}, {1351, 1}, {1265, 1}, {1349, 1}, {1267, 1}, {886, 20}, {1353, 1}, {1207, 1}, {1129, 1}, {4170, 1}, {4302, 1}, {4298, 1}, {4300, 1}, {4304, 1}, {4306, 1}, {4308, 1}, {4310, 1}, {995, 200}, {319, 1}, {2138, 1}, {668, 1}, {453, 1}, {440, 1}, {1739, 1}, {314, 5}, {1734, 6}, {1733, 1}, {1511, 1}, {686, 1}, {697, 1}, {1625, 1}, {1627, 1}, {199, 1}, {201, 1}, {203, 1}}, 20, 22.5, 4, 3),
  49. HAM_GUARD(new int[] {1710, 1711, 1712}, new int[][] {{882, 20}, {1351, 1}, {1265, 1}, {1349, 1}, {1267, 1}, {886, 20}, {1353, 1}, {1207, 1}, {1129, 1}, {4170, 1}, {4302, 1}, {4298, 1}, {4300, 1}, {4304, 1}, {4306, 1}, {4308, 1}, {4310, 1}, {995, 200}, {319, 1}, {2138, 1}, {668, 1}, {453, 1}, {440, 1}, {1739, 1}, {314, 5}, {1734, 6}, {1733, 1}, {1511, 1}, {686, 1}, {697, 1}, {1625, 1}, {1627, 1}, {199, 1}, {201, 1}, {203, 1}, {5321, 4}, {5323, 4}, {5319, 4}, {5324, 1}}, 20, 22.5, 4, 3),
  50. WARRIOR_WOMAN(new int[] {15}, new int[][] {{995, 220}}, 25, 26, 5, 2),
  51. AL_KHARID_WARRIOR(new int[] {18}, new int[][] {{995, 230}}, 25, 26, 5, 2),
  52. ROGUE(new int[] {187}, new int[][] {{995, 250}, {556, 8}, {1523, 1}, {1219, 1}, {1993, 1}, {2357, 1}, {1227, 1}}, 32, 35.5, 5, 20),
  53. MASTER_FARMER(new int[] {2234, 2235}, new int[][] {{5318, 1}, {5319, 1}, {5324, 3}, {5323, 2}, {5321, 2}, {5305, 4}, {5307, 2}, {5308, 2}, {5306, 3}, {5309, 2}, {5310, 1}, {5311, 1}, {5101, 1}, {5102, 1}, {5103, 1}, {5104, 1}, {5105, 1}, {5106, 1}, {5096, 1}, {5097, 1}, {5098, 1}, {5099, 1}, {5100, 1}, {5291, 1}, {5292, 1}, {5293, 1}, {5294, 1}, {5295, 1}, {5296, 1}, {5297, 1}, {5298, 1}, {5299, 1}, {5300, 1}, {5301, 1}, {5302, 1}, {5303, 1}, {5304, 1}, {5280, 1}, {5281, 1}}, 38, 43, 5, 3),
  54. GUARD(new int[] {9, 10}, new int[][] {{995, 270}}, 40, 46.5, 5, 2),
  55. POLLNIVIAN_BEARDED_BANDIT(new int[] {1880, 1881}, new int[][] {{995, 280}}, 45, 65, 5, 5),
  56. DESERT_BANDIT(new int[] {1926, 1927, 1928, 1929, 1930, 1931}, new int[][] {{995, 290}, {179, 1}, {1523, 1}}, 53, 79.5, 5, 30),
  57. KNIGHT_OF_ARDOUGNE(new int[] {23, 26}, new int[][] {{995, 300}}, 55, 84.3, 5, 3),
  58. POLLNIVIAN_BANDIT(new int[] {1883, 1884}, new int[][] {{995, 310}}, 55, 84.3, 5, 5),
  59. YANILLE_WATCHMEN(new int[] {32}, new int[][] {{995, 320}, {2309, 1}}, 65, 137.5, 5, 3),
  60. MENAPHITE_THUG(new int[] {1904, 1905}, new int[][] {{995, 330}, {6392, 1}, {6394, 1}, {6396, 1}, {6398, 1}, {6400, 1}, {6402, 1}, {6404, 1}, {6406, 1}}, 65, 137.5, 5, 5),
  61. PALADIN(new int[] {20, 365, 2256}, new int[][] {{995, 340}, {562, 2}}, 70, 151.75, 5, 3),
  62. GNOME(new int[] {66, 67, 68}, new int[][] {{995, 350}, {557, 1}, {444, 1}, {569, 1}, {2150, 1}, {2162, 1}}, 75, 198.5, 5, 1),
  63. HERO(new int[] {21}, new int[][] {{995, 355}, {560, 2}, {565, 1}, {444, 1}, {1993, 1}, {569, 1}, {1601, 1}}, 80, 273.3, 6, 4);
  64.  
  65. public int[] npcId;
  66. public int[][] npcYield;
  67. public int level, stunTime, damage;
  68. public double xp;
  69.  
  70. pickpocket(int[] npcId, int[][] npcYield, int level, double xp, int stunTime, int damage) {
  71. this.npcId = npcId;
  72. this.npcYield = npcYield;
  73. this.level = level;
  74. this.xp = xp;
  75. this.stunTime = stunTime;
  76. this.damage = damage;
  77. }
  78.  
  79. public static HashMap<Integer, pickpocket> pick = new HashMap<Integer, pickpocket>();
  80.  
  81. public static pickpocket forNpcId(int npcId) {
  82. return pick.get(npcId);
  83. }
  84.  
  85. static {
  86. for (pickpocket p : pickpocket.values()) {
  87. for (int npcId : p.npcId) {
  88. pick.put(npcId, p);
  89. }
  90. }
  91. }
  92.  
  93. public int[][] getNpcYield() {
  94. return npcYield;
  95. }
  96.  
  97. public int getRequiredLevel() {
  98. return level;
  99. }
  100.  
  101. public double getXp() {
  102. return xp;
  103. }
  104.  
  105. public int getStunTime() {
  106. return stunTime;
  107. }
  108.  
  109. public int damageDealt() {
  110. return damage;
  111. }
  112. }
  113.  
  114. /**
  115. * This boolean checks to see if the npc can be pickpocketed or not
  116. * @param npcType The npc id
  117. * @return If the npc is an npc that can be pickpocketed or not
  118. */
  119.  
  120. public static boolean isPickPocketNpc(final int npcType) {
  121. final pickpocket p = pickpocket.forNpcId(npcType);
  122. for (int i = 0; i < p.npcId.length; i++) {
  123. if (npcType == p.npcId[i]) {
  124. return true;
  125. }
  126. }
  127. return false;
  128. }
  129.  
  130. /**
  131. * The lower the return value, the lower the failure rate
  132. * @param c the client
  133. * @param npcType the npc id
  134. * @return an integer to determine how often you will fail
  135. */
  136.  
  137. private int failureRate(final Client c, final int npcType) {
  138. final pickpocket p = pickpocket.forNpcId(npcType);
  139. double npcFactor = p.getRequiredLevel() / 10;
  140. double levelFactor = 100 / ((c.playerLevel[Player.playerThieving] + 1) - p.getRequiredLevel());
  141. return (int)Math.floor((levelFactor + npcFactor) / 2);
  142. }
  143.  
  144. /**
  145. * Checks to see if the client has the required level to pickpocket the npc
  146. * @param c the client
  147. * @param npcType the npc id
  148. * @return if the player has the required level or not
  149. */
  150.  
  151. private boolean canThieveNpc(final Client c, final int npcType) {
  152. final pickpocket p = pickpocket.forNpcId(npcType);
  153. if (c.playerLevel[Player.playerThieving] >= p.getRequiredLevel()) {
  154. return true;
  155. }
  156. c.sendMessage("You need a thieving level of "+ p.getRequiredLevel() +" to pickpocket this "+ p.toString().toLowerCase().replaceAll("_", " "));
  157. return false;
  158. }
  159.  
  160. /**
  161. * This will add the item that you pickpocket
  162. * @param c the client
  163. * @param npcType the npc id
  164. */
  165.  
  166. private void addThievedItem(final Client c, final int npcType) {
  167. final pickpocket p = pickpocket.forNpcId(npcType);
  168. int i = Misc.random(p.getNpcYield().length - 1);
  169. c.getItems().addItem(p.npcYield[i][0], p.npcYield[i][1]);
  170. c.getPA().addSkillXP((int) p.getXp() * Config.THIEVING_EXPERIENCE, Player.playerThieving);
  171.  
  172. }
  173.  
  174. /**
  175. * What will happen if you fail to pickpocket the npc
  176. * @param c the client
  177. * @param stunTime how long you will be stunned for
  178. * @param damage how much damage will be dealt
  179. * @param npcId the npc id
  180. */
  181.  
  182. private void applyStun(final Client c, final int stunTime, final int damage, int npcId) {
  183. c.startAnimation(c.getCombat().getBlockEmote());
  184. c.setHitDiff(damage);
  185. c.setHitUpdateRequired(true);
  186. c.playerLevel[3] -= damage;
  187. c.getPA().refreshSkill(3);
  188. playerIsStunned = true;
  189. c.gfx100(80);
  190. CycleEventHandler.addEvent(c, new CycleEvent() {
  191. @Override
  192. public void execute(CycleEventContainer container) {
  193. if (System.currentTimeMillis() - lastStunned > stunTime) {
  194. container.stop();
  195. }
  196. }
  197. @Override
  198. public void stop() {
  199. playerIsStunned = false;
  200. c.startAnimation(65535);
  201. }
  202. }, 4);
  203. }
  204.  
  205. /**
  206. * This is the actual method to pickpocket the npc
  207. * @param c the client
  208. * @param npcType the npc id
  209. */
  210.  
  211. public void pickpocketNpc(final Client c, final int npcType) {
  212. final pickpocket p = pickpocket.forNpcId(npcType);
  213. if (playerIsPickpocketing) {
  214. return;
  215. }
  216. if (playerIsStunned) {
  217. c.sendMessage("You are stunned!");
  218. return;
  219. }
  220. if (canThieveNpc(c, npcType)) {
  221. c.startAnimation(881);
  222. c.sendMessage("You attempt to pickpocket the "+ p.toString().toLowerCase().replaceAll("_", " ") +".");
  223. CycleEventHandler.addEvent(c, new CycleEvent() {
  224.  
  225.  
  226. @Override
  227. public void execute(CycleEventContainer container) {
  228. playerIsPickpocketing = true;
  229. c.startAnimation(881);
  230. if (Misc.random(100) < failureRate(c, npcType)) {
  231. c.sendMessage("You failed to pickpocket the "+ p.toString().toLowerCase().replaceAll("_", " "));
  232. successfulThief = false;
  233. container.stop();
  234. } else {
  235. successfulThief = true;
  236. container.stop();
  237. }
  238. }
  239. @Override
  240. public void stop() {
  241. playerIsPickpocketing = false;
  242. if (successfulThief) {
  243. addThievedItem(c, npcType);
  244. c.sendMessage("You successfully pickpocket the "+ p.toString().toLowerCase().replaceAll("_", " ") +".");
  245. return;
  246. } else if (!successfulThief) {
  247. applyStun(c, p.getStunTime() * 1000, p.damageDealt(), npcType);
  248. lastStunned = System.currentTimeMillis();
  249. return;
  250. }
  251. }
  252. }, 1);
  253. }
  254. }
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement