Advertisement
Guest User

Cooking.java

a guest
Nov 26th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. public class Cooking {
  2.  
  3. /***
  4. *
  5. * @author Gavin @Seth Rogen
  6. *
  7. */
  8.  
  9. private enum Data {
  10. SHRIMP(317, 315, 323, 100, 1),
  11. ANCHOVIES(321, 319, 323, 200, 2),
  12. TROUT(335, 333, 343, 300, 15),
  13. SALMON(331, 329, 343, 400, 25),
  14. TUNA(359, 361, 367, 500, 35),
  15. LOBSTER(377, 379, 381, 600, 40),
  16. SWORDFISH(371, 373, 375, 700, 45),
  17. SHARK(383, 385, 387, 800, 80);
  18.  
  19. Data(int rawId, int cookedId, int burntId, int EXP, int levelREQ) {
  20. this.rawId = rawId;
  21. this.cookedId = cookedId;
  22. this.burntId = burntId;
  23. this.EXP = EXP;
  24. this.levelREQ = levelREQ;
  25. }
  26.  
  27. private int rawId, cookedId, burntId, EXP, levelREQ;
  28.  
  29. private int getRawId() {
  30. return rawId;
  31. }
  32.  
  33. private int getCookedId() {
  34. return cookedId;
  35. }
  36.  
  37. private int getBurntId() {
  38. return burntId;
  39. }
  40.  
  41. private int getEXP() {
  42. return EXP;
  43. }
  44.  
  45. private int getLevelREQ() {
  46. return levelREQ;
  47. }
  48.  
  49. private static Map<Object, Data> data = new HashMap<Object, Data>();
  50.  
  51. static {
  52. for (Data d : Data.values()) {
  53. Data.data.put(d.getRawId(), d);
  54. }
  55. }
  56. }
  57.  
  58. /**
  59. * Displays the cooking interface
  60. */
  61. public static void sendCookingInterface(Client player, int itemId) {
  62. final Data data = Data.data.get(itemId);
  63. if (itemId == data.getRawId()) {
  64.  
  65. /**
  66. * Is the player already skilling?
  67. */
  68. if (!player.isSkilling()) {
  69.  
  70. /**
  71. * We check if the player's cooking level is high enough to cook the fish
  72. */
  73. if (player.playerLevel[player.playerCooking] >= data.getLevelREQ()) {
  74. player.turnPlayerTo(player.objectX, player.objectY);
  75. player.cookingId = itemId;
  76. player.getPA().sendFrame164(1743);
  77. player.getPA().sendFrame246(13716, 190, itemId);
  78. player.getPA().sendFrame126(player.getItems().getItemName(itemId), 13717);
  79. } else {
  80. player.sendMessage("You need a Cooking level of at least " + data.getLevelREQ() + " to make this.");
  81. }
  82. }
  83. }
  84. }
  85.  
  86. /**
  87. * Handles the cooking amount options
  88. */
  89. public static void clickingInterfaceButtons(Client player, int buttonId) {
  90. switch (buttonId) {
  91. case 53152: // Cook 1
  92. handleCooking(player, 1);
  93. break;
  94. case 53151: // Cook 5
  95. handleCooking(player, 5);
  96. break;
  97. case 53150: // Cook X
  98. case 53149: // Cook All
  99. handleCooking(player, 28);
  100. break;
  101. }
  102. }
  103.  
  104. /**
  105. * Handles the cooking itself
  106. */
  107. private static void handleCooking(final Client player, final int xAmount) {
  108. final Data data = Data.data.get(player.cookingId);
  109.  
  110. if (data == null) {
  111. return;
  112. }
  113.  
  114. /**
  115. * Closes the cooking interface
  116. */
  117. player.getPA().removeAllWindows();
  118.  
  119. /**
  120. * We set the player's status as skilling.
  121. */
  122. player.setSkilling(true);
  123.  
  124. player.startAnimation(883);
  125.  
  126. CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
  127.  
  128. int amount = xAmount;
  129.  
  130. @Override
  131. public void execute(CycleEventContainer container) {
  132.  
  133. /**
  134. * If the player walks away from the cooking source, or somehow stops skilling,
  135. * we end the tick.
  136. */
  137. if (!player.isSkilling()) {
  138. player.startAnimation(65535);
  139. container.stop();
  140. return;
  141. }
  142. if (amount > 0) {
  143.  
  144. /**
  145. * We check if the player has anymore raw fish
  146. */
  147. if (!player.getItems().playerHasItem(data.getRawId())) {
  148. player.sendMessage("You ran out of " + player.getItems().getItemName(data.getRawId()).toLowerCase() + ".");
  149. player.setSkilling(false);
  150. player.startAnimation(65535);
  151. container.stop();
  152. } else {
  153. player.getItems().deleteItem(data.getRawId(), player.getItems().getItemSlot(data.getRawId()), 1);
  154.  
  155. /**
  156. * We check if the player will burn the food, based on his cooking level
  157. * etc.
  158. */
  159. if (isSuccess(player)) {
  160.  
  161. /**
  162. * Cooks the food
  163. */
  164. player.getItems().addItem(data.getCookedId(), 1);
  165. player.getPA().addSkillXP(data.getEXP(), player.playerCooking);
  166. player.sendMessage("You successfully cooked the " + player.getItems().getItemName(data.getRawId()).toLowerCase() + ".");
  167. } else {
  168.  
  169. /**
  170. * Burns the food
  171. */
  172. player.getItems().addItem(data.getBurntId(), 1);
  173. player.sendMessage("You accidentally burnt the " + player.getItems().getItemName(data.getRawId()).toLowerCase() + ".");
  174. }
  175. player.startAnimation(883);
  176. amount--;
  177. }
  178. } else {
  179. player.setSkilling(false);
  180. player.startAnimation(65535);
  181. container.stop();
  182. }
  183. }
  184.  
  185. @Override
  186. public void stop() {
  187. // TODO Auto-generated method stub
  188.  
  189. }
  190. }, 3);
  191. }
  192.  
  193. /**
  194. * We determine whether or not the player is going to burn
  195. * the food or not
  196. */
  197. private static boolean isSuccess(Client player) {
  198. final Data data = Data.data.get(player.cookingId);
  199. int level = player.playerLevel[player.playerCooking];
  200. double successChance = Math.ceil((level * 50 - data.getLevelREQ() * 15) / data.getLevelREQ() / 3 * 4);
  201. int randomizedSuccessChance = Misc.random(99);
  202. if (successChance >= randomizedSuccessChance) {
  203. return true;
  204. }
  205. return false;
  206. }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement