Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.content.skill.herblore;
- import java.util.HashMap;
- import java.util.Map;
- import org.content.Content;
- import org.content.packet.ButtonHandler;
- import org.content.packet.ItemOnItemHandler;
- import org.content.packet.ItemOptionHandler;
- import org.model.Animation;
- import org.model.character.Skills;
- import org.model.character.action.Action;
- import org.model.character.player.Player;
- import org.model.item.Item;
- import org.world.definition.ItemDefinition;
- public class Herblore extends Content implements ItemOnItemHandler, ItemOptionHandler, ButtonHandler {
- private static final int[] UNCRUSHED = {237, 243, 1973, 9735, 10109};
- private static final int[] CRUSHED = {235, 241, 1975, 9736, 10111};
- public Herblore() {
- super(new Object[][] {
- {ItemOptionHandler.class, new int[] {3214}},
- {ItemOnItemHandler.class, Potion.getItemArray()},
- {ButtonHandler.class, new int[] {2799, 2798, 1748, 1747}}
- }
- );
- }
- private enum Herb {
- GUAM(199, 249, 1, 2.5),
- MARRENTILL(201, 251, 5, 5),
- TARROMIN(203, 253, 9, 3.8),
- HARRALANDER(205, 255, 20, 6.3),
- RANARR(207, 257, 25, 7.5),
- TOADFLAX(3049, 2998, 30, 8),
- IRIT(209, 259, 40, 8.8),
- AVANTOE(211, 261, 48, 10),
- KWUARM(213, 263, 54, 11.3),
- SNAPDRAGON(3051, 3000, 59, 11.8),
- CADANTINE(215, 265, 65, 12.5),
- LANTADYME(2485, 2481, 67, 13.1),
- DWARF_WEED(217, 267, 70, 13.8),
- TORSTOL(219, 269, 75, 15);
- int grimyId, cleanId, cleaningLevelRequirement;
- double cleaningXp;
- private Herb(int grimyId, int cleanId, int cleaningLevelRequirement, double cleaningXp) {
- this.grimyId = grimyId;
- this.cleanId = cleanId;
- this.cleaningLevelRequirement = cleaningLevelRequirement;
- this.cleaningXp = cleaningXp;
- }
- private static Map<Integer, Herb> herbs = new HashMap<Integer, Herb>();
- public static Herb forId(int item) {
- return herbs.get(item);
- }
- private int getGrimyId() {
- return grimyId;
- }
- private int getCleanId() {
- return cleanId;
- }
- private int getLevelRequirement() {
- return cleaningLevelRequirement;
- }
- private double getCleaningXp() {
- return cleaningXp;
- }
- static {
- for (Herb herb : Herb.values()) {
- herbs.put(herb.getGrimyId(), herb);
- herbs.put(herb.getCleanId(), herb);
- }
- }
- }
- private enum Potion {
- ATTACK_POTION(1, 25, 249, 221, 91, 121),
- ANTIPOISON_POTION(5, 37, 251, 235, 93, 175),
- STRENGTH_POTION(12, 50, 253, 225, 95, 115),
- RESTORE_POTION(22, 62, 255, 223, 97, 127),
- ENERGY_POTION(26, 67, 255, 1975, 97, 3010),
- DEFENCE_POTION(30, 75, 257, 239, 99, 133),
- AGILITY_POTION(34, 80, 2998, 2152, 3002, 3034),
- COMBAT_POTION(36, 84, 255, 9735, 97, 9741),
- PRAYER_POTION(38, 87, 257, 231, 99, 139),
- SUPER_ATTACK_POTION(45, 100, 259, 221, 101, 145),
- SUPER_ANTIPOISON_POTION(48, 106, 259, 235, 101, 181),
- SUPER_ENERGY_POTION(52, 117, 259, 2970, 103, 3018),
- SUPER_STRENGTH_POTION(55, 125, 263, 225, 105, 157),
- WEAPON_POISON_POTION(60, 137, 263, 241, 105, 5937),
- SUPER_RESTORE_POTION(63, 142, 3000, 223, 3004, 3026),
- SUPER_DEFENCE_POTION(66, 150, 265, 239, 107, 163),
- ANTIFIRE_POTION(69, 157, 2481, 241, 2483, 2454),
- MAGIC_POTION(76, 172, 2481, 221, 2483, 3042),
- RANGING_POTION(72, 162, 267, 245, 109, 169),
- ZAMORAK_BREW_POTION(76, 175, 269, 247, 111, 189),
- SARADOMIN_BREW_POTION(81, 180, 269, 6693, 3002, 6687);
- private final int requiredLevel, herb, secondaryIngredient, unfinishedPotion, finishedPotion;
- private final double xp;
- private Potion(int requiredLevel, double xp, int herb, int secondaryIngredient, int unfinishedPotion, int finishedPotion) {
- this.requiredLevel = requiredLevel;
- this.xp = xp;
- this.herb = herb;
- this.secondaryIngredient = secondaryIngredient;
- this.unfinishedPotion = unfinishedPotion;
- this.finishedPotion = finishedPotion;
- }
- private static Map<Integer, Potion> potions = new HashMap<Integer, Potion>();
- public int getRequiredLevel() {
- return requiredLevel;
- }
- public int getHerb() {
- return herb;
- }
- public int getSecondaryIngredient() {
- return secondaryIngredient;
- }
- public int getUnfinishedPotion() {
- return unfinishedPotion;
- }
- public int getFinishedPotion() {
- return finishedPotion;
- }
- public double getXp() {
- return xp;
- }
- public static Potion forId(int item) {
- return potions.get(item);
- }
- public static int[] getItemArray() {
- int[] items = new int[Potion.values().length + 55];
- int offset = 0;
- for (Potion potion : Potion.values()) {
- items[offset] = potion.getHerb();
- items[offset + 1] = potion.getSecondaryIngredient();
- items[offset + 2] = potion.getUnfinishedPotion();
- offset += 3;
- }
- for (int i = 0; i < CRUSHED.length; i++) {
- items[offset + i] = CRUSHED[i];
- }
- for (int j = 0; j < UNCRUSHED.length; j++) {
- items[offset + j] = UNCRUSHED[j];
- }
- offset += (CRUSHED.length + UNCRUSHED.length) - 2;
- items[offset + 1] = 233;
- items[offset + 2] = 227;
- return items;
- }
- static {
- for (Potion potion : Potion.values()) {
- potions.put(potion.getHerb(), potion);
- potions.put(potion.getUnfinishedPotion(), potion);
- potions.put(potion.getFinishedPotion(), potion);
- for (int i = 0; i < UNCRUSHED.length; i++) {
- potions.put(UNCRUSHED[i], potion);
- }
- }
- }
- }
- @Override
- public boolean handleItemOnItem(Player player, int packetId, int interfaceId, int usedId, int usedSlot, int withId, int withSlot) {
- System.out.println("1");
- Potion potion = Potion.forId(usedId);
- if (potion == null) {
- potion = Potion.forId(withId);
- }
- System.out.println("2");
- if (potion == null) {
- System.out.println("stopping here");
- return false;
- }
- System.out.println("3");
- if (((usedId == 227 || withId == 227) && (potion.getHerb() == usedId || potion.getHerb() == withId)) && potion != null) {
- player.getActionSender().sendInterfaceItem(1746, 175, potion.getUnfinishedPotion());
- player.getActionSender().sendMoveChildId(1746, 3, 20);
- player.getActionSender().sendString(ItemDefinition.getName(potion.getUnfinishedPotion()), 2799);
- player.getActionSender().sendChatBoxInterface(4429);
- player.addTemporary("POTION", potion);
- player.addTemporary("FIRST_INGREDIENT", true);
- return true;
- } else if((usedId == potion.getSecondaryIngredient() || withId == potion.getSecondaryIngredient()) && potion != null) {
- player.getActionSender().sendInterfaceItem(1746, 175, potion.getFinishedPotion());
- player.getActionSender().sendMoveChildId(1746, 3, 20);
- player.getActionSender().sendString(ItemDefinition.getName(potion.getFinishedPotion()), 2799);
- player.getActionSender().sendChatBoxInterface(4429);
- player.addTemporary("POTION", potion);
- player.addTemporary("FIRST_INGREDIENT", false);
- return true;
- }
- System.out.println("4");
- for (int j = 0; j < UNCRUSHED.length; j++) {
- System.out.println(usedId + " withID: " + withId + "uncrushed: " + UNCRUSHED[j]);
- if ((usedId == 233 || withId == 233) && (usedId == UNCRUSHED[j] || withId == UNCRUSHED[j])) {
- player.playAnimation(new Animation(364));
- player.getInventory().remove(new Item(UNCRUSHED[j]));
- player.getInventory().add(new Item(CRUSHED[j]));
- player.getActionSender().sendMessage("You grind the " + ItemDefinition.getName(UNCRUSHED[j]) + " into a fine dust.");
- return true;
- }
- }
- return false;
- }
- @Override
- public boolean handleItemOption(Player player, int option, int interfaceId, int itemSlot, int itemId) {
- System.out.println("item option herby");
- if (option == 1) {
- Herb herb = Herb.forId(itemId);
- if (herb == null) {
- System.out.println("herb be null");
- return false;
- }
- if(player.getSkills().getLevelForExperience(Skills.HERBLORE) < herb.getLevelRequirement()) {
- player.getActionSender().sendMessage("You need an herblore level of " + herb.getLevelRequirement() + " to clean this herb.");
- return false;
- } else {
- player.getInventory().replace(new Item(herb.getGrimyId()), new Item(herb.getCleanId()), itemSlot);
- player.getSkills().addExperience(Skills.HERBLORE, herb.getCleaningXp());
- player.getActionSender().sendMessage("You clean the " + ItemDefinition.getName(herb.getGrimyId()) + ".");
- return true;
- }
- }
- return false;
- }
- @Override
- public boolean handleButton(Player player, int buttonId) {
- if(player == null || player.getTemporary("POTION") == null || player.getTemporary("FIRST_INGREDIENT") == null) {
- return false;
- }
- switch(buttonId) {
- case 2799:
- createPotion(player, 1);
- return true;
- case 2798:
- createPotion(player, 5);
- return true;
- case 1748:
- player.getActionSender().sendEnterAmountInterface();
- return true;
- case 1747:
- createPotion(player, 28);
- return true;
- }
- return false;
- }
- public void createPotion(final Player player, final int amount) {
- final Potion potion = (Potion) player.getTemporary("POTION");
- player.getActionSender().sendClearInterfaces();
- if(player.getSkills().getLevelForExperience(Skills.HERBLORE) < potion.getRequiredLevel()) {
- player.getActionSender().sendMessage("You need an herblore level of " + potion.getRequiredLevel() + " to make this potion.");
- } else {
- player.startAction(new Action <Player> (1, true, player) {
- int amt = amount;
- @Override
- public void execute() {
- if(player.getBoolean("FIRST_INGREDIENT") == true) {
- if (!player.getInventory().contains(potion.getHerb()) || !player.getInventory().contains(227) || amt < 1) {
- player.playAnimation(new Animation(-1));
- player.removeTemporary("POTION");
- player.removeTemporary("FIRST_INGREDIENT");
- this.stop();
- return;
- }
- } else {
- if (!player.getInventory().contains(potion.getSecondaryIngredient()) || !player.getInventory().contains(potion.getUnfinishedPotion()) || amt < 1) {
- player.playAnimation(new Animation(-1));
- player.removeTemporary("POTION");
- System.out.println("stopping here");
- player.removeTemporary("FIRST_INGREDIENT");
- this.stop();
- return;
- }
- }
- player.playAnimation(new Animation(363));
- if(player.getBoolean("FIRST_INGREDIENT") == true) {
- player.getInventory().remove(potion.getHerb(), 1);
- player.getInventory().remove(new Item(227, 1));
- player.getInventory().add(new Item(potion.getUnfinishedPotion()));
- player.getSkills().addExperience(Skills.HERBLORE, ((potion.getXp()) / 10));
- player.getActionSender().sendMessage("You mix the herb into the vial of water.");
- } else {
- player.getInventory().remove(potion.getUnfinishedPotion());
- player.getInventory().remove(potion.getSecondaryIngredient());
- player.getInventory().add(new Item(potion.getFinishedPotion())) ;
- player.getSkills().addExperience(Skills.HERBLORE, potion.getXp());
- player.getActionSender().sendMessage("You make a " + ItemDefinition.getName(potion.getFinishedPotion()) + ".");
- }
- amt--;
- }
- });
- }
- }
- @Override
- public Object getInstance() {
- return this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement