Code:
package com.ruseps.world.content.skill.impl.woodcutting;
import com.ruseps.engine.task.Task;
import com.ruseps.engine.task.TaskManager;
import com.ruseps.model.Animation;
import com.ruseps.model.GameObject;
import com.ruseps.model.Skill;
import com.ruseps.model.container.impl.Equipment;
import com.ruseps.util.Misc;
import com.ruseps.world.content.Achievements;
import com.ruseps.world.content.CustomObjects;
import com.ruseps.world.content.EvilTrees;
import com.ruseps.world.content.Sounds;
import com.ruseps.world.content.Achievements.AchievementData;
import com.ruseps.world.content.Sounds.Sound;
import com.ruseps.world.content.skill.impl.firemaking.Logdata;
import com.ruseps.world.content.skill.impl.firemaking.Logdata.logData;
import com.ruseps.world.content.skill.impl.woodcutting.WoodcuttingData.Hatchet;
import com.ruseps.world.content.skill.impl.woodcutting.WoodcuttingData.Trees;
import com.ruseps.world.entity.impl.player.Player;
public class Woodcutting {
public static void cutWood(final Player player, final GameObject object, boolean restarting) {
if(!restarting)
player.getSkillManager().stopSkilling();
if(player.getInventory().getFreeSlots() == 0) {
player.getPacketSender().sendMessage("You don't have enough free inventory space.");
return;
}
player.setPositionToFace(object.getPosition());
final int objId = object.getId();
final Hatchet h = Hatchet.forId(WoodcuttingData.getHatchet(player));
if (h != null) {
if (player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING) >= h.getRequiredLevel()) {
final WoodcuttingData.Trees t = WoodcuttingData.Trees.forId(objId);
if (t != null) {
player.setEntityInteraction(object);
if (player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING) >= t.getReq()) {
player.performAnimation(new Animation(h.getAnim()));
int delay = Misc.getRandom(t.getTicks() - WoodcuttingData.getChopTimer(player, h)) +1;
player.setCurrentTask(new Task(1, player, false) {
int cycle = 0, reqCycle = delay >= 2 ? delay : Misc.getRandom(1) + 1;
@Override
public void execute() {
if(player.getInventory().getFreeSlots() == 0) {
player.performAnimation(new Animation(65535));
player.getPacketSender().sendMessage("You don't have enough free inventory space.");
this.stop();
return;
}
if (cycle != reqCycle) {
cycle++;
player.performAnimation(new Animation(h.getAnim()));
} else if (cycle >= reqCycle) {
int xp = t.getXp();
if(lumberJack(player))
xp *= 1.5;
player.getSkillManager().addExperience(Skill.WOODCUTTING, xp);
cycle = 0;
BirdNests.dropNest(player);
this.stop();
if (object.getId() == 11434) {
if (EvilTrees.SPAWNED_TREE == null || EvilTrees.SPAWNED_TREE.getTreeObject().getCutAmount() >= EvilTrees.MAX_CUT_AMOUNT) {
player.getPacketSender().sendClientRightClickRemoval();
player.getSkillManager().stopSkilling();
return;
} else {
EvilTrees.SPAWNED_TREE.getTreeObject().incrementCutAmount();
}
//} else {
//player.performAnimation(new Animation(65535));
}
if (!t.isMulti() || Misc.getRandom(10) == 2) {
treeRespawn(player, object);
player.getPacketSender().sendMessage("You've chopped the tree down.");
player.performAnimation(new Animation(65535));
player.setSkillPoints(player.getSkillPoints() + 1);
player.sendMessage("<img=10>You now have @red@" + player.getSkillPoints() + " Skilling Points!");
} else {
cutWood(player, object, true);
player.getPacketSender().sendMessage("You get some logs..");
player.setSkillPoints(player.getSkillPoints() + 1);
player.sendMessage("<img=10>You now have @red@" + player.getSkillPoints() + " Skilling Points!");
}
Sounds.sendSound(player, Sound.WOODCUT);
if(!(infernoAdze(player) && Misc.getRandom(5) <= 2)) {
player.getInventory().add(t.getReward(), 1);
} else if(Misc.getRandom(5) <= 2) {
logData fmLog = Logdata.getLogData(player, t.getReward());
if(fmLog != null) {
player.getSkillManager().addExperience(Skill.FIREMAKING, fmLog.getXp());
player.getPacketSender().sendMessage("Your Inferno Adze burns the log, granting you Firemaking experience.");
if(fmLog == Logdata.logData.OAK) {
Achievements.finishAchievement(player, AchievementData.BURN_AN_OAK_LOG);
} else if(fmLog == Logdata.logData.MAGIC) {
Achievements.doProgress(player, AchievementData.BURN_100_MAGIC_LOGS);
Achievements.doProgress(player, AchievementData.BURN_2500_MAGIC_LOGS);
}
}
}
if(t == Trees.OAK) {
Achievements.finishAchievement(player, AchievementData.CUT_AN_OAK_TREE);
} else if(t == Trees.MAGIC) {
Achievements.doProgress(player, AchievementData.CUT_100_MAGIC_LOGS);
Achievements.doProgress(player, AchievementData.CUT_5000_MAGIC_LOGS);
}
}
}
});
TaskManager.submit(player.getCurrentTask());
} else {
player.getPacketSender().sendMessage("You need a Woodcutting level of at least "+t.getReq()+" to cut this tree.");
}
}
} else {
player.getPacketSender().sendMessage("You do not have a hatchet which you have the required Woodcutting level to use.");
}
} else {
player.getPacketSender().sendMessage("You do not have a hatchet that you can use.");
}
}
public static boolean lumberJack(Player player) {
return player.getEquipment().get(Equipment.HEAD_SLOT).getId() == 10941 && player.getEquipment().get(Equipment.BODY_SLOT).getId() == 10939 && player.getEquipment().get(Equipment.LEG_SLOT).getId() == 10940 && player.getEquipment().get(Equipment.FEET_SLOT).getId() == 10933;
}
public static boolean infernoAdze(Player player) {
return player.getEquipment().get(Equipment.WEAPON_SLOT).getId() == 13661;
}
public static void treeRespawn(final Player player, final GameObject oldTree) {
if(oldTree == null || oldTree.getPickAmount() >= 1)
return;
oldTree.setPickAmount(1);
for(Player players : player.getLocalPlayers()) {
if(players == null)
continue;
if(players.getInteractingObject() != null && players.getInteractingObject().getPosition().equals(player.getInteractingObject().getPosition().copy())) {
players.getSkillManager().stopSkilling();
players.getPacketSender().sendClientRightClickRemoval();
}
}
player.getPacketSender().sendClientRightClickRemoval();
player.getSkillManager().stopSkilling();
CustomObjects.globalObjectRespawnTask(new GameObject(1343, oldTree.getPosition().copy(), 10, 0), oldTree, 20 + Misc.getRandom(10));
}
}
Code:
package com.ruseps.world.content.skill.impl.woodcutting;
import java.util.HashMap;
import java.util.Map;
import com.ruseps.model.Skill;
import com.ruseps.model.container.impl.Equipment;
import com.ruseps.world.entity.impl.player.Player;
public class WoodcuttingData {
public static enum Hatchet {
BRONZE(1351, 1, 879, 1.0),
IRON(1349, 1, 877, 1.3),
STEEL(1353, 6, 875, 1.5),
BLACK(1361, 6, 873, 1.7),
MITHRIL(1355, 21, 871, 1.9),
ADAMANT(1357, 31, 869, 2),
RUNE(1359, 41, 867, 2.2),
DRAGON(6739, 61, 2846, 2.28),
ADZE(13661, 80, 10227, 2.5);
private int id, req, anim;
private double speed;
private Hatchet(int id, int level, int animation, double speed) {
this.id = id;
this.req = level;
this.anim = animation;
this.speed = speed;
}
public static Map<Integer, Hatchet> hatchets = new HashMap<Integer, Hatchet>();
public static Hatchet forId(int id) {
return hatchets.get(id);
}
static {
for(Hatchet hatchet : Hatchet.values()) {
hatchets.put(hatchet.getId(), hatchet);
}
}
public int getId() {
return id;
}
public int getRequiredLevel() {
return req;
}
public int getAnim() {
return anim;
}
public double getSpeed() {
return speed;
}
}
public static enum Trees {
NORMAL(1, 3655, 1511, new int[] { 1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1319, 1330, 1331, 1332, 1365, 1383, 1384, 3033, 3034, 3035, 3036, 3881, 3882, 3883, 5902, 5903, 5904 }, 4, false),
ACHEY(1, 3655, 2862, new int[] { 2023 }, 4, false),
OAK(15, 4684, 1521, new int[] { 1281, 3037 }, 5, true),
WILLOW(30, 6346, 1519, new int[] { 1308, 5551, 5552, 5553 }, 6, true),
TEAK(35, 6544, 6333, new int[] { 9036 }, 7, true),
DRAMEN(36, 6581, 771, new int[] { 1292 }, 7, true),
MAPLE(45, 7935, 1517, new int[] { 1307, 4677 }, 7, true),
MAHOGANY(50, 8112, 6332, new int[] { 9034 }, 7, true),
YEW(60, 8417, 1515, new int[] { 1309 }, 8, true),
MAGIC(75, 9127, 1513, new int[] { 1306 }, 9, true);
private int[] objects;
private int req, xp, log, ticks;
private boolean multi;
private Trees(int req, int xp, int log, int[] obj, int ticks, boolean multi) {
this.req = req;
this.xp = xp;
this.log = log;
this.objects = obj;
this.ticks = ticks;
this.multi = multi;
}
public boolean isMulti() {
return multi;
}
public int getTicks() {
return ticks;
}
public int getReward() {
return log;
}
public int getXp() {
return xp;
}
public int getReq() {
return req;
}
private static final Map<Integer, Trees> tree = new HashMap<Integer, Trees>();
public static Trees forId(int id) {
return tree.get(id);
}
static {
for (Trees t : Trees.values()) {
for (int obj : t.objects) {
tree.put(obj, t);
}
}
}
}
public static int getHatchet(Player p) {
for (Hatchet h : Hatchet.values()) {
if (p.getEquipment().getItems()[Equipment.WEAPON_SLOT].getId() == h.getId()) {
return h.getId();
} else if (p.getInventory().contains(h.getId())) {
return h.getId();
}
}
return -1;
}
public static int getChopTimer(Player player, Hatchet h) {
int skillReducement = (int) (player.getSkillManager().getMaxLevel(Skill.WOODCUTTING) * 0.05);
int axeReducement = (int) h.getSpeed();
return skillReducement + axeReducement;
}
}