Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs.game.player;
- import java.io.Serializable;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- import java.util.ArrayList;
- import com.rs.Settings;
- import com.rs.game.player.content.custom.TimeManager;
- import com.rs.game.player.dialogues.impl.LevelUp;
- public final class Skills implements Serializable {
- private static final long serialVersionUID = -7086829989489745985L;
- public static final double MAXIMUM_EXP = 200000000;
- public static final int ATTACK = 0, DEFENCE = 1, STRENGTH = 2,
- HITPOINTS = 3, RANGE = 4, PRAYER = 5, MAGIC = 6, COOKING = 7,
- WOODCUTTING = 8, FLETCHING = 9, FISHING = 10, FIREMAKING = 11,
- CRAFTING = 12, SMITHING = 13, MINING = 14, HERBLORE = 15,
- AGILITY = 16, THIEVING = 17, SLAYER = 18, FARMING = 19,
- RUNECRAFTING = 20, CONSTRUCTION = 22, HUNTER = 21, SUMMONING = 23,
- DUNGEONEERING = 24;
- public static int getSkillId(String name) {
- for (int i = 0; i < SKILLS.length; i++) {
- if (name.toLowerCase().equals(SKILLS[i].toLowerCase())) {
- return i;
- }
- }
- return -1;
- }
- public static final String[] SKILLS = {"Attack", "Defence",
- "Strength", "Constitution", "Ranged", "Prayer", "Magic", "Cooking",
- "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting",
- "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer",
- "Farming", "Runecrafting", "Hunter", "Construction", "Summoning",
- "Dungeoneering"
- };
- public short level[];
- private double xp[];
- private double[] xpTracks;
- private boolean[] trackSkills;
- private boolean[] locked;
- private byte[] trackSkillsIds;
- private boolean xpDisplay, xpPopup;
- public boolean[] getLockedSkills() {
- if (locked == null)
- locked = new boolean[25];
- return locked;
- }
- public boolean isLocked(int id) {
- if (locked == null)
- locked = new boolean[25];
- return locked[id];
- }
- public void lockSkill(int id) {
- if (locked == null)
- locked = new boolean[25];
- this.locked[id] = true;
- player.sendMessage("You have <col=FF0000>locked</col> your "+SKILLS[id]+" exp!");
- }
- public void unlockSkill(int id) {
- if (locked == null)
- locked = new boolean[25];
- this.locked[id] = false;
- player.sendMessage("You have <col=00FF00>unlocked</col> your "+SKILLS[id]+" exp!");
- }
- private transient int currentCounter;
- private transient Player player;
- public void passLevels(Player p) {
- this.level = p.getSkills().level;
- this.xp = p.getSkills().xp;
- }
- public Skills() {
- level = new short[25];
- xp = new double[25];
- for (int i = 0; i < level.length; i++) {
- level[i] = 1;
- xp[i] = 0;
- }
- level[3] = 10;
- xp[3] = 1184;
- level[HERBLORE] = 3;
- xp[HERBLORE] = 250;
- xpPopup = true;
- xpTracks = new double[3];
- trackSkills = new boolean[3];
- locked = new boolean[25];
- trackSkillsIds = new byte[3];
- trackSkills[0] = true;
- for (int i = 0; i < trackSkillsIds.length; i++)
- trackSkillsIds[i] = 30;
- }
- public void sendXPDisplay() {
- for (int i = 0; i < trackSkills.length; i++) {
- player.getPackets().sendConfigByFile(10444 + i,
- trackSkills[i] ? 1 : 0);
- player.getPackets().sendConfigByFile(10440 + i,
- trackSkillsIds[i] + 1);
- refreshCounterXp(i);
- }
- }
- public void setupXPCounter() {
- player.getInterfaceManager().sendXPDisplay(1214);
- }
- public void refreshCurrentCounter() {
- player.getPackets().sendConfig(2478, currentCounter + 1);
- }
- public void setCurrentCounter(int counter) {
- if (counter != currentCounter) {
- currentCounter = counter;
- refreshCurrentCounter();
- }
- }
- public void switchTrackCounter() {
- trackSkills[currentCounter] = !trackSkills[currentCounter];
- player.getPackets().sendConfigByFile(10444 + currentCounter,
- trackSkills[currentCounter] ? 1 : 0);
- }
- public void resetCounterXP() {
- xpTracks[currentCounter] = 0;
- refreshCounterXp(currentCounter);
- }
- public void setCounterSkill(int skill) {
- xpTracks[currentCounter] = 0;
- trackSkillsIds[currentCounter] = (byte) skill;
- player.getPackets().sendConfigByFile(10440 + currentCounter,
- trackSkillsIds[currentCounter] + 1);
- refreshCounterXp(currentCounter);
- }
- public void refreshCounterXp(int counter) {
- player.getPackets().sendConfig(counter == 0 ? 1801 : 2474 + counter,
- (int) (xpTracks[counter] * 10));
- }
- public void handleSetupXPCounter(int componentId) {
- if (componentId == 18)
- player.getInterfaceManager().sendXPDisplay();
- else if (componentId >= 22 && componentId <= 24)
- setCurrentCounter(componentId - 22);
- else if (componentId == 27)
- switchTrackCounter();
- else if (componentId == 61)
- resetCounterXP();
- else if (componentId >= 31 && componentId <= 57)
- if (componentId == 33)
- setCounterSkill(4);
- else if (componentId == 34)
- setCounterSkill(2);
- else if (componentId == 35)
- setCounterSkill(3);
- else if (componentId == 42)
- setCounterSkill(18);
- else if (componentId == 49)
- setCounterSkill(11);
- else
- setCounterSkill(componentId >= 56 ? componentId - 27
- : componentId - 31);
- }
- public void restoreSummoning() {
- level[23] = (short) getLevelForXp(23);
- refresh(23);
- }
- public void sendInterfaces() {
- if (xpDisplay)
- player.getInterfaceManager().sendXPDisplay();
- if (xpPopup)
- player.getInterfaceManager().sendXPPopup();
- }
- public void switchXPDisplay() {
- xpDisplay = !xpDisplay;
- if (xpDisplay)
- player.getInterfaceManager().sendXPDisplay();
- else
- player.getInterfaceManager().closeXPDisplay();
- }
- public void switchXPPopup() {
- xpPopup = !xpPopup;
- player.getPackets().sendGameMessage(
- "XP pop-ups are now " + (xpPopup ? "en" : "dis") + "abled.");
- if (xpPopup)
- player.getInterfaceManager().sendXPPopup();
- else
- player.getInterfaceManager().closeXPPopup();
- }
- public void restoreSkills() {
- for (int skill = 0; skill < level.length; skill++) {
- level[skill] = (short) getLevelForXp(skill);
- refresh(skill);
- }
- }
- public void setPlayer(Player player) {
- this.player = player;
- // temporary
- if (locked == null)
- locked = new boolean[25];
- if (xpTracks == null) {
- xpPopup = true;
- xpTracks = new double[3];
- trackSkills = new boolean[3];
- trackSkillsIds = new byte[3];
- trackSkills[0] = true;
- for (int i = 0; i < trackSkillsIds.length; i++)
- trackSkillsIds[i] = 30;
- }
- }
- public short[] getLevels() {
- return level;
- }
- public double[] getXp() {
- return xp;
- }
- public int getLevel(int skill) {
- return level[skill];
- }
- public double getXp(int skill) {
- return xp[skill];
- }
- public boolean hasRequiriments(int... skills) {
- for (int i = 0; i < skills.length; i += 2) {
- int skillId = skills[i];
- int skillLevel = skills[i + 1];
- if (getLevelForXp(skillId) < skillLevel)
- return false;
- }
- return true;
- }
- public int getCombatLevel() {
- int attack = getLevelForXp(0);
- int defence = getLevelForXp(1);
- int strength = getLevelForXp(2);
- int hp = getLevelForXp(3);
- int prayer = getLevelForXp(5);
- int ranged = getLevelForXp(4);
- int magic = getLevelForXp(6);
- int combatLevel = 3;
- combatLevel = (int) ((defence + hp + Math.floor(prayer / 2)) * 0.25) + 1;
- double melee = (attack + strength) * 0.325;
- double ranger = Math.floor(ranged * 1.5) * 0.325;
- double mage = Math.floor(magic * 1.5) * 0.325;
- if (melee >= ranger && melee >= mage) {
- combatLevel += melee;
- } else if (ranger >= melee && ranger >= mage) {
- combatLevel += ranger;
- } else if (mage >= melee && mage >= ranger) {
- combatLevel += mage;
- }
- return combatLevel;
- }
- public void set(int skill, int newLevel) {
- level[skill] = (short) newLevel;
- refresh(skill);
- }
- public int drainLevel(int skill, int drain) {
- int drainLeft = drain - level[skill];
- if (drainLeft < 0) {
- drainLeft = 0;
- }
- level[skill] -= drain;
- if (level[skill] < 0) {
- level[skill] = 0;
- }
- refresh(skill);
- return drainLeft;
- }
- public int getCombatLevelWithSummoning() {
- return getCombatLevel() + getSummoningCombatLevel();
- }
- public int getSummoningCombatLevel() {
- return getLevelForXp(Skills.SUMMONING) / 8;
- }
- public void drainSummoning(int amt) {
- int level = getLevel(Skills.SUMMONING);
- if (level == 0)
- return;
- set(Skills.SUMMONING, amt > level ? 0 : level - amt);
- }
- public static int getXPForLevel(int level) {
- int points = 0;
- int output = 0;
- for (int lvl = 1; lvl <= level; lvl++) {
- points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
- if (lvl >= level) {
- return output;
- }
- output = (int) Math.floor(points / 4);
- }
- return 0;
- }
- public int getLevelForXp(int skill) {
- double exp = xp[skill];
- int points = 0;
- int output = 0;
- for (int lvl = 1; lvl <= (skill == DUNGEONEERING ? 120 : 99); lvl++) {
- points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
- output = (int) Math.floor(points / 4);
- if ((output - 1) >= exp) {
- return lvl;
- }
- }
- return skill == DUNGEONEERING ? 120 : 99;
- }
- public int getTotal(Player player) {
- int totallevel = 0;
- for (int i = 0; i <=6; i++) {
- totallevel += player.getSkills().getLevelForXp(i);
- }
- return totallevel;
- }
- public int getTotalLevel(Player player) {
- int totallevel = 0;
- for (int i = 0; i <= 24; i++) {
- totallevel += player.getSkills().getLevelForXp(i);
- }
- return totallevel;
- }
- public boolean hasMaxedCombat() {
- return hasRequiriments(ATTACK, 120, STRENGTH, 120, DEFENCE, 120, RANGE, 120, PRAYER, 120, MAGIC, 120, HITPOINTS, 120);
- }
- public boolean hasMaxedSkills() {
- return hasRequiriments(COOKING, 120, WOODCUTTING, 120, FLETCHING, 120, FISHING, 120, FIREMAKING,120 ,
- CRAFTING, 120, SMITHING, 120, MINING,120, HERBLORE, 120, AGILITY, 120,
- THIEVING, 120, SLAYER, 120, FARMING, 120, RUNECRAFTING, 120, CONSTRUCTION, 120,
- HUNTER, 120, SUMMONING, 120, DUNGEONEERING, 120);
- }
- public boolean hasMaxedPrestigeSkills() {
- return hasRequiriments(COOKING, 99, WOODCUTTING, 99, FLETCHING, 99, FISHING, 99, FIREMAKING,99 ,
- CRAFTING, 99, SMITHING, 99, MINING,99, HERBLORE, 99, AGILITY, 99,
- THIEVING, 99, SLAYER, 99, FARMING, 99, RUNECRAFTING, 99, CONSTRUCTION, 99,
- HUNTER, 99, SUMMONING, 99, DUNGEONEERING, 99, ATTACK, 99, STRENGTH, 99, DEFENCE, 99, RANGE, 99, PRAYER, 99, MAGIC, 99, HITPOINTS, 99);
- }
- public String getTotalXp(Player player) {
- double totalxp = 0;
- for (double xp : player.getSkills().getXp()) {
- totalxp += xp;
- }
- NumberFormat formatter = new DecimalFormat("#######");
- return ""+formatter.format(totalxp)+"";
- }
- public long getXp(Player player) {
- long totalxp = 0;
- for (double xp : player.getSkills().getXp()) {
- totalxp += xp;
- }
- return totalxp;
- }
- public void init() {
- for (int skill = 0; skill < level.length; skill++)
- refresh(skill);
- sendXPDisplay();
- }
- public void refresh(int skill) {
- player.getPackets().sendSkillLevel(skill);
- }
- public int getCounterSkill(int skill) {
- switch (skill) {
- case ATTACK:
- return 0;
- case STRENGTH:
- return 1;
- case DEFENCE:
- return 4;
- case RANGE:
- return 2;
- case HITPOINTS:
- return 5;
- case PRAYER:
- return 6;
- case AGILITY:
- return 7;
- case HERBLORE:
- return 8;
- case THIEVING:
- return 9;
- case CRAFTING:
- return 10;
- case MINING:
- return 12;
- case SMITHING:
- return 13;
- case FISHING:
- return 14;
- case COOKING:
- return 15;
- case FIREMAKING:
- return 16;
- case WOODCUTTING:
- return 17;
- case SLAYER:
- return 19;
- case FARMING:
- return 20;
- case CONSTRUCTION:
- return 21;
- case HUNTER:
- return 22;
- case SUMMONING:
- return 23;
- case DUNGEONEERING:
- return 24;
- case MAGIC:
- return 3;
- case FLETCHING:
- return 18;
- case RUNECRAFTING:
- return 11;
- default:
- return -1;
- }
- }
- public void addXp(int skill, double exp) {
- player.getControlerManager().trackXP(skill, (int) exp);
- if (player.isXpLocked())
- return;
- if (player.isDonator())
- exp *= 1.5;
- if (player.isSuper())
- exp *= 2.0;
- if (player.isExtreme())
- exp *= 2.5;
- if (player.allowChange() == true) {
- player.setAllowChange(false);
- player.sendMessage("<col=FF0000>You can now no longer change your Difficulty.");
- }
- if (player.getDifficulty() == 1) {
- exp *= 300; // Super Easy
- } else if (player.getDifficulty() == 2) {
- exp *= 200; // Easy
- } else if (player.getDifficulty() == 3) {
- exp *= 150; // Normal
- } else if (player.getDifficulty() == 4) {
- exp *= 50; // Hard
- } else if (player.getDifficulty() == 5) {
- exp *= 5; // Extreme
- }
- if (player.isDonator())
- exp *= 1.5;
- if (player.isSuper())
- exp *= 2.0;
- if (player.isExtreme())
- exp *= 2.5;
- player.getControlerManager().trackXP(skill, (int) exp);
- exp *= player.getAuraManager().usingWisdom() == true ? 1.025 : 1;
- exp *= TimeManager.isWeekend() == true ? 1.7 : 1.0;
- int oldLevel = getLevelForXp(skill);
- int oldXP = (int) xp[skill];
- xp[skill] += exp;
- for (int i = 0; i < trackSkills.length; i++) {
- if (trackSkills[i]) {
- if (trackSkillsIds[i] == 30
- || (trackSkillsIds[i] == 29 && (skill == Skills.ATTACK
- || skill == Skills.DEFENCE
- || skill == Skills.STRENGTH
- || skill == Skills.MAGIC
- || skill == Skills.RANGE || skill == Skills.HITPOINTS))
- || trackSkillsIds[i] == getCounterSkill(skill)) {
- xpTracks[i] += exp;
- refreshCounterXp(i);
- }
- }
- }
- if (xp[skill] > MAXIMUM_EXP) {
- xp[skill] = MAXIMUM_EXP;
- if (oldXP < 104273167 && xp[skill] > 104273167){
- LevelUp.send104m(player, skill);
- }
- }
- int newLevel = getLevelForXp(skill);
- int levelDiff = newLevel - oldLevel;
- if (newLevel > oldLevel) {
- level[skill] += levelDiff;
- player.getDialogueManager().startDialogue("LevelUp", skill);
- if (skill == SUMMONING || (skill >= ATTACK && skill <= MAGIC)) {
- player.getAppearence().generateAppearenceData();
- if (skill == HITPOINTS)
- player.heal(levelDiff * 10);
- else if (skill == PRAYER)
- player.getPrayer().restorePrayer(levelDiff * 10);
- }
- player.getQuestManager().checkCompleted();
- }
- refresh(skill);
- }
- private boolean getRights() {
- // TODO Auto-generated method stub
- return false;
- }
- public void addSkillXpRefresh(int skill, double xp) {
- this.xp[skill] += xp;
- level[skill] = (short) getLevelForXp(skill);
- }
- public void resetSkillNoRefresh(int skill) {
- xp[skill] = 0;
- level[skill] = 1;
- }
- public void setXp(int skill, double exp) {
- xp[skill] = exp;
- refresh(skill);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement