Thread: [PI] Redone PotionMixing Class

Results 1 to 8 of 8
  1. #1 [PI] Redone PotionMixing Class 
    Registered Member
    Join Date
    Feb 2012
    Posts
    44
    Thanks given
    9
    Thanks received
    14
    Rep Power
    14
    You will need to modify the imports and packaging to your server. This includes most potions for the #377 revision.

    Conventions are poor when using ID, however that is what I prefer.

    Add this class:

    Code:
    import server.game.players.Client;
    
    /**
     * 
     * @author 0021sordna & 210jrellik
     * @date 2-28-2012
     * @category Potions
     * 
     */
    
    public class PotionMixing {
    
    	private final Client c;
    
    	public PotionMixing(final Client c) {
    		this.c = c;
    	}
    	
    	/*
    	 * Constants for use later.
    	 */
    	
    	private static final int VIAL = 227;
    	private static final int EMPTY_VIAL = 229;
    	
    	/**
    	 * 
    	 * @author 210jrellik
    	 * @date 2-28-2012
    	 */
    	
    	public enum CombiningDoses {
    		
    		STRENGTH(119, 117, 115, 113, VIAL, "Strength"),
    		SUPER_STRENGTH(161, 159, 157, 2440, VIAL, "Super strength"),
    		ATTACK(125, 123, 121, 2428, VIAL, "Attack"),
    		SUPER_ATTACK(149, 147, 145, 2436, VIAL, "Super attack"),
    		DEFENCE(137, 135, 133, 2432, VIAL, "Defence"),
    		SUPER_DEFENCE(167, 165, 163, 2442, VIAL, "Super defence"),
    		RANGING_POTION(173, 171, 169, 2444, VIAL, "Ranging"),
    		FISHING(155, 153, 151, 2438, VIAL, "Fishing"),
    		PRAYER(143, 141, 139, 2434, VIAL, "Prayer"),
    		ANTIFIRE(2458, 2456, 2454, 2452, VIAL, "Antifire"),
    		ZAMORAK_BREW(193, 191, 189, 2450, VIAL, "Zamorakian brew"),
    		ANTIPOISON(179, 177, 175, 2446, VIAL, "Antipoison"),
    		RESTORE(131, 129, 127, 2430, VIAL, "Restoration"),	
    		MAGIC_POTION(3046, 3044, 3042, 3040, VIAL, "Magic"),
    		SUPER_RESTORE(3030, 3028, 3026, 3024, VIAL, "Super Restoration"),		
    		ENERGY(3014, 3012, 3010, 3008, VIAL, "Energy"),
    		SUPER_ENERGY(3022, 3020, 3018, 3016, VIAL, "Super Energy"),
    		AGILITY(3038, 3036, 3034, 3032, VIAL, "Agility"),			
    		SARADOMIN_BREW(6691, 6689, 6687, 6685, VIAL, "Saradomin brew"),		
    		ANTIPOISON1(5949, 5947, 5945, 5943, VIAL, "Antipoison(+)"),
    		ANTIPOISON2(5958, 5956, 5954, 5952, VIAL, "Antipoison(++)"),	
    		SUPER_ANTIPOISON(185, 183, 181, 2448, VIAL, "Super Antipoison"),		
    		RELICYMS_BALM(4848, 4846, 4844, 4842, VIAL, "Relicym's balm"),
    		SERUM_207(3414, 3412, 3410, 3408, VIAL, "Serum 207"),	
    		COMBAT(9745, 9743, 9741, 9739, VIAL, "Combat");
    		
    		/*
    		 * This is what the data in the above enumeration is, in order.
    		 * EX:
    		 * COMBAT(oneDosePotionID, twoDosePotionID, threeDosePotionID, fourDosePotionID, vial, "potionName");
    		 */
    		
    		int oneDosePotionID, twoDosePotionID, threeDosePotionID, fourDosePotionID, vial;
    		String potionName;
    		
    		/**
    		 * @param oneDosePotionID - This is the ID for the potion when it contains one dose.
    		 * 
    		 * @param twoDosePotionID - This is the ID for the potion when it contains two doses.
    		 * 
    		 * @param threeDosePotionID - This is the ID for the potion when it contains three doses.
    		 * 
    		 * @param fourDosePotionID - This is the ID for the (full) potion when it contains four doses.
    		 * 
    		 * @param vial - This is referenced from:
    		 * private static final int VIAL = 227;
    		 * It's a constant and its value never changes.
    		 * 
    		 * @param potionName - This is a string which is used to set a name for the potion. 
    		 * Within an enumeration you can use the name(). method to take the name in-front of the stored data. This however could not be done because of some potion names.
    		 */
    		
    		private CombiningDoses(int oneDosePotionID, int twoDosePotionID, int threeDosePotionID, int fourDosePotionID, int vial, String potionName) {
    			this.oneDosePotionID = oneDosePotionID;
    			this.twoDosePotionID = twoDosePotionID;
    			this.threeDosePotionID = threeDosePotionID;
    			this.fourDosePotionID = fourDosePotionID;
    			this.vial = vial;
    			this.potionName = potionName;
    		}
    		
    		/*
    		 * These are code getters to use the data stored in the above enumeration.
    		 */
    
    		public int getDoseID1() {
    			return oneDosePotionID;
    		}
    		
    		public int getDoseID2() {
    			return twoDosePotionID;
    		}
    		
    		public int getDoseID3() {
    			return threeDosePotionID;
    		}
    		
    		public int getFourDosePotionID() {
    			return fourDosePotionID;
    		}
    		
    		public int getVial() {
    			return vial;
    		}
    		
    		public String getPotionName() {
    			return potionName;
    		}
    		
    		/**
    		 * 
    		 * @param id
    		 * @return The dose that this id represents for this potion, or -1 if it doesn't belong to this potion.
    		 * @date 2/28/12
    		 * @author 0021sordna
    		 */
    		
    		public int getDoseForID(int id) {
    			if (id == this.oneDosePotionID) {
    				return 1;
    			}
    			if (id == this.twoDosePotionID) {
    				return 2; 
    			}
    			if (id == this.threeDosePotionID) {
    				return 3;
    			}
    			if (id == this.fourDosePotionID) {
    				return 4;
    			}
    			return -1;
    		}
    		
    		/**
    		 * 
    		 * @param dose
    		 * @return The ID for this dose of the potion, or -1 if this dose doesn't exist.
    		 * @date 2/28/12
    		 * @author 0021sordna
    		 */
    		
    		public int getIDForDose(int dose) {
    			if (dose == 1) {
    				return this.oneDosePotionID;
    			}
    			if (dose == 2) {
    				return this.twoDosePotionID;
    			}
    			if (dose == 3) {
    				return this.threeDosePotionID;
    			}
    			if (dose == 4) {
    				return this.fourDosePotionID;
    			}
    			if (dose == 0) {
    				return EMPTY_VIAL;
    			}
    			return -1;
    		}
    		
    		/**
    		 * 
    		 * @param ID
    		 * @return The potion that matches the ID. ID can be any dose of the potion.
    		 * @date 2/28/12
    		 * @author 0021sordna
    		 */
    		
    		public static CombiningDoses getPotionByID(int id) {
    			for (CombiningDoses potion : CombiningDoses.values()) {
    				if (id == potion.oneDosePotionID) {
    					return potion;
    				}
    				if (id == potion.twoDosePotionID) {
    					return potion;
    				}
    				if (id == potion.threeDosePotionID) {
    					return potion;
    				}
    				if (id == potion.fourDosePotionID) {
    					return potion;
    				}
    			}
    			return null;
    		}
    	}
    	
    	/**
    	 * 
    	 * @param firstPotID
    	 * @param secondPotID
    	 * @date 2/28/12
    	 * @author 0021sordna & 210jrellik
    	 */
    	
    	public void potionCombination(int firstPotID, int secondPotID) {
    		CombiningDoses potion = CombiningDoses.getPotionByID(firstPotID);
    		
    		if (potion == null) {
    			return;
    		}
    		
    		if (potion.getDoseForID(secondPotID) > 0) {
    			int firstPotAmount = potion.getDoseForID(firstPotID);
    			int secondPotAmount = potion.getDoseForID(secondPotID);
    			
    			if (firstPotAmount + secondPotAmount <= 4) { 
    				c.getItems().deleteItem(firstPotID, c.getItems().getItemSlot(firstPotID), 1); 
    				c.getItems().deleteItem(secondPotID, c.getItems().getItemSlot(secondPotID), 1);
    				c.getItems().addItem(potion.getIDForDose(firstPotAmount + secondPotAmount), 1);
    				c.getItems().addItem(EMPTY_VIAL, 1); 
    			} else { 
    				int overflow = (firstPotAmount + secondPotAmount) - 4; 
    				c.getItems().deleteItem(firstPotID, c.getItems().getItemSlot(firstPotID), 1); 
    				c.getItems().deleteItem(secondPotID, c.getItems().getItemSlot(secondPotID), 1);
    				c.getItems().addItem(potion.getIDForDose(4), 1); 
    				c.getItems().addItem(potion.getIDForDose(overflow), 1); 
    			}
    		} else {
    			c.sendMessage("You can't combine a " + potion.getPotionName() + " potion with a " + CombiningDoses.getPotionByID(secondPotID).getPotionName() + " potion.");
    		}
    	}
    }
    Within UseItem class either replace or add:

    Code:
    		/*
    		 * Herblore Potion Mixing
    		 */
    		
    		if (c.getItems().getItemName(itemUsed).contains("(") && c.getItems().getItemName(useWith).contains("(")) {
    			c.getPotMixing().potionCombination(itemUsed, useWith);
    		}
    It remains un-tested.
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Feb 2012
    Age
    24
    Posts
    474
    Thanks given
    20
    Thanks received
    65
    Rep Power
    0
    Looks clean. I'll try it.
    Reply With Quote  
     

  3. #3  
    q.q


    Join Date
    Dec 2010
    Posts
    6,535
    Thanks given
    1,072
    Thanks received
    3,534
    Rep Power
    4752
    this is very bad to do it, you can easily devise a formula for it
    Reply With Quote  
     

  4. #4  
    Extreme Donator


    Join Date
    Oct 2006
    Posts
    1,370
    Thanks given
    64
    Thanks received
    197
    Rep Power
    426
    enums have .name() for a reason
    [Only registered and activated users can see links. ]


    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Feb 2012
    Posts
    44
    Thanks given
    9
    Thanks received
    14
    Rep Power
    14
    Quote Originally Posted by phl0w View Post
    enums have .name() for a reason
    Not all of the potions can be appropriately named within the enum itself.

    EG: Antipoison(+), Antipoison(++), Recilym's Balm. Along with a bunch of other potions if you add on from a later revision other than #377.
    Reply With Quote  
     

  6. #6  
    Extreme Donator


    Join Date
    Oct 2006
    Posts
    1,370
    Thanks given
    64
    Thanks received
    197
    Rep Power
    426
    Item.getItemName(id) is also there
    [Only registered and activated users can see links. ]


    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Feb 2012
    Posts
    44
    Thanks given
    9
    Thanks received
    14
    Rep Power
    14
    Quote Originally Posted by phl0w View Post
    Item.getItemName(id) is also there
    True and that would have worked just fine as well. However, it's technically antidote++ if read through cache. I prefer antipoison++. To each his own though, as that's a much cleaner way to do it.
    Reply With Quote  
     

  8. #8  
    Donator

    Join Date
    Jun 2011
    Posts
    287
    Thanks given
    0
    Thanks received
    0
    Rep Power
    46
    Not bad
    Reply With Quote  
     


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. [PI] Crafting, redone.
    By phl0w in forum Snippets
    Replies: 38
    Last Post: 07-06-2014, 04:03 AM
  2. Replies: 19
    Last Post: 05-25-2010, 02:22 PM
  3. 2 old ones redone
    By tcuzza in forum Showcase
    Replies: 2
    Last Post: 06-27-2009, 09:40 AM
  4. Dialogue Redone :)
    By Vastiko in forum Snippets
    Replies: 17
    Last Post: 05-06-2009, 02:19 AM
  5. Burden Redone
    By Full Metalst in forum Showcase
    Replies: 1
    Last Post: 04-15-2009, 08:28 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
  •