public static void cutTree(Player p, ushort treeId, Location treeLocation, int i, bool newCut, int distance) { if (!newCut && p.getTemporaryAttribute("cuttingTree") == null) { return; } if (newCut) { if (i == 10 || i == 11) { // Magic or Yew tree. if (!Server.getGlobalObjects().objectExists(treeId, treeLocation)) { // misc.WriteError(p.getUsername() + " tried to cut a non existing Magic or Yew tree!"); // return; } } Tree newTree = new Tree(i, treeId, treeLocation, LOGS[i], LEVEL[i], TREE_NAME[i], XP[i], distance); p.setTemporaryAttribute("cuttingTree", newTree); } Tree treeToCut = (Tree) p.getTemporaryAttribute("cuttingTree"); if (!canCut(p, treeToCut, null)) { resetWoodcutting(p); return; } if (newCut) { p.setLastAnimation(new Animation(getAxeAnimation(p))); p.setFaceLocation(treeLocation); p.getPackets().sendMessage("You begin to swing your axe at the tree.."); } int delay = getCutTime(p, treeToCut.getTreeIndex()); Event cutTreeEvent = new Event(delay); cutTreeEvent.setAction(() => { cutTreeEvent.stop(); if (p.getTemporaryAttribute("cuttingTree") == null) { resetWoodcutting(p); return; } Tree tree = (Tree) p.getTemporaryAttribute("cuttingTree"); if (!canCut(p, treeToCut, tree)) { resetWoodcutting(p); return; } Server.getGlobalObjects().lowerHealth(tree.getTreeId(), tree.getTreeLocation()); if (!Server.getGlobalObjects().originalObjectExists(tree.getTreeId(), tree.getTreeLocation())) { resetWoodcutting(p); p.setLastAnimation(new Animation(65535)); } if (p.getInventory().addItem(tree.getLog())) { p.getPackets().closeInterfaces(); int index = tree.getTreeIndex(); string s = index == 1 || index == 3 || index == 8 ? "an" : "a"; p.getSkills().addXp(Skills.SKILL.WOODCUTTING, tree.getXp()); if (index == 6 ) { p.getPackets().sendMessage("You retrieve some Hollow bark from the tree."); } else { p.getPackets().sendMessage("You cut down " + s + " " + tree.getName() + " log."); } if (misc.random(3) == 0) { int nestId = misc.random(10) == 0 ? 5073 : 5074; GroundItem g = new GroundItem(nestId, 1, new Location(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ()), p); Server.getGroundItems().newEntityDrop(g); p.getPackets().sendMessage("Something falls out of the tree and lands at your feet."); } } cutTree(p, tree.getTreeId(), tree.getTreeLocation(), tree.getTreeIndex(), false, tree.getDistance()); }); Server.registerEvent(cutTreeEvent); if (delay >= 2550) { Event treeCuttingAnimationEvent = new Event(2550); int time = delay; treeCuttingAnimationEvent.setAction(() => { time -= 2550; if (time <= 0) { treeCuttingAnimationEvent.stop(); } Tree tree = (Tree) p.getTemporaryAttribute("cuttingTree"); if (!canCut(p, treeToCut, tree)) { treeCuttingAnimationEvent.stop(); return; } p.setFaceLocation(treeLocation); p.setLastAnimation(new Animation(getAxeAnimation(p))); }); Server.registerEvent(treeCuttingAnimationEvent); } }
private static void chopTree( Player p, Patch patch) { if (patch.isFruitTree()) { chopFruitTree(p, patch); return; } if (!Woodcutting.hasAxe(p)) { p.getPackets().sendMessage("You don't have an axe."); return; } if (!hasLevelToCutTree(p, patch)) { p.getPackets().sendMessage("You will recieve no logs from this tree, due to your Woodcutting level."); } Tree newTree = new Tree(0, 0, null, (int)SEEDS[patch.getSeedIndex()][2], 0, (string)SEEDS[patch.getSeedIndex()][7], (double)SEEDS[patch.getSeedIndex()][11], 0); p.setTemporaryAttribute("cuttingTree", newTree); p.setLastAnimation(new Animation(Woodcutting.getAxeAnimation(p))); p.getPackets().sendMessage("You begin to swing your axe at the tree.."); long delay = getCutTime(p, patch); bool canRecieveLog = hasLevelToCutTree(p, patch); Event chopTreeEvent = new Event(delay); chopTreeEvent.setAction(() => { long timeSinceLastAnimation = Environment.TickCount; if (!Woodcutting.hasAxe(p)) { p.getPackets().sendMessage("You don't have an axe."); Woodcutting.resetWoodcutting(p); chopTreeEvent.stop(); return; } if (p.getTemporaryAttribute("cuttingTree") == null) { Woodcutting.resetWoodcutting(p); chopTreeEvent.stop(); return; } Tree tree = (Tree)p.getTemporaryAttribute("cuttingTree"); if (!newTree.Equals(tree)) { chopTreeEvent.stop(); return; } if (canRecieveLog) { string s = tree.getLog() == 1521 ? "an" : "a"; if (p.getInventory().addItem(tree.getLog())) { p.getSkills().addXp(Skills.SKILL.WOODCUTTING, tree.getXp()); p.getPackets().sendMessage("You cut down " + s + " " + tree.getName() + " log."); } else { p.getPackets().sendChatboxInterface(210); p.getPackets().modifyText("Your inventory is too full to carry any logs.", 210, 1); p.setLastAnimation(new Animation(65535)); chopTreeEvent.stop(); return; } } if (misc.random(canRecieveLog ? 2 : 0) == 0) { p.setLastAnimation(new Animation(65535)); patch.setStatus(patch.getConfigLength() - 1); setConfig(p, patch); chopTreeEvent.stop(); return; } if (Environment.TickCount - timeSinceLastAnimation >= 2550) { p.setLastAnimation(new Animation(Woodcutting.getAxeAnimation(p))); timeSinceLastAnimation = Environment.TickCount; } }); Server.registerEvent(chopTreeEvent); }
private static bool canCut(Player p, Tree tree, Tree tree2) { if (tree == null || p == null || !Server.getGlobalObjects().originalObjectExists(tree.getTreeId(), tree.getTreeLocation())) { return false; } if (!p.getLocation().withinDistance(tree.getTreeLocation(), tree.getDistance())) { return false; } if (tree2 != null) { if (!tree.Equals(tree2)) { return false; } } if (p.getSkills().getGreaterLevel(Skills.SKILL.WOODCUTTING) < tree.getLevel()) { p.getPackets().sendMessage("You need a Woodcutting level of " + tree.getLevel() + " to cut that tree."); return false; } if (!hasAxe(p)) { p.getPackets().sendMessage("You need an axe to cut down a tree!"); return false; } if (p.getInventory().findFreeSlot() == -1) { p.getPackets().sendChatboxInterface(210); p.getPackets().modifyText("Your inventory is too full to carry any logs.", 210, 1); return false; } return true; }