Thread: [PI] Potion system

Results 1 to 5 of 5
  1. #1 [PI] Potion system 
    Registered Member jelleplomp's Avatar
    Join Date
    Oct 2012
    Age
    26
    Posts
    549
    Thanks given
    73
    Thanks received
    6
    Rep Power
    11
    Hello Rune-Server,

    I started working on SeVen's awesome base: Project Aeolus and wanted to add a potion system,
    when I looked around on rune-server, I saw alot of messy code so I rewrote it to look cleaner:

    Spoiler for potion class:
    Code:
    package core.game.content.consumables;
    
    import core.game.content.skills.SkillConstants;
    import core.game.model.entity.player.Player;
    import core.game.model.item.ItemDefinition;
    
    public class Potion {
    
    	static int VIAL_ID = 229;
    
    	public enum potionData {
    
    		MAGIC_POTION4(3040, 3042), MAGIC_POTION3(3042, 3044), MAGIC_POTION2(
    				3044, 3046), MAGIC_POTION1(3046, VIAL_ID),
    
    		SUPER_ATTACK4(2436, 145), SUPER_ATTACK3(145, 147), SUPER_ATTACK2(147,
    				149), SUPER_ATTACK1(149, VIAL_ID),
    
    		SUPER_STRENGTH4(2440, 157), SUPER_STRENGTH3(157, 159), SUPER_STRENGTH2(
    				159, 161), SUPER_STRENGTH1(161, VIAL_ID),
    
    		RANGING_POTION4(2444, 169), RANGING_POTION3(169, 171), RANGING_POTION2(
    				171, 173), RANGING_POTION1(173, VIAL_ID),
    
    		SUPER_DEFENCE4(2442, 163), SUPER_DEFENCE3(163, 165), SUPER_DEFENCE2(
    				165, 167), SUPER_DEFENCE1(167, VIAL_ID),
    
    		DEFENCE_POTION4(2432, 133), DEFENCE_POTION3(133, 135), DEFENCE_POTION2(
    				135, 137), DEFENCE_POTION1(137, VIAL_ID),
    
    		STRENGTH_POTION4(113, 115), STRENGTH_POTION3(115, 117), STRENGTH_POTION2(
    				117, 119), STRENGTH_POTION1(119, VIAL_ID),
    
    		ATTACK_POTION4(2428, 121), ATTACK_POTION3(121, 123), ATTACK_POTION2(
    				123, 125), ATTACK_POTION1(125, VIAL_ID),
    
    		SUPER_RESTORE4(3024, 3026), SUPER_RESTORE3(3026, 3028), SUPER_RESTORE2(
    				3028, 3030), SUPER_RESTORE1(3030, VIAL_ID),
    
    		PRAYER_POTION4(2434, 139), PRAYER_POTION3(139, 141), PRAYER_POTION2(
    				141, 143), PRAYER_POTION1(143, VIAL_ID),
    
    		SARADOMIN_BREW4(6685, 6687), SARADOMIN_BREW3(6687, 6689), SARADOMIN_BREW2(
    				6689, 6691), SARADOMIN_BREW1(6691, VIAL_ID),
    		
    		SUPER_COMBAT4(9739, 9741), SUPER_COMBAT3(9741, 9743), SUPER_COMBAT2(
    				9743, 9745), SUPER_COMBAT1(9745, VIAL_ID);
    
    		private int itemId, newId;
    
    		potionData(int itemId, int newID) {
    			this.itemId = itemId;
    			this.newId = newID;
    		}
    
    		public int getItemId() {
    			return itemId;
    		}
    
    		public int getNewID() {
    			return newId;
    		}
    
    		public static potionData getPotion(int potion) {
    			for (potionData potiondata : potionData.values())
    				if (potiondata.getItemId() == potion)
    					return potiondata;
    			return null;
    		}
    
    	}
    
    	private static boolean allowedToDrinkPotion(Player p) {
    		return System.currentTimeMillis() - p.potDelay >= 1200
    				&& !p.duelRule[5] && !p.isDead && p.playerLevel[3] > 0;
    	}
    
    	public static void drinkPotion(Player c, int itemId, int slot) {
    		potionData potion = potionData.getPotion(itemId);
    
    		if (!allowedToDrinkPotion(c) || potion == null)
    			return;
    
    		c.startAnimation(829);
    
    		c.potDelay = System.currentTimeMillis();
    
    		c.attackTimer++;
    
    		if (potion.getNewID() != VIAL_ID)
    			c.getPacketSender().sendMessage(
    					isSaradominBrew(ItemDefinition.DEFINITIONS[itemId]
    							.getName()) ? "You drink some of the foul liquid"
    							: "You drink some of your "
    									+ ItemDefinition.DEFINITIONS[itemId]
    											.getName() + ".");
    		else
    			c.getPacketSender().sendMessage("You have finished your potion.");
    
    		c.playerItems[slot] = potion.getNewID() + 1;
    
    		switch (potion) {
    		
    		case ATTACK_POTION1: case ATTACK_POTION2: case ATTACK_POTION3: case ATTACK_POTION4:
    			normalPotion(c, SkillConstants.ATTACK);
    			break;
    			
    		case STRENGTH_POTION1: case STRENGTH_POTION2: case STRENGTH_POTION3: case STRENGTH_POTION4:
    			normalPotion(c, SkillConstants.STRENGTH);
    			break;
    			
    		case DEFENCE_POTION1: case DEFENCE_POTION2: case DEFENCE_POTION3: case DEFENCE_POTION4:
    			normalPotion(c, SkillConstants.DEFENCE);
    			break;
    			
    		case MAGIC_POTION1: case MAGIC_POTION2: case MAGIC_POTION3: case MAGIC_POTION4:
    			normalPotion(c, SkillConstants.MAGIC);
    			break;
    			
    		case RANGING_POTION1: case RANGING_POTION2: case RANGING_POTION3: case RANGING_POTION4:
    			normalPotion(c, SkillConstants.RANGED);
    			break;	
    			
    		case PRAYER_POTION1: case PRAYER_POTION2: case PRAYER_POTION3: case PRAYER_POTION4:
    			prayerPotion(c, false);
    			break;
    			
    		case SUPER_ATTACK1: case SUPER_ATTACK2: case SUPER_ATTACK3: case SUPER_ATTACK4:
    			superPotion(c, SkillConstants.ATTACK);
    			break;
    
    		case SUPER_STRENGTH1: case SUPER_STRENGTH2: case SUPER_STRENGTH3: case SUPER_STRENGTH4:
    			superPotion(c, SkillConstants.STRENGTH);
    			break;
    			
    		case SUPER_DEFENCE1: case SUPER_DEFENCE2: case SUPER_DEFENCE3: case SUPER_DEFENCE4:
    			superPotion(c, SkillConstants.DEFENCE);
    			break;	
    			
    		case SUPER_RESTORE1: case SUPER_RESTORE2: case SUPER_RESTORE3: case SUPER_RESTORE4:
    			prayerPotion(c, true);
    			break;	
    			
    		case SARADOMIN_BREW1: case SARADOMIN_BREW2: case SARADOMIN_BREW3: case SARADOMIN_BREW4:
    			saradominBrew(c);
    			break;
    		case SUPER_COMBAT1: case SUPER_COMBAT2: case SUPER_COMBAT3: case SUPER_COMBAT4:
    			superCombatPotion(c);
    			break;
    
    		}
    		c.getEquipment().resetItems(3214);
    	}
    
    	private static void superCombatPotion(Player c) {
    		superPotion(c, SkillConstants.ATTACK);
    		superPotion(c, SkillConstants.STRENGTH);
    		superPotion(c, SkillConstants.DEFENCE);
    	}
    
    	public static void prayerPotion(Player c, boolean restore) {
    		c.playerLevel[5] += (c.getLevelForXP(c.playerXP[5]) * .33);
    		if (restore)
    			c.playerLevel[5] += 1;
    		if (c.playerLevel[5] > c.getLevelForXP(c.playerXP[5]))
    			c.playerLevel[5] = c.getLevelForXP(c.playerXP[5]);
    		c.getPacketSender().refreshSkill(5);
    		if (restore)
    			restoreStats(c);
    	}
    
    	private static void superPotion(Player c, int skill) {
    		c.playerLevel[skill] += getBoostedStat(c, skill, true);
    		c.getPacketSender().refreshSkill(skill);
    	}
    
    	private static void normalPotion(Player c, int skill) {
    		c.playerLevel[skill] += getBoostedStat(c, skill, false);
    		c.getPacketSender().refreshSkill(skill);
    	}
    
    	public static int getBoostedStat(Player c, int skill, boolean sup) {
    		int increaseBy = 0;
    		if (sup)
    			increaseBy = (int) (c.getLevelForXP(c.playerXP[skill]) * .20);
    		else
    			increaseBy = (int) (c.getLevelForXP(c.playerXP[skill]) * .13) + 1;
    		if (c.playerLevel[skill] + increaseBy > c
    				.getLevelForXP(c.playerXP[skill]) + increaseBy + 1) {
    			return c.getLevelForXP(c.playerXP[skill]) + increaseBy
    					- c.playerLevel[skill];
    		}
    		return increaseBy;
    	}
    
    	private static void saradominBrew(Player c) {
    		if (c.duelRule[6]) {
    			c.getPacketSender().sendMessage("You may not eat in this duel.");
    			return;
    		}
    
    		int[] toDecrease = { 0, 2, 4, 6 };
    
    		for (int tD : toDecrease) {
    			c.playerLevel[tD] -= brewStat(c, tD, .10);
    			if (c.playerLevel[tD] < 0)
    				c.playerLevel[tD] = 1;
    			c.getPacketSender().refreshSkill(tD);
    			c.getPacketSender().setSkillLevel(tD, c.playerLevel[tD],
    					c.playerXP[tD]);
    		}
    
    		c.playerLevel[1] += brewStat(c, 1, .20);
    		if (c.playerLevel[1] > (c.getLevelForXP(c.playerXP[1]) * 1.2 + 1)) {
    			c.playerLevel[1] = (int) (c.getLevelForXP(c.playerXP[1]) * 1.2);
    		}
    		c.getPacketSender().refreshSkill(1);
    
    		c.playerLevel[3] += brewStat(c, 3, .15);
    		if (c.playerLevel[3] > (c.getLevelForXP(c.playerXP[3]) * 1.17 + 1)) {
    			c.playerLevel[3] = (int) (c.getLevelForXP(c.playerXP[3]) * 1.17);
    		}
    		c.getPacketSender().refreshSkill(3);
    	}
    
    	public static void restoreStats(Player c) {
    		for (int j = 0; j <= 6; j++) {
    			if (j == 5 || j == 3)
    				continue;
    			if (c.playerLevel[j] < c.getLevelForXP(c.playerXP[j])) {
    				c.playerLevel[j] += (c.getLevelForXP(c.playerXP[j]) * .33);
    				if (c.playerLevel[j] > c.getLevelForXP(c.playerXP[j])) {
    					c.playerLevel[j] = c.getLevelForXP(c.playerXP[j]);
    				}
    				c.getPacketSender().refreshSkill(j);
    				c.getPacketSender().setSkillLevel(j, c.playerLevel[j],
    						c.playerXP[j]);
    			}
    		}
    	}
    
    	public static int brewStat(Player c, int skill, double amount) {
    		return (int) (c.getLevelForXP(c.playerXP[skill]) * amount);
    	}
    
    	private static boolean isSaradominBrew(String name) {
    		return name.contains("Saradomin");
    	}
    
    }


    since I'm learning, criticism is always welcome (:
    Reply With Quote  
     

  2. #2  
    Banned [PI] Potion system Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    you don't need a constant for each potion amount. one constant for all 4 amounts is fine, use an array
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    need java lessons
    Eclipse's Avatar
    Join Date
    Aug 2012
    Posts
    4,436
    Thanks given
    686
    Thanks received
    898
    Rep Power
    490
    since you're only using 2 values for the enum, you could always use a map. Easier/cleaner.

    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  
     

  5. Thankful users:


  6. #4  
    Registered Member jelleplomp's Avatar
    Join Date
    Oct 2012
    Age
    26
    Posts
    549
    Thanks given
    73
    Thanks received
    6
    Rep Power
    11
    Quote Originally Posted by Eclipse View Post
    since you're only using 2 values for the enum, you could always use a map. Easier/cleaner.
    Quote Originally Posted by lare96 View Post
    you don't need a constant for each potion amount. one constant for all 4 amounts is fine, use an array
    How would i use a array/map? I'm not quite familiar with them.
    Reply With Quote  
     

  7. #5  
    Banned [PI] Potion system Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Quote Originally Posted by jelleplomp View Post
    How would i use a array/map? I'm not quite familiar with them.
    Code:
    enum Potion {
    ATTACK_POTION(int[] {id at (4), id at (3), id at (2), id at (1) }, ... (other data here));
    
    ...
    
    
    // after you drink a potion
    private int getNextPotion(int id) {
        int index = 0;
        for(int it : potionIds) {
            if(it == id) {
                if(index == 3) {
                    return VIAL_ID;
                }
                return potionIds[index + 1];
            }
            index++;
        }
    }
    
    }
    etc. etc. you get the point
    Reply With Quote  
     

  8. Thankful user:



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. Understanding PI Drop System.
    By The Almost in forum Help
    Replies: 5
    Last Post: 08-22-2014, 12:25 AM
  2. [PI]Huge Better PI Thieving System [PI]
    By Akeid in forum Snippets
    Replies: 21
    Last Post: 11-05-2010, 09:18 PM
  3. [PI] Potion Help
    By Harambe_ in forum Help
    Replies: 0
    Last Post: 09-05-2010, 12:23 AM
  4. Request for PI Jail system.
    By Zylsium in forum Requests
    Replies: 4
    Last Post: 08-12-2010, 10:07 PM
  5. Potion System
    By Michael old in forum Snippets
    Replies: 1
    Last Post: 03-03-2009, 03:45 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •