diff --git a/Server/src/org/crandor/game/content/skill/Skills.java b/Server/src/org/crandor/game/content/skill/Skills.java
index 04ec9ec11..16312fa73 100644
--- a/Server/src/org/crandor/game/content/skill/Skills.java
+++ b/Server/src/org/crandor/game/content/skill/Skills.java
@@ -301,596 +301,608 @@ public final class Skills {
return mod;*/
}
-/**
- * Adds experience to the skills.
- */
-public void addExperience(final int slot, double experience) {
- addExperience(slot, experience, false);
-}
+ /**
+ * Adds experience to the skills.
+ */
+ public void addExperience(final int slot, double experience) {
+ addExperience(slot, experience, false);
+ }
-/**
- * Gets the highest combat skill id.
- * @return The id of the highest combat skill.
- */
-public int getHighestCombatSkill() {
- int id = 0;
- int last = 0;
- for (int i = 0; i < 5; i++) {
- if (staticLevels[i] > last) {
- last = staticLevels[i];
- id = i;
+ /**
+ * Gets the highest combat skill id.
+ * @return The id of the highest combat skill.
+ */
+ public int getHighestCombatSkill() {
+ int id = 0;
+ int last = 0;
+ for (int i = 0; i < 5; i++) {
+ if (staticLevels[i] > last) {
+ last = staticLevels[i];
+ id = i;
+ }
}
+ return id;
}
- return id;
-}
-/**
- * Returns the dynamic levels to the static levels
- */
-public void restore() {
- for (int i = 0; i < 24; i++) {
- int staticLevel = getStaticLevel(i);
- setLevel(i, staticLevel);
- }
- if (entity instanceof Player) {
- entity.asPlayer().getAudioManager().send(2674);
- }
- rechargePrayerPoints();
-}
-
-/**
- * Parses the skill data from the buffer.
- * @param buffer The byte buffer.
- */
-public void parse(ByteBuffer buffer) {
- for (int i = 0; i < 24; i++) {
- experience[i] = ((double) buffer.getInt() / 10D);
- dynamicLevels[i] = buffer.get() & 0xFF;
- if (i == HITPOINTS) {
- lifepoints = dynamicLevels[i];
- } else if (i == PRAYER) {
- prayerPoints = dynamicLevels[i];
+ /**
+ * Returns the dynamic levels to the static levels
+ */
+ public void restore() {
+ for (int i = 0; i < 24; i++) {
+ int staticLevel = getStaticLevel(i);
+ setLevel(i, staticLevel);
}
- staticLevels[i] = buffer.get() & 0xFF;
- }
- experienceGained = buffer.getInt();
-}
-
-public void parseExpRate(ByteBuffer buffer) {
- experienceMutiplier = buffer.getDouble();
-}
-
-/**
- * Saves the skill data on the buffer.
- * @param buffer The byte buffer.
- */
-public void save(ByteBuffer buffer) {
- for (int i = 0; i < 24; i++) {
- buffer.putInt((int) (experience[i] * 10));
- if (i == HITPOINTS) {
- buffer.put((byte) lifepoints);
- } else if (i == PRAYER) {
- buffer.put((byte) Math.ceil(prayerPoints));
- } else {
- buffer.put((byte) dynamicLevels[i]);
- }
- buffer.put((byte) staticLevels[i]);
- }
- buffer.putInt(experienceGained);
-}
-
-public void saveExpRate(ByteBuffer buffer) {
- buffer.putDouble(experienceMutiplier);
-}
-
-/**
- * Refreshes all the skill levels.
- */
-public void refresh() {
- if (!(entity instanceof Player)) {
- return;
- }
- Player player = (Player) entity;
- for (int i = 0; i < 24; i++) {
- PacketRepository.send(SkillLevel.class, new SkillContext(player, i));
- }
- LevelUp.sendFlashingIcons(player, -1);
-}
-
-/**
- * Gets the static level.
- * @param slot The skill's slot.
- * @return The level.
- */
-public int getStaticLevelByExperience(int slot) {
- double exp = experience[slot];
-
- int points = 0;
- int output = 0;
- for (byte lvl = 1; lvl < 100; 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 99;
-}
-
-/**
- * Gets the experience for a certain level.
- * @param level The level.
- * @return The experience needed.
- */
-public int getExperienceByLevel(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;
-}
-
-/**
- * Updates the combat level.
- * @return {@code True} if the combat level changed.
- */
-@SuppressWarnings("deprecation")
-public boolean updateCombatLevel() {
- boolean update = false;
- int level = calculateCombatLevel();
- update = level != entity.getProperties().getCombatLevel();
- if (entity instanceof Player) {
- Player player = (Player) entity;
- int summon = staticLevels[SUMMONING] / 8;
- if (summon != player.getFamiliarManager().getSummoningCombatLevel()) {
- player.getFamiliarManager().setSummoningCombatLevel(summon);
- update = true;
- }
- }
- entity.getProperties().setCombatLevel(level);
- return update;
-}
-
-/**
- * Gets the combat level (ignoring summoning).
- * @return The combat level.
- */
-private int calculateCombatLevel() {
- if (entity instanceof NPC) {
- return ((NPC) entity).getDefinition().getCombatLevel();
- }
- int combatLevel = 0;
- int melee = staticLevels[ATTACK] + staticLevels[STRENGTH];
- int range = (int) (1.5 * staticLevels[RANGE]);
- int mage = (int) (1.5 * staticLevels[MAGIC]);
- if (melee > range && melee > mage) {
- combatLevel = melee;
- } else if (range > melee && range > mage) {
- combatLevel = range;
- } else {
- combatLevel = mage;
- }
- combatLevel = staticLevels[DEFENCE] + staticLevels[HITPOINTS] + (staticLevels[PRAYER] / 2) + (int) (1.3 * combatLevel);
- return combatLevel / 4;
-}
-
-/**
- * @return the player
- */
-public Entity getEntity() {
- return entity;
-}
-
-/**
- * Gets the experience.
- * @param slot The slot.
- * @return The experience.
- */
-public double getExperience(int slot) {
- return experience[slot];
-}
-
-/**
- * Gets the static skill level.
- * @param slot The slot.
- * @return The static level.
- */
-public int getStaticLevel(int slot) {
- return staticLevels[slot];
-}
-
-/**
- * Sets the experience gained.
- * @param experienceGained The experience gained.
- */
-public void setExperienceGained(int experienceGained) {
- this.experienceGained = experienceGained;
-}
-
-/**
- * Gets the experience gained.
- * @return The experience gained.
- */
-public int getExperienceGained() {
- return experienceGained;
-}
-
-/**
- * Sets a dynamic level.
- * @param slot The skill id.
- * @param level The level.
- */
-public void setLevel(int slot, int level) {
- if (slot == HITPOINTS) {
- lifepoints = level;
- } else if (slot == PRAYER) {
- prayerPoints = level;
- }
- dynamicLevels[slot] = level;
- if (restoration[slot] != null) {
- restoration[slot].restart();
- }
- if (entity instanceof Player) {
- PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, slot));
- }
-}
-
-/**
- * Gets a dynamic level.
- * @param slot The skill id.
- * @return The dynamic level.
- */
-public int getLevel(int slot, boolean discardAssist) {
- if (!discardAssist) {
if (entity instanceof Player) {
- final Player p = (Player) entity;
- final AssistSession assist = p.getExtension(AssistSession.class);
- if (assist != null && assist.getPlayer() != p) {
- Player assister = assist.getPlayer();
- int index = assist.getSkillIndex(slot);
- if (index != -1 && !assist.isRestricted()) {
- // System.out.println(index + ", " +
- // assist.getSkills()[index] + ", " + SKILL_NAME[slot]);
- if (assist.getSkills()[index]) {
- int assistLevel = assister.getSkills().getLevel(slot);
- int playerLevel = dynamicLevels[slot];
- if (assistLevel > playerLevel) {
- return assistLevel;
+ entity.asPlayer().getAudioManager().send(2674);
+ }
+ rechargePrayerPoints();
+ }
+
+ /**
+ * Parses the skill data from the buffer.
+ * @param buffer The byte buffer.
+ */
+ public void parse(ByteBuffer buffer) {
+ for (int i = 0; i < 24; i++) {
+ experience[i] = ((double) buffer.getInt() / 10D);
+ dynamicLevels[i] = buffer.get() & 0xFF;
+ if (i == HITPOINTS) {
+ lifepoints = dynamicLevels[i];
+ } else if (i == PRAYER) {
+ prayerPoints = dynamicLevels[i];
+ }
+ staticLevels[i] = buffer.get() & 0xFF;
+ }
+ experienceGained = buffer.getInt();
+ }
+
+ public void parseExpRate(ByteBuffer buffer) {
+ experienceMutiplier = buffer.getDouble();
+ }
+
+ /**
+ * Saves the skill data on the buffer.
+ * @param buffer The byte buffer.
+ */
+ public void save(ByteBuffer buffer) {
+ for (int i = 0; i < 24; i++) {
+ buffer.putInt((int) (experience[i] * 10));
+ if (i == HITPOINTS) {
+ buffer.put((byte) lifepoints);
+ } else if (i == PRAYER) {
+ buffer.put((byte) Math.ceil(prayerPoints));
+ } else {
+ buffer.put((byte) dynamicLevels[i]);
+ }
+ buffer.put((byte) staticLevels[i]);
+ }
+ buffer.putInt(experienceGained);
+ }
+
+ public void saveExpRate(ByteBuffer buffer) {
+ buffer.putDouble(experienceMutiplier);
+ }
+
+ /**
+ * Refreshes all the skill levels.
+ */
+ public void refresh() {
+ if (!(entity instanceof Player)) {
+ return;
+ }
+ Player player = (Player) entity;
+ for (int i = 0; i < 24; i++) {
+ PacketRepository.send(SkillLevel.class, new SkillContext(player, i));
+ }
+ LevelUp.sendFlashingIcons(player, -1);
+ }
+
+ /**
+ * Gets the static level.
+ * @param slot The skill's slot.
+ * @return The level.
+ */
+ public int getStaticLevelByExperience(int slot) {
+ double exp = experience[slot];
+
+ int points = 0;
+ int output = 0;
+ for (byte lvl = 1; lvl < 100; 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 99;
+ }
+
+ /**
+ * Gets the experience for a certain level.
+ * @param level The level.
+ * @return The experience needed.
+ */
+ public int getExperienceByLevel(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;
+ }
+
+ /**
+ * Updates the combat level.
+ * @return {@code True} if the combat level changed.
+ */
+ @SuppressWarnings("deprecation")
+ public boolean updateCombatLevel() {
+ boolean update = false;
+ int level = calculateCombatLevel();
+ update = level != entity.getProperties().getCombatLevel();
+ if (entity instanceof Player) {
+ Player player = (Player) entity;
+ int summon = staticLevels[SUMMONING] / 8;
+ if (summon != player.getFamiliarManager().getSummoningCombatLevel()) {
+ player.getFamiliarManager().setSummoningCombatLevel(summon);
+ update = true;
+ }
+ }
+ entity.getProperties().setCombatLevel(level);
+ return update;
+ }
+
+ /**
+ * Gets the combat level (ignoring summoning).
+ * @return The combat level.
+ */
+ private int calculateCombatLevel() {
+ if (entity instanceof NPC) {
+ return ((NPC) entity).getDefinition().getCombatLevel();
+ }
+ int combatLevel = 0;
+ int melee = staticLevels[ATTACK] + staticLevels[STRENGTH];
+ int range = (int) (1.5 * staticLevels[RANGE]);
+ int mage = (int) (1.5 * staticLevels[MAGIC]);
+ if (melee > range && melee > mage) {
+ combatLevel = melee;
+ } else if (range > melee && range > mage) {
+ combatLevel = range;
+ } else {
+ combatLevel = mage;
+ }
+ combatLevel = staticLevels[DEFENCE] + staticLevels[HITPOINTS] + (staticLevels[PRAYER] / 2) + (int) (1.3 * combatLevel);
+ return combatLevel / 4;
+ }
+
+ /**
+ * @return the player
+ */
+ public Entity getEntity() {
+ return entity;
+ }
+
+ /**
+ * Gets the experience.
+ * @param slot The slot.
+ * @return The experience.
+ */
+ public double getExperience(int slot) {
+ return experience[slot];
+ }
+
+ /**
+ * Gets the static skill level.
+ * @param slot The slot.
+ * @return The static level.
+ */
+ public int getStaticLevel(int slot) {
+ return staticLevels[slot];
+ }
+
+ /**
+ * Sets the experience gained.
+ * @param experienceGained The experience gained.
+ */
+ public void setExperienceGained(int experienceGained) {
+ this.experienceGained = experienceGained;
+ }
+
+ /**
+ * Gets the experience gained.
+ * @return The experience gained.
+ */
+ public int getExperienceGained() {
+ return experienceGained;
+ }
+
+ /**
+ * Sets a dynamic level.
+ * @param slot The skill id.
+ * @param level The level.
+ */
+ public void setLevel(int slot, int level) {
+ if (slot == HITPOINTS) {
+ lifepoints = level;
+ } else if (slot == PRAYER) {
+ prayerPoints = level;
+ }
+ dynamicLevels[slot] = level;
+ if (restoration[slot] != null) {
+ restoration[slot].restart();
+ }
+ if (entity instanceof Player) {
+ PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, slot));
+ }
+ }
+
+ /**
+ * Gets a dynamic level.
+ * @param slot The skill id.
+ * @return The dynamic level.
+ */
+ public int getLevel(int slot, boolean discardAssist) {
+ if (!discardAssist) {
+ if (entity instanceof Player) {
+ final Player p = (Player) entity;
+ final AssistSession assist = p.getExtension(AssistSession.class);
+ if (assist != null && assist.getPlayer() != p) {
+ Player assister = assist.getPlayer();
+ int index = assist.getSkillIndex(slot);
+ if (index != -1 && !assist.isRestricted()) {
+ // System.out.println(index + ", " +
+ // assist.getSkills()[index] + ", " + SKILL_NAME[slot]);
+ if (assist.getSkills()[index]) {
+ int assistLevel = assister.getSkills().getLevel(slot);
+ int playerLevel = dynamicLevels[slot];
+ if (assistLevel > playerLevel) {
+ return assistLevel;
+ }
}
}
}
}
}
+ return dynamicLevels[slot];
}
- return dynamicLevels[slot];
-}
-/**
- * Gets the level.
- * @param slot the slot.
- * @return the level.
- */
-public int getLevel(int slot) {
- return getLevel(slot, false);
-}
-
-/**
- * Sets the current amount of lifepoints.
- * @param lifepoints The lifepoints.
- */
-public void setLifepoints(int lifepoints) {
- this.lifepoints = lifepoints;
- if (this.lifepoints < 0) {
- this.lifepoints = 0;
+ /**
+ * Gets the level.
+ * @param slot the slot.
+ * @return the level.
+ */
+ public int getLevel(int slot) {
+ return getLevel(slot, false);
}
- lifepointsUpdate = true;
-}
-/**
- * Gets the lifepoints.
- * @return The lifepoints.
- */
-public int getLifepoints() {
- return lifepoints;
-}
-
-/**
- * Gets the maximum amount of lifepoints.
- * @return The maximum amount.
- */
-public int getMaximumLifepoints() {
- return staticLevels[HITPOINTS] + lifepointsIncrease;
-}
-
-/**
- * Sets the amount of lifepoints increase.
- * @param amount The amount.
- */
-public void setLifepointsIncrease(int amount) {
- this.lifepointsIncrease = amount;
-}
-
-/**
- * Adds lifepoints to the entity.
- * @param health The amount to add.
- * @return The amount of overflow.
- */
-public int heal(int health) {
- lifepoints += health;
- int left = 0;
- if (lifepoints > getMaximumLifepoints()) {
- left = lifepoints - getMaximumLifepoints();
- lifepoints = getMaximumLifepoints();
+ /**
+ * Sets the current amount of lifepoints.
+ * @param lifepoints The lifepoints.
+ */
+ public void setLifepoints(int lifepoints) {
+ this.lifepoints = lifepoints;
+ if (this.lifepoints < 0) {
+ this.lifepoints = 0;
+ }
+ lifepointsUpdate = true;
}
- lifepointsUpdate = true;
- return left;
-}
-/**
- * @Deprecated Use
- * {@link ImpactHandler#manualHit(Entity, int, ImpactHandler.HitsplatType)}
- * or
the hitsplat WILL NOT show and combat will be
- * desynchronized!
- * @param damage The amount to remove.
- * @return The amount of overflow.
- */
-public int hit(int damage) {
- lifepoints -= damage;
- int left = 0;
- if (lifepoints < 0) {
- left = -lifepoints;
- lifepoints = 0;
+ /**
+ * Gets the lifepoints.
+ * @return The lifepoints.
+ */
+ public int getLifepoints() {
+ return lifepoints;
}
- lifepointsUpdate = true;
- return left;
-}
-/**
- * Gets the prayer points.
- * @return The prayer points.
- */
-public double getPrayerPoints() {
- return prayerPoints;
-}
+ /**
+ * Gets the maximum amount of lifepoints.
+ * @return The maximum amount.
+ */
+ public int getMaximumLifepoints() {
+ return staticLevels[HITPOINTS] + lifepointsIncrease;
+ }
-/**
- * Recharges the prayer points.
- */
-public void rechargePrayerPoints() {
- prayerPoints = staticLevels[PRAYER];
- if (entity instanceof Player) {
- PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, PRAYER));
+ /**
+ * Sets the amount of lifepoints increase.
+ * @param amount The amount.
+ */
+ public void setLifepointsIncrease(int amount) {
+ this.lifepointsIncrease = amount;
}
-}
-/**
- * Updates the current amount of prayer points (by decrementing).
- * @param amount The amount to decrement with.
- */
-public void decrementPrayerPoints(double amount) {
- prayerPoints -= amount;
- if (prayerPoints < 0) {
- prayerPoints = 0;
+ /**
+ * Adds lifepoints to the entity.
+ * @param health The amount to add.
+ * @return The amount of overflow.
+ */
+ public int heal(int health) {
+ lifepoints += health;
+ int left = 0;
+ if (lifepoints > getMaximumLifepoints()) {
+ left = lifepoints - getMaximumLifepoints();
+ lifepoints = getMaximumLifepoints();
+ }
+ lifepointsUpdate = true;
+ return left;
}
- // if (prayerPoints > staticLevels[PRAYER]) {
- // prayerPoints = staticLevels[PRAYER];
- // }
- if (entity instanceof Player) {
- PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, PRAYER));
- }
-}
-/**
- * Updates the current amount of prayer points (by incrementing)
- * @param amount The amount to decrement with.
- */
-public void incrementPrayerPoints(double amount) {
- prayerPoints += amount;
- if (prayerPoints < 0) {
- prayerPoints = 0;
+ /**
+ * @Deprecated Use
+ * {@link ImpactHandler#manualHit(Entity, int, ImpactHandler.HitsplatType)}
+ * or
the hitsplat WILL NOT show and combat will be
+ * desynchronized!
+ * @param damage The amount to remove.
+ * @return The amount of overflow.
+ */
+ public int hit(int damage) {
+ lifepoints -= damage;
+ int left = 0;
+ if (lifepoints < 0) {
+ left = -lifepoints;
+ lifepoints = 0;
+ }
+ lifepointsUpdate = true;
+ return left;
}
- if (prayerPoints > staticLevels[PRAYER]) {
+
+ /**
+ * Gets the prayer points.
+ * @return The prayer points.
+ */
+ public double getPrayerPoints() {
+ return prayerPoints;
+ }
+
+ /**
+ * Recharges the prayer points.
+ */
+ public void rechargePrayerPoints() {
prayerPoints = staticLevels[PRAYER];
- }
- if (entity instanceof Player) {
- PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, PRAYER));
- }
-}
-
-/**
- * Sets the current prayer points (without checking for being higher than
- * max)
- * @param amount The amount.
- */
-public void setPrayerPoints(double amount) {
- prayerPoints = amount;
- if (entity instanceof Player) {
- PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, PRAYER));
- }
-}
-
-/**
- * Updates the current skill level (by incrementing the current amount with
- * the given amount, up to the given maximum).
- * @param skill The skill id.
- * @param amount The amount to increment.
- * @param maximum The maximum amount the skill can be.
- * @return The amount of "overflow".
- */
-public int updateLevel(int skill, int amount, int maximum) {
- if (amount > 0 && dynamicLevels[skill] > maximum) {
- return -amount;
- }
- int left = (dynamicLevels[skill] + amount) - maximum;
- int level = dynamicLevels[skill] += amount;
- if (level < 0) {
- dynamicLevels[skill] = 0;
- } else if (amount < 0 && level < maximum) {
- dynamicLevels[skill] = maximum;
- } else if (amount > 0 && level > maximum) {
- dynamicLevels[skill] = maximum;
- }
- if (restoration[skill] != null) {
- restoration[skill].restart();
- }
- if (entity instanceof Player) {
- PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, skill));
- }
- return left;
-}
-
-/**
- * Updates a level.
- * @param skill the skill.
- * @param amount the amount.
- * @return the left.
- */
-public int updateLevel(int skill, int amount) {
- return updateLevel(skill, amount, amount >= 0 ? getStaticLevel(skill) + amount : getStaticLevel(skill) - amount);
-}
-
-/**
- * Drains a certain percentage of a level.
- * @param skill The skill.
- * @param drainPercentage The drain percentage (0.05 indicates 5% drain).
- * @param maximumDrainPercentage The maximum drain percentage (0.05
- * indicates 5%).
- */
-public void drainLevel(int skill, double drainPercentage, double maximumDrainPercentage) {
- int drain = (int) (dynamicLevels[skill] * drainPercentage);
- int minimum = (int) (staticLevels[skill] * (1.0 - maximumDrainPercentage));
- updateLevel(skill, -drain, minimum);
-}
-
-/**
- * Sets the static level.
- * @param skill The skill id.
- * @param level The level to set.
- */
-public void setStaticLevel(int skill, int level) {
- experience[skill] = getExperienceByLevel(staticLevels[skill] = dynamicLevels[skill] = level);
- if (entity instanceof Player) {
- PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, skill));
- }
-}
-
-/**
- * Gets the restoration pulses.
- * @return The restoration pulse array.
- */
-public SkillRestoration[] getRestoration() {
- return restoration;
-}
-
-/**
- * Gets the amount of mastered skills.
- * @return The amount of mastered skills.
- */
-public int getMasteredSkills() {
- int count = 0;
- for (int i = 0; i < 23; i++) {
- if (getStaticLevel(i) >= 99) {
- count++;
+ if (entity instanceof Player) {
+ PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, PRAYER));
}
}
- return count;
-}
-/**
- * Method used to get the skill by the name.
- * @param name the name.
- * @return the skill.
- */
-public static int getSkillByName(final String name) {
- for (int i = 0; i < SKILL_NAME.length; i++) {
- if (SKILL_NAME[i].equalsIgnoreCase(name)) {
- return i;
+ /**
+ * Updates the current amount of prayer points (by decrementing).
+ * @param amount The amount to decrement with.
+ */
+ public void decrementPrayerPoints(double amount) {
+ prayerPoints -= amount;
+ if (prayerPoints < 0) {
+ prayerPoints = 0;
+ }
+ // if (prayerPoints > staticLevels[PRAYER]) {
+ // prayerPoints = staticLevels[PRAYER];
+ // }
+ if (entity instanceof Player) {
+ PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, PRAYER));
}
}
- return -1;
-}
-/**
- * Gets the total level.
- * @return the total level.
- */
-public int getTotalLevel() {
- int level = 0;
- for (int i = 0; i < 24; i++) {
- level += getStaticLevel(i);
+ /**
+ * Updates the current amount of prayer points (by incrementing)
+ * @param amount The amount to decrement with.
+ */
+ public void incrementPrayerPoints(double amount) {
+ prayerPoints += amount;
+ if (prayerPoints < 0) {
+ prayerPoints = 0;
+ }
+ if (prayerPoints > staticLevels[PRAYER]) {
+ prayerPoints = staticLevels[PRAYER];
+ }
+ if (entity instanceof Player) {
+ PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, PRAYER));
+ }
}
- return level;
-}
-/**
- * Gets the lifepointsUpdate.
- * @return The lifepointsUpdate.
- */
-public boolean isLifepointsUpdate() {
- return lifepointsUpdate;
-}
+ /**
+ * Sets the current prayer points (without checking for being higher than
+ * max)
+ * @param amount The amount.
+ */
+ public void setPrayerPoints(double amount) {
+ prayerPoints = amount;
+ if (entity instanceof Player) {
+ PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, PRAYER));
+ }
+ }
-/**
- * Sets the lifepointsUpdate.
- * @param lifepointsUpdate The lifepointsUpdate to set.
- */
-public void setLifepointsUpdate(boolean lifepointsUpdate) {
- this.lifepointsUpdate = lifepointsUpdate;
-}
+ /**
+ * Updates the current skill level (by incrementing the current amount with
+ * the given amount, up to the given maximum).
+ * @param skill The skill id.
+ * @param amount The amount to increment.
+ * @param maximum The maximum amount the skill can be.
+ * @return The amount of "overflow".
+ */
+ public int updateLevel(int skill, int amount, int maximum) {
+ if (amount > 0 && dynamicLevels[skill] > maximum) {
+ return -amount;
+ }
+ int left = (dynamicLevels[skill] + amount) - maximum;
+ int level = dynamicLevels[skill] += amount;
+ if (level < 0) {
+ dynamicLevels[skill] = 0;
+ } else if (amount < 0 && level < maximum) {
+ dynamicLevels[skill] = maximum;
+ } else if (amount > 0 && level > maximum) {
+ dynamicLevels[skill] = maximum;
+ }
+ if (restoration[skill] != null) {
+ restoration[skill].restart();
+ }
+ if (entity instanceof Player) {
+ PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, skill));
+ }
+ return left;
+ }
-/**
- * Gets the statis levels.
- * @return the level.
- */
-public int[] getStaticLevels() {
- return staticLevels;
-}
+ /**
+ * Updates a level.
+ * @param skill the skill.
+ * @param amount the amount.
+ * @return the left.
+ */
+ public int updateLevel(int skill, int amount) {
+ return updateLevel(skill, amount, amount >= 0 ? getStaticLevel(skill) + amount : getStaticLevel(skill) - amount);
+ }
-/**
- * Checks if the player has the required level.
- * @param skillId the skill id.
- * @param i the level.
- * @return {@code True} if so.
- */
-public boolean hasLevel(int skillId, int i) {
- return getStaticLevel(skillId) >= i;
-}
+ /**
+ * Drains a certain percentage of a level.
+ * @param skill The skill.
+ * @param drainPercentage The drain percentage (0.05 indicates 5% drain).
+ * @param maximumDrainPercentage The maximum drain percentage (0.05
+ * indicates 5%).
+ */
+ public void drainLevel(int skill, double drainPercentage, double maximumDrainPercentage) {
+ int drain = (int) (dynamicLevels[skill] * drainPercentage);
+ int minimum = (int) (staticLevels[skill] * (1.0 - maximumDrainPercentage));
+ updateLevel(skill, -drain, minimum);
+ }
-/**
- * Gets the combatMilestone value.
- * @return The combatMilestone.
- */
-public int getCombatMilestone() {
- return combatMilestone;
-}
+ /**
+ * Sets the static level.
+ * @param skill The skill id.
+ * @param level The level to set.
+ */
+ public void setStaticLevel(int skill, int level) {
+ experience[skill] = getExperienceByLevel(staticLevels[skill] = dynamicLevels[skill] = level);
+ if (entity instanceof Player) {
+ PacketRepository.send(SkillLevel.class, new SkillContext((Player) entity, skill));
+ }
+ }
-/**
- * Sets the combatMilestones value.
- * @param combatMilestone The combatMilestones to set.
- */
-public void setCombatMilestone(int combatMilestone) {
- this.combatMilestone = combatMilestone;
-}
+ /**
+ * Gets the restoration pulses.
+ * @return The restoration pulse array.
+ */
+ public SkillRestoration[] getRestoration() {
+ return restoration;
+ }
-/**
- * Gets the skillMilestone value.
- * @return The skillMilestone.
- */
-public int getSkillMilestone() {
- return skillMilestone;
-}
+ /**
+ * Gets the amount of mastered skills.
+ * @return The amount of mastered skills.
+ */
+ public int getMasteredSkills() {
+ int count = 0;
+ for (int i = 0; i < 23; i++) {
+ if (getStaticLevel(i) >= 99) {
+ count++;
+ }
+ }
+ return count;
+ }
-/**
- * Sets the skillMilestone value.
- * @param skillMilestone The skillMilestone to set.
- */
-public void setSkillMilestone(int skillMilestone) {
- this.skillMilestone = skillMilestone;
-}
+ /**
+ * Method used to get the skill by the name.
+ * @param name the name.
+ * @return the skill.
+ */
+ public static int getSkillByName(final String name) {
+ for (int i = 0; i < SKILL_NAME.length; i++) {
+ if (SKILL_NAME[i].equalsIgnoreCase(name)) {
+ return i;
+ }
+ }
+ return -1;
+ }
-}
\ No newline at end of file
+ /**
+ * Gets the total level.
+ * @return the total level.
+ */
+ public int getTotalLevel() {
+ int level = 0;
+ for (int i = 0; i < 24; i++) {
+ level += getStaticLevel(i);
+ }
+ return level;
+ }
+
+ /**
+ * Gets the total exp.
+ * @return the exp.
+ */
+ public int getTotalXp() {
+ int total = 0;
+ for (int skill = 0; skill < Skills.SKILL_NAME.length; skill++) {
+ total += this.getExperience(skill);
+ }
+ return total;
+ }
+
+ /**
+ * Gets the lifepointsUpdate.
+ * @return The lifepointsUpdate.
+ */
+ public boolean isLifepointsUpdate() {
+ return lifepointsUpdate;
+ }
+
+ /**
+ * Sets the lifepointsUpdate.
+ * @param lifepointsUpdate The lifepointsUpdate to set.
+ */
+ public void setLifepointsUpdate(boolean lifepointsUpdate) {
+ this.lifepointsUpdate = lifepointsUpdate;
+ }
+
+ /**
+ * Gets the statis levels.
+ * @return the level.
+ */
+ public int[] getStaticLevels() {
+ return staticLevels;
+ }
+
+ /**
+ * Checks if the player has the required level.
+ * @param skillId the skill id.
+ * @param i the level.
+ * @return {@code True} if so.
+ */
+ public boolean hasLevel(int skillId, int i) {
+ return getStaticLevel(skillId) >= i;
+ }
+
+ /**
+ * Gets the combatMilestone value.
+ * @return The combatMilestone.
+ */
+ public int getCombatMilestone() {
+ return combatMilestone;
+ }
+
+ /**
+ * Sets the combatMilestones value.
+ * @param combatMilestone The combatMilestones to set.
+ */
+ public void setCombatMilestone(int combatMilestone) {
+ this.combatMilestone = combatMilestone;
+ }
+
+ /**
+ * Gets the skillMilestone value.
+ * @return The skillMilestone.
+ */
+ public int getSkillMilestone() {
+ return skillMilestone;
+ }
+
+ /**
+ * Sets the skillMilestone value.
+ * @param skillMilestone The skillMilestone to set.
+ */
+ public void setSkillMilestone(int skillMilestone) {
+ this.skillMilestone = skillMilestone;
+ }
+
+ }
\ No newline at end of file