package com.rs2.game.content.consumables; import java.util.HashMap; import com.rs2.game.players.Client; import com.rs2.util.Misc; /** * Handles food * * @author Enzo42 * */ public class Food { /** * The item Ids of food the player can eat */ public static short[] foodIds = { 315, 325, 319, 329, 333, 339, 347, 351, 355, 361, 379, 373, 1963, 1965, 1971, 1982, 1985, 1942, 1961, 2140, 1891, 1893, 1897, 1899, 2289, 2293, 2297, 2325, 2333, 2327, 2323, 2003, 2335, 2331, 2142, 1895, 1901, 2291, 2295, 2299, 2309, 385 }; /** * An enum that holds food data */ private enum eat { SHRIMP(315, -1, 3, "shrimps"), SARDINE(325, -1, 4, "sardine"), ANCHOVIES( 319, -1, 1, "anchovies"), SALMON(329, -1, 9, "salmon"), TROUT( 333, -1, 7, "trout"), COD(339, -1, 7, "cod"), HERRING(347, -1, 5, "herring"), PIKE(351, -1, 8, "pike"), MACKEREL(355, -1, 6, "mackerel"), TUNA(361, -1, 10, "tuna"), LOBSTER(379, -1, 12, "lobster"), SWORDFISH(373, -1, 14, "swordfish"), BANANA(1963, -1, 2, "banana"), CABBAGE(1965, -1, 2, "cabbage"), KEBAB(1971, -1, Misc.random(8), "kebab"), TOMATO(1982, -1, 2, "tomato"), CHEESE( 1985, -1, 2, "cheese"), POTATO(1942, -1, 2, "potato"), CHICKEN( 2140, -1, 3, "cooked chicken"), MEAT(2142, -1, 3, "cooked meat"), FULL_CAKE( 1891, 1893, 4, "cake"), HALF_CAKE(1893, 1895, 4, "2/3 cake"), CAKE( 1895, -1, 4, "slice of cake"), FULL_CHOC(1897, 1899, 5, "chocolate cake"), HALF_CHOC(1899, 1901, 5, "2/3 chocolate cake"), CHOC_CAKE(1901, -1, 5, "chocolate slice"), FULL_PLAIN( 2289, 2291, 7, "plain pizza"), PLAIN_PIZZA(2291, -1, 7, "1/2 plain pizza"), FULL_MEAT(2293, 2295, 8, "meat pizza"), MEAT_PIZZA( 2295, -1, 8, "1/2 meat pizza"), FULL_ANCHOVY(2297, 2299, 9, "anchovy pizza"), ACHO_PIZZA(2299, -1, 9, "1/2 anchovy pizza"), REDBERRY_PIE( 2325, 2333, 5, "redberry pie"), HALF_REDBERRY(2333, 2313, 5, "half a redberry pie"), MEAT_PIE(2327, 2331, 6, "meat pie"), HALF_MEAT( 2331, 2313, 6, "half a meat pie"), APPLE_PIE(2323, 2335, 7, "apple pie"), STEW(2003, 1923, 11, "stew"), HALF_APPLE(2335, 2313, 7, "half an apple pie"), BREAD(2309, -1, 5, "bread"), EASTER_EGG( 1961, -1, 12, "easter egg"), SHARK(385, -1, 20, "shark"); private final int itemId; private final int getItem; private final int HEAL; private final String FOOD_NAME; eat(final int itemId, final int getItem, final int HEAL, final String FOOD_NAME) { this.itemId = itemId; this.getItem = getItem; this.HEAL = HEAL; this.FOOD_NAME = FOOD_NAME; } private int getId() { return itemId; } private int getnewItem() { return getItem; } private int getHeal() { return HEAL; } private String getName() { return FOOD_NAME; } private static HashMap food = new HashMap(); static { for (final eat f : eat.values()) food.put(f.getId(), f); } } /** * Eating the food * * @param c * The player * @param ID * The food to eat */ public static void Eat(final Client c, final int ID) { if (System.currentTimeMillis() - c.foodDelay > 2000) { final eat f = eat.food.get(ID); c.foodDelay = System.currentTimeMillis(); c.getPacketSender().sendMessage("You eat the " + f.getName() + "."); c.getUpdateFlags().sendAnimation(0x33D); if (c.currentHealth < c.playerLevel[c.playerHitpoints]) { c.getPacketSender().sendMessage("It heals some health."); } c.getInventory().delete(ID, c.getInventory().getItemSlot(ID), 1); if (f.getnewItem() != -1) { c.getInventory().add(f.getnewItem(), 1); } c.currentHealth += f.getHeal(); if (c.currentHealth > c.playerLevel[c.playerHitpoints]) c.currentHealth = c.playerLevel[c.playerHitpoints]; } c.getPacketSender().sendString("" + c.currentHealth + "", 4016); } }