Code:
package org.fury.rs2.model.content.skill.gathering;
import org.fury.rs2.model.action.Action;
import org.fury.rs2.model.Animation;
import org.fury.rs2.model.entity.player.Player;
import org.fury.rs2.model.Item;
import org.fury.rs2.model.World;
import org.fury.rs2.net.packet.out.SendMessagePacket;
public class Woodcutting {
public enum Tree {
OAK_TREE(new int[] {1281, 2037},
150, 37.5, 1521),
WILLOW_TREE(new int[] {1308,5551, 5552, 5553},
30, 67.5, 1519),
TEAK_TREE(new int[] {9036},
35, 85, 6333),
MAPLE_TREE(new int[] {1307, 4677},
45, 100, 1517),
HOLLOW_TREE(new int[] {2289, 4060},
45, 83, 3239),
MAHOGANY_TREE(new int[] {9034},
50, 125, 6332),
YEW_TREE(new int[] {1309},
60, 175, 1515),
MAGIC_TREE(new int[] {1306},
75, 250, 1513),
DRAMEN_TREE(new int[] {1292},
36, 0, 771),
NORMAL_TREE(new int[] {
1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284,
1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1319,
1330, 1331, 1332, 1333, 1365, 1383, 1384, 2409, 3033,
3034, 3035, 3036, 3881, 3882, 3883, 5902, 5903, 5904 },
1, 25, 1511);
private int[] id;
private int level, log;
private double xp;
public static Tree getTree(int id) {
for (Tree tree : Tree.values()) {
for (int ids : tree.getId()) {
if (ids == id) {
return tree;
}
}
}
return null;
}
private Tree(int[] id, int level, double xp, int log) {
this.id = id;
this.level = level;
this.xp = xp;
this.log = log;
}
public int[] getId() { return id; };
public int getLevel() { return level; };
public double getXP() { return xp; };
public int getLog() { return log; };
}
public static final int AXE_DATA[][] = {
{1359, 867, 600},
{1357, 869, 800},
{1355, 871, 1000},
{1361, 873, 1200},
{1353, 875, 1400},
{1349, 877, 1600},
{1351, 879, 1800}
};
public static void handle(final Player player, int id) {
player.SKILLING_TEMP = -1;
final Tree tree = Tree.getTree(id);
if (tree == null) {
return;
}
if (player.getSkills().getLevel(8) < tree.getLevel()) {
player.write(new SendMessagePacket("You need a Woodcutting level of @dre@" + tree.getLevel() + "@bla@ to cut @dre@" + tree.toString().replace('_', ' ').toLowerCase() + "s@bla@."));
return;
}
//player.write(new SendMessagePacket("/" + player.getEquipment().get(3).getDefinition().getId()));
for (int i = 0; i < AXE_DATA.length; i++){
if (player.SKILLING_TEMP > -1) {
break;
} else if (player.getInventory().playerHasItem(AXE_DATA[i][0]) || player.getEquipment().get(3).getDefinition().getId() == AXE_DATA[i][0]) {
player.SKILLING_TEMP = i;
break;
} else {
player.SKILLING_TEMP = -1;
}
}
if (player.SKILLING_TEMP == -1) {
player.write(new SendMessagePacket("@red@You don't have an axe to start woodcutting."));
return;
}
if (player.getInventory().freeSlots() <= 0 && !player.getInventory().playerHasItem(tree.getLog())) {
player.write(new SendMessagePacket("@red@There isn't enough room in your inventory to cut logs."));
return;
}
player.getActionQueue().addAction(new Action(player, AXE_DATA[player.SKILLING_TEMP][2]) {
@Override
public QueuePolicy getQueuePolicy() {
return QueuePolicy.NEVER;
}
@Override
public WalkablePolicy getWalkablePolicy() {
return WalkablePolicy.NON_WALKABLE;
}
@Override
public void execute() {
player.write(new SendMessagePacket("tick"));
player.getInventory().add(new Item(tree.getLog(), 1));
player.playAnimation(Animation.create(AXE_DATA[player.SKILLING_TEMP][1])); // NEED TO TRIGGER EVERY 4 TICKS.
}
@Override
public StackPolicy getStackPolicy() {
return StackPolicy.NEVER;
}
@Override
public AnimationPolicy getAnimationPolicy() {
return AnimationPolicy.RESET_ANIMATION;
}
@Override
public void stop() {
player.write(new SendMessagePacket("@red@You stop woodcutting."));
super.stop();
getPlayer().playAnimation(Animation.create(-1));
player.getActionQueue().processNextAction();
}
});
}
}
There is also a
ObjectHarvestingAction class, should I be utilizing this? I used it but noticed no major difference really to my understanding but if some could shine some light on that it would be useful. The mentioned class is below:
Code:
package org.fury.rs2.model.action.impl;
import org.fury.rs2.model.Animation;
import org.fury.rs2.model.action.Action;
import org.fury.rs2.model.entity.player.Player;
import org.fury.rs2.model.object.GameObject;
/**
* Handles object harvesting actions.
*
* @author Thomas
*
*/
public abstract class ObjectHarvestingAction extends Action {
/**
* Constructs a new <code>ObjectHarvestingAction</code>.
*
* @param player
* The player to construct the action for.
* @param object
* The object to harvest from.
*/
public ObjectHarvestingAction(Player player, GameObject object) {
super(player, 0);
this.object = object;
}
@Override
public QueuePolicy getQueuePolicy() {
return QueuePolicy.NEVER;
}
@Override
public WalkablePolicy getWalkablePolicy() {
return WalkablePolicy.NON_WALKABLE;
}
@Override
public void execute() {
if (this.getDelay() == 0) {
this.setDelay(getHarvestDelay());
this.canHarvest();
} else {
if (!this.process()) {
getPlayer().playAnimation(Animation.create(-1));
this.stop();
return;
}
this.init();
}
}
/**
* The <code>GameObject we're harvesting.
*/
protected GameObject object;
/**
* Gets the harvest delay.
* @return The harvest delay.
*/
public abstract long getHarvestDelay();
/**
* Called when the action is initialized.
*/
public abstract void init();
/**
* Can the player harvest?
* @return If the player can harvest; <code>true</code>, if the player can not harvest;
* <code>false</code>.
*/
public abstract boolean canHarvest();
/**
* Process stuff in the action (i.e. animations).
* @return If the action can continue to process; <code>true</code>, if the action
* can not continue to process; <code>false</code>.
*/
public abstract boolean process();
}
It's not meant to mimic RuneScape, I'm looking on feedback on how it's working currently. Thanks for your time
edit; also need to change time to harvest logs depending on woodcutting level AND axe not just a preset time for each axe.
edit2: maybe "not meant to mimic RuneScape" was too vague, I have no intention on adding a tree becoming a stump but I think I'll add birds nests.
edit3:
_Partick_ suggested changing the AXE_DATA array to an enum, you can find what I wrote
here but it's what you'd expect really. Also noticed that I need to loop the woodcutting animation correctly, I found
https://www.rune-server.org/runescap...-cheaphax.html but not sure if that's the right way but it's pointing me in the right direction. So this is what I have now:
Code:
package org.fury.rs2.model.content.skill.gathering;
import org.fury.rs2.model.action.Action;
import org.fury.rs2.model.Animation;
import org.fury.rs2.model.entity.player.Player;
import org.fury.rs2.model.Item;
import org.fury.rs2.model.World;
import org.fury.rs2.net.packet.out.SendMessagePacket;
/**
* Woodcutting skill
*
* @author cloak
*
*/
public class Woodcutting {
public enum Tree {
OAK_TREE(new int[] {1281, 2037},
150, 37.5, 1521),
WILLOW_TREE(new int[] {1308,5551, 5552, 5553},
30, 67.5, 1519),
TEAK_TREE(new int[] {9036},
35, 85, 6333),
MAPLE_TREE(new int[] {1307, 4677},
45, 100, 1517),
HOLLOW_TREE(new int[] {2289, 4060},
45, 83, 3239),
MAHOGANY_TREE(new int[] {9034},
50, 125, 6332),
YEW_TREE(new int[] {1309},
60, 175, 1515),
MAGIC_TREE(new int[] {1306},
75, 250, 1513),
DRAMEN_TREE(new int[] {1292},
36, 0, 771),
NORMAL_TREE(new int[] {
1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284,
1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1319,
1330, 1331, 1332, 1333, 1365, 1383, 1384, 2409, 3033,
3034, 3035, 3036, 3881, 3882, 3883, 5902, 5903, 5904 },
1, 25, 1511);
private int[] id;
private int level, log;
private double xp;
public static Tree getTree(int id) {
for (Tree tree : Tree.values()) {
for (int ids : tree.getId()) {
if (ids == id) {
return tree;
}
}
}
return null;
}
private Tree(int[] id, int level, double xp, int log) {
this.id = id;
this.level = level;
this.xp = xp;
this.log = log;
}
public int[] getId() { return id; };
public int getLevel() { return level; };
public double getXP() { return xp; };
public int getLog() { return log; };
}
public enum Axe {
BRONZE_AXE(1351, 1, 879),
IRON_AXE(1349, 1, 877),
STEEL_AXE(1353, 6, 875),
BLACK_AXE(1361, 11, 873),
MITHRIL_AXE(1355, 21, 871),
ADAMANT_AXE(1357, 31, 869),
RUNE_AXE(1359, 41, 867);
int id, level, anim, delay;
public static Axe getAxe(Player player) {
for (Axe axe : Axe.values()) {
if (player.getInventory().playerHasItem(axe.getId()) || player.getEquipment().contains(axe.getId())) {
return axe;
}
}
return null;
}
private Axe(int id, int level, int anim) {
this.id = id;
this.level = level;
this.anim = anim;
}
public int getId() { return id; };
public int getLevel() { return level; };
public int getAnim() { return anim; };
}
public static void handle(final Player player, int id) {
final Tree tree = Tree.getTree(id);
final Axe axe = Axe.getAxe(player);
if (tree == null) {
return;
}
if (axe == null) {
player.write(new SendMessagePacket("@red@You don't have an axe to start woodcutting."));
return;
}
if (player.getSkills().getLevel(8) < tree.getLevel()) {
player.write(new SendMessagePacket("You need a Woodcutting level of @dre@" + tree.getLevel() + "@bla@ to cut @dre@" + tree.toString().replace('_', ' ').toLowerCase() + "s@bla@."));
return;
}
if (player.getSkills().getLevel(8) < axe.getLevel()) {
player.write(new SendMessagePacket("You need a Woodcutting level of @dre@" + axe.getLevel() + "@bla@ to use a @dre@" + axe.toString().replace('_', ' ').toLowerCase() + "@bla@."));
return;
}
if (player.getInventory().freeSlots() <= 0 && !player.getInventory().playerHasItem(tree.getLog())) {
player.write(new SendMessagePacket("@red@There isn't enough room in your inventory to cut logs."));
return;
}
player.getActionQueue().addAction(new Action(player, 600) {
@Override
public QueuePolicy getQueuePolicy() {
return QueuePolicy.NEVER;
}
@Override
public WalkablePolicy getWalkablePolicy() {
return WalkablePolicy.NON_WALKABLE;
}
@Override
public void execute() {
player.write(new SendMessagePacket("tick"));
player.getInventory().add(new Item(tree.getLog(), 1));
player.playAnimation(Animation.create(axe.getAnim())); // NEED TO TRIGGER EVERY 4 TICKS.
}
@Override
public StackPolicy getStackPolicy() {
return StackPolicy.NEVER;
}
@Override
public AnimationPolicy getAnimationPolicy() {
return AnimationPolicy.RESET_ANIMATION;
}
@Override
public void stop() {
player.write(new SendMessagePacket("@red@You stop woodcutting."));
super.stop();
getPlayer().playAnimation(Animation.create(-1));
player.getActionQueue().processNextAction();
}
});
}
}
Thanks for the help! if there's anything else please reply, I'd like to make sure I'm doing things correctly.