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");
}
}