Thread: New Herblore

Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1 New Herblore 
    Boy Wonder


    Join Date
    Mar 2012
    Posts
    849
    Thanks given
    139
    Thanks received
    80
    Rep Power
    99
    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);
    		}

    Reply With Quote  
     

  2. #2  
    ~! Legit ~!

    Join Date
    Nov 2010
    Posts
    1,973
    Thanks given
    183
    Thanks received
    211
    Rep Power
    237
    Not bad its decent.
    [email protected]
    Spoiler for My Vouches:
    Quote Originally Posted by mattsforeal View Post
    I paid $5 went first, he fixed my problem and it worked. 100% legit would do it again.
    Quote Originally Posted by Mythic View Post
    Vouch for him, very smooth and fast trade, purchased his last 4m. Have fun with your new membership
    Quote Originally Posted by Harlan View Post
    Vouch, trustworthy guy.
    Quote Originally Posted by iPhisher™ View Post
    Vouch for Super-Man, he is a very legit and trustable guy.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Zivik's Avatar
    Join Date
    Oct 2007
    Age
    28
    Posts
    4,421
    Thanks given
    891
    Thanks received
    1,527
    Rep Power
    3285
    Thanks for the share.
    Reply With Quote  
     

  4. #4  
    Rune-Server Affiliate

    Join Date
    Aug 2015
    Posts
    431
    Thanks given
    55
    Thanks received
    114
    Rep Power
    126
    Thank you for this.
    Reply With Quote  
     

  5. #5  
    Boy Wonder


    Join Date
    Mar 2012
    Posts
    849
    Thanks given
    139
    Thanks received
    80
    Rep Power
    99
    Welcome all, some more feedback would be nice.

    Reply With Quote  
     

  6. #6  
    need java lessons
    Eclipse's Avatar
    Join Date
    Aug 2012
    Posts
    4,436
    Thanks given
    686
    Thanks received
    898
    Rep Power
    490
    your code in clickitem can be shortened (lambada)
    no need for a player reference in herblore.java, make it static.

    Would write more if I wasn't typing on a Brooken phone

    Quote Originally Posted by jerryrocks317 View Post
    i am 14 and have my own laptop im on almost 24/7 currently creating rsps lol so please get off my thread lol
    Reply With Quote  
     

  7. #7  
    Ż\_(ツ)_/Ż


    Join Date
    Jul 2014
    Posts
    1,803
    Thanks given
    928
    Thanks received
    550
    Rep Power
    299
    Pretty good, could've included the chatbox interfaces.
    Also, some code could be shortened/improved.

    Gj though, ill probably use this and add the chatbox interfaces with it.
    Reply With Quote  
     

  8. #8  
    Registered Member
    hc747's Avatar
    Join Date
    Dec 2013
    Age
    26
    Posts
    1,474
    Thanks given
    3,312
    Thanks received
    691
    Rep Power
    1098
    Code:
    public void cleanHerb(int id) {		for(HerbData data : HerbData.values()) {
    			if(data.getGrimy() == id){
    				if (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
    					c.sendMessage("You do not have the required level to clean this herb.");
    				break;
    			}
    		}
    	}
    Same can be applied to other areas where you've looped.
    Reply With Quote  
     

  9. #9  
    Boy Wonder


    Join Date
    Mar 2012
    Posts
    849
    Thanks given
    139
    Thanks received
    80
    Rep Power
    99
    Quote Originally Posted by Eclipse View Post
    your code in clickitem can be shortened (lambada)
    no need for a player reference in herblore.java, make it static.

    Would write more if I wasn't typing on a Brooken phone
    Can i have an example of the clickItem lambda expression, im having trouble understanding how to use lambda, i've been over the oracle docs but i can't grasp it for some reason.

    Quote Originally Posted by Bumhole View Post
    Pretty good, could've included the chatbox interfaces.
    Also, some code could be shortened/improved.

    Gj though, ill probably use this and add the chatbox interfaces with it.
    i was also thinking about the chatbox interface but i never went that far, if i get around to it ill probably add it onto this thread.



    Quote Originally Posted by hc747 View Post
    Code:
    public void cleanHerb(int id) {		for(HerbData data : HerbData.values()) {
    			if(data.getGrimy() == id){
    				if (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
    					c.sendMessage("You do not have the required level to clean this herb.");
    				break;
    			}
    		}
    	}
    Same can be applied to other areas where you've looped.
    What do you mean by it can be applied to other areas? Confused as to what your trying to say.

    Thanks everyone for the c&c will set to work on all the suggestions mentioned.

    Reply With Quote  
     

  10. #10  
    need java lessons
    Eclipse's Avatar
    Join Date
    Aug 2012
    Posts
    4,436
    Thanks given
    686
    Thanks received
    898
    Rep Power
    490
    Quote Originally Posted by Metorrite View Post
    Can i have an example of the clickItem lambda expression, im having trouble understanding how to use lambda, i've been over the oracle docs but i can't grasp it for some reason.



    i was also thinking about the chatbox interface but i never went that far, if i get around to it ill probably add it onto this thread.





    What do you mean by it can be applied to other areas? Confused as to what your trying to say.

    Thanks everyone for the c&c will set to work on all the suggestions mentioned.
    Code:
    package legion.player.skills;
    
    import java.util.Arrays;
    import java.util.Optional;
    import java.util.function.Predicate;
    
    import legion.player.Player;
    
    /**
     * Herblore data
     * 
     * @author Daniel - Sep 9, 2015 - www.rune-server.org/members/eclipse
     */
    
    public class Herblore {
    
    	public static Optional<HerbData> forHerb(int id) {
    		Predicate<HerbData> herb = (HerbData h) -> h.getGrimy() == id;
    		return Arrays.stream(HerbData.values()).filter(herb).findFirst();
    	}
    
    	public static Optional<PotData> forPotion(int item, int itemUsedOn) {
    		Predicate<PotData> potion = (PotData p) -> (
    				p.getBase() == item
    				|| p.getBase() == itemUsedOn 
    				|| p.getPrimary() == item
    				|| p.getPrimary() == itemUsedOn 
    				|| p.getUnfinished() == item
    				|| p.getUnfinished() == itemUsedOn 
    				|| p.getSecondary() == item 
    				|| p.getSecondary() == itemUsedOn);
    		return Arrays.stream(PotData.values()).filter(potion).findFirst();
    	}
    
    	public static void cleanHerb(Player c, int id) {
    		Optional<HerbData> herb = forHerb(id);
    		if(herb == null) {
    			return;
    		}
    		if(c.playerLevel[Skills.HERBLORE.getId()] < herb.get().getLevel()) {
    			c.sendMessage("You do not have the required level to clean this herb.");
    			return;
    		} else {
    			c.sendMessage("You clean the grimy " + herb.get().getName() + ".");
    			c.getItems().replaceItemOne(c, herb.get().getGrimy(), herb.get().getClean())
    			c.getPA().addSkillXP(herb.get().getXp(), Skills.HERBLORE.getId());
    		}
    	}
    
    	public static void makePot(Player c, int one, int two) {
    		Optional<PotData> potion = forPotion(one, two);
    		if ((potion.get().getBase() == one && potion.get().getPrimary() == two)
    				|| (potion.get().getUnfinished() == one && potion.get()
    						.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);
    
    		}
    	}
    }
    that's how i would do it

    Quote Originally Posted by jerryrocks317 View Post
    i am 14 and have my own laptop im on almost 24/7 currently creating rsps lol so please get off my thread lol
    Reply With Quote  
     

  11. Thankful user:


Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. EazyPk 317 (New Server)
    By eazy317 in forum Advertise
    Replies: 39
    Last Post: 11-15-2014, 04:03 AM
  2. Ultima PvP 317 New PvP Server - great fun!
    By jtox in forum Advertise
    Replies: 19
    Last Post: 07-29-2013, 01:34 AM
  3. [NEW] PwnScapeFTW! [317][NEW ECONOMY!]
    By oGLOBEo in forum Advertise
    Replies: 6
    Last Post: 12-03-2009, 04:20 PM
  4. CanadaScape (317) ( NEW )
    By OwnerPreston in forum Advertise
    Replies: 0
    Last Post: 11-22-2009, 05:51 AM
  5. R A V E D 317 - New PK video!
    By francisco123bz in forum Advertise
    Replies: 7
    Last Post: 06-30-2009, 06:44 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •