Thread: [Elvarg / OSRSPK] Woodcutting Skill

Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1 [Elvarg / OSRSPK] Woodcutting Skill 
    Registered Member Farage's Avatar
    Join Date
    Jan 2017
    Posts
    252
    Thanks given
    24
    Thanks received
    22
    Rep Power
    0
    Hello everyone, I'm back for my 3rd release for the base Elvarg. Copy the code below. i have renamed all my packages in this so you will need to change that yourself, shouldn't be hard.
    This release contains the most accurate formulas i could find and things like 1/3 chance of burning log when using infernal axe, best axe searching (includes inventory and equipment) and much much more.

    First of all copy the Tree.java enum that holds all the data for the tree, it is not completed and is the only bit thats not finished but you should be able to find it with a bit of time.
    Code:
    package com.superscape.world.content.skills.woodcutting;
    
    import com.superscape.world.model.Animation;
    
    public enum Tree {
    	STANDARD_TREE_1(1276, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_2(1277, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1343),
    	STANDARD_TREE_3(1278, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_4(1279, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_5(1280, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1343),
    	STANDARD_TREE_6(1330, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_7(1331, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_8(1332, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_9(2409, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_10(3033, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_11(3034, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_12(3035, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1347),
    	STANDARD_TREE_13(3036, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1351),
    	STANDARD_TREE_14(3879, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_15(3881, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_16(3882, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_17(3883, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3884),
    	STANDARD_TREE_18(10041, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_19(14308, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_20(14309, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_21(16264, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_22(16265, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342);
    
    	private int id;
    	int level;
    	int respawnRate;
    	int reward;
    	int rewardAmount;
    	int emptyId;
    	double rate,experience;
    	String name;
    	Animation animation;
    	
    	private Tree(int id, int level, double rate, int respawnRate, double experience, int reward, int rewardAmount, String name, Animation animation, int emptyId) {
    		this.id = id;
    		this.level = level;
    		this.rate = rate;
    		this.respawnRate = respawnRate;
    		this.experience = experience;
    		this.reward = reward;
    		this.rewardAmount = rewardAmount;
    		this.name = name;
    		this.animation = animation;
    		this.emptyId = emptyId;
    	}
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    }
    Now copy the Axe.java enum, it contains things such as its item id, its ratio for chopping down the tree (Math stuff and also used to detirmine which axe is best to use) and the animation for it
    Code:
    package com.superscape.world.content.skills.woodcutting;
    
    import com.superscape.world.model.Animation;
    
    public enum Axe {
    	
    	BRONZE_AXE(1351, 1, 0.05D, new Animation(879)),
    	IRON_AXE(1349, 1, 0.1D, new Animation(877)),
    	STEEL_AXE(1353, 6, 0.2D, new Animation(875)),
    	BLACK_AXE(1361, 6, 0.25D, new Animation(873)),
    	MITHRIL_AXE(1355, 21, 0.30D, new Animation(871)),
    	ADAMANT_AXE(1357, 31, 0.45D, new Animation(869)),
    	RUNE_AXE(1359, 41, 0.65D, new Animation(867)),
    	DRAGON_AXE(6739, 61, 0.85D, new Animation(2846)),
    	INFERNAL(13241,61,1D,new Animation(2117));
    	
    	private int id,level;
    	private double ratio;
    	private Animation animation;
    	
    	private Axe(int id,int level, double ratio, Animation animation) {
    		this.id = id;
    		this.level = level;
    		this.ratio = ratio;
    		this.animation = animation;
    	}
    	
    	
    
    	public int getLevel() {
    		return level;
    	}
    
    	public void setLevel(int level) {
    		this.level = level;
    	}
    
    	public Animation getAnimation() {
    		return animation;
    	}
    
    	public void setAnimation(Animation animation) {
    		this.animation = animation;
    	}
    
    	public double getRatio() {
    		return ratio;
    	}
    
    	public void setRatio(double ratio) {
    		this.ratio = ratio;
    	}
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    	
    }
    And now for Woodcutting.java itself
    Code:
    package com.superscape.world.content.skills.woodcutting;
    
    import java.security.SecureRandom;
    
    import com.superscape.GameConstants;
    import com.superscape.engine.task.Task;
    import com.superscape.engine.task.TaskManager;
    import com.superscape.world.collision.region.RegionClipping;
    import com.superscape.world.content.skills.firemaking.LogData;
    import com.superscape.world.entity.impl.object.GameObject;
    import com.superscape.world.entity.impl.object.ObjectHandler;
    import com.superscape.world.entity.impl.player.Player;
    import com.superscape.world.grounditems.GroundItemManager;
    import com.superscape.world.model.Animation;
    import com.superscape.world.model.GroundItem;
    import com.superscape.world.model.Item;
    import com.superscape.world.model.Position;
    import com.superscape.world.model.Skill;
    import com.superscape.world.model.container.impl.Equipment;
    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.DialogueType;
    
    public class Woodcutting {
    	
    	Player player;
    	
    	Tree tree;
    	
    	Axe axe;
    	
    	GameObject ob;
    	
    	int ticks;
    	
    	Position originalPosition;
    	
    	public Woodcutting(Player player,Tree tree,GameObject ob) {
    		this.player = player;
    		this.tree = tree;
    		this.ob = ob;
    	}
    	
    	public void start() {
    		axe = getBestAxe();
    		if (player.isChopping()) {
    			player.getPacketSender().sendMessage("You're already chopping a tree.");
    			return;
    		}
    		if (tree.level > player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING)) {
    			player.getPacketSender().sendMessage("You cannot chop this tree. You need level " + tree.level+" to chop it.");
    			return;
    		}
    		if (axe == null) {
    			player.getPacketSender().sendMessage("You do not have an axe that you have the level to use.");
    			return;
    		}
    //		if (player.getInventory().isFull()) {
    //			player.getPacketSender().sendMessage("Your inventory cannot hold anymore logs.");
    //			return;
    //		}
    		/**
    		 * If the checks were succesfull
    		 */
    		player.getPacketSender().sendMessage("You swing your axe at the tree.");
    		originalPosition = player.getPosition();
    		player.setChopping(true);
    		player.performAnimation(axe.getAnimation());
    		TaskManager.submit(new Task(1,player,false) {
    
    			@Override
    			protected void execute() {
    				if (tree.getId() == 10041) {
    					player.setChopping(false);
    					DialogueManager.start(player, new Dialogue() {
    
    						@Override
    						public DialogueType type() {
    							return DialogueType.NPC_STATEMENT;
    						}
    
    						@Override
    						public DialogueExpression animation() {
    							return DialogueExpression.ANGRY;
    						}
    						
    						@Override
    						public int npcId() {
    							return 394;
    						}
    						
    						@Override
    						public Dialogue nextDialogue() {
    							return new Dialogue() {
    
    								@Override
    								public DialogueType type() {
    									return DialogueType.PLAYER_STATEMENT;
    								}
    
    								@Override
    								public DialogueExpression animation() {
    									return DialogueExpression.SAD;
    								}
    
    								@Override
    								public int nextDialogueId() {
    									return -1;
    								}
    								
    								@Override
    								public String[] dialogue() {
    									return new String[] {"Sorry."};
    								}
    								
    							};
    						}
    
    						@Override
    						public String[] dialogue() {
    							return new String[] {new SecureRandom().nextInt() % 2 == 0 ? "You'll blow my cover! I'm meant to be hidden!" : "Will you stop that?"};
    						}
    						
    					});
    					TaskManager.submit(new Task(3,player,false) {
    
    						@Override
    						protected void execute() {
    							player.performAnimation(Animation.DEFAULT_RESET_ANIMATION);
    							this.stop();
    							return;
    						}
    						
    					});
    					this.stop();
    					return;
    				}
    				if (player.getPosition() != originalPosition) {
    					player.setChopping(false);
    					stop();
    					return;
    				}
    				if (++ticks % 4 != 0) {
    					return;
    				}
    				if (!checkReward()) {
    					return;
    				}
    				SecureRandom RANDOM = new SecureRandom();
    				Position objd = ob.getPosition();
    				boolean fired = false;
    				player.getSkillManager().addExperience(Skill.WOODCUTTING,(int) (tree.experience * GameConstants.EXP_MULTIPLIER));
    				if (axe.getId() == 13241) {
    					if (RANDOM.nextInt() % 3 == 0) {
    						player.getSkillManager().addExperience(Skill.FIREMAKING, (int)(LogData.forId(tree.reward).getExperience() / 2) *(int) GameConstants.EXP_MULTIPLIER);
    						if (!ObjectHandler.objectExists(player.getPosition())) {
    							GameObject fireObject = new GameObject(LogData.forId(tree.reward).getFire(),player.getPosition());
    							ObjectHandler.spawnGlobalObject(fireObject);
    							TaskManager.submit(new Task((int)LogData.forId(tree.reward).getLife(),false) {
    
    								@Override
    								protected void execute() {
    									ObjectHandler.despawnGlobalObject(fireObject);
    									this.stop();
    									return;
    								}
    								
    							});
    						}
    						fired = true;
    					}
    				}
    				player.getPacketSender().sendMessage("You chop down the tree.");
    				player.setChopping(false);
    				ObjectHandler.despawnGlobalObject(ob);
    				ObjectHandler.spawnGlobalObject(new GameObject(tree.emptyId,objd));
    				player.performAnimation(Animation.DEFAULT_RESET_ANIMATION);
    				if (!fired) {
    					if (player.getInventory().isFull()) {
    						GroundItemManager.spawnGroundItem(player, new GroundItem(new Item(tree.reward),player.getPosition(),player.getUsername(),player.getHostAddress(),false,200,true,200));
    					} else {
    						player.getInventory().add(new Item(tree.reward,tree.rewardAmount));
    					}
    				}
    				TaskManager.submit(new Task(tree.respawnRate,false) {
    
    					@Override
    					protected void execute() {
    //						objd
    						GameObject go = RegionClipping.getGameObject(objd);
    						if (go == null) {
    							stop();
    							return;
    						}
    						ObjectHandler.despawnGlobalObject(go);
    						ObjectHandler.spawnGlobalObject(new GameObject(tree.getId(),objd));
    						
    					}
    					
    				});
    				this.stop();
    				return;
    			}
    			
    		});
    		
    	}
    	
    	boolean checkReward() {
    		int level = 1 + player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING);
    		double hostRatio = Math.random() * (100.0 * tree.rate);
    		double clientRatio = Math.random() * ((level - tree.level) * (1.0 + axe.getRatio()));
    		return hostRatio < clientRatio;
    	}
    	
    	
    	
    	public Axe getBestAxe() {
    		double rat = 0;
    		Axe a = null;
    		for (Item i : player.getInventory().getItems()) {
    			for (Axe axe : Axe.values()) {
    				if (i.getId() == axe.getId()) {
    					if (axe.getRatio() > rat && player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING) >= axe.getLevel()) {
    						rat = axe.getRatio();
    						a = axe;
    					}
    				}
    			}
    		}
    			for (Axe axe : Axe.values()) {
    				if (player.getEquipment().get(Equipment.WEAPON_SLOT).getId() == axe.getId()) {
    					if (axe.getRatio() > rat && player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING) >= axe.getLevel()) {
    						rat = axe.getRatio();
    						a = axe;
    					}
    				}
    			}
    		
    		return a;
    	}
    	
    	
    	
    	
    	
    	public static void init(Player player,Tree tree,GameObject ob) {
    		new Woodcutting(player,tree,ob).start();
    	}
    
    }
    And if you want to you can put in making the infernal axe by adding the below code.
    Code:
    package com.superscape.world.content.skills.woodcutting;
    
    import com.superscape.world.entity.impl.player.Player;
    import com.superscape.world.model.Animation;
    import com.superscape.world.model.Graphic;
    import com.superscape.world.model.Item;
    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.DialogueType;
    
    public class CreateInfernalAxe {
    	
    	/**
    	 * The player
    	 */
    	Player player;
    	
    	/**
    	 * The fusing animation
    	 */
    	private final Animation ANIMATION = new Animation(4511);
    	private final Graphic GFX = new Graphic(1240);
    	
    	public CreateInfernalAxe(Player player) {
    		this.player = player;
    	}
    	
    	public static void init(Player player) {
    		new CreateInfernalAxe(player).start();
    	}
    	
    	public void start() {
    		player.performAnimation(Animation.DEFAULT_RESET_ANIMATION);
    		player.performAnimation(ANIMATION);
    		player.performGraphic(GFX);
    		player.getInventory().delete(new Item(6739,1));
    		player.getInventory().delete(new Item(13233,1));
    		player.getInventory().add(new Item(13241,1));
    		DialogueManager.start(player, new Dialogue() {
    			@Override
    			public DialogueType type() {
    				return DialogueType.PLAYER_STATEMENT;
    			}
    
    			@Override
    			public DialogueExpression animation() {
    				return DialogueExpression.DEFAULT;
    			}
    
    			@Override
    			public String[] dialogue() {
    				return new String[] {"Wow! I created an extension of the axe.","I think I should try this out later."};
    			}
    			
    		});
    		return;//finished
    	}
    
    }
    Now for the changes in ObjectActionPacketListener.java right above the switch method and below the wilderness obelisk handling code put this
    Code:
    for (Tree tree : Tree.values()) {
    					if (id == tree.getId()) {
    						Woodcutting.init(player, tree,RegionClipping.getGameObject(position));
    						return;
    					}
    				}
    In UseItemPacketListener.java inside of the itemOnItem method add this code
    Code:
    if ((used.getId() == 6739 && usedWith.getId() == 13233) || (used.getId() == 13233 && usedWith.getId() == 6739)) {
    			CreateInfernalAxe.init(player);
    			return;
    		}
    and finally in Player.java define
    Code:
    private boolean chopping = false;
    Make its getters and setters too as its private

    If im missing anything from the code let me know and i will try fill in the bits im missing / update the code with better code.
    - Oscar < S C A P E >
    Have a nice day all

    Last edited by Farage; 07-22-2017 at 08:22 PM. Reason: Forgot the chopping boolean in Player.java
    Have a nice day!
    Иди в пизду!
    Bonne journée!
    Einen schönen Tag noch!
    Hezký den!
    祝你今天愉快!
    Reply With Quote  
     

  2. #2  
    Member
    Join Date
    Mar 2017
    Posts
    143
    Thanks given
    10
    Thanks received
    18
    Rep Power
    0
    Quote Originally Posted by S C A P E View Post
    Hello everyone, I'm back for my 3rd release for the base Elvarg. Copy the code below. i have renamed all my packages in this so you will need to change that yourself, shouldn't be hard.
    This release contains the most accurate formulas i could find and things like 1/3 chance of burning log when using infernal axe, best axe searching (includes inventory and equipment) and much much more.

    First of all copy the Tree.java enum that holds all the data for the tree, it is not completed and is the only bit thats not finished but you should be able to find it with a bit of time.
    Code:
    package com.superscape.world.content.skills.woodcutting;
    
    import com.superscape.world.model.Animation;
    
    public enum Tree {
    	STANDARD_TREE_1(1276, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_2(1277, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1343),
    	STANDARD_TREE_3(1278, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_4(1279, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_5(1280, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1343),
    	STANDARD_TREE_6(1330, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_7(1331, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_8(1332, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_9(2409, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_10(3033, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_11(3034, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_12(3035, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1347),
    	STANDARD_TREE_13(3036, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1351),
    	STANDARD_TREE_14(3879, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_15(3881, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_16(3882, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_17(3883, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3884),
    	STANDARD_TREE_18(10041, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_19(14308, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_20(14309, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_21(16264, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_22(16265, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342);
    
    	private int id;
    	int level;
    	int respawnRate;
    	int reward;
    	int rewardAmount;
    	int emptyId;
    	double rate,experience;
    	String name;
    	Animation animation;
    	
    	private Tree(int id, int level, double rate, int respawnRate, double experience, int reward, int rewardAmount, String name, Animation animation, int emptyId) {
    		this.id = id;
    		this.level = level;
    		this.rate = rate;
    		this.respawnRate = respawnRate;
    		this.experience = experience;
    		this.reward = reward;
    		this.rewardAmount = rewardAmount;
    		this.name = name;
    		this.animation = animation;
    		this.emptyId = emptyId;
    	}
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    }
    Now copy the Axe.java enum, it contains things such as its item id, its ratio for chopping down the tree (Math stuff and also used to detirmine which axe is best to use) and the animation for it
    Code:
    package com.superscape.world.content.skills.woodcutting;
    
    import com.superscape.world.model.Animation;
    
    public enum Axe {
    	
    	BRONZE_AXE(1351, 1, 0.05D, new Animation(879)),
    	IRON_AXE(1349, 1, 0.1D, new Animation(877)),
    	STEEL_AXE(1353, 6, 0.2D, new Animation(875)),
    	BLACK_AXE(1361, 6, 0.25D, new Animation(873)),
    	MITHRIL_AXE(1355, 21, 0.30D, new Animation(871)),
    	ADAMANT_AXE(1357, 31, 0.45D, new Animation(869)),
    	RUNE_AXE(1359, 41, 0.65D, new Animation(867)),
    	DRAGON_AXE(6739, 61, 0.85D, new Animation(2846)),
    	INFERNAL(13241,61,1D,new Animation(2117));
    	
    	private int id,level;
    	private double ratio;
    	private Animation animation;
    	
    	private Axe(int id,int level, double ratio, Animation animation) {
    		this.id = id;
    		this.level = level;
    		this.ratio = ratio;
    		this.animation = animation;
    	}
    	
    	
    
    	public int getLevel() {
    		return level;
    	}
    
    	public void setLevel(int level) {
    		this.level = level;
    	}
    
    	public Animation getAnimation() {
    		return animation;
    	}
    
    	public void setAnimation(Animation animation) {
    		this.animation = animation;
    	}
    
    	public double getRatio() {
    		return ratio;
    	}
    
    	public void setRatio(double ratio) {
    		this.ratio = ratio;
    	}
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    	
    }
    And now for Woodcutting.java itself
    Code:
    package com.superscape.world.content.skills.woodcutting;
    
    import java.security.SecureRandom;
    
    import com.superscape.GameConstants;
    import com.superscape.engine.task.Task;
    import com.superscape.engine.task.TaskManager;
    import com.superscape.world.collision.region.RegionClipping;
    import com.superscape.world.content.skills.firemaking.LogData;
    import com.superscape.world.entity.impl.object.GameObject;
    import com.superscape.world.entity.impl.object.ObjectHandler;
    import com.superscape.world.entity.impl.player.Player;
    import com.superscape.world.grounditems.GroundItemManager;
    import com.superscape.world.model.Animation;
    import com.superscape.world.model.GroundItem;
    import com.superscape.world.model.Item;
    import com.superscape.world.model.Position;
    import com.superscape.world.model.Skill;
    import com.superscape.world.model.container.impl.Equipment;
    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.DialogueType;
    
    public class Woodcutting {
    	
    	Player player;
    	
    	Tree tree;
    	
    	Axe axe;
    	
    	GameObject ob;
    	
    	int ticks;
    	
    	Position originalPosition;
    	
    	public Woodcutting(Player player,Tree tree,GameObject ob) {
    		this.player = player;
    		this.tree = tree;
    		this.ob = ob;
    	}
    	
    	public void start() {
    		axe = getBestAxe();
    		if (player.isChopping()) {
    			player.getPacketSender().sendMessage("You're already chopping a tree.");
    			return;
    		}
    		if (tree.level > player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING)) {
    			player.getPacketSender().sendMessage("You cannot chop this tree. You need level " + tree.level+" to chop it.");
    			return;
    		}
    		if (axe == null) {
    			player.getPacketSender().sendMessage("You do not have an axe that you have the level to use.");
    			return;
    		}
    //		if (player.getInventory().isFull()) {
    //			player.getPacketSender().sendMessage("Your inventory cannot hold anymore logs.");
    //			return;
    //		}
    		/**
    		 * If the checks were succesfull
    		 */
    		player.getPacketSender().sendMessage("You swing your axe at the tree.");
    		originalPosition = player.getPosition();
    		player.setChopping(true);
    		player.performAnimation(axe.getAnimation());
    		TaskManager.submit(new Task(1,player,false) {
    
    			@Override
    			protected void execute() {
    				if (tree.getId() == 10041) {
    					player.setChopping(false);
    					DialogueManager.start(player, new Dialogue() {
    
    						@Override
    						public DialogueType type() {
    							return DialogueType.NPC_STATEMENT;
    						}
    
    						@Override
    						public DialogueExpression animation() {
    							return DialogueExpression.ANGRY;
    						}
    						
    						@Override
    						public int npcId() {
    							return 394;
    						}
    						
    						@Override
    						public Dialogue nextDialogue() {
    							return new Dialogue() {
    
    								@Override
    								public DialogueType type() {
    									return DialogueType.PLAYER_STATEMENT;
    								}
    
    								@Override
    								public DialogueExpression animation() {
    									return DialogueExpression.SAD;
    								}
    
    								@Override
    								public int nextDialogueId() {
    									return -1;
    								}
    								
    								@Override
    								public String[] dialogue() {
    									return new String[] {"Sorry."};
    								}
    								
    							};
    						}
    
    						@Override
    						public String[] dialogue() {
    							return new String[] {new SecureRandom().nextInt() % 2 == 0 ? "You'll blow my cover! I'm meant to be hidden!" : "Will you stop that?"};
    						}
    						
    					});
    					TaskManager.submit(new Task(3,player,false) {
    
    						@Override
    						protected void execute() {
    							player.performAnimation(Animation.DEFAULT_RESET_ANIMATION);
    							this.stop();
    							return;
    						}
    						
    					});
    					this.stop();
    					return;
    				}
    				if (player.getPosition() != originalPosition) {
    					player.setChopping(false);
    					stop();
    					return;
    				}
    				if (++ticks % 4 != 0) {
    					return;
    				}
    				if (!checkReward()) {
    					return;
    				}
    				SecureRandom RANDOM = new SecureRandom();
    				Position objd = ob.getPosition();
    				boolean fired = false;
    				player.getSkillManager().addExperience(Skill.WOODCUTTING,(int) (tree.experience * GameConstants.EXP_MULTIPLIER));
    				if (axe.getId() == 13241) {
    					if (RANDOM.nextInt() % 3 == 0) {
    						player.getSkillManager().addExperience(Skill.FIREMAKING, (int)(LogData.forId(tree.reward).getExperience() / 2) *(int) GameConstants.EXP_MULTIPLIER);
    						if (!ObjectHandler.objectExists(player.getPosition())) {
    							GameObject fireObject = new GameObject(LogData.forId(tree.reward).getFire(),player.getPosition());
    							ObjectHandler.spawnGlobalObject(fireObject);
    							TaskManager.submit(new Task((int)LogData.forId(tree.reward).getLife(),false) {
    
    								@Override
    								protected void execute() {
    									ObjectHandler.despawnGlobalObject(fireObject);
    									this.stop();
    									return;
    								}
    								
    							});
    						}
    						fired = true;
    					}
    				}
    				player.getPacketSender().sendMessage("You chop down the tree.");
    				player.setChopping(false);
    				ObjectHandler.despawnGlobalObject(ob);
    				ObjectHandler.spawnGlobalObject(new GameObject(tree.emptyId,objd));
    				player.performAnimation(Animation.DEFAULT_RESET_ANIMATION);
    				if (!fired) {
    					if (player.getInventory().isFull()) {
    						GroundItemManager.spawnGroundItem(player, new GroundItem(new Item(tree.reward),player.getPosition(),player.getUsername(),player.getHostAddress(),false,200,true,200));
    					} else {
    						player.getInventory().add(new Item(tree.reward,tree.rewardAmount));
    					}
    				}
    				TaskManager.submit(new Task(tree.respawnRate,false) {
    
    					@Override
    					protected void execute() {
    //						objd
    						GameObject go = RegionClipping.getGameObject(objd);
    						if (go == null) {
    							stop();
    							return;
    						}
    						ObjectHandler.despawnGlobalObject(go);
    						ObjectHandler.spawnGlobalObject(new GameObject(tree.getId(),objd));
    						
    					}
    					
    				});
    				this.stop();
    				return;
    			}
    			
    		});
    		
    	}
    	
    	boolean checkReward() {
    		int level = 1 + player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING);
    		double hostRatio = Math.random() * (100.0 * tree.rate);
    		double clientRatio = Math.random() * ((level - tree.level) * (1.0 + axe.getRatio()));
    		return hostRatio < clientRatio;
    	}
    	
    	
    	
    	public Axe getBestAxe() {
    		double rat = 0;
    		Axe a = null;
    		for (Item i : player.getInventory().getItems()) {
    			for (Axe axe : Axe.values()) {
    				if (i.getId() == axe.getId()) {
    					if (axe.getRatio() > rat && player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING) >= axe.getLevel()) {
    						rat = axe.getRatio();
    						a = axe;
    					}
    				}
    			}
    		}
    			for (Axe axe : Axe.values()) {
    				if (player.getEquipment().get(Equipment.WEAPON_SLOT).getId() == axe.getId()) {
    					if (axe.getRatio() > rat && player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING) >= axe.getLevel()) {
    						rat = axe.getRatio();
    						a = axe;
    					}
    				}
    			}
    		
    		return a;
    	}
    	
    	
    	
    	
    	
    	public static void init(Player player,Tree tree,GameObject ob) {
    		new Woodcutting(player,tree,ob).start();
    	}
    
    }
    And if you want to you can put in making the infernal axe by adding the below code.
    Code:
    package com.superscape.world.content.skills.woodcutting;
    
    import com.superscape.world.entity.impl.player.Player;
    import com.superscape.world.model.Animation;
    import com.superscape.world.model.Graphic;
    import com.superscape.world.model.Item;
    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.DialogueType;
    
    public class CreateInfernalAxe {
    	
    	/**
    	 * The player
    	 */
    	Player player;
    	
    	/**
    	 * The fusing animation
    	 */
    	private final Animation ANIMATION = new Animation(4511);
    	private final Graphic GFX = new Graphic(1240);
    	
    	public CreateInfernalAxe(Player player) {
    		this.player = player;
    	}
    	
    	public static void init(Player player) {
    		new CreateInfernalAxe(player).start();
    	}
    	
    	public void start() {
    		player.performAnimation(Animation.DEFAULT_RESET_ANIMATION);
    		player.performAnimation(ANIMATION);
    		player.performGraphic(GFX);
    		player.getInventory().delete(new Item(6739,1));
    		player.getInventory().delete(new Item(13233,1));
    		player.getInventory().add(new Item(13241,1));
    		DialogueManager.start(player, new Dialogue() {
    			@Override
    			public DialogueType type() {
    				return DialogueType.PLAYER_STATEMENT;
    			}
    
    			@Override
    			public DialogueExpression animation() {
    				return DialogueExpression.DEFAULT;
    			}
    
    			@Override
    			public String[] dialogue() {
    				return new String[] {"Wow! I created an extension of the axe.","I think I should try this out later."};
    			}
    			
    		});
    		return;//finished
    	}
    
    }
    Now for the changes in ObjectActionPacketListener.java right above the switch method and below the wilderness obelisk handling code put this
    Code:
    for (Tree tree : Tree.values()) {
    					if (id == tree.getId()) {
    						Woodcutting.init(player, tree,RegionClipping.getGameObject(position));
    						return;
    					}
    				}
    In UseItemPacketListener.java inside of the itemOnItem method add this code
    Code:
    if ((used.getId() == 6739 && usedWith.getId() == 13233) || (used.getId() == 13233 && usedWith.getId() == 6739)) {
    			CreateInfernalAxe.init(player);
    			return;
    		}
    and finally in Player.java define
    Code:
    private boolean chopping = false;
    Make its getters and setters too as its private

    If im missing anything from the code let me know and i will try fill in the bits im missing / update the code with better code.
    - Oscar < S C A P E >
    Have a nice day all


    why is ur log automaticly burning?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    May 2017
    Posts
    67
    Thanks given
    1
    Thanks received
    3
    Rep Power
    0
    Quote Originally Posted by zanariss View Post
    why is ur log automaticly burning?

    This release contains the most accurate formulas i could find and things like 1/3 chance of burning log when using infernal axe
    Here is ur answer, scroll up and read.
    Reply With Quote  
     

  4. #4  
    Registered Member Farage's Avatar
    Join Date
    Jan 2017
    Posts
    252
    Thanks given
    24
    Thanks received
    22
    Rep Power
    0
    Quote Originally Posted by mbongo View Post
    Here is ur answer, scroll up and read.
    Saved me time. Thanks. I don't think it should burn i might be wrong i don't have my own Infernal Axe in OSRS to test with, just scraps of info from the osrs wiki.
    Have a nice day!
    Иди в пизду!
    Bonne journée!
    Einen schönen Tag noch!
    Hezký den!
    祝你今天愉快!
    Reply With Quote  
     

  5. #5  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    978
    Thanks given
    684
    Thanks received
    449
    Rep Power
    672
    Quote Originally Posted by S C A P E View Post
    Code:
    	STANDARD_TREE_1(1276, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    wtf is this shit in the enum bro.

    Also in your second enum you don't have to include the "D" on the end of all the double values afaik.
    Reply With Quote  
     

  6. Thankful users:


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

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    24
    Posts
    538
    Thanks given
    216
    Thanks received
    98
    Rep Power
    113
    You must just love using the player parameter to instance everything..
    Code:
    	public CreateInfernalAxe(Player player) {
    		this.player = player;
    	}
    	
    	public static void init(Player player) {
    		new CreateInfernalAxe(player).start();
    	}
    Just, why?
    That entire class could be;
    Code:
    	public static void start(final Player player) {
    		player.performAnimation(Animation.DEFAULT_RESET_ANIMATION);
    		player.performAnimation(ANIMATION);
    		player.performGraphic(GFX);
    		player.getInventory().delete(new Item(6739,1));
    		player.getInventory().delete(new Item(13233,1));
    		player.getInventory().add(new Item(13241,1));
    		DialogueManager.start(player, new Dialogue() {
    			@Override
    			public DialogueType type() {
    				return DialogueType.PLAYER_STATEMENT;
    			}
    
    			@Override
    			public DialogueExpression animation() {
    				return DialogueExpression.DEFAULT;
    			}
    
    			@Override
    			public String[] dialogue() {
    				return new String[] {"Wow! I created an extension of the axe.","I think I should try this out later."};
    			}
    			
    		});
    		return;//finished
    	}
    Code:
    	STANDARD_TREE_1(1276, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_2(1277, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1343),
    	STANDARD_TREE_3(1278, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_4(1279, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_5(1280, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1343),
    	STANDARD_TREE_6(1330, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_7(1331, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_8(1332, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1341),
    	STANDARD_TREE_9(2409, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_10(3033, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_11(3034, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1345),
    	STANDARD_TREE_12(3035, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1347),
    	STANDARD_TREE_13(3036, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1351),
    	STANDARD_TREE_14(3879, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_15(3881, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_16(3882, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3880),
    	STANDARD_TREE_17(3883, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 3884),
    	STANDARD_TREE_18(10041, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_19(14308, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_20(14309, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_21(16264, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342),
    	STANDARD_TREE_22(16265, 1, 0.05, 50 | 100 << 16, 25.0, 1511, 1, "tree", null, 1342);
    You can definitely tell which tree is which with this.

    Why are you giving regular logs for all of these trees? Are they all normal trees? If these are all normal trees, you're misusing this enum terribly.
    Why are you defining a reward amount, and the log as an integer? Separately no less. All it takes is "new Item(1511)", or "new Item(1511, 1)"

    Again, assuming that these are possibly all regular trees, and the ONLY values different for each constant is the id, and the 'emptyId'..
    Why didn't you use an array for the id, and emptyId, effectively creating only a single constant for all the data?
    Then, you don't have this clutter of utter crap when you go to add Oak, Willow, Maple, and so on.
    Code:
    	STANDARD_TREE(new int[] {1276, 1277, 1278}, 1, 0.05, (50 | 100 << 16), 25.0, 1511, 1, "tree", null, new int[] {1342, 1343, 1345}),
    Oh and as you can see^ parenthesis aren't always bad, it makes this much easier to read.

    And yet again, you've created a setter in the Tree enum.
    Code:
    	public void setId(int id) {
    		this.id = id;
    	}
    Quote Originally Posted by S C A P E View Post
    Saved me time. Thanks. I don't think it should burn i might be wrong i don't have my own Infernal Axe in OSRS to test with, just scraps of info from the osrs wiki.
    I've never seen it myself, but I would have to assume its like adze and instead of actually creating a fire object,
    I would assume it instead of giving the player a log to begin with, just gives them firemaking experience, and sends a message.

    Spoiler for Revy is perfect:
    Reply With Quote  
     

  8. Thankful users:


  9. #7  
    Howdy

    gold_fish's Avatar
    Join Date
    Nov 2010
    Posts
    1,062
    Thanks given
    144
    Thanks received
    147
    Rep Power
    107
    Quote Originally Posted by Andys1814 View Post
    wtf is this shit in the enum bro.

    Also in your second enum you don't have to include the "D" on the end of all the double values afaik.
    Those would be bitwise operators...

    Reply With Quote  
     

  10. #8  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    978
    Thanks given
    684
    Thanks received
    449
    Rep Power
    672
    Quote Originally Posted by nMik View Post
    Those would be bitwise operators...
    lol thanks genius. Now why is he using them?
    Reply With Quote  
     

  11. Thankful users:


  12. #9  
    Registered Member Farage's Avatar
    Join Date
    Jan 2017
    Posts
    252
    Thanks given
    24
    Thanks received
    22
    Rep Power
    0
    Quote Originally Posted by Andys1814 View Post
    lol thanks genius. Now why is he using them?
    Arios used them and i got the respawn rates off of arios. They used alot of bitwise operators its quite odd.
    Have a nice day!
    Иди в пизду!
    Bonne journée!
    Einen schönen Tag noch!
    Hezký den!
    祝你今天愉快!
    Reply With Quote  
     

  13. #10  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    20
    Posts
    3,377
    Thanks given
    7,120
    Thanks received
    1,879
    Discord
    View profile
    Rep Power
    3454
    Doesn't seem like you like to take criticism of your code seeing as you don't seem to have improved your design at all since your last two releases.
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  14. Thankful users:


Page 1 of 3 123 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] Cooking Skill
    By Farage in forum Snippets
    Replies: 10
    Last Post: 07-22-2017, 09:32 PM
  2. [Elvarg / OSRSPK] Firemaking Skill
    By Farage in forum Snippets
    Replies: 32
    Last Post: 07-20-2017, 05:49 AM
  3. Replies: 9
    Last Post: 08-07-2016, 06:59 PM
  4. Need Help With Woodcutting Skill [718]
    By ItsStino in forum Help
    Replies: 9
    Last Post: 05-31-2014, 06:21 AM
  5. Replies: 3
    Last Post: 08-12-2011, 04:19 PM
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
  •