This is a version of herblore i wrote to reduce all the needless code that i previously had. Just replace your herblore classes with these. Some potion data (and herb data if you need it) is still missing, you just need to add the data for it, they're just id's i didn't have time to look for. Lastly you will need to change the imports / packaging to your own. Constructive criticism please!!
Add / Replace these classes.
Herblore
Code:
package com.game.content.skills.herblore;
import com.game.content.skills.Skills;
import com.game.node.entity.players.Client;
/**
* Herblore.java
*
* @author Metorrite
**/
public class Herblore {
private Client c;
public Herblore(Client c) {
this.c = c;
}
public void cleanHerb(int id) {
for(HerbData data : HerbData.values()) {
if(data.getGrimy() == id && c.playerLevel[Skills.HERBLORE.getId()] >= data.getLevel()) {
c.getItems().replaceItemOne(c, data.getGrimy(), data.getClean());
c.sendMessage("You clean the grimy " + data.getName() + ".");
c.getPA().addSkillXP(data.getXp(), Skills.HERBLORE.getId());
} else if(data.getGrimy() == id && c.playerLevel[Skills.HERBLORE.getId()] < data.getLevel())
c.sendMessage("You do not have the required level to clean this herb.");
}
}
public void makePot(int one, int two) {
for(PotData data : PotData.values()) {
if((data.getBase() == one && data.getPrimary() == two) || (data.getUnfinished() == one && data.getSecondary() == two)) {
if(c.playerLevel[Skills.HERBLORE.getId()] <= data.getLevel()) {
c.sendMessage("You need a herblore level of at least " + data.getLevel() + " to make this potion.");
return;
}
c.getItems().deleteItem(one, 1);
c.getItems().deleteItem(two, 1);
c.getPA().addSkillXP(data.getXp(), Skills.HERBLORE.getId());
c.getItems().addItem(data.getBase() == one ? data.getUnfinished() : data.getFinished(), 1);
}
}
}
}
Code:
package com.game.content.skills.herblore;
public enum HerbData {
GUAM("Guam", 199, 249, 3, 2.5),
MARRENTILL("Marrentill", 201, 251, 5, 3.8),
TARROMIN("Tarromin", 203, 253, 11, 5),
HARRALANDER("Harralander", 205, 255, 20, 6.25),
RANARR("Ranarr", 207, 257, 25, 7.5),
TOADFLAX("Toadflax", 3049, 2998, 30, 8),
IRIT("Irit", 209, 259, 40, 8.75),
AVANTOE("Avantoe", 211, 261, 48, 10),
KWUARM("Kwuarm", 213, 263, 54, 11.25),
SNAPDRAGON("Snapdragon", 3051, 3000, 59, 11.75),
CADANTINE("Cadantine", 215, 265, 65, 12.5),
LANTADYME("Lantadyme", 2485, 2481, 67, 13.125),
DWARF("Dwarf Weed", 0, 267, 70, 13.75),
TORSTOL("Torstol", 219, 269, 75, 15);
private int grimy, clean, level;
private String name;
double xp;
private HerbData(String name, int grimy, int clean, int level, double xp) {
this.name = name;
this.grimy = grimy;
this.clean = clean;
this.level = level;
this.xp = xp;
}
public String getName() {
return name;
}
public int getGrimy() {
return grimy;
}
public int getClean() {
return clean;
}
public int getLevel() {
return level;
}
public double getXp() {
return xp;
}
}
Code:
package com.game.content.skills.herblore;
public enum PotData {
ATTACK("Attack Potion", 3, 25, 227, HerbData.GUAM.getClean(), 221, 91, 121),
ANTI_POISON("Antipoison Potion", 5, 37.5, 227, HerbData.MARRENTILL.getClean(), 235, 93, 175),
STRENGTH("Strength Potion", 12, 50, 227, HerbData.TARROMIN.getClean(), 225, 95, 115),
RESTORE("Stat Restore Potion", 22, 62.5, 227, HerbData.HARRALANDER.getClean(), 592, 97, 127),
ENERGY("Potion", 0, 0, 0, 0, 0, 0, 0),
DEFENCE("Defence Potion", 30, 75, 227, HerbData.RANARR.getClean(), 239, 99, 133),
AGILITY("Potion", 0, 0, 0, 0, 0, 0, 0),
PRAYER("Prayer Potion", 38, 87.5, 227, HerbData.RANARR.getClean(), 231, 99, 139),
SUPER_ATTACK("Super Attack Potion", 45, 100, 227, HerbData.IRIT.getClean(), ATTACK.getSecondary(), 101, 145),
SUPER_ANTIPOISON("Potion", 0, 0, 0, 0, 0, 0, 0),
SUPER_ENERGY("Potion", 0, 0, 0, 0, 0, 0, 0),
SUPER_STRENGTH("Super Strength Potion", 55, 125, 227, HerbData.KWUARM.getClean(), STRENGTH.getSecondary(), 105, 157),
SUPER_RESTORE("Super Restore Potion", 63, 142.5, 227, HerbData.SNAPDRAGON.getClean(), 223, 3004, 3026),
;
private int level, base, primary, secondary, unfinished, finished;
private double xp;
private String name;
private PotData (String name, int level, double xp, int base, int primary, int secondary, int unfinished, int finished) {
this.name = name;
this.level = level;
this.xp = xp;
this.base = base;
this.primary = primary;
this.secondary = secondary;
this.unfinished = unfinished;
this.finished = finished;
}
public int getLevel() {
return level;
}
public int getBase() {
return base;
}
public int getPrimary() {
return primary;
}
public int getSecondary() {
return secondary;
}
public int getUnfinished() {
return unfinished;
}
public int getFinished() {
return finished;
}
public double getXp() {
return xp;
}
public String getName() {
return name;
}
}
Add these where they go.
UserItem
Code:
for(PotData data : PotData.values()) {
int[] ingridients = new int[2];
if(data.getBase() == itemUsed || data.getBase() == useWith)
ingridients[0] = data.getBase();
if(data.getPrimary() == itemUsed || data.getPrimary() == useWith)
ingridients[1] = data.getPrimary();
if(data.getUnfinished() == itemUsed || data.getUnfinished() == useWith)
ingridients[0] = data.getUnfinished();
if(data.getSecondary() == itemUsed || data.getSecondary() == useWith)
ingridients[1] = data.getSecondary();
if(ingridients[0] > 0 && ingridients[1] > 0) {
c.getHerblore().makePot(ingridients[0], ingridients[1]);
return;
}
}
ClickItem
Code:
for(HerbData data : HerbData.values()) {
if(data.getGrimy() == itemId)
c.getHerblore().cleanHerb(itemId);
}