Thread: [Azure]Consumables

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 [Azure]Consumables 
    Registered Member

    Join Date
    Jan 2008
    Age
    31
    Posts
    1,380
    Thanks given
    76
    Thanks received
    384
    Rep Power
    962
    Purpose: To add Consumables to the server (food, potions, ect)
    Difficulty: 0
    Assumed Knowledge: How Azure works?
    Classes Modified: Consumables, ItemPacketHandler, PacketManager
    Tested On(if it applies):Azure V3

    Step 1: Alright lets start out by adding the Consumables class file into the content package (com.rs2.model.content)

    And then lets add this code into the class file:

    Code:
    package com.rs2.model.content;
    
    import com.rs2.model.players.Item;
    import com.rs2.model.players.Player;
    
    public class Consumables {
    	
    	private static final Object[][] CONSUMABLES = {
    		{391, "Manta ray", 22, false, -1},
    		
    		{2434, "restore prayer", 7, true, 139},
    		
    		{139, "restore prayer", 7, true, 141},
    		
    		{141, "restore prayer", 7, true, 143},
    		
    		{143, "restore prayer", 7, true, 229}
    	};
    	
    	private static long timer;
    	
    	public static void consume(Player player, int slot, int itemId) {
    		if (System.currentTimeMillis() - timer < 1200) {
    			return;
    		}
    		int id = 0;
    		String name = null;
    		int statEffect = 0;
    		boolean isPotion = false;
    		int newItem = -1;
    		for (Object[] data : CONSUMABLES) {
    			id = (Integer) data[0];
    			name = (String) data[1];
    			statEffect = (Integer) data[2];
    			isPotion = (Boolean) data[3];
    			newItem = (Integer) data[4];
    			if (id == itemId) {
    				player.getUpdateFlags().sendAnimation(829, 0);
    				if (isPotion) {
    					player.getActionSender().sendMessage("You drink some of your " + name + " potion.");
    					player.getActionSender().sendMessage("You have " + getDose(new Item(id)) + " doses of potion left.");
    					int[]  prayers = {2434, 139, 141, 143};
    					for (int i : prayers) {
    						if (i == itemId) {
    							int prayerDivide = player.getSkill().getLevelForXP(
    									player.getSkill().getExp()[5]) / 4;
    							player.getSkill().increaseSkill(5, statEffect + prayerDivide);
    							player.setPrayerPoints(player.getSkill().getLevel()[5]);
    						}
    					}
    					if (newItem == -1) {
    						player.getInventory().removeItem(new Item(id));
    					} else if (newItem > -1) {
    						player.getInventory().addItemToSlot(new Item(newItem, 1), slot);
    					}
    					player.getActionSender().sendSound(334, 1, 0);
    				} else {
    					player.getSkill().increaseSkill(3, statEffect);
    					int maxHP = player.getSkill().getLevelForXP(player.getSkill().getExp()[3]);
    					int hp = player.getSkill().getLevel()[3];
    					player.getActionSender().sendMessage("You eat the " + name +".");
    					if (hp < maxHP) {
    						player.getActionSender().sendMessage("It restores some hitpoints.");
    					}
    					player.getActionSender().sendSound(317, 1, 0);
    					player.getInventory().removeItemSlot(new Item(id, 1), slot);
    				}
    				player.setAttacking(false);
    				timer = System.currentTimeMillis();
    			}
    		}
    	}
    	
    	private static String getDose(Item item) {
    		if (item == null) {
    			return "";
    		}
    		if (item.getDefinition().getName().contains("(4)")) {
    			return "3";
    		}
    		if (item.getDefinition().getName().contains("(3)")) {
    			return "2";
    		}
    		if (item.getDefinition().getName().contains("(2)")) {
    			return "1";
    		}
    		return "no";
    	}
    
    	public static void setTimer(long timer) {
    		Consumables.timer = timer;
    	}
    
    	public static long getTimer() {
    		return timer;
    	}
    
    }
    Alright so basically we declare a 2D array that is defined as a Object so we can have multiple values (integer, boolean, string, ect) inside one 2D array.

    The first index (which is really index 0) is the item id, the second (first index) is the name the consumabl, the third (second index) is how much that stat is gained by like 22 with the manta ray will heal your hp by 22 points. the fourth (third index) defines if it is a potion or not (true for potion, false for food) the fifth and file index (fourth index) is the the new item we get after eating or drinking a potion for example the prayer pot with one dose left we get a empty vial after drinking that so we put 229 for the new item id.

    The timer is used for delaying the consumable per rate. Two cycles seems perfect.

    Step 2: Replace your Skill.java with this:

    Code:
    package com.rs2.model.players;
    
    import com.rs2.Constants;
    import com.rs2.model.World;
    
    public class Skill {
    	
    	private Player player;
    	
    	public static final int SKILL_COUNT = 22;
    	public static final int MAXIMUM_EXP = 200000000;
    	
    	private int[] level = new int[SKILL_COUNT];
    	private double[] exp = new double[SKILL_COUNT];
    	
    	public static final String[] SKILL_NAME = { "Attack", "Defence",
    		"Strength", "Hitpoints", "Range", "Prayer", "Magic", "Cooking",
    		"Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting",
    		"Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer",
    		"Farming", "Runecrafting" };
    
    	public static final int ATTACK = 0, DEFENCE = 1, STRENGTH = 2,
    		HITPOINTS = 3, RANGE = 4, PRAYER = 5, MAGIC = 6, COOKING = 7,
    		WOODCUTTING = 8, FLETCHING = 9, FISHING = 10, FIREMAKING = 11,
    		CRAFTING = 12, SMITHING = 13, MINING = 14, HERBLORE = 15,
    		AGILITY = 16, THIEVING = 17, SLAYER = 18, FARMING = 19,
    		RUNECRAFTING = 20;
    	
    	public Skill(Player player) {
    		this.player = player;
    		for (int i = 0; i < level.length; i ++) {
    			if (i == 3) {
    				level[3] = 10;
    				exp[3] = 1164;
    			} else {
    				level[i] = 1;
    				exp[i] = 0;
    			}
    		}
    	}
    	
    	public int[][] CHAT_INTERFACES = {
    		{ATTACK, 6247, 0, 0},
    		{DEFENCE, 6253, 0, 0},
    		{STRENGTH, 6206, 0, 0},
    		{HITPOINTS, 6216, 0, 0},
    		{RANGE, 4443, 5453, 6114},
    		{PRAYER, 6242, 0, 0},
    		{MAGIC, 6211, 0, 0},
    		{COOKING, 6226, 0, 0},
    		{WOODCUTTING, 4272, 0, 0},
    		{FLETCHING, 6231, 0, 0},
    		{FISHING, 6258, 0, 0},
    		{FIREMAKING, 4282, 0, 0},
    		{CRAFTING, 6263, 0, 0},
    		{SMITHING, 6221, 0, 0},
    		{MINING, 4416, 4417, 4438},
    		{HERBLORE, 6237, 0, 0},
    		{AGILITY, 4277, 0, 0},
    		{THIEVING, 4261, 4263, 4264},
    		{SLAYER, 12122, 0, 0},
    		{FARMING, 4887, 4889, 4890},//TODO: FIND THE REAL ID
    		{RUNECRAFTING, 4267, 0, 0},
    	};
    	
    	public void sendSkillsOnLogin() {
    		refresh();
    	}
    	
    	public void refresh() {
    		for (int i = 0; i < level.length; i++) {
    			player.getActionSender().sendSkill(i, level[i], exp[i]);
    		}
    		player.setAppearanceUpdateRequired(true);
    		player.getActionSender().sendString("" + level[5] + "", 4012);
    		player.getActionSender().sendString("" + getLevelForXP(exp[5]) + "", 4013);
    		player.getActionSender().sendString("" + level[3] + "", 4016);
    		player.getActionSender().sendString("" + getLevelForXP(exp[3]) + "", 4017);
    	}
    	
    	public void refresh(int skill) {
    		player.getActionSender().sendSkill(skill, level[skill], exp[skill]);
    		player.setAppearanceUpdateRequired(true);
    		player.getActionSender().sendString("" + level[5] + "", 4012);
    		player.getActionSender().sendString("" + getLevelForXP(exp[5]) + "", 4013);
    		player.getActionSender().sendString("" + level[3] + "", 4016);
    		player.getActionSender().sendString("" + getLevelForXP(exp[3]) + "", 4017);
    	}
    	
    	public int getLevelForXP(double exp) {
    		int points = 0;
    		int output = 0;
    		for (int lvl = 1; lvl <= 99; lvl++) {
    			points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
    			output = (int) Math.floor(points / 4);
    			if (output >= exp)
    				return lvl;
    		}
    		return 99;
    	}
    
    	public int getXPForLevel(int level) {
    		int points = 0;
    		int output = 0;
    		for (int lvl = 1; lvl <= level; lvl++) {
    			points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
    			if (lvl >= level) {
    				return output;
    			}
    			output = (int) Math.floor(points / 4);
    		}
    		return 0;
    	}
    	
    	public int getTotalLevel() {
    		int total = 0;
    		for (int i = 0; i < level.length; i++) {
    			total += getLevelForXP(i);
    		}
    		return total;
    	}
    	
    	public void addExp(int skill, double xp) {
    		xp *= Constants.EXP_RATE;
    		int oldLevel = level[skill];
    		exp[skill] += xp;
    		if (exp[skill] > MAXIMUM_EXP) {
    			exp[skill] = MAXIMUM_EXP;
    		}
    		int newLevel = getLevelForXP(exp[skill]);
    		int levelDiff = newLevel - oldLevel;
    		if (levelDiff > 0) {
    			level[skill] += levelDiff;
    			player.setAppearanceUpdateRequired(true);
    			for (Player players : World.getPlayers()) {
    				if (players == null)
    					continue;
    				players.getActionSender().sendStillGraphic(199, player.getPosition(), 0);
    			}
    			sendLevelUpMessage(skill);
    		}
    		refresh(skill);
    	}
    	
    	private void sendLevelUpMessage(int skill) {
    		final String line1 = "Congratulations! You've just advanced a " 
    			+ SKILL_NAME[skill] + " level!";
    		final String line2 = "You have reached level " 
    			+ level[skill] + "!";
    		player.getActionSender().sendMessage(line1);
    		player.getActionSender().sendMessage(line2);
    		for (int[] chatData : CHAT_INTERFACES) {
    			if (chatData[0] == skill) {
    				player.getActionSender().sendChatInterface(chatData[1]);
    				if (skill != RANGE && skill != MINING && skill != THIEVING && 
    						skill != FARMING) {
    					player.getActionSender().sendString(line1, chatData[1] + 1);
    					player.getActionSender().sendString(line2, chatData[1] + 2);
    				} else {
    					player.getActionSender().sendString(line1, chatData[2]);
    					player.getActionSender().sendString(line2, chatData[3]);
    				}
    			}
    		}
    	}
    	
    	public int getCombatLevel() {
    		final int attack = getLevelForXP(exp[ATTACK]);
    		final int defence = getLevelForXP(exp[DEFENCE]);
    		final int strength = getLevelForXP(exp[STRENGTH]);
    		final int hp = getLevelForXP(exp[HITPOINTS]);
    		final int prayer = getLevelForXP(exp[PRAYER]);
    		final int ranged = getLevelForXP(exp[RANGE]);
    		final int magic = getLevelForXP(exp[MAGIC]);
    		int combatLevel = 3;
    		combatLevel = (int) ((defence + hp + Math.floor(prayer / 2)) * 0.2535) + 1;
    		final double melee = (attack + strength) * 0.325;
    		final double ranger = Math.floor(ranged * 1.5) * 0.325;
    		final double mage = Math.floor(magic * 1.5) * 0.325;
    		if (melee >= ranger && melee >= mage) {
    			combatLevel += melee;
    		} else if (ranger >= melee && ranger >= mage) {
    			combatLevel += ranger;
    		} else if (mage >= melee && mage >= ranger) {
    			combatLevel += mage;
    		}
    		if (combatLevel <= 126) {
    			return combatLevel;
    		} else {
    			return 126;
    		}
    	}
    	
    	public void increaseSkill(int skillId, int amount) {
    		int maxLevel = getLevelForXP(getExp()[skillId]);
    		if (getLevel()[skillId] + amount > maxLevel) {
    			getLevel()[skillId] = maxLevel;
    		} else {
    			getLevel()[skillId] += amount;
    		}
    		refresh();
    	}
    
    	public void setLevel(int[] level) {
    		this.level = level;
    	}
    
    	public int[] getLevel() {
    		return level;
    	}
    
    	public double[] getExp() {
    		return exp;
    	}
    
    	public void setExp(double[] exp) {
    		this.exp = exp;
    	}
    
    }
    Why are you replacing that file? It fixes the the exp amount glitch and adds a new method increaseSkill. I also send the hitpoints and prayer sendString for people who have orbs in the client.

    Step 3: We now want to go into ItemPacketHandler class and add this import.

    Code:
    import com.rs2.model.content.Consumables;
    add this with the other final variables at the top

    Code:
    public static final int USE_ITEM = 122;
    Then under
    Code:
    case EQUIP_ITEM:
    			handleEquipItem(player, packet);
    			break;
    Add this:

    Code:
    case USE_ITEM:
    			useItem(player, packet);
    			break;
    We check if the packet id is the USE_ITEM (122) packet id we will handle the use item method.

    So add this method in that class:

    Code:
    private void useItem(Player player, Packet packet) {
    		@SuppressWarnings("unused")
    		int interfaceId = packet.getIn().readShort(StreamBuffer.ValueType.A, 
    				StreamBuffer.ByteOrder.LITTLE);
    		int slot = packet.getIn().readShort(StreamBuffer.ValueType.A);
    		if (slot < 0 || slot > 28) {
    			return;
    		}
    		int itemId = packet.getIn().readShort(StreamBuffer.ByteOrder.LITTLE);
    		Consumables.consume(player, slot, itemId);
    	}
    Step 4: Now go into PacketManager.java and below this:
    Code:
    packets[ItemPacketHandler.EQUIP_ITEM] = item;
    Add this:
    Code:
    packets[ItemPacketHandler.USE_ITEM] = item;
    Picture: Note i was 6 hp then ate a manta ray picture also shows prayer pot doses usage and shows it gives the the next dose down.


    Post errors and or questions.

    Enjoy.
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member
    Purple's Avatar
    Join Date
    Feb 2010
    Age
    29
    Posts
    2,799
    Thanks given
    467
    Thanks received
    260
    Rep Power
    312
    Good job, adding this
    Reply With Quote  
     

  4. #3  
    Registered Member DestriX's Avatar
    Join Date
    Nov 2008
    Posts
    1,323
    Thanks given
    490
    Thanks received
    152
    Rep Power
    257
    Sexxi will use.
    Attached image
    Reply With Quote  
     

  5. #4  
    Registered Member Scion's Avatar
    Join Date
    Jan 2011
    Age
    33
    Posts
    31
    Thanks given
    0
    Thanks received
    1
    Rep Power
    2
    Nice work, going to add when I have a bit of spare time. ^-^
    Reply With Quote  
     

  6. #5  
    Registered Member
    sadgrills's Avatar
    Join Date
    Dec 2009
    Age
    28
    Posts
    1,419
    Thanks given
    120
    Thanks received
    194
    Rep Power
    863
    Under CONSUMABLES:
    Code:
    		{319, "Anchovies", 1, false, -1},
    
    		{315, "Shrimp", 3, false, -1},
    
    		{2140, "Cooked chicken", 3, false, -1},
    
    		{2142, "Cooked meat", 3, false, -1},
    
    		{325, "Sardine", 4, false, -1},
    
    		{2309, "Bread", 5, false, -1},
    
    		{347, "Herring", 5, false, -1},
    
    		{355, "Mackerel", 6, false, -1},
    
    		{333, "Trout", 7, false, -1},
    
    		{339, "Cod", 7, false, -1},
    
    		{351, "Pike", 8, false, -1},
    
    		{329, "Salmon", 9, false, -1},
    
    		{361, "Tuna", 10, false, -1},
    
    		{1891, "Cake", 4, false, 1893},
    
    		{1893, "2/3 cake", 4, false, 1895},
    
    		{1895, "Slice of cake", 4, false, -1}, 
    
    		{379, "Lobster", 12, false, -1},
    
    		{365, "Bass", 13, false, -1},
    
    		{373, "Swordfish", 14, false, -1},
    
    		//Do bottle of wine here, reduces attack by 3
    
    		{6705, "Potato with cheese", 16, false, -1},
    
    		{7946, "Monkfish", 16, false, -1},
    
    		{2297, "Anchovy pizza", 9, false, 2299},
    
    		{2299, "1/2 anchovy pizza", 9, false, -1},
    		
    		{385, "Shark", 20, false, -1},
    
    		{397, "Sea turtle", 21, false, -1},
    
    		{2301, "Pineapple pizza", 11, false, 2303},
    
    		{2303, "1/2 p'apple pizza", 11, false, -1},
    
    		{7060, "Tuna potato", 22, false, -1},
    
    		//Wild pie
    
    		//Summer pie
    I'll work on Wild pie later and potions.

    Also if you're too lazy to figure out how potions work:
    http://www.rune-server.org/runescape...ml#post2492321


    Reply With Quote  
     

  7. Thankful users:


  8. #6  
    Registered Member

    Join Date
    Jan 2008
    Age
    31
    Posts
    1,380
    Thanks given
    76
    Thanks received
    384
    Rep Power
    962
    Just found something. It increase your hp before it checks the message thats a no no haha.

    find:
    Code:
    player.getSkill().increaseSkill(3, statEffect);
    remove it and

    put it below
    Code:
    if (hp < maxHP) {
    						player.getActionSender().sendMessage("It restores some hitpoints.");
    					}
    [:
    Reply With Quote  
     

  9. #7  
    Hi.

    'Mystic Flow's Avatar
    Join Date
    Nov 2007
    Posts
    7,146
    Thanks given
    256
    Thanks received
    1,252
    Rep Power
    3714
    Great job on this , btw the eat delay shouldn't be static and just return null instead of "no" since a new string is made every time "no" is created .



    Reply With Quote  
     

  10. #8  
    Super Donator


    Join Date
    Mar 2009
    Age
    28
    Posts
    1,388
    Thanks given
    316
    Thanks received
    408
    Rep Power
    608
    Or you could load consumables via XML? That would be easier if you needed to change something without restarting the server I guess. Non the less good job.
    Reply With Quote  
     

  11. #9  
    Registered Member
    Join Date
    Jan 2011
    Posts
    33
    Thanks given
    0
    Thanks received
    9
    Rep Power
    0
    good work
    Active member in the JBoss community. Java programmer.

    Quote Originally Posted by Destruction' View Post
    It's not a shit. It's Delta.
    Reply With Quote  
     

  12. #10  
    Respected Member


    kLeptO's Avatar
    Join Date
    Dec 2006
    Age
    28
    Posts
    2,955
    Thanks given
    1,183
    Thanks received
    754
    Rep Power
    3084
    Great job on this.
    Quite nice system for such thing.
    Reply With Quote  
     

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. [RuneSource] Azure
    By Ashen Sky in forum Downloads
    Replies: 92
    Last Post: 09-13-2011, 05:40 AM
  2. Azure 317.
    By Ashen Sky in forum Projects
    Replies: 85
    Last Post: 02-15-2011, 01:49 PM
  3. Azure 508 (old)
    By Ashen Sky in forum Downloads
    Replies: 5
    Last Post: 12-23-2010, 09:14 PM
  4. Azure Pk -- Webclient -- Awesome PvP
    By Defiled-X in forum Advertise
    Replies: 12
    Last Post: 08-30-2010, 07:24 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •