Jump to content
Existing user? Sign In

Sign In



Sign Up

[Elvarg / OSRSPK] Cooking Skill


Sanity

Recommended Posts

Hello everyone! im here to release my 2nd snippet for the elvarg base by professor oak, i have kind of changed my designing of code and spaced things out alot so it doesn't look like a clumped up mess. Anyways here is the code

Your gonna start off by defining CookingFood.java as an enum for holding the data of your food such as the raw item the cooked item, the burnt item, the exp, level and burn level all inside for use later

package com.elvarg.world.content.skills.cooking;

import com.elvarg.world.model.Item;
/**
 * 
 * @author Oscar Morton <S C A P E on RuneServer>
 *
 */
public enum CookingFood {
	/**
	 * Defining the food
	 */
	SHRIMP(new Item(317),new Item(315),new Item(323),1,30,33),
	ANCHOVIES(new Item(321),new Item(319),new Item(323),1,30,34),
	KARAMBWANJI(new Item(3150),new Item(3151),new Item(592),1,10,25),
	SARDINE(new Item(327),new Item(325),new Item(369),1,40,35),
	HERRING(new Item(345),new Item(347),new Item(357),5,50,41),
	MACKEREL(new Item(353),new Item(355),new Item(357),10,60,45),
	TROUT(new Item(335),new Item(333),new Item(343),15,70,50),
	COD(new Item(341),new Item(339),new Item(343),18,75,52),
	PIKE(new Item(349),new Item(351),new Item(343),20,80,59),
	SLIMY_EEL(new Item(3379),new Item(3381),new Item(3383),28,95,58),
	SALMON(new Item(331), new Item(329),new Item(343),25,90,58),
	TUNA(new Item(359),new Item(361),new Item(367),30,100,64),
	RAINBOW_FISH(new Item(10138),new Item(10136),new Item(10140),35,110,63),
	CAVE_EEL(new Item(5001),new Item(5003),new Item(5002),38,115,42),
	LOBSTER(new Item(377),new Item(379),new Item(381),40,120,74),
	BASS(new Item(363),new Item(365),new Item(367),43,130,80),
	SWORDFISH(new Item(371),new Item(373),new Item(375),45,140,86),
	MONKFISH(new Item(7944),new Item(7946),new Item(7948),62,150,90),
	SHARK(new Item(383),new Item(385),new Item(387),80,210,99),
	ANGLERFISH(new Item(13439),new Item(13441),new Item(13443),84,230,99),
	DARK_CRAB(new Item(11934),new Item(11936),new Item(11938),90,215,99),
	KARAMBWAN(new Item(3142), new Item(3144),new Item(3148),30,190,99)
	;
	
	private Item raw;
	private Item cooked;
	private Item burnt;
	private int level;
	private int exp;
	private int burnlevel;
	private CookingFood(Item raw, Item cooked, Item burnt, int level,int exp,int burnlevel) {
		setRaw(raw);
		setCooked(cooked);
		setLevel(level);
		setExp(exp);
		setBurnt(burnt);
		setBurnlevel(burnlevel);
	}
	public Item getRaw() {
		return raw;
	}
	public void setRaw(Item raw) {
		this.raw = raw;
	}
	public Item getCooked() {
		return cooked;
	}
	public void setCooked(Item cooked) {
		this.cooked = cooked;
	}
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	public int getExp() {
		return exp;
	}
	public void setExp(int exp) {
		this.exp = exp;
	}
	public Item getBurnt() {
		return burnt;
	}
	public void setBurnt(Item burnt) {
		this.burnt = burnt;
	}
	public int getBurnlevel() {
		return burnlevel;
	}
	public void setBurnlevel(int burnlevel) {
		this.burnlevel = burnlevel;
	}
}

CookingTask which is the Task which will be submitted to TaskManager and processed, this class will Cook the food check if you can cook it and everything else :P

package com.superscape.world.content.skills.cooking;

import java.security.SecureRandom;

import com.superscape.GameConstants;
import com.superscape.engine.task.Task;
import com.superscape.world.entity.impl.object.GameObject;
import com.superscape.world.entity.impl.player.Player;
import com.superscape.world.model.Position;
import com.superscape.world.model.Skill;
/**
 * 
 * @author Oscar Morton <S C A P E On RuneServer>
 *
 */
public class CookingTask extends Task {

	Player player;
	
	CookingFood food;
	
	Position StartingPos;
	
	Cooking cooking;
	
	GameObject cookingObject;
	
	boolean running = true;
	
	private int foodCooked = 0;
	
	private int cycles;
	
	public CookingTask(Player player,CookingFood food,Cooking cooking,GameObject cookingObject, int cycles) {
		this.player = player;
		this.cooking = cooking;
		this.cookingObject = cookingObject;
		this.food = food;
		this.bind(player);
		this.setDelay(0);
		this.StartingPos = player.getPosition();
		this.cycles = cycles;
	}
	
	@Override
	protected void execute() {
				if (foodCooked >= cycles) {
					stop();
					return;
				}
				if (cookingObject.getId() == 114 && player.getCooksAssistant().getStage() != 100) {
					player.getPacketSender().sendMessage("You need to complete the Cooks Assistant quest first!");
					stop();
					return;
				}
				if (!cooking.gotRequierments()) {
					player.getPacketSender().sendMessage("You need level " + food.getLevel() + " cooking to cook this.");
					this.stop();
					return;
				}
				if (!player.getInventory().contains(food.getRaw()) || player.getPosition() != StartingPos || !running || food == null || player == null) {
					this.stop();
					return;
				}
				
				cooking.animatePlayer();
				player.setPositionToFace(cookingObject.getPosition());
				player.getInventory().delete(food.getRaw());
				boolean burnt = false;
				burnt = isBurned();
				player.getInventory().add(!burnt ? food.getCooked() : food.getBurnt());
				player.getPacketSender().sendMessage(burnt ? "You burn the " + food.name().toLowerCase().replace("_", " ")+"." : "You succesfully cook the " + food.name().toLowerCase().replace("_", " ")+".");
				player.getSkillManager().addExperience(Skill.COOKING, burnt ? 0 : food.getExp() * (int)GameConstants.EXP_MULTIPLIER);
				
				if (foodCooked == 0) {
					this.setDelay(2);
					foodCooked += 1;
					return;
				}
				if (foodCooked > 0) {
					foodCooked += 1;
					this.setDelay(cookingObject.getDefinition().getName().toLowerCase().contains("fir") ? 4 : 5);
					return;
				}
				foodCooked += 1;
				

				
				return;
}
		
	
	
	
	public boolean isBurned() {
		SecureRandom RANDOM = new SecureRandom();
		if (player.getSkillManager().getCurrentLevel(Skill.COOKING) > food.getBurnlevel() && food.getRaw().getId() != 11934) {
			return false;
		}
		double burn_chance = (55.0 - (cookingObject.getDefinition().getName().toLowerCase().equals("fire") ? 0.0 : 3.0));
		double cook_level = (double) player.getSkillManager().getCurrentLevel(Skill.COOKING);
		double lev_needed = (double) food.getLevel();
		double burn_stop = (double) food.getBurnlevel();
		double multi_a = (burn_stop - lev_needed);
		double burn_dec = (burn_chance / multi_a);
		double multi_b = (cook_level - lev_needed);
		burn_chance -= (multi_b * burn_dec);
		double randNum = RANDOM.nextDouble() * 100.0;
		return burn_chance <= randNum ? false : true;
	}

	public int getFoodCooked() {
		return foodCooked;
	}

	public void setFoodCooked(int foodCooked) {
		this.foodCooked = foodCooked;
	}

	public int getCycles() {
		return cycles;
	}

	public void setCycles(int cycles) {
		this.cycles = cycles;
	}
		
	

}

Here is the cooking class itself for storing data like anims and the static init method 

package com.superscape.world.content.skills.cooking;

import java.util.ArrayList;

import com.superscape.engine.task.TaskManager;
import com.superscape.world.entity.impl.object.GameObject;
import com.superscape.world.entity.impl.player.Player;
import com.superscape.world.model.Animation;
import com.superscape.world.model.Skill;
import com.superscape.world.model.dialogue.Dialogue;
import com.superscape.world.model.dialogue.DialogueExpression;
import com.superscape.world.model.dialogue.DialogueManager;
import com.superscape.world.model.dialogue.DialogueOptions;
import com.superscape.world.model.dialogue.DialogueType;
/**
 * 
 * @author Oscar Morton <S C A P E on RuneServer>
 *
 */
public class Cooking {
	
	Player p;
	
	CookingFood food;
	
	GameObject cookingObject;
	
	
	private final static ArrayList<Integer> FIRES = new ArrayList<Integer>();
	private final static ArrayList<Integer> RANGES = new ArrayList<Integer>();
	
	final Animation RANGE_ANIM = new Animation(883);
	final Animation FIRE_ANIM = new Animation(897);
	
	public Cooking(Player p,CookingFood food,GameObject cookingObject) {
		this.p = p;
		this.food = food;
		this.cookingObject = cookingObject;
	}
	
	public static void populateFires() {
		FIRES.add(26185);
		FIRES.add(20001);
		FIRES.add(20000);
		FIRES.add(26186);
		FIRES.add(26575);
		FIRES.add(26576);
	}
	
	public static void populateRanges() {
		RANGES.add(114);
		RANGES.add(2859);
		RANGES.add(4172);
		RANGES.add(7183);
		RANGES.add(8750);
		RANGES.add(9682);//use
//		RANGES.add(e)
	}
	
	public static ArrayList<Integer> getCookingObjects() {
		ArrayList<Integer> r = new ArrayList<Integer>();
		r.addAll(FIRES);
		r.addAll(RANGES);
		return r;
	}
	
	public static void init(Player p, CookingFood food, GameObject cookingObject) {
		new Cooking(p,food,cookingObject).start();
	}

	
	int cycles = 0;
	public void start() {
		CookingTask task = new CookingTask(p,food,this,cookingObject,cycles);
		p.setDialogueOptions(new DialogueOptions() {
			
			@Override
			public void handleOption(Player player, int option) {
				switch (option) {
				case 1:
					
					cycles = 1;
					break;
				case 2:
					cycles = 5;
					break;
				case 3:
					cycles = 10;
					break;
				case 4:
					cycles = 28;
					break;
				}
				player.getPacketSender().sendInterfaceRemoval();
				task.setCycles(cycles);
				TaskManager.submit(task);
				
			}
			
		});
		DialogueManager.start(p,new Dialogue() {

			@Override
			public DialogueType type() {
				return DialogueType.OPTION;
			}

			@Override
			public DialogueExpression animation() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public String[] dialogue() {
				return new String[] {"Cook 1", "Cook 5", "Cook 10", "Cook All"};
			}
			
		});
		
	}
	
	public boolean gotRequierments() {
		return p.getSkillManager().getCurrentLevel(Skill.COOKING) >= food.getLevel();
	}

	public void animatePlayer() {
		p.performAnimation(!cookingObject.getDefinition().getName().toLowerCase().contains("fir") ? RANGE_ANIM : FIRE_ANIM);
	}

	public static ArrayList<Integer> getFires() {
		return FIRES;
	}

	public static ArrayList<Integer> getRanges() {
		return RANGES;
	}

	

	
	

}

and add this to UseItemPacketListener.java under the itemOnObject 

for (int OBJ : Cooking.getFires()) {
			if (OBJ == gameObject.getId()) {
				for (final CookingFood food : CookingFood.values()) {
					if (food.getRaw().getId() == itemId) {
						Cooking.init(player, food, gameObject);
					}
				}
			}
		}

Add this to Elvarg.java before the serviceLoader.shutdown();

Cooking.populateFires();
Cooking.populateRanges();

There are things to be added such as the ability of range cooking but that will come later and i will update the thread when such things happen.
Any improvments post below.
Here is a gif of it working

36498686cff696bb2c44c4417c5a9f8c.gif

Link to comment
Share on other sites

  • 3 months later...

@Sanity Great job feller! Thank you so much man ;) think you could point me to the method of chopping wood please, i would like to focus on that, move to fire making then move to cooking, this is 2  in front of what i want to start on! i am not a coder just to put it out there, but i am slowly starting to learn how coding works :D Could you make a tutorial on how to start action cut log to how manny logs go to inventry to when the tree runs out please, with the animation ? 

Link to comment
Share on other sites

  • 10 months later...
  • 3 years later...

Also in 

UseItemPacketListener.java

 

Add 

for (int OBJ : Cooking.getRanges()) {
			if (OBJ == gameObject.getId()) {
				for (final CookingFood food : CookingFood.values()) {
					if (food.getRaw().getId() == itemId) {
						Cooking.init(player, food, gameObject);
					}
				}
			}
		}

Or none of the ranges will work. But nevertheless good release.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Contact

[email protected]

astra.security

What is a RSPS?

A RSPS, also known as RuneScape private server, is an online game based on RuneScape, and controlled by independent individuals.

Popular RSPS Servers

Runewild Ikov RedemptionRSPS

Disclaimer

Runesuite is not affiliated with runescape, jagex in any way & exists solely for educational purposes.

×
×
  • Create New...