Advertisement
Guest User

Untitled

a guest
Feb 1st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.56 KB | None | 0 0
  1. package com.rs.game.player;
  2.  
  3. import java.io.Serializable;
  4. import java.text.DecimalFormat;
  5. import java.text.NumberFormat;
  6. import java.util.ArrayList;
  7.  
  8. import com.rs.Settings;
  9. import com.rs.game.player.content.custom.TimeManager;
  10. import com.rs.game.player.dialogues.impl.LevelUp;
  11.  
  12. public final class Skills implements Serializable {
  13.  
  14. private static final long serialVersionUID = -7086829989489745985L;
  15.  
  16. public static final double MAXIMUM_EXP = 200000000;
  17.  
  18. public static final int ATTACK = 0, DEFENCE = 1, STRENGTH = 2,
  19. HITPOINTS = 3, RANGE = 4, PRAYER = 5, MAGIC = 6, COOKING = 7,
  20. WOODCUTTING = 8, FLETCHING = 9, FISHING = 10, FIREMAKING = 11,
  21. CRAFTING = 12, SMITHING = 13, MINING = 14, HERBLORE = 15,
  22. AGILITY = 16, THIEVING = 17, SLAYER = 18, FARMING = 19,
  23. RUNECRAFTING = 20, CONSTRUCTION = 22, HUNTER = 21, SUMMONING = 23,
  24. DUNGEONEERING = 24;
  25.  
  26. public static int getSkillId(String name) {
  27. for (int i = 0; i < SKILLS.length; i++) {
  28. if (name.toLowerCase().equals(SKILLS[i].toLowerCase())) {
  29. return i;
  30. }
  31. }
  32. return -1;
  33. }
  34.  
  35. public static final String[] SKILLS = {"Attack", "Defence",
  36. "Strength", "Constitution", "Ranged", "Prayer", "Magic", "Cooking",
  37. "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting",
  38. "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer",
  39. "Farming", "Runecrafting", "Hunter", "Construction", "Summoning",
  40. "Dungeoneering"
  41. };
  42.  
  43. public short level[];
  44. private double xp[];
  45. private double[] xpTracks;
  46. private boolean[] trackSkills;
  47. private boolean[] locked;
  48. private byte[] trackSkillsIds;
  49. private boolean xpDisplay, xpPopup;
  50.  
  51. public boolean[] getLockedSkills() {
  52. if (locked == null)
  53. locked = new boolean[25];
  54. return locked;
  55. }
  56. public boolean isLocked(int id) {
  57. if (locked == null)
  58. locked = new boolean[25];
  59. return locked[id];
  60. }
  61.  
  62. public void lockSkill(int id) {
  63. if (locked == null)
  64. locked = new boolean[25];
  65. this.locked[id] = true;
  66. player.sendMessage("You have <col=FF0000>locked</col> your "+SKILLS[id]+" exp!");
  67. }
  68.  
  69. public void unlockSkill(int id) {
  70. if (locked == null)
  71. locked = new boolean[25];
  72. this.locked[id] = false;
  73. player.sendMessage("You have <col=00FF00>unlocked</col> your "+SKILLS[id]+" exp!");
  74. }
  75.  
  76. private transient int currentCounter;
  77. private transient Player player;
  78.  
  79. public void passLevels(Player p) {
  80. this.level = p.getSkills().level;
  81. this.xp = p.getSkills().xp;
  82. }
  83.  
  84. public Skills() {
  85. level = new short[25];
  86. xp = new double[25];
  87. for (int i = 0; i < level.length; i++) {
  88. level[i] = 1;
  89. xp[i] = 0;
  90. }
  91. level[3] = 10;
  92. xp[3] = 1184;
  93. level[HERBLORE] = 3;
  94. xp[HERBLORE] = 250;
  95. xpPopup = true;
  96. xpTracks = new double[3];
  97. trackSkills = new boolean[3];
  98. locked = new boolean[25];
  99. trackSkillsIds = new byte[3];
  100. trackSkills[0] = true;
  101. for (int i = 0; i < trackSkillsIds.length; i++)
  102. trackSkillsIds[i] = 30;
  103.  
  104. }
  105.  
  106. public void sendXPDisplay() {
  107. for (int i = 0; i < trackSkills.length; i++) {
  108. player.getPackets().sendConfigByFile(10444 + i,
  109. trackSkills[i] ? 1 : 0);
  110. player.getPackets().sendConfigByFile(10440 + i,
  111. trackSkillsIds[i] + 1);
  112. refreshCounterXp(i);
  113. }
  114. }
  115.  
  116. public void setupXPCounter() {
  117. player.getInterfaceManager().sendXPDisplay(1214);
  118. }
  119.  
  120. public void refreshCurrentCounter() {
  121. player.getPackets().sendConfig(2478, currentCounter + 1);
  122. }
  123.  
  124. public void setCurrentCounter(int counter) {
  125. if (counter != currentCounter) {
  126. currentCounter = counter;
  127. refreshCurrentCounter();
  128. }
  129. }
  130.  
  131. public void switchTrackCounter() {
  132. trackSkills[currentCounter] = !trackSkills[currentCounter];
  133. player.getPackets().sendConfigByFile(10444 + currentCounter,
  134. trackSkills[currentCounter] ? 1 : 0);
  135. }
  136.  
  137. public void resetCounterXP() {
  138. xpTracks[currentCounter] = 0;
  139. refreshCounterXp(currentCounter);
  140. }
  141.  
  142. public void setCounterSkill(int skill) {
  143. xpTracks[currentCounter] = 0;
  144. trackSkillsIds[currentCounter] = (byte) skill;
  145. player.getPackets().sendConfigByFile(10440 + currentCounter,
  146. trackSkillsIds[currentCounter] + 1);
  147. refreshCounterXp(currentCounter);
  148. }
  149.  
  150. public void refreshCounterXp(int counter) {
  151. player.getPackets().sendConfig(counter == 0 ? 1801 : 2474 + counter,
  152. (int) (xpTracks[counter] * 10));
  153. }
  154.  
  155. public void handleSetupXPCounter(int componentId) {
  156. if (componentId == 18)
  157. player.getInterfaceManager().sendXPDisplay();
  158. else if (componentId >= 22 && componentId <= 24)
  159. setCurrentCounter(componentId - 22);
  160. else if (componentId == 27)
  161. switchTrackCounter();
  162. else if (componentId == 61)
  163. resetCounterXP();
  164. else if (componentId >= 31 && componentId <= 57)
  165. if (componentId == 33)
  166. setCounterSkill(4);
  167. else if (componentId == 34)
  168. setCounterSkill(2);
  169. else if (componentId == 35)
  170. setCounterSkill(3);
  171. else if (componentId == 42)
  172. setCounterSkill(18);
  173. else if (componentId == 49)
  174. setCounterSkill(11);
  175. else
  176. setCounterSkill(componentId >= 56 ? componentId - 27
  177. : componentId - 31);
  178.  
  179. }
  180.  
  181. public void restoreSummoning() {
  182. level[23] = (short) getLevelForXp(23);
  183. refresh(23);
  184. }
  185.  
  186. public void sendInterfaces() {
  187. if (xpDisplay)
  188. player.getInterfaceManager().sendXPDisplay();
  189. if (xpPopup)
  190. player.getInterfaceManager().sendXPPopup();
  191. }
  192.  
  193. public void switchXPDisplay() {
  194. xpDisplay = !xpDisplay;
  195. if (xpDisplay)
  196. player.getInterfaceManager().sendXPDisplay();
  197. else
  198. player.getInterfaceManager().closeXPDisplay();
  199. }
  200.  
  201. public void switchXPPopup() {
  202. xpPopup = !xpPopup;
  203. player.getPackets().sendGameMessage(
  204. "XP pop-ups are now " + (xpPopup ? "en" : "dis") + "abled.");
  205. if (xpPopup)
  206. player.getInterfaceManager().sendXPPopup();
  207. else
  208. player.getInterfaceManager().closeXPPopup();
  209. }
  210.  
  211. public void restoreSkills() {
  212. for (int skill = 0; skill < level.length; skill++) {
  213. level[skill] = (short) getLevelForXp(skill);
  214. refresh(skill);
  215. }
  216. }
  217.  
  218. public void setPlayer(Player player) {
  219. this.player = player;
  220. // temporary
  221. if (locked == null)
  222. locked = new boolean[25];
  223. if (xpTracks == null) {
  224. xpPopup = true;
  225. xpTracks = new double[3];
  226. trackSkills = new boolean[3];
  227. trackSkillsIds = new byte[3];
  228. trackSkills[0] = true;
  229. for (int i = 0; i < trackSkillsIds.length; i++)
  230. trackSkillsIds[i] = 30;
  231. }
  232. }
  233.  
  234. public short[] getLevels() {
  235. return level;
  236. }
  237.  
  238. public double[] getXp() {
  239. return xp;
  240. }
  241.  
  242. public int getLevel(int skill) {
  243. return level[skill];
  244. }
  245.  
  246. public double getXp(int skill) {
  247. return xp[skill];
  248. }
  249.  
  250. public boolean hasRequiriments(int... skills) {
  251. for (int i = 0; i < skills.length; i += 2) {
  252. int skillId = skills[i];
  253. int skillLevel = skills[i + 1];
  254. if (getLevelForXp(skillId) < skillLevel)
  255. return false;
  256.  
  257. }
  258. return true;
  259. }
  260.  
  261. public int getCombatLevel() {
  262. int attack = getLevelForXp(0);
  263. int defence = getLevelForXp(1);
  264. int strength = getLevelForXp(2);
  265. int hp = getLevelForXp(3);
  266. int prayer = getLevelForXp(5);
  267. int ranged = getLevelForXp(4);
  268. int magic = getLevelForXp(6);
  269. int combatLevel = 3;
  270. combatLevel = (int) ((defence + hp + Math.floor(prayer / 2)) * 0.25) + 1;
  271. double melee = (attack + strength) * 0.325;
  272. double ranger = Math.floor(ranged * 1.5) * 0.325;
  273. double mage = Math.floor(magic * 1.5) * 0.325;
  274. if (melee >= ranger && melee >= mage) {
  275. combatLevel += melee;
  276. } else if (ranger >= melee && ranger >= mage) {
  277. combatLevel += ranger;
  278. } else if (mage >= melee && mage >= ranger) {
  279. combatLevel += mage;
  280. }
  281. return combatLevel;
  282. }
  283.  
  284. public void set(int skill, int newLevel) {
  285. level[skill] = (short) newLevel;
  286. refresh(skill);
  287. }
  288.  
  289. public int drainLevel(int skill, int drain) {
  290. int drainLeft = drain - level[skill];
  291. if (drainLeft < 0) {
  292. drainLeft = 0;
  293. }
  294. level[skill] -= drain;
  295. if (level[skill] < 0) {
  296. level[skill] = 0;
  297. }
  298. refresh(skill);
  299. return drainLeft;
  300. }
  301.  
  302. public int getCombatLevelWithSummoning() {
  303. return getCombatLevel() + getSummoningCombatLevel();
  304. }
  305.  
  306. public int getSummoningCombatLevel() {
  307. return getLevelForXp(Skills.SUMMONING) / 8;
  308. }
  309.  
  310. public void drainSummoning(int amt) {
  311. int level = getLevel(Skills.SUMMONING);
  312. if (level == 0)
  313. return;
  314. set(Skills.SUMMONING, amt > level ? 0 : level - amt);
  315. }
  316.  
  317. public static int getXPForLevel(int level) {
  318. int points = 0;
  319. int output = 0;
  320. for (int lvl = 1; lvl <= level; lvl++) {
  321. points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
  322. if (lvl >= level) {
  323. return output;
  324. }
  325. output = (int) Math.floor(points / 4);
  326. }
  327. return 0;
  328. }
  329.  
  330. public int getLevelForXp(int skill) {
  331. double exp = xp[skill];
  332. int points = 0;
  333. int output = 0;
  334. for (int lvl = 1; lvl <= (skill == DUNGEONEERING ? 120 : 99); lvl++) {
  335. points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
  336. output = (int) Math.floor(points / 4);
  337. if ((output - 1) >= exp) {
  338. return lvl;
  339. }
  340. }
  341. return skill == DUNGEONEERING ? 120 : 99;
  342. }
  343.  
  344. public int getTotal(Player player) {
  345. int totallevel = 0;
  346. for (int i = 0; i <=6; i++) {
  347. totallevel += player.getSkills().getLevelForXp(i);
  348. }
  349. return totallevel;
  350. }
  351.  
  352. public int getTotalLevel(Player player) {
  353. int totallevel = 0;
  354. for (int i = 0; i <= 24; i++) {
  355. totallevel += player.getSkills().getLevelForXp(i);
  356. }
  357. return totallevel;
  358. }
  359.  
  360. public boolean hasMaxedCombat() {
  361. return hasRequiriments(ATTACK, 120, STRENGTH, 120, DEFENCE, 120, RANGE, 120, PRAYER, 120, MAGIC, 120, HITPOINTS, 120);
  362. }
  363.  
  364. public boolean hasMaxedSkills() {
  365. return hasRequiriments(COOKING, 120, WOODCUTTING, 120, FLETCHING, 120, FISHING, 120, FIREMAKING,120 ,
  366. CRAFTING, 120, SMITHING, 120, MINING,120, HERBLORE, 120, AGILITY, 120,
  367. THIEVING, 120, SLAYER, 120, FARMING, 120, RUNECRAFTING, 120, CONSTRUCTION, 120,
  368. HUNTER, 120, SUMMONING, 120, DUNGEONEERING, 120);
  369. }
  370.  
  371. public boolean hasMaxedPrestigeSkills() {
  372. return hasRequiriments(COOKING, 99, WOODCUTTING, 99, FLETCHING, 99, FISHING, 99, FIREMAKING,99 ,
  373. CRAFTING, 99, SMITHING, 99, MINING,99, HERBLORE, 99, AGILITY, 99,
  374. THIEVING, 99, SLAYER, 99, FARMING, 99, RUNECRAFTING, 99, CONSTRUCTION, 99,
  375. HUNTER, 99, SUMMONING, 99, DUNGEONEERING, 99, ATTACK, 99, STRENGTH, 99, DEFENCE, 99, RANGE, 99, PRAYER, 99, MAGIC, 99, HITPOINTS, 99);
  376. }
  377.  
  378. public String getTotalXp(Player player) {
  379. double totalxp = 0;
  380. for (double xp : player.getSkills().getXp()) {
  381. totalxp += xp;
  382. }
  383. NumberFormat formatter = new DecimalFormat("#######");
  384. return ""+formatter.format(totalxp)+"";
  385. }
  386.  
  387. public long getXp(Player player) {
  388. long totalxp = 0;
  389. for (double xp : player.getSkills().getXp()) {
  390. totalxp += xp;
  391. }
  392. return totalxp;
  393. }
  394.  
  395. public void init() {
  396. for (int skill = 0; skill < level.length; skill++)
  397. refresh(skill);
  398. sendXPDisplay();
  399. }
  400.  
  401. public void refresh(int skill) {
  402. player.getPackets().sendSkillLevel(skill);
  403. }
  404.  
  405. public int getCounterSkill(int skill) {
  406. switch (skill) {
  407. case ATTACK:
  408. return 0;
  409. case STRENGTH:
  410. return 1;
  411. case DEFENCE:
  412. return 4;
  413. case RANGE:
  414. return 2;
  415. case HITPOINTS:
  416. return 5;
  417. case PRAYER:
  418. return 6;
  419. case AGILITY:
  420. return 7;
  421. case HERBLORE:
  422. return 8;
  423. case THIEVING:
  424. return 9;
  425. case CRAFTING:
  426. return 10;
  427. case MINING:
  428. return 12;
  429. case SMITHING:
  430. return 13;
  431. case FISHING:
  432. return 14;
  433. case COOKING:
  434. return 15;
  435. case FIREMAKING:
  436. return 16;
  437. case WOODCUTTING:
  438. return 17;
  439. case SLAYER:
  440. return 19;
  441. case FARMING:
  442. return 20;
  443. case CONSTRUCTION:
  444. return 21;
  445. case HUNTER:
  446. return 22;
  447. case SUMMONING:
  448. return 23;
  449. case DUNGEONEERING:
  450. return 24;
  451. case MAGIC:
  452. return 3;
  453. case FLETCHING:
  454. return 18;
  455. case RUNECRAFTING:
  456. return 11;
  457. default:
  458. return -1;
  459. }
  460.  
  461. }
  462.  
  463. public void addXp(int skill, double exp) {
  464. player.getControlerManager().trackXP(skill, (int) exp);
  465. if (player.isXpLocked())
  466. return;
  467. if (player.isDonator())
  468. exp *= 1.5;
  469. if (player.isSuper())
  470. exp *= 2.0;
  471. if (player.isExtreme())
  472. exp *= 2.5;
  473.  
  474.  
  475.  
  476.  
  477. if (player.allowChange() == true) {
  478. player.setAllowChange(false);
  479. player.sendMessage("<col=FF0000>You can now no longer change your Difficulty.");
  480. }
  481.  
  482. if (player.getDifficulty() == 1) {
  483. exp *= 300; // Super Easy
  484. } else if (player.getDifficulty() == 2) {
  485. exp *= 200; // Easy
  486. } else if (player.getDifficulty() == 3) {
  487. exp *= 150; // Normal
  488. } else if (player.getDifficulty() == 4) {
  489. exp *= 50; // Hard
  490. } else if (player.getDifficulty() == 5) {
  491. exp *= 5; // Extreme
  492. }
  493. if (player.isDonator())
  494. exp *= 1.5;
  495. if (player.isSuper())
  496. exp *= 2.0;
  497. if (player.isExtreme())
  498. exp *= 2.5;
  499.  
  500.  
  501. player.getControlerManager().trackXP(skill, (int) exp);
  502. exp *= player.getAuraManager().usingWisdom() == true ? 1.025 : 1;
  503. exp *= TimeManager.isWeekend() == true ? 1.7 : 1.0;
  504.  
  505. int oldLevel = getLevelForXp(skill);
  506. int oldXP = (int) xp[skill];
  507. xp[skill] += exp;
  508. for (int i = 0; i < trackSkills.length; i++) {
  509. if (trackSkills[i]) {
  510. if (trackSkillsIds[i] == 30
  511. || (trackSkillsIds[i] == 29 && (skill == Skills.ATTACK
  512. || skill == Skills.DEFENCE
  513. || skill == Skills.STRENGTH
  514. || skill == Skills.MAGIC
  515. || skill == Skills.RANGE || skill == Skills.HITPOINTS))
  516. || trackSkillsIds[i] == getCounterSkill(skill)) {
  517. xpTracks[i] += exp;
  518. refreshCounterXp(i);
  519. }
  520. }
  521. }
  522.  
  523. if (xp[skill] > MAXIMUM_EXP) {
  524. xp[skill] = MAXIMUM_EXP;
  525. if (oldXP < 104273167 && xp[skill] > 104273167){
  526. LevelUp.send104m(player, skill);
  527. }
  528. }
  529.  
  530. int newLevel = getLevelForXp(skill);
  531. int levelDiff = newLevel - oldLevel;
  532. if (newLevel > oldLevel) {
  533. level[skill] += levelDiff;
  534. player.getDialogueManager().startDialogue("LevelUp", skill);
  535. if (skill == SUMMONING || (skill >= ATTACK && skill <= MAGIC)) {
  536. player.getAppearence().generateAppearenceData();
  537. if (skill == HITPOINTS)
  538. player.heal(levelDiff * 10);
  539. else if (skill == PRAYER)
  540. player.getPrayer().restorePrayer(levelDiff * 10);
  541. }
  542. player.getQuestManager().checkCompleted();
  543. }
  544. refresh(skill);
  545. }
  546.  
  547. private boolean getRights() {
  548. // TODO Auto-generated method stub
  549. return false;
  550. }
  551. public void addSkillXpRefresh(int skill, double xp) {
  552. this.xp[skill] += xp;
  553. level[skill] = (short) getLevelForXp(skill);
  554. }
  555.  
  556. public void resetSkillNoRefresh(int skill) {
  557. xp[skill] = 0;
  558. level[skill] = 1;
  559. }
  560.  
  561. public void setXp(int skill, double exp) {
  562. xp[skill] = exp;
  563. refresh(skill);
  564. }
  565. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement