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.
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 itCode: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; } }
And now for Woodcutting.java itselfCode: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 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 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(); } }
Now for the changes in ObjectActionPacketListener.java right above the switch method and below the wilderness obelisk handling code put thisCode: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 } }
In UseItemPacketListener.java inside of the itemOnItem method add this codeCode:for (Tree tree : Tree.values()) { if (id == tree.getId()) { Woodcutting.init(player, tree,RegionClipping.getGameObject(position)); return; } }
and finally in Player.java defineCode:if ((used.getId() == 6739 && usedWith.getId() == 13233) || (used.getId() == 13233 && usedWith.getId() == 6739)) { CreateInfernalAxe.init(player); return; }
Make its getters and setters too as its privateCode:private boolean chopping = false;
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?









Just, why?


