Thread: [Shard]Food and Potions

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 [Shard]Food and Potions 
    Banned

    Join Date
    Jan 2009
    Age
    34
    Posts
    3,143
    Thanks given
    27
    Thanks received
    92
    Rep Power
    0
    How do I add them?
    Do I use seperate classes or just one?

    Tbh, I just need a base with one food and one pot, then I can learn it, L.

    Read the second page please.
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Jan 2009
    Age
    34
    Posts
    3,143
    Thanks given
    27
    Thanks received
    92
    Rep Power
    0
    Bump.
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Sep 2007
    Age
    32
    Posts
    2,396
    Thanks given
    5
    Thanks received
    436
    Rep Power
    902
    you can use seperate classes or one more general class file,

    one class file would be alot better since potions and food are very simlar and the methods you would make will be pretty much the same
    Hyperion V2 Martin's Updates.

    Scar says:
    i hate it when it hits your face
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jan 2009
    Age
    34
    Posts
    3,143
    Thanks given
    27
    Thanks received
    92
    Rep Power
    0
    Quote Originally Posted by Martin View Post
    you can use seperate classes or one more general class file,

    one class file would be alot better since potions and food are very simlar and the methods you would make will be pretty much the same
    Alright, where would I put the class?
    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Sep 2007
    Age
    32
    Posts
    2,396
    Thanks given
    5
    Thanks received
    436
    Rep Power
    902
    Code:
    package com.rs.worldserver.content;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.List;
    
    import com.rs.worldserver.Server;
    import com.rs.worldserver.events.Event;
    import com.rs.worldserver.events.EventContainer;
    import com.rs.worldserver.events.EventManager;
    import com.rs.worldserver.model.player.Client;
    import com.rs.worldserver.world.PersistenceManager;
    
    /**
     * Food and potion system.
     * @author Graham
    * @author MadTurnip - minor fixes and tweaks
     *
     */
    public class Food {
    	
    	/**
    	 * Animation IDs sent to the client.
    	 */
    	public static final int ANIMATION_EAT_ID 	= 829,
    							ANIMATION_DRINK_ID 	= 829;//1652
    	
    	private static List<FoodItem> foods;
    	
    	public static class FoodItem {
    		private int id, heal, newId, skillId, skillAdd;
    		private boolean drink;
    		public int getId() {
    			return id;
    		}
    		public int getHeal() {
    			return heal;
    		}
    		public int getNewId() {
    			return newId;
    		}
    		public int getSkillId() {
    			return skillId;
    		}
    		public int getSkillAdd() {
    			return skillAdd;
    		}
    		public boolean isDrink() {
    			return drink;
    		}
    	}
    	
    	@SuppressWarnings("unchecked")
    	public static void init() throws FileNotFoundException {
    		foods = (List<FoodItem>) PersistenceManager.load(new FileInputStream("./config/XML/food.xml"));
    	}
    	
    	private static FoodItem get(int id) {
    		for(FoodItem i : foods) {
    			if(i.getId() == id) {
    				return i;
    			}
    		}
    		return null;
    	}
    	
    	/**
    	 * Eating hook.
    	 * @param client
    	 * @param id
    	 * @return
    	 */
    	public static boolean eat(final Client client, final int id,final int slot) {
    		
    		final FoodItem foodItem = get(id);
    		if(foodItem == null) return false;
    		
    		//TODO FIX THE MASSING
    		if(System.currentTimeMillis() - client.foodTimer < 1600)
    			return true;
    		
    		if(!client.getActionAssistant().isItemInBag(client,id)) return true;
    		
    		client.foodTimer = System.currentTimeMillis();
    		//TODO: fix :)
    		/*if(client.getCombatManager().isFighting()) {
    			if(client.getCombatManager().supressTurn()) return true;
    			client.getCombatManager().setSupressTurn(true);
    		} else if(!client.checkBusy()) {
    			client.setBusy(true);
    		} else {
    			return true;
    		}*/
    		if((foodItem.isDrink() && client.duelRule[6]) || (!foodItem.isDrink() && client.duelRule[7])){
    			client.getActionAssistant().sendMessage(client,"You cannot use this in a duel.");
    		}
    		client.isUsingItem = true;
    		if(!foodItem.isDrink())
    			client.getActionAssistant().startAnimation(client,ANIMATION_EAT_ID);
    		else 
    			client.getActionAssistant().startAnimation(client,ANIMATION_DRINK_ID);
    		EventManager.getSingleton().addEvent(client, new Event() {
    			
    			public void execute(EventContainer container) {
    				client.getActionAssistant().deleteItem(client,id,slot, 1);
    				if(foodItem.getNewId() != -1) {
    					//client.getActionAssistant().addItem(client,foodItem.getNewId(),slot, 1);
    					client.playerItems[slot] = (foodItem.getNewId()+1);
    					client.playerItemsN[slot] = 1;
    					client.getActionAssistant().resetItems(client);
    				}
    				if(foodItem.isDrink()) {
    					client.getActionAssistant().sendMessage(client,"You drink the " + Server.getItemManager().getItemDefinition(id).getName() + ".");
    				} else {
    					client.getActionAssistant().sendMessage(client,"You eat the " + Server.getItemManager().getItemDefinition(id).getName() + ".");
    				}
    				if(foodItem.getHeal() < 0 || (foodItem.getHeal() > 0 && client.playerLevel[3] != client.getActionAssistant().getLevelForXP(client,client.playerXP[3]))) {
    					client.playerLevel[3] += foodItem.getHeal();
    					if(client.playerLevel[3] > client.getActionAssistant().getLevelForXP(client,client.playerXP[3])) {
    						client.playerLevel[3] = client.getActionAssistant().getLevelForXP(client,client.playerXP[3]);
    					}
    					if(client.playerLevel[3] < 0) {
    						client.playerLevel[3] = 0;
    					}
    					if(foodItem.getHeal() < 0) {
    						if(client.hitDiff == -1) {
    							client.hitDiff = Math.abs(foodItem.getHeal());
    							client.hitType = 1;
    							client.hitUpdateRequired = true;
    							client.updateRequired = true;
    						}
    					}
    					client.getActionAssistant().setSkillLevel(client,3, client.playerLevel[3], client.playerXP[3]);
    				}
    				if(foodItem.getSkillId() != -1 && foodItem.getSkillAdd() != -1) {
    					if(client.playerLevel[foodItem.getSkillId()] <= client.getActionAssistant().getLevelForXP(client,client.playerXP[foodItem.getSkillId()])) {
    						client.playerLevel[foodItem.getSkillId()] += foodItem.getSkillAdd();
    						client.getActionAssistant().setSkillLevel(client,foodItem.getSkillId(), client.playerLevel[foodItem.getSkillId()], client.playerXP[foodItem.getSkillId()]);
    					}
    				}
    				container.stop();
    			}
    			
    			public void stop() {
    				//TODO FIX THIS
    				/*if(client.getCombatManager().supressTurn()) {
    					client.getCombatManager().setSupressTurn(false);
    					client.hitUpdateRequired = true;
    					client.updateRequired = true;
    				} else {*/
    					client.isUsingItem = false;
    					client.setBusy(false);
    				//}
    			}
    		}, 1500);
    		return true;
    	}
    	
    	/*
    	 * We are a wholly static class.
    	 */
    	private Food() {}
    
    }
    now that is a class file that will parse an xml file and load the food and potions so create your

    "./config/XML/food.xml"

    file and heres 1 food and 1 pot for you.

    Code:
    <list>
    	<foodItem>
    		<id>315</id>
    		<heal>3</heal>
    		<newId>-1</newId>
    		<skillId>-1</skillId>
    		<skillAdd>-1</skillAdd>
    		<drink>false</drink>
    	</foodItem>
    	<foodItem>
    		<id>2442</id>
    		<heal>0</heal>
    		<newId>163</newId>
    		<skillId>1</skillId>
    		<skillAdd>12</skillAdd>
    		<drink>true</drink>
    	</foodItem>
    </list>
    Hyperion V2 Martin's Updates.

    Scar says:
    i hate it when it hits your face
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Jan 2009
    Age
    31
    Posts
    2,661
    Thanks given
    66
    Thanks received
    207
    Rep Power
    0
    do u no how to use the packet 122 in that base
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Jan 2009
    Age
    34
    Posts
    3,143
    Thanks given
    27
    Thanks received
    92
    Rep Power
    0
    Errors, not surprised at all.

    Code:
    Compiler Initialized.
    src\com\rs\worldserver\content\Food.java:12: cannot find symbol
    symbol  : class PersistenceManager
    location: package com.rs.worldserver.world
    import com.rs.worldserver.world.PersistenceManager;
                                   ^
    src\com\rs\worldserver\content\Food.java:54: cannot find symbol
    symbol  : variable PersistenceManager
    location: class com.rs.worldserver.content.Food
                    foods = (List<FoodItem>) PersistenceManager.load(new FileInputSt
    ream("./config/XML/food.xml"));
                                             ^
    src\com\rs\worldserver\content\Food.java:78: cannot find symbol
    symbol  : variable foodTimer
    location: class com.rs.worldserver.model.player.Client
                    if(System.currentTimeMillis() - client.foodTimer < 1600)
                                                          ^
    src\com\rs\worldserver\content\Food.java:81: isItemInBag(int) in com.rs.worldser
    ver.model.player.ActionAssistant cannot be applied to (com.rs.worldserver.model.
    player.Client,int)
                    if(!client.getActionAssistant().isItemInBag(client,id)) return t
    rue;
                                                   ^
    src\com\rs\worldserver\content\Food.java:83: cannot find symbol
    symbol  : variable foodTimer
    location: class com.rs.worldserver.model.player.Client
                    client.foodTimer = System.currentTimeMillis();
                          ^
    src\com\rs\worldserver\content\Food.java:93: cannot find symbol
    symbol  : variable duelRule
    location: class com.rs.worldserver.model.player.Client
                    if((foodItem.isDrink() && client.duelRule[6]) || (!foodItem.isDr
    ink() && client.duelRule[7])){
                                                    ^
    src\com\rs\worldserver\content\Food.java:93: cannot find symbol
    symbol  : variable duelRule
    location: class com.rs.worldserver.model.player.Client
                    if((foodItem.isDrink() && client.duelRule[6]) || (!foodItem.isDr
    ink() && client.duelRule[7])){
    
                   ^
    src\com\rs\worldserver\content\Food.java:94: sendMessage(java.lang.String) in co
    m.rs.worldserver.model.player.ActionAssistant cannot be applied to (com.rs.world
    server.model.player.Client,java.lang.String)
                            client.getActionAssistant().sendMessage(client,"You cann
    ot use this in a duel.");
                                                       ^
    src\com\rs\worldserver\content\Food.java:96: cannot find symbol
    symbol  : variable isUsingItem
    location: class com.rs.worldserver.model.player.Client
                    client.isUsingItem = true;
                          ^
    src\com\rs\worldserver\content\Food.java:98: cannot find symbol
    symbol  : method startAnimation(com.rs.worldserver.model.player.Client,int)
    location: class com.rs.worldserver.model.player.ActionAssistant
                            client.getActionAssistant().startAnimation(client,ANIMAT
    ION_EAT_ID);
                                                       ^
    src\com\rs\worldserver\content\Food.java:100: cannot find symbol
    symbol  : method startAnimation(com.rs.worldserver.model.player.Client,int)
    location: class com.rs.worldserver.model.player.ActionAssistant
                            client.getActionAssistant().startAnimation(client,ANIMAT
    ION_DRINK_ID);
                                                       ^
    src\com\rs\worldserver\content\Food.java:104: cannot find symbol
    symbol  : method deleteItem(com.rs.worldserver.model.player.Client,int,int,int)
    location: class com.rs.worldserver.model.player.ActionAssistant
                                    client.getActionAssistant().deleteItem(client,id
    ,slot, 1);
                                                               ^
    src\com\rs\worldserver\content\Food.java:109: cannot find symbol
    symbol  : method resetItems(com.rs.worldserver.model.player.Client)
    location: class com.rs.worldserver.model.player.ActionAssistant
                                            client.getActionAssistant().resetItems(c
    lient);
                                                                       ^
    src\com\rs\worldserver\content\Food.java:112: sendMessage(java.lang.String) in c
    om.rs.worldserver.model.player.ActionAssistant cannot be applied to (com.rs.worl
    dserver.model.player.Client,java.lang.String)
                                            client.getActionAssistant().sendMessage(
    client,"You drink the " + Server.getItemManager().getItemDefinition(id).getName(
    ) + ".");
                                                                       ^
    src\com\rs\worldserver\content\Food.java:114: sendMessage(java.lang.String) in c
    om.rs.worldserver.model.player.ActionAssistant cannot be applied to (com.rs.worl
    dserver.model.player.Client,java.lang.String)
                                            client.getActionAssistant().sendMessage(
    client,"You eat the " + Server.getItemManager().getItemDefinition(id).getName()
    + ".");
                                                                       ^
    src\com\rs\worldserver\content\Food.java:116: getLevelForXP(int) in com.rs.world
    server.model.player.ActionAssistant cannot be applied to (com.rs.worldserver.mod
    el.player.Client,int)
                                    if(foodItem.getHeal() < 0 || (foodItem.getHeal()
     > 0 && client.playerLevel[3] != client.getActionAssistant().getLevelForXP(clien
    t,client.playerXP[3]))) {
    
                                                                ^
    src\com\rs\worldserver\content\Food.java:118: getLevelForXP(int) in com.rs.world
    server.model.player.ActionAssistant cannot be applied to (com.rs.worldserver.mod
    el.player.Client,int)
                                            if(client.playerLevel[3] > client.getAct
    ionAssistant().getLevelForXP(client,client.playerXP[3])) {
    
                  ^
    src\com\rs\worldserver\content\Food.java:119: getLevelForXP(int) in com.rs.world
    server.model.player.ActionAssistant cannot be applied to (com.rs.worldserver.mod
    el.player.Client,int)
                                                    client.playerLevel[3] = client.g
    etActionAssistant().getLevelForXP(client,client.playerXP[3]);
    
                       ^
    src\com\rs\worldserver\content\Food.java:132: setSkillLevel(int,int,int) in com.
    rs.worldserver.model.player.ActionAssistant cannot be applied to (com.rs.worldse
    rver.model.player.Client,int,int,int)
                                            client.getActionAssistant().setSkillLeve
    l(client,3, client.playerLevel[3], client.playerXP[3]);
                                                                       ^
    src\com\rs\worldserver\content\Food.java:135: getLevelForXP(int) in com.rs.world
    server.model.player.ActionAssistant cannot be applied to (com.rs.worldserver.mod
    el.player.Client,int)
                                            if(client.playerLevel[foodItem.getSkillI
    d()] <= client.getActionAssistant().getLevelForXP(client,client.playerXP[foodIte
    m.getSkillId()])) {
    
                                       ^
    src\com\rs\worldserver\content\Food.java:137: setSkillLevel(int,int,int) in com.
    rs.worldserver.model.player.ActionAssistant cannot be applied to (com.rs.worldse
    rver.model.player.Client,int,int,int)
                                                    client.getActionAssistant().setS
    killLevel(client,foodItem.getSkillId(), client.playerLevel[foodItem.getSkillId()
    ], client.playerXP[foodItem.getSkillId()]);
                                                                               ^
    src\com\rs\worldserver\content\Food.java:150: cannot find symbol
    symbol  : variable isUsingItem
    location: class com.rs.worldserver.model.player.Client
                                            client.isUsingItem = false;
                                                  ^
    22 errors
    Compiling Finished.
    Press any key to continue . . .
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Sep 2007
    Age
    32
    Posts
    2,396
    Thanks given
    5
    Thanks received
    436
    Rep Power
    902
    that was a guide, i never said to just rip it....
    Hyperion V2 Martin's Updates.

    Scar says:
    i hate it when it hits your face
    Reply With Quote  
     

  9. #9  
    Banned

    Join Date
    Jan 2009
    Age
    34
    Posts
    3,143
    Thanks given
    27
    Thanks received
    92
    Rep Power
    0
    I know that, I need to find out what I need to add to correct the errors, that's why I posted them.
    Reply With Quote  
     

  10. #10  
    Registered Member
    Chachi's Avatar
    Join Date
    Sep 2008
    Posts
    1,536
    Thanks given
    49
    Thanks received
    103
    Rep Power
    602
    lol you need to declare a lot of the things he suggested
    [/CENTER]
    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

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