Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Cooking {
- /***
- *
- * @author Gavin @Seth Rogen
- *
- */
- private enum Data {
- SHRIMP(317, 315, 323, 100, 1),
- ANCHOVIES(321, 319, 323, 200, 2),
- TROUT(335, 333, 343, 300, 15),
- SALMON(331, 329, 343, 400, 25),
- TUNA(359, 361, 367, 500, 35),
- LOBSTER(377, 379, 381, 600, 40),
- SWORDFISH(371, 373, 375, 700, 45),
- SHARK(383, 385, 387, 800, 80);
- Data(int rawId, int cookedId, int burntId, int EXP, int levelREQ) {
- this.rawId = rawId;
- this.cookedId = cookedId;
- this.burntId = burntId;
- this.EXP = EXP;
- this.levelREQ = levelREQ;
- }
- private int rawId, cookedId, burntId, EXP, levelREQ;
- private int getRawId() {
- return rawId;
- }
- private int getCookedId() {
- return cookedId;
- }
- private int getBurntId() {
- return burntId;
- }
- private int getEXP() {
- return EXP;
- }
- private int getLevelREQ() {
- return levelREQ;
- }
- private static Map<Object, Data> data = new HashMap<Object, Data>();
- static {
- for (Data d : Data.values()) {
- Data.data.put(d.getRawId(), d);
- }
- }
- }
- /**
- * Displays the cooking interface
- */
- public static void sendCookingInterface(Client player, int itemId) {
- final Data data = Data.data.get(itemId);
- if (itemId == data.getRawId()) {
- /**
- * Is the player already skilling?
- */
- if (!player.isSkilling()) {
- /**
- * We check if the player's cooking level is high enough to cook the fish
- */
- if (player.playerLevel[player.playerCooking] >= data.getLevelREQ()) {
- player.turnPlayerTo(player.objectX, player.objectY);
- player.cookingId = itemId;
- player.getPA().sendFrame164(1743);
- player.getPA().sendFrame246(13716, 190, itemId);
- player.getPA().sendFrame126(player.getItems().getItemName(itemId), 13717);
- } else {
- player.sendMessage("You need a Cooking level of at least " + data.getLevelREQ() + " to make this.");
- }
- }
- }
- }
- /**
- * Handles the cooking amount options
- */
- public static void clickingInterfaceButtons(Client player, int buttonId) {
- switch (buttonId) {
- case 53152: // Cook 1
- handleCooking(player, 1);
- break;
- case 53151: // Cook 5
- handleCooking(player, 5);
- break;
- case 53150: // Cook X
- case 53149: // Cook All
- handleCooking(player, 28);
- break;
- }
- }
- /**
- * Handles the cooking itself
- */
- private static void handleCooking(final Client player, final int xAmount) {
- final Data data = Data.data.get(player.cookingId);
- if (data == null) {
- return;
- }
- /**
- * Closes the cooking interface
- */
- player.getPA().removeAllWindows();
- /**
- * We set the player's status as skilling.
- */
- player.setSkilling(true);
- player.startAnimation(883);
- CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
- int amount = xAmount;
- @Override
- public void execute(CycleEventContainer container) {
- /**
- * If the player walks away from the cooking source, or somehow stops skilling,
- * we end the tick.
- */
- if (!player.isSkilling()) {
- player.startAnimation(65535);
- container.stop();
- return;
- }
- if (amount > 0) {
- /**
- * We check if the player has anymore raw fish
- */
- if (!player.getItems().playerHasItem(data.getRawId())) {
- player.sendMessage("You ran out of " + player.getItems().getItemName(data.getRawId()).toLowerCase() + ".");
- player.setSkilling(false);
- player.startAnimation(65535);
- container.stop();
- } else {
- player.getItems().deleteItem(data.getRawId(), player.getItems().getItemSlot(data.getRawId()), 1);
- /**
- * We check if the player will burn the food, based on his cooking level
- * etc.
- */
- if (isSuccess(player)) {
- /**
- * Cooks the food
- */
- player.getItems().addItem(data.getCookedId(), 1);
- player.getPA().addSkillXP(data.getEXP(), player.playerCooking);
- player.sendMessage("You successfully cooked the " + player.getItems().getItemName(data.getRawId()).toLowerCase() + ".");
- } else {
- /**
- * Burns the food
- */
- player.getItems().addItem(data.getBurntId(), 1);
- player.sendMessage("You accidentally burnt the " + player.getItems().getItemName(data.getRawId()).toLowerCase() + ".");
- }
- player.startAnimation(883);
- amount--;
- }
- } else {
- player.setSkilling(false);
- player.startAnimation(65535);
- container.stop();
- }
- }
- @Override
- public void stop() {
- // TODO Auto-generated method stub
- }
- }, 3);
- }
- /**
- * We determine whether or not the player is going to burn
- * the food or not
- */
- private static boolean isSuccess(Client player) {
- final Data data = Data.data.get(player.cookingId);
- int level = player.playerLevel[player.playerCooking];
- double successChance = Math.ceil((level * 50 - data.getLevelREQ() * 15) / data.getLevelREQ() / 3 * 4);
- int randomizedSuccessChance = Misc.random(99);
- if (successChance >= randomizedSuccessChance) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement