Guest User

Untitled

a guest
Nov 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.23 KB | None | 0 0
  1. package server.model.players;
  2.  
  3. import server.event.EventManager;
  4. import server.event.Event;
  5. import server.event.EventContainer;
  6.  
  7. /**
  8. * @author InsidiaX
  9. */
  10.  
  11. public class Potions {
  12.  
  13. private Client c;
  14.  
  15. public Potions(Client c) {
  16. this.c = c;
  17. }
  18.  
  19. public void handlePotion(int itemId, int slot) {
  20. if (c.duelRule[5]) {
  21. c.sendMessage("You may not drink potions in this duel.");
  22. return;
  23. }
  24. if (System.currentTimeMillis() - c.potDelay >= 750) {
  25. c.potDelay = System.currentTimeMillis();
  26. c.foodDelay = c.potDelay;
  27. c.getCombat().resetPlayerAttack();
  28. c.attackTimer++;
  29. c.sendMessage("You drink some of your "+ server.model.items.Item.getItemName(itemId) +".");
  30. String item = server.model.items.Item.getItemName(itemId);
  31. if(item.endsWith("(4)"))
  32. {
  33. c.sendMessage("You have 3 doses of potion left.");
  34. } else if(item.endsWith("(3)"))
  35. {
  36. c.sendMessage("You have 2 doses of potion left.");
  37. } else if(item.endsWith("(2)"))
  38. {
  39. c.sendMessage("You have 1 dose of potion left.");
  40. } else if(item.endsWith("(1)"))
  41. {
  42. c.sendMessage("You have finished your potion.");
  43. }
  44. switch (itemId) {
  45. case 6685: //brews
  46. doTheBrew(itemId, 6687, slot);
  47. break;
  48. case 15272: //brews
  49. Rocktail(itemId, 15272, slot);
  50. break;
  51. //Magic pots
  52. case 3040:
  53. drinkMagicPotion(itemId,3042,slot,6,false);
  54. break;
  55. case 3042:
  56. drinkMagicPotion(itemId,3044,slot,6,false);
  57. break;
  58. case 3044:
  59. drinkMagicPotion(itemId,3046,slot,6,false);
  60. break;
  61. case 3046:
  62. drinkMagicPotion(itemId,229,slot,6,false);
  63. break;
  64. case 6687:
  65. doTheBrew(itemId, 6689, slot);
  66. break;
  67. case 6689:
  68. doTheBrew(itemId, 6691, slot);
  69. break;
  70. case 6691:
  71. doTheBrew(itemId, 229, slot);
  72. break;
  73. case 2436:
  74. drinkStatPotion(itemId,145,slot,0,true); //sup attack
  75. break;
  76. case 145:
  77. drinkStatPotion(itemId,147,slot,0,true);
  78. break;
  79. case 147:
  80. drinkStatPotion(itemId,149,slot,0,true);
  81. break;
  82. case 149:
  83. drinkStatPotion(itemId,229,slot,0,true);
  84. break;
  85. case 2440:
  86. drinkStatPotion(itemId,157,slot,2,true); //sup str
  87. break;
  88. case 157:
  89. drinkStatPotion(itemId,159,slot,2,true);
  90. break;
  91. case 159:
  92. drinkStatPotion(itemId,161,slot,2,true);
  93. break;
  94. case 161:
  95. drinkStatPotion(itemId,229,slot,2,true);
  96. break;
  97. case 2444:
  98. drinkStatPotion(itemId,169,slot,4,false); //range pot
  99. break;
  100. case 169:
  101. drinkStatPotion(itemId,171,slot,4,false);
  102. break;
  103. case 171:
  104. drinkStatPotion(itemId,173,slot,4,false);
  105. break;
  106. case 173:
  107. drinkStatPotion(itemId,229,slot,4,false);
  108. break;
  109. case 2432:
  110. drinkStatPotion(itemId,133,slot,1,false); //def pot
  111. break;
  112. case 133:
  113. drinkStatPotion(itemId,135,slot,1,false);
  114. break;
  115. case 135:
  116. drinkStatPotion(itemId,137,slot,1,false);
  117. break;
  118. case 137:
  119. drinkStatPotion(itemId,229,slot,1,false);
  120. break;
  121. case 113:
  122. drinkStatPotion(itemId,115,slot,2,false); //str pot
  123. break;
  124. case 115:
  125. drinkStatPotion(itemId,117,slot,2,false);
  126. break;
  127. case 117:
  128. drinkStatPotion(itemId,119,slot,2,false);
  129. break;
  130. case 119:
  131. drinkStatPotion(itemId,229,slot,2,false);
  132. break;
  133. case 2428:
  134. drinkStatPotion(itemId,121,slot,0,false); //attack pot
  135. break;
  136. case 121:
  137. drinkStatPotion(itemId,123,slot,0,false);
  138. break;
  139. case 123:
  140. drinkStatPotion(itemId,125,slot,0,false);
  141. break;
  142. case 125:
  143. drinkStatPotion(itemId,229,slot,0,false);
  144. break;
  145. case 2442:
  146. drinkStatPotion(itemId,163,slot,1,true); //super def pot
  147. break;
  148. case 163:
  149. drinkStatPotion(itemId,165,slot,1,true);
  150. break;
  151. case 165:
  152. drinkStatPotion(itemId,167,slot,1,true);
  153. break;
  154. case 167:
  155. drinkStatPotion(itemId,229,slot,1,true);
  156. break;
  157. case 3024:
  158. drinkPrayerPot(itemId,3026,slot,true); //sup restore
  159. break;
  160. case 3026:
  161. drinkPrayerPot(itemId,3028,slot,true);
  162. break;
  163. case 3028:
  164. drinkPrayerPot(itemId,3030,slot,true);
  165. break;
  166. case 3030:
  167. drinkPrayerPot(itemId,229,slot,true);
  168. break;
  169. case 10925:
  170. drinkPrayerPot(itemId,10927,slot,true); //sanfew serums
  171. curePoison(300000);
  172. break;
  173. case 10927:
  174. drinkPrayerPot(itemId,10929,slot,true);
  175. curePoison(300000);
  176. break;
  177. case 10929:
  178. drinkPrayerPot(itemId,10931,slot,true);
  179. curePoison(300000);
  180. break;
  181. case 10931:
  182. drinkPrayerPot(itemId,229,slot,true);
  183. curePoison(300000);
  184. break;
  185. case 2434:
  186. drinkPrayerPot(itemId,139,slot,false); //pray pot
  187. break;
  188. case 15300: //Recover Special
  189. recoverSpecial(itemId, 15301, slot);
  190. break;
  191. case 15301: //Recover Special
  192. recoverSpecial(itemId, 15302, slot);
  193. break;
  194. case 15302: //Recover Special
  195. recoverSpecial(itemId, 15303, slot);
  196. break;
  197. case 15303: //Recover Special
  198. recoverSpecial(itemId, 229, slot);
  199. break;
  200. case 15328: //Super Prayer
  201. drinkExtremePrayer(itemId, 15329, slot, true);
  202. break;
  203. case 15329: //Super Prayer
  204. drinkExtremePrayer(itemId, 15330, slot, true);
  205. break;
  206. case 15330: //Super Prayer
  207. drinkExtremePrayer(itemId, 15331, slot, true);
  208. break;
  209. case 15331: //Super Prayer
  210. drinkExtremePrayer(itemId, 229, slot, true);
  211. break;
  212. case 139:
  213. drinkPrayerPot(itemId,141,slot,false);
  214. break;
  215. case 141:
  216. drinkPrayerPot(itemId,143,slot,false);
  217. break;
  218. case 143:
  219. drinkPrayerPot(itemId,229,slot,false);
  220. break;
  221. case 2446:
  222. drinkAntiPoison(itemId,175,slot,30000); //anti poisons
  223. break;
  224. case 175:
  225. drinkAntiPoison(itemId,177,slot,30000);
  226. break;
  227. case 177:
  228. drinkAntiPoison(itemId,179,slot,30000);
  229. break;
  230. case 179:
  231. drinkAntiPoison(itemId,229,slot,30000);
  232. break;
  233. case 2448:
  234. drinkAntiPoison(itemId,181,slot,300000); //anti poisons
  235. break;
  236. case 181:
  237. drinkAntiPoison(itemId,183,slot,300000);
  238. break;
  239. case 183:
  240. drinkAntiPoison(itemId,185,slot,300000);
  241. break;
  242. case 185:
  243. drinkAntiPoison(itemId,229,slot,300000);
  244. break;
  245. }
  246. }
  247. }
  248.  
  249. public void drinkAntiPoison(int itemId, int replaceItem, int slot, long delay) {
  250. c.startAnimation(829);
  251. c.playerItems[slot] = replaceItem + 1;
  252. c.getItems().resetItems(3214);
  253. curePoison(delay);
  254. }
  255.  
  256. public void recoverSpecial(int itemId, int replaceItem, int slot) {
  257. if (c.inWild()) {
  258. c.sendMessage("You are unable to restore special in the wilderness.");
  259. return;
  260. } else if (c.specAmount >= 7.5) {
  261. c.sendMessage("You are unable to drink the potion as your special is above 75%.");
  262. } else if (c.specRestore > 0) {
  263. c.specAmount += 2.5;
  264. c.startAnimation(829);
  265. c.sendMessage("As you drink drink the potion, you feel your special attack slightly regenerate.");
  266. c.playerItems[slot] = replaceItem + 1;
  267. c.getItems().resetItems(3214);
  268. c.getItems().updateSpecialBar();
  269. c.specRestore = 180;
  270. } else {
  271. c.sendMessage("You can only restore your special once every 3 minutes.");
  272. }
  273. }
  274.  
  275.  
  276. public void drinkExtremePrayer(int itemId, int replaceItem, int slot, boolean rest) {
  277. c.startAnimation(829);
  278. c.playerItems[slot] = replaceItem + 1;
  279. c.getItems().resetItems(3214);
  280. c.playerLevel[5] += (c.getLevelForXP(c.playerXP[5]) * .38);
  281. if (rest)
  282. c.playerLevel[5] += 1;
  283. if (c.playerLevel[5] > c.getLevelForXP(c.playerXP[5]))
  284. c.playerLevel[5] = c.getLevelForXP(c.playerXP[5]);
  285. c.getPA().refreshSkill(5);
  286. if (rest)
  287. restoreStats();
  288. }
  289.  
  290. public void drinkExtremePotion(int itemId, int replaceItem, int slot, int stat, boolean sup) {
  291. c.startAnimation(829);
  292. c.playerItems[slot] = replaceItem + 1;
  293. c.getItems().resetItems(3214);
  294. enchanceStat2(stat,sup);
  295. }
  296.  
  297. public void drinkMagicPotion(int itemId, int replaceItem, int slot, int stat, boolean sup) {
  298. c.startAnimation(829);
  299. c.playerItems[slot] = replaceItem + 1;
  300. c.getItems().resetItems(3214);
  301. enchanceMagic(stat,sup);
  302.  
  303. }
  304.  
  305. public void enchanceMagic(int skillID, boolean sup) {
  306. c.playerLevel[skillID] += getBoostedMagic(skillID, sup);
  307. c.getPA().refreshSkill(skillID);
  308. }
  309.  
  310. public int getBoostedMagic(int skill, boolean sup) {
  311. int increaseBy = 0;
  312. if (sup)
  313. increaseBy = (int)(c.getLevelForXP(c.playerXP[skill])*.05);
  314. else
  315. increaseBy = (int)(c.getLevelForXP(c.playerXP[skill])*.05) + 1;
  316. if (c.playerLevel[skill] + increaseBy > c.getLevelForXP(c.playerXP[skill]) + increaseBy + 1) {
  317. return c.getLevelForXP(c.playerXP[skill]) + increaseBy - c.playerLevel[skill];
  318. }
  319. return increaseBy;
  320. }
  321.  
  322.  
  323. public void enchanceStat2(int skillID, boolean sup) {
  324. c.playerLevel[skillID] += getExtremeStat(skillID, sup);
  325. c.getPA().refreshSkill(skillID);
  326. }
  327.  
  328. public int getExtremeStat(int skill, boolean sup) {
  329. int increaseBy = 0;
  330. if (sup)
  331. increaseBy = (int)(c.getLevelForXP(c.playerXP[skill])*.25);
  332. else
  333. increaseBy = (int)(c.getLevelForXP(c.playerXP[skill])*.25) + 1;
  334. if (c.playerLevel[skill] + increaseBy > c.getLevelForXP(c.playerXP[skill]) + increaseBy + 1) {
  335. return c.getLevelForXP(c.playerXP[skill]) + increaseBy - c.playerLevel[skill];
  336. }
  337. return increaseBy;
  338. }
  339.  
  340. public void curePoison(long delay) {
  341. c.poisonDamage = 0;
  342. c.poisonImmune = delay;
  343. c.lastPoisonSip = System.currentTimeMillis();
  344. }
  345.  
  346. public void drinkStatPotion(int itemId, int replaceItem, int slot, int stat, boolean sup) {
  347. c.startAnimation(829);
  348. c.playerItems[slot] = replaceItem + 1;
  349. c.getItems().resetItems(3214);
  350. enchanceStat(stat,sup);
  351. }
  352.  
  353. public void drinkPrayerPot(int itemId, int replaceItem, int slot, boolean rest) {
  354. c.startAnimation(829);
  355. c.playerItems[slot] = replaceItem + 1;
  356. c.getItems().resetItems(3214);
  357. c.playerLevel[5] += (c.getLevelForXP(c.playerXP[5]) * .33);
  358. if (rest)
  359. c.playerLevel[5] += 1;
  360. if (c.playerLevel[5] > c.getLevelForXP(c.playerXP[5]))
  361. c.playerLevel[5] = c.getLevelForXP(c.playerXP[5]);
  362. c.getPA().refreshSkill(5);
  363. if (rest)
  364. restoreStats();
  365. }
  366.  
  367.  
  368. public void restoreStats() {
  369. for (int j = 0; j <= 6; j++) {
  370. if (j == 5 || j == 3)
  371. continue;
  372. if (c.playerLevel[j] < c.getLevelForXP(c.playerXP[j])) {
  373. c.playerLevel[j] += (c.getLevelForXP(c.playerXP[j]) * .33);
  374. if (c.playerLevel[j] > c.getLevelForXP(c.playerXP[j])) {
  375. c.playerLevel[j] = c.getLevelForXP(c.playerXP[j]);
  376. }
  377. c.getPA().refreshSkill(j);
  378. c.getPA().setSkillLevel(j, c.playerLevel[j], c.playerXP[j]);
  379. }
  380. }
  381. }
  382.  
  383. public void Rocktail(int itemId, int replaceItem, int slot) {
  384. c.startAnimation(829);
  385. if (c.duelRule[6]) {
  386. c.sendMessage("You may not eat in this duel.");
  387. return;
  388. }
  389. if (System.currentTimeMillis() - c.foodDelay >= 1500 && c.playerLevel[3] > 0) {
  390. c.startAnimation(829);
  391. c.getCombat().resetPlayerAttack();
  392. c.attackTimer += 2;
  393. if (c.playerLevel[3] < c.getLevelForXP(c.playerXP[3])) {
  394. c.playerLevel[3] += 24;
  395. c.playerLevel[3] += getBrewStat(3, .15);
  396. }
  397. c.foodDelay = System.currentTimeMillis();
  398. c.getPA().refreshSkill(3);
  399. c.sendMessage("You eat the Rocktail.");
  400. }
  401. if (c.playerLevel[3] > (c.getLevelForXP(c.playerXP[3]))) {
  402. c.playerLevel[3] = (int)(c.getLevelForXP(c.playerXP[3])*1.09);
  403. }
  404. c.getPA().refreshSkill(3);
  405. }
  406.  
  407. public void doTheBrew(int itemId, int replaceItem, int slot) {
  408. if (c.duelRule[6]) {
  409. c.sendMessage("You may not eat in this duel.");
  410. return;
  411. }
  412. c.startAnimation(829);
  413. c.playerItems[slot] = replaceItem + 1;
  414. c.getItems().resetItems(3214);
  415. int[] toDecrease = {0,2,4,6};
  416.  
  417. int[] toIncrease = {1,3};
  418. for (int tD : toDecrease) {
  419. c.playerLevel[tD] -= getBrewStat(tD, .10);
  420. if (c.playerLevel[tD] < 0)
  421. c.playerLevel[tD] = 1;
  422. c.getPA().refreshSkill(tD);
  423. c.getPA().setSkillLevel(tD, c.playerLevel[tD], c.playerXP[tD]);
  424. }
  425. c.playerLevel[1] += getBrewStat(1, .20);
  426. if (c.playerLevel[1] > (c.getLevelForXP(c.playerXP[1])*1.2 + 1)) {
  427. c.playerLevel[1] = (int)(c.getLevelForXP(c.playerXP[1])*1.2);
  428. }
  429. c.getPA().refreshSkill(1);
  430.  
  431. c.playerLevel[3] += getBrewStat(3, .15);
  432. if (c.playerLevel[3] > (c.getLevelForXP(c.playerXP[3])*1.17 + 1)) {
  433. c.playerLevel[3] = (int)(c.getLevelForXP(c.playerXP[3])*1.17);
  434. }
  435. c.getPA().refreshSkill(3);
  436. }
  437.  
  438. public void enchanceStat(int skillID, boolean sup) {
  439. c.playerLevel[skillID] += getBoostedStat(skillID, sup);
  440. c.getPA().refreshSkill(skillID);
  441. }
  442.  
  443. public int getBrewStat(int skill, double amount) {
  444. return (int)(c.getLevelForXP(c.playerXP[skill]) * amount);
  445. }
  446.  
  447. public int getBoostedStat(int skill, boolean sup) {
  448. int increaseBy = 0;
  449. if (sup)
  450. increaseBy = (int)(c.getLevelForXP(c.playerXP[skill])*.20);
  451. else
  452. increaseBy = (int)(c.getLevelForXP(c.playerXP[skill])*.13) + 1;
  453. if (c.playerLevel[skill] + increaseBy > c.getLevelForXP(c.playerXP[skill]) + increaseBy + 1) {
  454. return c.getLevelForXP(c.playerXP[skill]) + increaseBy - c.playerLevel[skill];
  455. }
  456. return increaseBy;
  457. }
  458.  
  459. public boolean isPotion(int itemId) {
  460. String name = c.getItems().getItemName(itemId);
  461. return name.contains("(4)") || name.contains("(3)") || name.contains("(2)") || name.contains("(1)");
  462. }
  463. }
Add Comment
Please, Sign In to add comment