mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Add utility methods to Skill and SkillSet.
This commit is contained in:
@@ -87,13 +87,6 @@ public final class Skill {
|
||||
*/
|
||||
public static final int RUNECRAFT = 20;
|
||||
|
||||
/**
|
||||
* The skill names.
|
||||
*/
|
||||
private static final String SKILL_NAMES[] = { "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer",
|
||||
"Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining",
|
||||
"Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft" };
|
||||
|
||||
/**
|
||||
* The slayer id.
|
||||
*/
|
||||
@@ -119,6 +112,13 @@ public final class Skill {
|
||||
*/
|
||||
public static final int WOODCUTTING = 8;
|
||||
|
||||
/**
|
||||
* The skill names.
|
||||
*/
|
||||
private static final String[] SKILL_NAMES = { "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer",
|
||||
"Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining",
|
||||
"Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft" };
|
||||
|
||||
/**
|
||||
* Gets the name of a skill.
|
||||
*
|
||||
@@ -139,6 +139,43 @@ public final class Skill {
|
||||
return skill >= ATTACK && skill <= MAGIC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a skill from an existing skill, using the existing skill's experience and maximum level values, but the
|
||||
* specified current level.
|
||||
*
|
||||
* @param currentLevel The current level.
|
||||
* @param skill The existing skill.
|
||||
*
|
||||
* @return The new skill with the updated current level.
|
||||
*/
|
||||
public static Skill updateCurrentLevel(int currentLevel, Skill skill) {
|
||||
return new Skill(skill.experience, currentLevel, skill.maximumLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a skill from an existing skill, using the existing skill's current and maximum level values, but the
|
||||
* specified experience.
|
||||
*
|
||||
* @param experience The experience.
|
||||
* @param skill The existing skill.
|
||||
* @return The new skill with the updated experience.
|
||||
*/
|
||||
public static Skill updateExperience(double experience, Skill skill) {
|
||||
return new Skill(experience, skill.currentLevel, skill.maximumLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a skill from an existing skill, using the existing skill's experience and current level values, but the
|
||||
* specified maximum level.
|
||||
*
|
||||
* @param maximumLevel experience The maximum level.
|
||||
* @param skill The existing skill.
|
||||
* @return The new skill with the updated maximum level.
|
||||
*/
|
||||
public static Skill updateMaximumLevel(int maximumLevel, Skill skill) {
|
||||
return new Skill(skill.experience, skill.currentLevel, maximumLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* The current level.
|
||||
*/
|
||||
|
||||
@@ -12,16 +12,16 @@ import org.apollo.game.model.skill.SkillListener;
|
||||
*/
|
||||
public final class SkillSet {
|
||||
|
||||
/**
|
||||
* The minimum amounts of experience required for the levels.
|
||||
*/
|
||||
private static final int[] EXPERIENCE_FOR_LEVEL = new int[100];
|
||||
|
||||
/**
|
||||
* The maximum allowed experience.
|
||||
*/
|
||||
public static final double MAXIMUM_EXP = 200_000_000;
|
||||
|
||||
/**
|
||||
* The minimum amounts of experience required for the levels.
|
||||
*/
|
||||
private static final int[] EXPERIENCE_FOR_LEVEL = new int[100];
|
||||
|
||||
/**
|
||||
* The number of skills.
|
||||
*/
|
||||
@@ -151,18 +151,6 @@ public final class SkillSet {
|
||||
this.combatLevel = (int) (base + Math.max(melee, Math.max(range, mage)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the bounds of the id.
|
||||
*
|
||||
* @param id The id.
|
||||
* @throws IndexOutOfBoundsException If the id is out of bounds.
|
||||
*/
|
||||
private void checkBounds(int id) {
|
||||
if (id < 0 || id >= skills.length) {
|
||||
throw new IndexOutOfBoundsException("Skill id is out of bounds.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces this skill set to refresh.
|
||||
*/
|
||||
@@ -179,6 +167,36 @@ public final class SkillSet {
|
||||
return combatLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current level of the specified skill.
|
||||
*
|
||||
* @param skill The skill.
|
||||
* @return The current level.
|
||||
*/
|
||||
public int getCurrentLevel(int skill) {
|
||||
return getSkill(skill).getCurrentLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the experience of the specified skill.
|
||||
*
|
||||
* @param skill The skill.
|
||||
* @return The experience.
|
||||
*/
|
||||
public double getExperience(int skill) {
|
||||
return getSkill(skill).getExperience();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum level of the specified skill.
|
||||
*
|
||||
* @param skill The skill.
|
||||
* @return The maximum level.
|
||||
*/
|
||||
public int getMaximumLevel(int skill) {
|
||||
return getSkill(skill).getMaximumLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a skill by its id.
|
||||
*
|
||||
@@ -203,15 +221,6 @@ public final class SkillSet {
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the skill set.
|
||||
*/
|
||||
private void init() {
|
||||
for (int id = 0; id < skills.length; id++) {
|
||||
skills[id] = (id == Skill.HITPOINTS ? new Skill(1154, 10, 10) : new Skill(0, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the skills in this set.
|
||||
*/
|
||||
@@ -228,6 +237,111 @@ public final class SkillSet {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the {@link SkillListener}s.
|
||||
*/
|
||||
public void removeAllListeners() {
|
||||
listeners.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link SkillListener}.
|
||||
*
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public boolean removeListener(SkillListener listener) {
|
||||
return listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current level of the specified skill.
|
||||
*
|
||||
* @param skill The skill.
|
||||
* @param level The level.
|
||||
*/
|
||||
public void setCurrentLevel(int skill, int level) {
|
||||
Skill old = getSkill(skill);
|
||||
setSkill(skill, Skill.updateCurrentLevel(level, old));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the experience level of the specified skill.
|
||||
*
|
||||
* @param skill The skill.
|
||||
* @param experience The experience.
|
||||
*/
|
||||
public void setExperience(int skill, double experience) {
|
||||
Skill old = getSkill(skill);
|
||||
setSkill(skill, Skill.updateExperience(experience, old));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum level of the specified skill.
|
||||
*
|
||||
* @param skill The skill.
|
||||
* @param level The level.
|
||||
*/
|
||||
public void setMaximumLevel(int skill, int level) {
|
||||
Skill old = getSkill(skill);
|
||||
setSkill(skill, Skill.updateMaximumLevel(level, old));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link Skill}.
|
||||
*
|
||||
* @param id The id.
|
||||
* @param skill The skill.
|
||||
*/
|
||||
public void setSkill(int id, Skill skill) {
|
||||
checkBounds(id);
|
||||
skills[id] = skill;
|
||||
notifySkillUpdated(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of {@link Skill}s in this set.
|
||||
*
|
||||
* @return The number of skills.
|
||||
*/
|
||||
public int size() {
|
||||
return skills.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the firing of events.
|
||||
*/
|
||||
public void startFiringEvents() {
|
||||
firingEvents = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops events from being fired.
|
||||
*/
|
||||
public void stopFiringEvents() {
|
||||
firingEvents = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the bounds of the id.
|
||||
*
|
||||
* @param id The id.
|
||||
* @throws IndexOutOfBoundsException If the id is out of bounds.
|
||||
*/
|
||||
private void checkBounds(int id) {
|
||||
if (id < 0 || id >= skills.length) {
|
||||
throw new IndexOutOfBoundsException("Skill id is out of bounds.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the skill set.
|
||||
*/
|
||||
private void init() {
|
||||
for (int id = 0; id < skills.length; id++) {
|
||||
skills[id] = (id == Skill.HITPOINTS ? new Skill(1154, 10, 10) : new Skill(0, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies listeners that a skill has been levelled up.
|
||||
*
|
||||
@@ -267,55 +381,4 @@ public final class SkillSet {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the {@link SkillListener}s.
|
||||
*/
|
||||
public void removeAllListeners() {
|
||||
listeners.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link SkillListener}.
|
||||
*
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public boolean removeListener(SkillListener listener) {
|
||||
return listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link Skill}.
|
||||
*
|
||||
* @param id The id.
|
||||
* @param skill The skill.
|
||||
*/
|
||||
public void setSkill(int id, Skill skill) {
|
||||
checkBounds(id);
|
||||
skills[id] = skill;
|
||||
notifySkillUpdated(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of {@link Skill}s in this set.
|
||||
*
|
||||
* @return The number of skills.
|
||||
*/
|
||||
public int size() {
|
||||
return skills.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the firing of events.
|
||||
*/
|
||||
public void startFiringEvents() {
|
||||
firingEvents = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops events from being fired.
|
||||
*/
|
||||
public void stopFiringEvents() {
|
||||
firingEvents = false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user