Thread: [Elvarg / OSRSPK] Cooking Skill

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 [Elvarg / OSRSPK] Cooking Skill 
    Registered Member Farage's Avatar
    Join Date
    Jan 2017
    Posts
    252
    Thanks given
    24
    Thanks received
    22
    Rep Power
    0
    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
    Code:
    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
    Code:
    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
    Code:
    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

    Code:
    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();
    Code:
    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.

    UPDATES LOG
    Spoiler for updates:

    Added different animations and cooking ticks for ranges and fires.
    Added chatbox options for cooking. Also remove the cooks assistant requierment for one of the ranges btw.


    Here is a gif of it working
    Attached image
    - S C A P E
    Have a nice day!
    Иди в пизду!
    Bonne journée!
    Einen schönen Tag noch!
    Hezký den!
    祝你今天愉快!
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Feb 2013
    Posts
    1,682
    Thanks given
    401
    Thanks received
    402
    Rep Power
    446
    On the gif there's almost no delay between the first edible is being cooked and the second one, the animation reset super quickly but when you start to cook the 3rd one, the delay seems to adjust itself and become proper. You should consideradding the chatbox options in the future updates.

    Good job buddy
    Reply With Quote  
     

  3. #3  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    In your "CookingFood" enum, you don't actually need those gross setter methods.

    Instead, initialize all the values in your constructor. As such:

    Code:
    private CookingFood(Item raw, Item cooked, Item burnt, int level,int exp,int burnlevel) {
    		this.raw = raw;
    		this.cooked = cooked;
    		this.level = level'
    		this.exp = exp;
    		this.burnt = burnt;
    		this.burnLevel = burnLevel
               }
    This achieves the same thing in a way that doesn't require those setter methods (which are stupid to have anyway since you're never going to change a value in the enum after initialization).

    Also, you should further declare your intended visibility scope for all your fields. Right now, you have package-private visibility on a lot of modifiers which isn't actually what you intend to do probably. Try to make your variables as "least-exposed" as possible.

    also make sure to declare every class final that you don't intend to extend upon.
    Reply With Quote  
     

  4. Thankful users:


  5. #4  
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    27
    Posts
    543
    Thanks given
    224
    Thanks received
    100
    Rep Power
    113
    Everything you have in the "Cooking" class can be effectively used in the "CookingTask" class.

    Instead of calling the static method to initiate the task from the Cooking class..
    Just create a new CookingTask for the player if they pass the conditions.


    I'm not sure why you even created extra methods to have the player perform an animation, check the requirements, or get the 'FIRES' array..
    1.) The FIRES array is static, and if you had made it public you could have just used "Cooking.FIRES" in the for loop, although you don't need the entire Cooking class.
    Betters ways to go about that array but for now, I will just say, you can also put that in the CookingTask class and reference it from there or something.
    2.) You're calling "cooking.animatePlayer();" when that too could just be "player.performAnimation(COOKING_ANIMATION)" the whole method is useless.
    3.) It appears you're instancing the Cooking class for the player, which would be pointless if you just had a cooking class with a static method that created a new task.

    The list goes on, but I've kind-of lost track, lol.
    Don't take it harshly though, I congratulate you on taking the effort and having pride in your success.
    Here's an example of how I have Prayer done, I'm sure even this can be improved upon, but this is a pretty basic and decent way to get it done as far as I know.
    Spoiler for Prayer:
    Code:
    public final class Prayer {
    	
    	public static void buryRemains(final Player player, final Bones item) {
    		
    		if(!player.getAttributes().skillAnimationTimer.finished())
    			return;
    		
    		player.getAttributes().setSkillEventTicks(2);
    		
    		TaskManager.submit(new Task(1, player, true) {
    			@Override
    			public void execute() {
    				if (!player.getInventory().contains(item.getPrayerItem().getId()))
    					stop();
    				
    				if (player.getAttributes().getSkillEventTicks() == 2) {
    					player.getMovementQueue().setMovementStatus(MovementStatus.DISABLED);
    					player.performAnimation(SkillConstants.BURY_ANIMATION);
    					player.getInventory().delete(item.getPrayerItem().getId(), 1);
    					player.getSkills().addExperience(Skill.PRAYER, item.getExperience());
    					player.getAttributes().skillAnimationTimer.start(SkillConstants.BURY_DELAY);
    				}
    				player.getAttributes().setSkillEventTicks(player.getAttributes().getSkillEventTicks() - 1);
    				
    				if (player.getAttributes().getSkillEventTicks() == 0)
    					stop();
    			}
    			@Override
    			public void stop() {
    				setEventRunning(false);
    				player.getAttributes().finishSkillInteraction();
    				return;
    			}
    		});
    	}
    	public static void makeOffering(final Player player, final Bones item, final GameObject object, final int amount) {
    		
    		player.getAttributes().setSkillEventTicks(amount);
    		
    		TaskManager.submit(new Task(4, player, true) {
    			@Override
    			public void execute() {
    				
    				final int y = player.getPosition().getY();
    				Position altarGraphic = new Position(2853, y >= 3349 ? 3349 : y <= 3348 ? 3348 : 3349);
    				
    				if (!player.getInventory().contains(item.getPrayerItem().getId()))
    					stop();
    				
    				if (!player.getAttributes().performingSkill())
    					stop();
    				
    				if (player.getAttributes().performingSkill() && player.getInventory().contains(item.getPrayerItem().getId())) {
    					player.performAnimation(SkillConstants.OFFERING_ANIMATION);
    					player.getPacketSender().sendGlobalGraphic(SkillConstants.OFFERING_GRAPHIC, altarGraphic);
    					player.getSkills().addExperience(Skill.PRAYER, item.getExperience() * 3);
    					player.getInventory().delete(item.getPrayerItem().getId(), 1);
    					player.getAttributes().setSkillEventTicks(player.getAttributes().getSkillEventTicks() - 1);
    				}
    				
    				if (player.getAttributes().getSkillEventTicks() == 0)
    					stop();
    			}
    			@Override
    			public void stop() {
    				setEventRunning(false);
    				player.getAttributes().finishSkillInteraction();
    				return;
    			}
    		});
    	}
    	public static void prayAtAltar(Player player) {
    	//TODO
    	}
    }
    Code:
    public enum Bones {
    	
    	BONES(new Item (526), 5),
    	BAT_BONES(new Item (530), 5),
    	WOLF_BONES(new Item (2859), 5),
    	BIG_BONES(new Item (532), 15),
    	BABYDRAGON_BONES(new Item (534), 30),
    	JOGRE_BONES(new Item (3125), 15),
    	ZOGRE_BONES(new Item (4812), 23),
    	LONG_BONES(new Item (10976), 25),
    	CURVED_BONES(new Item (10977), 25),
    	SHAIKAHAN_BONES(new Item (3123), 25),
    	DRAGON_BONES(new Item (536), 72),
    	FAYRG_BONES(new Item (4830), 78),
    	RAURG_BONES(new Item (4832), 86),
    	DAGANNOTH_BONES(new Item (6729), 90),
    	OURG_BONES(new Item (14793), 96),
    	WYVERN_BONES(new Item (6812), 50),
    	LAVA_DRAGON_BONES(new Item (11943), 150);
    	
    	private final Item prayerItem;
    	
    	private final double experience;
    	
    	private double modifier = Misc.getRandomDouble(3);
    	
    	private Bones(final Item prayerItem, final double experience) {
    		this.prayerItem = prayerItem;
    		this.experience = experience;
    	}
    	
    	public Item getPrayerItem() {
    		return prayerItem;
    	}
    	
    	public int getExperience() {
    		return (int) (experience + modifier);
    	}
    	
    	public String getName() {
    		return Misc.capitalizeWords(name().toLowerCase().replaceAll("_", " "));
    	}
    	
    	public static Optional<Bones> getPrayerItem(int identifier) {
    		return Arrays.stream(values()).filter(s -> s.prayerItem.getId() == identifier).findFirst();
    	}
    	
    	public static final ImmutableSet<Integer> OFFERABLES = ImmutableSet.of(
    		BONES.prayerItem.getId(), DRAGON_BONES.prayerItem.getId(),
    		FAYRG_BONES.prayerItem.getId(), RAURG_BONES.prayerItem.getId(),
    		DAGANNOTH_BONES.prayerItem.getId(), OURG_BONES.prayerItem.getId(),
    		WYVERN_BONES.prayerItem.getId(), LAVA_DRAGON_BONES.prayerItem.getId()
    	);
    }
    And in this class I've started including constants for the skills, such as the animations.
    Code:
    public class SkillConstants {
    
    	/**
    	 * Used for all @Skills, the max level obtainable
    	 */
    	public static final int MAX_SKILL_LEVEL = 99;
    	
    	/**
    	 * Used for @Skill.PRAYER, the animation for burying remains
    	 */
    	public static final Animation BURY_ANIMATION = new Animation(827);
    	
    	/**
    	 * Used for @Skill.PRAYER, the delay between burying remains
    	 */
    	public static final int BURY_DELAY = 1;
    
    	/**
    	 * Used for @Skill.PRAYER, the animation for offering remains to an altar
    	 */
    	public static final Animation OFFERING_ANIMATION = new Animation(2044);
    	
    	/**
    	 * Used for @Skill.PRAYER, the graphic to be shown on an altar
    	 */
    	public static final Graphic OFFERING_GRAPHIC = new Graphic(624);
    	
    	/**
    	 * Used for @Skill.HERBLORE, the amount of experience for mixing a herb with a vial of water.
    	 */
    	public static final int HERB_MIXING_EXP = 1;
    	
    	/**
    	 * Used for @Skill.HERBLORE, the item id for the item 'vial of water'.
    	 */
    	public static final Item VIAL_OF_WATER = new Item(227);
    	
    	/**
    	 * Used for @Skill.HERBLORE, the @Item id of a vial
    	 */
    	public static final int EMPTY_VIAL = 229;
    	
    	/**
    	 * Used for @Skill.HERBLORE, the animation for mixing a finished potion.
    	 */
    	public static final Animation POTION_MIXING_ANIMATION = new Animation(363);
    	
    	/**
    	 * Used for @Skill.FIREMAKING, the @Item id of a tinderbox
    	 */
    	public static final Item TINDERBOX = new Item(590);
    	
    	/**
    	 * Used for @Skill.FIREMAKING, the @Item id of a golden tinderbox
    	 */
    	public static final Item GOLDEN_TINDERBOX = new Item(2946);
    	
    	/**
    	 * Used for @Skill.FIREMAKING, the @Item id of a golden tinderbox
    	 */
    	public static final Item ASHES = new Item(592);
    	
    	/**
    	 * Used for @Skill.FIREMAKING, the animation for lighting a fire.
    	 */
    	public static final Animation LIGHT_FIRE_ANIMATION = new Animation(733);
    }

    Spoiler for Revy is perfect:
    Reply With Quote  
     

  6. #5  
    Registered Member Farage's Avatar
    Join Date
    Jan 2017
    Posts
    252
    Thanks given
    24
    Thanks received
    22
    Rep Power
    0
    Quote Originally Posted by Lumiere View Post
    Everything you have in the "Cooking" class can be effectively used in the "CookingTask" class.

    Instead of calling the static method to initiate the task from the Cooking class..
    Just create a new CookingTask for the player if they pass the conditions.


    I'm not sure why you even created extra methods to have the player perform an animation, check the requirements, or get the 'FIRES' array..
    1.) The FIRES array is static, and if you had made it public you could have just used "Cooking.FIRES" in the for loop, although you don't need the entire Cooking class.
    Betters ways to go about that array but for now, I will just say, you can also put that in the CookingTask class and reference it from there or something.
    2.) You're calling "cooking.animatePlayer();" when that too could just be "player.performAnimation(COOKING_ANIMATION)" the whole method is useless.
    3.) It appears you're instancing the Cooking class for the player, which would be pointless if you just had a cooking class with a static method that created a new task.

    The list goes on, but I've kind-of lost track, lol.
    Don't take it harshly though, I congratulate you on taking the effort and having pride in your success.
    Here's an example of how I have Prayer done, I'm sure even this can be improved upon, but this is a pretty basic and decent way to get it done as far as I know.
    Spoiler for Prayer:
    Code:
    public final class Prayer {
    	
    	public static void buryRemains(final Player player, final Bones item) {
    		
    		if(!player.getAttributes().skillAnimationTimer.finished())
    			return;
    		
    		player.getAttributes().setSkillEventTicks(2);
    		
    		TaskManager.submit(new Task(1, player, true) {
    			@Override
    			public void execute() {
    				if (!player.getInventory().contains(item.getPrayerItem().getId()))
    					stop();
    				
    				if (player.getAttributes().getSkillEventTicks() == 2) {
    					player.getMovementQueue().setMovementStatus(MovementStatus.DISABLED);
    					player.performAnimation(SkillConstants.BURY_ANIMATION);
    					player.getInventory().delete(item.getPrayerItem().getId(), 1);
    					player.getSkills().addExperience(Skill.PRAYER, item.getExperience());
    					player.getAttributes().skillAnimationTimer.start(SkillConstants.BURY_DELAY);
    				}
    				player.getAttributes().setSkillEventTicks(player.getAttributes().getSkillEventTicks() - 1);
    				
    				if (player.getAttributes().getSkillEventTicks() == 0)
    					stop();
    			}
    			@Override
    			public void stop() {
    				setEventRunning(false);
    				player.getAttributes().finishSkillInteraction();
    				return;
    			}
    		});
    	}
    	public static void makeOffering(final Player player, final Bones item, final GameObject object, final int amount) {
    		
    		player.getAttributes().setSkillEventTicks(amount);
    		
    		TaskManager.submit(new Task(4, player, true) {
    			@Override
    			public void execute() {
    				
    				final int y = player.getPosition().getY();
    				Position altarGraphic = new Position(2853, y >= 3349 ? 3349 : y <= 3348 ? 3348 : 3349);
    				
    				if (!player.getInventory().contains(item.getPrayerItem().getId()))
    					stop();
    				
    				if (!player.getAttributes().performingSkill())
    					stop();
    				
    				if (player.getAttributes().performingSkill() && player.getInventory().contains(item.getPrayerItem().getId())) {
    					player.performAnimation(SkillConstants.OFFERING_ANIMATION);
    					player.getPacketSender().sendGlobalGraphic(SkillConstants.OFFERING_GRAPHIC, altarGraphic);
    					player.getSkills().addExperience(Skill.PRAYER, item.getExperience() * 3);
    					player.getInventory().delete(item.getPrayerItem().getId(), 1);
    					player.getAttributes().setSkillEventTicks(player.getAttributes().getSkillEventTicks() - 1);
    				}
    				
    				if (player.getAttributes().getSkillEventTicks() == 0)
    					stop();
    			}
    			@Override
    			public void stop() {
    				setEventRunning(false);
    				player.getAttributes().finishSkillInteraction();
    				return;
    			}
    		});
    	}
    	public static void prayAtAltar(Player player) {
    	//TODO
    	}
    }
    Code:
    public enum Bones {
    	
    	BONES(new Item (526), 5),
    	BAT_BONES(new Item (530), 5),
    	WOLF_BONES(new Item (2859), 5),
    	BIG_BONES(new Item (532), 15),
    	BABYDRAGON_BONES(new Item (534), 30),
    	JOGRE_BONES(new Item (3125), 15),
    	ZOGRE_BONES(new Item (4812), 23),
    	LONG_BONES(new Item (10976), 25),
    	CURVED_BONES(new Item (10977), 25),
    	SHAIKAHAN_BONES(new Item (3123), 25),
    	DRAGON_BONES(new Item (536), 72),
    	FAYRG_BONES(new Item (4830), 78),
    	RAURG_BONES(new Item (4832), 86),
    	DAGANNOTH_BONES(new Item (6729), 90),
    	OURG_BONES(new Item (14793), 96),
    	WYVERN_BONES(new Item (6812), 50),
    	LAVA_DRAGON_BONES(new Item (11943), 150);
    	
    	private final Item prayerItem;
    	
    	private final double experience;
    	
    	private double modifier = Misc.getRandomDouble(3);
    	
    	private Bones(final Item prayerItem, final double experience) {
    		this.prayerItem = prayerItem;
    		this.experience = experience;
    	}
    	
    	public Item getPrayerItem() {
    		return prayerItem;
    	}
    	
    	public int getExperience() {
    		return (int) (experience + modifier);
    	}
    	
    	public String getName() {
    		return Misc.capitalizeWords(name().toLowerCase().replaceAll("_", " "));
    	}
    	
    	public static Optional<Bones> getPrayerItem(int identifier) {
    		return Arrays.stream(values()).filter(s -> s.prayerItem.getId() == identifier).findFirst();
    	}
    	
    	public static final ImmutableSet<Integer> OFFERABLES = ImmutableSet.of(
    		BONES.prayerItem.getId(), DRAGON_BONES.prayerItem.getId(),
    		FAYRG_BONES.prayerItem.getId(), RAURG_BONES.prayerItem.getId(),
    		DAGANNOTH_BONES.prayerItem.getId(), OURG_BONES.prayerItem.getId(),
    		WYVERN_BONES.prayerItem.getId(), LAVA_DRAGON_BONES.prayerItem.getId()
    	);
    }
    And in this class I've started including constants for the skills, such as the animations.
    Code:
    public class SkillConstants {
    
    	/**
    	 * Used for all @Skills, the max level obtainable
    	 */
    	public static final int MAX_SKILL_LEVEL = 99;
    	
    	/**
    	 * Used for @Skill.PRAYER, the animation for burying remains
    	 */
    	public static final Animation BURY_ANIMATION = new Animation(827);
    	
    	/**
    	 * Used for @Skill.PRAYER, the delay between burying remains
    	 */
    	public static final int BURY_DELAY = 1;
    
    	/**
    	 * Used for @Skill.PRAYER, the animation for offering remains to an altar
    	 */
    	public static final Animation OFFERING_ANIMATION = new Animation(2044);
    	
    	/**
    	 * Used for @Skill.PRAYER, the graphic to be shown on an altar
    	 */
    	public static final Graphic OFFERING_GRAPHIC = new Graphic(624);
    	
    	/**
    	 * Used for @Skill.HERBLORE, the amount of experience for mixing a herb with a vial of water.
    	 */
    	public static final int HERB_MIXING_EXP = 1;
    	
    	/**
    	 * Used for @Skill.HERBLORE, the item id for the item 'vial of water'.
    	 */
    	public static final Item VIAL_OF_WATER = new Item(227);
    	
    	/**
    	 * Used for @Skill.HERBLORE, the @Item id of a vial
    	 */
    	public static final int EMPTY_VIAL = 229;
    	
    	/**
    	 * Used for @Skill.HERBLORE, the animation for mixing a finished potion.
    	 */
    	public static final Animation POTION_MIXING_ANIMATION = new Animation(363);
    	
    	/**
    	 * Used for @Skill.FIREMAKING, the @Item id of a tinderbox
    	 */
    	public static final Item TINDERBOX = new Item(590);
    	
    	/**
    	 * Used for @Skill.FIREMAKING, the @Item id of a golden tinderbox
    	 */
    	public static final Item GOLDEN_TINDERBOX = new Item(2946);
    	
    	/**
    	 * Used for @Skill.FIREMAKING, the @Item id of a golden tinderbox
    	 */
    	public static final Item ASHES = new Item(592);
    	
    	/**
    	 * Used for @Skill.FIREMAKING, the animation for lighting a fire.
    	 */
    	public static final Animation LIGHT_FIRE_ANIMATION = new Animation(733);
    }
    The code isn't finished and needs other things done to it. but yeah i only made seperate classes to make it a tad neater. working on combining foods together to make things like making cake when you put the flower and the milk in the pot and cook. That will prob be done using abstract classes, still needs work on though.

    But to answer the question
    1. Ill most likley rework the array. i only made it so i can have ranges array so it knows which thing to cook and which animation to use to cook.
    2. Read above about the animation stuff.
    3. The static method is to initiate the cooking skill then it instances it for the player as appose to doing new Cooking(player).start(); its easier to do Cooking.start(player)

    - S C A P E

    Quote Originally Posted by Andys1814 View Post
    In your "CookingFood" enum, you don't actually need those gross setter methods.

    Instead, initialize all the values in your constructor. As such:

    Code:
    private CookingFood(Item raw, Item cooked, Item burnt, int level,int exp,int burnlevel) {
    		this.raw = raw;
    		this.cooked = cooked;
    		this.level = level'
    		this.exp = exp;
    		this.burnt = burnt;
    		this.burnLevel = burnLevel
               }
    This achieves the same thing in a way that doesn't require those setter methods (which are stupid to have anyway since you're never going to change a value in the enum after initialization).

    Also, you should further declare your intended visibility scope for all your fields. Right now, you have package-private visibility on a lot of modifiers which isn't actually what you intend to do probably. Try to make your variables as "least-exposed" as possible.

    also make sure to declare every class final that you don't intend to extend upon.
    The getters and setters are there as a habit i have to look a tad nicer
    Last edited by Farage; 07-21-2017 at 12:24 PM. Reason: Answered questions further
    Have a nice day!
    Иди в пизду!
    Bonne journée!
    Einen schönen Tag noch!
    Hezký den!
    祝你今天愉快!
    Reply With Quote  
     

  7. #6  
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    27
    Posts
    543
    Thanks given
    224
    Thanks received
    100
    Rep Power
    113
    Quote Originally Posted by S C A P E View Post
    The code isn't finished and needs other things done to it. but yeah i only made seperate classes to make it a tad neater. working on combining foods together to make things like making cake when you put the flower and the milk in the pot and cook. That will prob be done using abstract classes, still needs work on though.

    But to answer the question
    1. Ill most likley rework the array. i only made it so i can have ranges array so it knows which thing to cook and which animation to use to cook.
    2. Read above about the animation stuff.
    3. The static method is to initiate the cooking skill then it instances it for the player as appose to doing new Cooking(player).start(); its easier to do Cooking.start(player)

    - S C A P E



    The getters and setters are there as a habit i have to look a tad nicer
    You're not understanding, It's verbose, you only need one class and one static method for this really.
    You can easily take what you have and do so to accomplish the exact same thing in again, one method and one class.

    As for having setters on the enum for the constructor, it doesn't look nicer or anything, it's terrible and is completely pointless..
    We're just trying to help man.. Exactly as Andys1814 stated, you're never going to change a value in the enum after it is initialized.

    Spoiler for Revy is perfect:
    Reply With Quote  
     

  8. #7  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    1. As Andys1814 said, you're incorrectly making the constructor in the enum.
    2. As Andys1814 said, make your fields and such as private as possible.
    3. Rename the following:
      Code:
      Position StartingPos;
      to camelCase:
      Code:
      Position startingPos;
    4. According to the docs, use underscores only for constants (with UPPER_CASE).
      By convention, the underscore character is never used elsewhere.
      So consider renaming those local variables.
    5. What's the point of the ArrayList? Why not just use an array? It's simple, and no need to unnecessarily add:
      Code:
      Cooking.populateFires();
      Cooking.populateRanges();
    6. When making a class, understand it's purpose. You said you made the classes to make it look more "neat," but to be honest it would be way more "neat" if they were in one place. They all assist in Cooking, why seperate it?
    7. Your Cooking class needs the Player variables to be passed to construct it, that's not logical. Logically, Cooking is a set of actions, so if you really want to make those seperate classes, consider making everything in your CookingTask class to be in Cooking. Your CookingTask is an instance of the player performing the actions in Cooking that way.
    8. I'd put that enum in Cooking, no need to be a seperate file.

    Quote Originally Posted by S C A P E View Post
    The getters and setters are there as a habit i have to look a tad nicer
    All habits aren't good.
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  9. Thankful user:


  10. #8  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    Quote Originally Posted by arham 4 View Post
    What's the point of the ArrayList? Why not just use an array? It's simple, and no need to unnecessarily add:
    Code:
    Cooking.populateFires();
    Cooking.populateRanges();
    Or he could initialize the values within the array list declaration. I have no idea why he did it in a separate method.
    Or he could initialize the values within the array list declaration. I have no idea why he did it in a separate method and used the list.add(object) method.
    Reply With Quote  
     

  11. #9  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by Andys1814 View Post
    Or he could initialize the values within the array list declaration. I have no idea why he did it in a separate method and used the list.add(object) method.
    An array is preferred in this case. Use lists when the size is dynamic. In this case, it's always the same - initiated at the launch of the server and never modified past that; perfect conditions for an array.. BUT
    This is completely pointless. You do not need to manually list out the ids of the objects - use object definitions name variable to determine whether the object is a fire, a range or something else; this would not only keep the code cleaner but also more efficient.
    As others have stated, set your variables and methods unused by outside classes private. Also, use the 'final' modifier wherever possible.
    Last thing that REALLY bothers me is how you do not ever put a space after a comma. What the fuck man? It looks like a clusterfuck without that. Haven't your teachers taught you that a space is ALWAYS added after a comma?
    Attached image
    Reply With Quote  
     

  12. Thankful users:


  13. #10  
    Registered Member Farage's Avatar
    Join Date
    Jan 2017
    Posts
    252
    Thanks given
    24
    Thanks received
    22
    Rep Power
    0
    Quote Originally Posted by Kris View Post
    An array is preferred in this case. Use lists when the size is dynamic. In this case, it's always the same - initiated at the launch of the server and never modified past that; perfect conditions for an array.. BUT
    This is completely pointless. You do not need to manually list out the ids of the objects - use object definitions name variable to determine whether the object is a fire, a range or something else; this would not only keep the code cleaner but also more efficient.
    As others have stated, set your variables and methods unused by outside classes private. Also, use the 'final' modifier wherever possible.
    Last thing that REALLY bothers me is how you do not ever put a space after a comma. What the fuck man? It looks like a clusterfuck without that. Haven't your teachers taught you that a space is ALWAYS added after a comma?
    Extra characters is extra space and wastes time.
    Have a nice day!
    Иди в пизду!
    Bonne journée!
    Einen schönen Tag noch!
    Hezký den!
    祝你今天愉快!
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [Elvarg / OSRSPK] Firemaking Skill
    By Farage in forum Snippets
    Replies: 32
    Last Post: 07-20-2017, 05:49 AM
  2. Replies: 3
    Last Post: 04-01-2017, 02:24 PM
  3. Cooking skill release
    By _Patrick_ in forum Snippets
    Replies: 16
    Last Post: 03-09-2017, 01:35 PM
  4. Showing off the Cooking skill
    By Nighel in forum Show-off
    Replies: 5
    Last Post: 12-14-2013, 10:57 PM
  5. Cooking Skill
    By Aeterna in forum Snippets
    Replies: 7
    Last Post: 02-21-2010, 11:44 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •