Since people are begging to use shard revolutions again and I got a couple of requests on msn for help adding this to their base I figured that i would release it for them, and for you. If you like it, cool if you don't, then you can flame me all day and I still wont care and you will have waisted all of your time making yourself look like a fool.
Difficulty: 1
Assumed knowledge: Ability to create Java documents and copy and paste.
What you are accomplishing: All fish food eating with correct healing amounts.
Alright now make a file in the content package called FoodManager.java.
Then paste this inside of it:
Code:
package com.rs.worldserver.content;
import com.rs.worldserver.events.Event;
import com.rs.worldserver.events.EventContainer;
import com.rs.worldserver.events.EventManager;
import com.rs.worldserver.model.player.Client;
/**
* This class manages eating food
*
* Latest update: Naira (Arian of Rune-Server) had a talk with me about object
* orientation and why not to use static methods, so I took his advise and completely
* redid the code at the cost of a few more lines of code in client.java and this class.
*
* @author Scott
*/
public class FoodManager {
/**
* The time that the player last ate a piece of food.
*/
private long lastEatTime;
/**
* Animation played when one takes a bite of a peace of food.
*/
private int eatingAnimation;
/**
* Gets the eating animation variable.
* @return the eating animation variable.
*/
private int getEatingAnimation() {
return eatingAnimation;
}
/**
* Sets the animation that will play when a player eats a peace of food.
* @param eatingAnimation the animation that is going to be executed.
*/
private void setEatingAnimation(int eatingAnimation) {
// 829 = Eating food animation
this.eatingAnimation = eatingAnimation;
}
/**
* How long after the item is clicked that the event will be executed.
*/
private int eatingDelay;
/**
* Gets how long after the item is clicked that the event will be executed.
* @return eathingDelay variable
*/
private int getEatingDelay() {
return eatingDelay;
}
/**
* Sets how long after the item is clicked that the event will be executed.
* @param eatingDelay
*/
private void setEatingDelay(int eatingDelay) {
this.eatingDelay = eatingDelay;
}
/**
* Click item hook
*/
public final boolean eatFood(final Client client, final int itemSlot) {
final int itemID = client.playerItems[itemSlot] - 1;
final int[][] FOOD_DATA = {
{319, 1}, {315, 3}, {325, 4}, {329, 9}, {333, 7}, {339, 7}, {347, 5}, {351, 8},
{355, 6}, {361, 10}, {365, 13}, {379, 12}, {373, 14}, {385, 20}, {391, 22}, {397, 21}
};
setEatingAnimation(829);
client.getActionAssistant().startAnimation(getEatingAnimation());
/**
* The eating food event.
*/
EventManager.getSingleton().addEvent(client, new Event() {
/**
* Executes the eating food event
*/
public void execute(EventContainer container) {
if (client.getActionAssistant().getItemSlot((itemID)) == -1) {
container.stop();
return;
}
if (System.currentTimeMillis() - lastEatTime >= 1500) {
if(!client.isDead()) {
for (int i = 0; i < FOOD_DATA.length; i++) {
if(itemID == FOOD_DATA[i][0]) {
addHP(client, FOOD_DATA[i][1]);
client.getActionAssistant().deleteItem(itemID, client.getActionAssistant().getItemSlot(itemID), 1);
}
}
}
lastEatTime = System.currentTimeMillis();
setEatingDelay(1000);
container.stop();
}
}
/**
* Stops the eating food event
*/
public void stop() {
client.getActionAssistant().startAnimation(-1);
}
}, getEatingDelay());
return true;
}
/**
* Adds hitpoints to the player.
* @param amount - The amount of hitpoints that are depleted or added.
*/
private void addHP(Client client, int amount) {
if (! client.isDead()) {
client.playerLevel[3] += amount;
if (client.playerLevel[3] > client.getActionAssistant().getLevelForXP(client.playerXP[3])) {
client.playerLevel[3] = client.getActionAssistant().getLevelForXP(client.playerXP[3]);
}
client.getActionAssistant().setSkillLevel(3, client.playerLevel[3], client.playerXP[3]);
}
}
}
Then go into com.rs.worldserver.model.player.Client and add this import:
Code:
import com.rs.worldserver.content.FoodManager;
Then find this:
Code:
private FriendsAssistant friendsAssistant = new FriendsAssistant(this);
Then under it add this:
Code:
private FoodManager foodManager = new FoodManager();
Then add this method in Client.java as well:
Code:
/**
* Gets the FoodManager Object.
*/
public FoodManager getFoodManager() {
return foodManager;
}
Now go into com.rs.worldserver.model.player.packet.BuryBones and under this:
Code:
if (Prayer.buryBones(client, burySlot)) {
}
Add the following:
Code:
if(client.getFoodManager().eatFood(client, burySlot)) {
}
Now you are done.
If there are any errors or anything that i missed please let me know.
Don't flame, Thanks
Deimos