Code:
package palidino76.rs2.skills.cooking;
import palidino76.rs2.players.Player;
import palidino76.rs2.Engine;
import palidino76.rs2.events.*;
import palidino76.rs2.util.Misc;
/**
* Info: This could be done a little better?
* @aurthor Mystic Flow
* @aurthor Tim
*/
public class CookingManager {
//TODO Interface :P
private static int counter , times;
/* {fishId, levelReq, cookedItem, burntId, XPGained} */
private final static int[][] cookingData =
{{317, 1, 315, 323, 70},
{335, 15, 333, 343, 110},
{331, 25, 329, 343, 180},
{349, 20, 351, 349, 150},
{377, 40, 379, 381, 400},
{371, 45, 373, 375, 700},
{383, 80, 385, 387, 1000},
{389, 91, 391, 393, 1500},
{395, 82, 397, 399, 1200}};
private final static int[] firePlaces = { };
private final static int[] stoves = {36973};
private static int getBurned(int item) {
for (int i = 0; cookingData.length > i; i++) {
if(cookingData[i][0] == item) {
return cookingData[i][3];
}
}
return -1;
}
private static int getCooked(int item) {
for (int i = 0; cookingData.length > i; i++) {
if(cookingData[i][0] == item) {
return cookingData[i][2];
}
}
return -1;
}
private static int getReq(int item) {
for (int i = 0; cookingData.length > i; i++) {
if(cookingData[i][0] == item) {
return cookingData[i][1];
}
}
return -1;
}
private static int getXP(int item) {
for (int i = 0; cookingData.length > i; i++) {
if(cookingData[i][0] == item) {
return cookingData[i][4];
}
}
return -1;
}
private static int getFish(final int item) {
for (int i = 0; cookingData.length > i; i++) {
if(cookingData[i][0] == item) {
return cookingData[i][0];
}
}
return -1;
}
private static int stove() {
for (int i = 0; stoves.length > i;) {
return stoves[i];
}
return -1;
}
private static int firePlace() {
for (int i = 0; firePlaces.length > i;) {
return firePlaces[i];
}
return -1;
}
public static void handleItemOnObject(Player p,int itemId, int objectId) {
if(objectId == stove()) {
if (stove() != -1 || objectId != -1) {
handleCooking(p, itemId, 1);
}
}
if(objectId == firePlace()) {
if (firePlace() != -1 || objectId != -1) {
handleCooking(p, itemId, 2);
}
}
}
private static void handleCooking(Player p, int itemId, int object) {
int emote = 883;
if (object == 1) {
emote = 883;
}
if(object == 2) {
emote = 899;
}
final int fishId = getFish(itemId);
p.isCooking = true;
if(p.skillLvl[7] >= getReq(fishId)) {
executeEvent(p, itemId, emote);
} else {
p.frames.sendMessage(p, "You need level " + getReq(fishId) + " Cooking to cook this.");
}
}
private static void executeEvent(final Player p, final int item, final int emote) {
final int fishId = getFish(item);
EventManager.getSingleton().addEvent(1000, new Event() {
public void execute(EventContainer skill) {
if (p == null || p.disconnected) {
skill.stop();
return;
}
if (!p.isCooking && item != -1) {
skill.stop();
return;
}
if (!hasFish(p, item)) {
skill.stop();
p.resetSkills();
p.frames.sendMessage(p, "You ran out of fish to cook!");
return;
}
if (counter == 0) {
p.requestAnim(emote, 0);
p.frames.playSound(p, 2577);
Engine.playerItems.deleteItem(p, item, Engine.playerItems.getItemSlot(p, item), 1);
if(sucess(p, fishId)) {
p.addSkillXP(getXP(fishId), 7);
p.frames.sendMessage(p, "You sucessfully cook the "+ Engine.items.getItemName(item) +".");
Engine.playerItems.addItem(p, getCooked(fishId), 1);
counter = 3;
} else {
p.frames.sendMessage(p, "Opps! You accidently burnt the " + Engine.items.getItemName(item) +".");
Engine.playerItems.addItem(p, getBurned(fishId), 1);
counter = 3;
}
}
counter--;
}
});
}
private static boolean sucess(Player p, int fishId) {
if (p.skillLvl[7] > 98) {
return true;
}
int level = p.skillLvl[7];
int fishLevel = getReq(fishId);
int random = Misc.random(level*2);
if(random > fishLevel) {
return true;
}
return false;
}
private static boolean hasFish(Player p, int fishId) {
for(int i = 0; i < p.items.length; i++) {
if(p.items[i] == fishId) {
return true;
}
}
return false;
}
}
Now in Player.java add