Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.13 KB | None | 0 0
  1. package org.content.skill.herblore;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import org.content.Content;
  7. import org.content.packet.ButtonHandler;
  8. import org.content.packet.ItemOnItemHandler;
  9. import org.content.packet.ItemOptionHandler;
  10. import org.model.Animation;
  11. import org.model.character.Skills;
  12. import org.model.character.action.Action;
  13. import org.model.character.player.Player;
  14. import org.model.item.Item;
  15. import org.world.definition.ItemDefinition;
  16.  
  17. public class Herblore extends Content implements ItemOnItemHandler, ItemOptionHandler, ButtonHandler {
  18.  
  19.     private static final int[] UNCRUSHED = {237, 243, 1973, 9735, 10109};
  20.    
  21.     private static final int[] CRUSHED = {235, 241, 1975, 9736, 10111};
  22.    
  23.     public Herblore() {
  24.         super(new Object[][] {
  25.                 {ItemOptionHandler.class, new int[] {3214}},
  26.                 {ItemOnItemHandler.class, Potion.getItemArray()},
  27.                 {ButtonHandler.class, new int[] {2799, 2798, 1748, 1747}}
  28.             }
  29.         );
  30.     }
  31.    
  32.     private enum Herb {
  33.         GUAM(199, 249, 1, 2.5),
  34.         MARRENTILL(201, 251, 5, 5),
  35.         TARROMIN(203, 253, 9, 3.8),
  36.         HARRALANDER(205, 255, 20, 6.3),
  37.         RANARR(207, 257, 25, 7.5),
  38.         TOADFLAX(3049, 2998, 30, 8),
  39.         IRIT(209, 259, 40, 8.8),
  40.         AVANTOE(211, 261, 48, 10),
  41.         KWUARM(213, 263, 54, 11.3),
  42.         SNAPDRAGON(3051, 3000, 59, 11.8),
  43.         CADANTINE(215, 265, 65, 12.5),
  44.         LANTADYME(2485, 2481, 67, 13.1),
  45.         DWARF_WEED(217, 267, 70, 13.8),
  46.         TORSTOL(219, 269, 75, 15);
  47.        
  48.         int grimyId, cleanId, cleaningLevelRequirement;
  49.         double cleaningXp;
  50.        
  51.         private Herb(int grimyId, int cleanId, int cleaningLevelRequirement, double cleaningXp) {
  52.             this.grimyId = grimyId;
  53.             this.cleanId = cleanId;
  54.             this.cleaningLevelRequirement = cleaningLevelRequirement;
  55.             this.cleaningXp = cleaningXp;
  56.         }
  57.        
  58.         private static Map<Integer, Herb> herbs = new HashMap<Integer, Herb>();
  59.        
  60.         public static Herb forId(int item) {
  61.             return herbs.get(item);
  62.         }
  63.        
  64.         private int getGrimyId() {
  65.             return grimyId;
  66.         }
  67.        
  68.         private int getCleanId() {
  69.             return cleanId;
  70.         }
  71.        
  72.         private int getLevelRequirement() {
  73.             return cleaningLevelRequirement;
  74.         }
  75.        
  76.         private double getCleaningXp() {
  77.             return cleaningXp;
  78.         }
  79.        
  80.         static {
  81.             for (Herb herb : Herb.values()) {
  82.                 herbs.put(herb.getGrimyId(), herb);
  83.                 herbs.put(herb.getCleanId(), herb);
  84.             }
  85.         }      
  86.     }
  87.    
  88.     private enum Potion {      
  89.         ATTACK_POTION(1, 25, 249, 221, 91, 121),
  90.         ANTIPOISON_POTION(5, 37, 251, 235, 93, 175),
  91.         STRENGTH_POTION(12, 50, 253, 225, 95, 115),
  92.         RESTORE_POTION(22, 62, 255, 223, 97, 127),
  93.         ENERGY_POTION(26, 67, 255, 1975, 97, 3010),
  94.         DEFENCE_POTION(30, 75, 257, 239, 99, 133),
  95.         AGILITY_POTION(34, 80, 2998, 2152, 3002, 3034),
  96.         COMBAT_POTION(36, 84, 255, 9735, 97, 9741),
  97.         PRAYER_POTION(38, 87, 257, 231, 99, 139),
  98.         SUPER_ATTACK_POTION(45, 100, 259, 221, 101, 145),
  99.         SUPER_ANTIPOISON_POTION(48, 106, 259, 235, 101, 181),
  100.         SUPER_ENERGY_POTION(52, 117, 259, 2970, 103, 3018),
  101.         SUPER_STRENGTH_POTION(55, 125, 263, 225, 105, 157),
  102.         WEAPON_POISON_POTION(60, 137, 263, 241, 105, 5937),
  103.         SUPER_RESTORE_POTION(63, 142, 3000, 223, 3004, 3026),
  104.         SUPER_DEFENCE_POTION(66, 150, 265, 239, 107, 163),
  105.         ANTIFIRE_POTION(69, 157, 2481, 241, 2483, 2454),
  106.         MAGIC_POTION(76, 172, 2481, 221, 2483, 3042),
  107.         RANGING_POTION(72, 162, 267, 245, 109, 169),
  108.         ZAMORAK_BREW_POTION(76, 175, 269, 247, 111, 189),
  109.         SARADOMIN_BREW_POTION(81, 180, 269, 6693, 3002, 6687);
  110.        
  111.         private final int requiredLevel, herb, secondaryIngredient, unfinishedPotion, finishedPotion;
  112.         private final double xp;
  113.  
  114.         private Potion(int requiredLevel, double xp, int herb, int secondaryIngredient, int unfinishedPotion, int finishedPotion) {
  115.             this.requiredLevel = requiredLevel;
  116.             this.xp = xp;
  117.             this.herb = herb;
  118.             this.secondaryIngredient = secondaryIngredient;
  119.             this.unfinishedPotion = unfinishedPotion;
  120.             this.finishedPotion = finishedPotion;
  121.         }
  122.        
  123.         private static Map<Integer, Potion> potions = new HashMap<Integer, Potion>();
  124.        
  125.         public int getRequiredLevel() {
  126.             return requiredLevel;
  127.         }
  128.        
  129.         public int getHerb() {
  130.             return herb;
  131.         }
  132.        
  133.         public int getSecondaryIngredient() {
  134.             return secondaryIngredient;
  135.         }
  136.        
  137.         public int getUnfinishedPotion() {
  138.             return unfinishedPotion;
  139.         }
  140.        
  141.         public int getFinishedPotion() {
  142.             return finishedPotion;
  143.         }
  144.        
  145.         public double getXp() {
  146.             return xp;
  147.         }
  148.        
  149.         public static Potion forId(int item) {
  150.             return potions.get(item);
  151.         }
  152.        
  153.         public static int[] getItemArray() {
  154.             int[] items = new int[Potion.values().length + 55];
  155.             int offset = 0;
  156.             for (Potion potion : Potion.values()) {
  157.                 items[offset] = potion.getHerb();
  158.                 items[offset + 1] = potion.getSecondaryIngredient();
  159.                 items[offset + 2] = potion.getUnfinishedPotion();
  160.                 offset += 3;
  161.             }
  162.             for (int i = 0; i < CRUSHED.length; i++) {
  163.                 items[offset + i] = CRUSHED[i];
  164.             }
  165.             for (int j = 0; j < UNCRUSHED.length; j++) {
  166.                 items[offset + j] = UNCRUSHED[j];
  167.             }
  168.             offset += (CRUSHED.length + UNCRUSHED.length) - 2;
  169.             items[offset + 1] = 233;
  170.             items[offset + 2] = 227;
  171.             return items;
  172.         }
  173.        
  174.         static {
  175.             for (Potion potion : Potion.values()) {
  176.                 potions.put(potion.getHerb(), potion);
  177.                 potions.put(potion.getUnfinishedPotion(), potion);
  178.                 potions.put(potion.getFinishedPotion(), potion);
  179.                 for (int i = 0; i < UNCRUSHED.length; i++) {
  180.                     potions.put(UNCRUSHED[i], potion);
  181.                 }
  182.             }
  183.         }
  184.     }
  185.  
  186.     @Override
  187.     public boolean handleItemOnItem(Player player, int packetId, int interfaceId, int usedId, int usedSlot, int withId, int withSlot) {
  188.         System.out.println("1");
  189.         Potion potion = Potion.forId(usedId);
  190.         if (potion == null) {
  191.             potion = Potion.forId(withId);
  192.         }
  193.         System.out.println("2");
  194.  
  195.         if (potion == null) {
  196.             System.out.println("stopping here");
  197.             return false;
  198.         }
  199.         System.out.println("3");
  200.  
  201.         if (((usedId == 227 || withId == 227) && (potion.getHerb() == usedId || potion.getHerb() == withId)) && potion != null) {
  202.             player.getActionSender().sendInterfaceItem(1746, 175, potion.getUnfinishedPotion());
  203.             player.getActionSender().sendMoveChildId(1746, 3, 20);
  204.             player.getActionSender().sendString(ItemDefinition.getName(potion.getUnfinishedPotion()), 2799);
  205.             player.getActionSender().sendChatBoxInterface(4429);
  206.             player.addTemporary("POTION", potion);
  207.             player.addTemporary("FIRST_INGREDIENT", true);
  208.             return true;
  209.         } else if((usedId == potion.getSecondaryIngredient() || withId == potion.getSecondaryIngredient()) && potion != null) {
  210.             player.getActionSender().sendInterfaceItem(1746, 175, potion.getFinishedPotion());
  211.             player.getActionSender().sendMoveChildId(1746, 3, 20);
  212.             player.getActionSender().sendString(ItemDefinition.getName(potion.getFinishedPotion()), 2799);
  213.             player.getActionSender().sendChatBoxInterface(4429);
  214.             player.addTemporary("POTION", potion);
  215.             player.addTemporary("FIRST_INGREDIENT", false);
  216.             return true;
  217.         }
  218.         System.out.println("4");
  219.  
  220.         for (int j = 0; j < UNCRUSHED.length; j++) {
  221.             System.out.println(usedId + " withID: " + withId + "uncrushed: " + UNCRUSHED[j]);
  222.             if ((usedId == 233 || withId == 233) && (usedId == UNCRUSHED[j] || withId == UNCRUSHED[j])) {
  223.                 player.playAnimation(new Animation(364));
  224.                 player.getInventory().remove(new Item(UNCRUSHED[j]));
  225.                 player.getInventory().add(new Item(CRUSHED[j]));
  226.                 player.getActionSender().sendMessage("You grind the " + ItemDefinition.getName(UNCRUSHED[j]) + " into a fine dust.");
  227.                 return true;           
  228.             }
  229.         }
  230.         return false;
  231.     }
  232.  
  233.     @Override
  234.     public boolean handleItemOption(Player player, int option, int interfaceId, int itemSlot, int itemId) {
  235.         System.out.println("item option herby");
  236.         if (option == 1) {
  237.             Herb herb = Herb.forId(itemId);
  238.             if (herb == null) {
  239.                 System.out.println("herb be null");
  240.                 return false;
  241.             }
  242.             if(player.getSkills().getLevelForExperience(Skills.HERBLORE) < herb.getLevelRequirement()) {
  243.                 player.getActionSender().sendMessage("You need an herblore level of " + herb.getLevelRequirement() + " to clean this herb.");
  244.                 return false;
  245.             } else {
  246.                 player.getInventory().replace(new Item(herb.getGrimyId()), new Item(herb.getCleanId()), itemSlot);
  247.                 player.getSkills().addExperience(Skills.HERBLORE, herb.getCleaningXp());
  248.                 player.getActionSender().sendMessage("You clean the " + ItemDefinition.getName(herb.getGrimyId()) + ".");
  249.                 return true;
  250.             }
  251.         }      
  252.         return false;
  253.     }
  254.    
  255.  
  256.     @Override
  257.     public boolean handleButton(Player player, int buttonId) {
  258.         if(player == null || player.getTemporary("POTION") == null || player.getTemporary("FIRST_INGREDIENT") == null) {
  259.             return false;
  260.         }
  261.         switch(buttonId) {
  262.         case 2799:
  263.             createPotion(player, 1);
  264.             return true;
  265.         case 2798:
  266.             createPotion(player, 5);
  267.             return true;
  268.         case 1748:
  269.             player.getActionSender().sendEnterAmountInterface();
  270.             return true;
  271.         case 1747:
  272.             createPotion(player, 28);
  273.             return true;
  274.         }
  275.         return false;
  276.     }
  277.    
  278.     public void createPotion(final Player player, final int amount) {
  279.         final Potion potion = (Potion) player.getTemporary("POTION");
  280.         player.getActionSender().sendClearInterfaces();    
  281.         if(player.getSkills().getLevelForExperience(Skills.HERBLORE) < potion.getRequiredLevel()) {
  282.             player.getActionSender().sendMessage("You need an herblore level of " + potion.getRequiredLevel() + " to make this potion.");
  283.         } else {
  284.             player.startAction(new Action <Player> (1, true, player) {
  285.                 int amt = amount;              
  286.                 @Override
  287.                 public void execute() {                
  288.                     if(player.getBoolean("FIRST_INGREDIENT") == true) {
  289.                         if (!player.getInventory().contains(potion.getHerb()) || !player.getInventory().contains(227) || amt < 1) {
  290.                             player.playAnimation(new Animation(-1));
  291.                             player.removeTemporary("POTION");
  292.                             player.removeTemporary("FIRST_INGREDIENT");
  293.                             this.stop();
  294.                             return;
  295.                         }
  296.                     } else {
  297.                         if (!player.getInventory().contains(potion.getSecondaryIngredient()) || !player.getInventory().contains(potion.getUnfinishedPotion()) || amt < 1) {
  298.                             player.playAnimation(new Animation(-1));
  299.                             player.removeTemporary("POTION");
  300.                             System.out.println("stopping here");
  301.                             player.removeTemporary("FIRST_INGREDIENT");
  302.                             this.stop();
  303.                             return;
  304.                         }
  305.                     }
  306.                     player.playAnimation(new Animation(363));
  307.                     if(player.getBoolean("FIRST_INGREDIENT") == true) {
  308.                         player.getInventory().remove(potion.getHerb(), 1);
  309.                         player.getInventory().remove(new Item(227, 1));
  310.                         player.getInventory().add(new Item(potion.getUnfinishedPotion()));
  311.                         player.getSkills().addExperience(Skills.HERBLORE, ((potion.getXp()) / 10));
  312.                         player.getActionSender().sendMessage("You mix the herb into the vial of water.");
  313.                     } else {
  314.                         player.getInventory().remove(potion.getUnfinishedPotion());
  315.                         player.getInventory().remove(potion.getSecondaryIngredient());
  316.                         player.getInventory().add(new Item(potion.getFinishedPotion())) ;
  317.                         player.getSkills().addExperience(Skills.HERBLORE, potion.getXp());
  318.                         player.getActionSender().sendMessage("You make a " + ItemDefinition.getName(potion.getFinishedPotion()) + ".");
  319.                     }
  320.                     amt--;
  321.                 }
  322.                
  323.             });
  324.         }      
  325.     }
  326.    
  327.     @Override
  328.     public Object getInstance() {
  329.         return this;
  330.     }
  331.  
  332. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement