RuneHive-Game
Loading...
Searching...
No Matches
WoodcuttingAction.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.woodcutting;
2
3import com.runehive.Config;
4import com.runehive.content.achievement.AchievementHandler;
5import com.runehive.content.achievement.AchievementKey;
6import com.runehive.content.activity.randomevent.RandomEventHandler;
7import com.runehive.content.clanchannel.content.ClanTaskKey;
8import com.runehive.content.pet.PetData;
9import com.runehive.content.pet.Pets;
10import com.runehive.content.prestige.PrestigePerk;
11import com.runehive.content.skill.impl.firemaking.FiremakingData;
12import com.runehive.content.skillcape.SkillCape;
13import com.runehive.game.action.Action;
14import com.runehive.game.action.policy.WalkablePolicy;
15import com.runehive.game.task.impl.ObjectReplacementEvent;
16import com.runehive.game.world.World;
17import com.runehive.game.world.entity.mob.player.Player;
18import com.runehive.game.world.entity.skill.Skill;
19import com.runehive.game.world.items.Item;
20import com.runehive.game.world.items.ItemDefinition;
21import com.runehive.game.world.object.GameObject;
22import com.runehive.game.world.position.Area;
23import com.runehive.net.packet.out.SendMessage;
24import com.runehive.util.RandomUtils;
25import com.runehive.util.Utility;
26
27import java.util.Optional;
28
29/**
30 * Handles the woodcutting action event.
31 *
32 * @author Daniel
33 */
34public class WoodcuttingAction extends Action<Player> {
35 private final GameObject object;
36 private final TreeData tree;
37 private final AxeData axe;
38
40 super(mob, 3, false);
41 this.object = object;
42 this.tree = tree;
43 this.axe = axe;
44 }
45
46 private boolean chop() {
47 if (getMob().inventory.getFreeSlots() == 0) {
48 getMob().dialogueFactory.sendStatement("You can't carry anymore logs.").execute();
49 return false;
50 }
51
52 getMob().animate(axe.animation);
53
55 if (object == null || !object.active()) {
56 return false;
57 }
58
61 Pets.onReward(getMob(), PetData.BEAVER.getItem(), 6250);
62 getMob().send(new SendMessage("You get some " + ItemDefinition.get(tree.item).getName() + ".", true));
64 getMob().playerAssistant.activateSkilling(1);
65 getMob().skills.addExperience(Skill.WOODCUTTING, tree.experience * Config.WOODCUTTING_MODIFICATION);
66
68 getMob().inventory.addOrDrop(new Item(tree.item, 1));
69 }
70 if (axe == AxeData.INFERNAL && Utility.random(3) == 0) {
71 Optional<FiremakingData> firemakingData = FiremakingData.forId(tree.item);
72
73 if (firemakingData.isPresent()) {
74 getMob().skills.addExperience(Skill.FIREMAKING, (firemakingData.get().getExperience() * Config.WOODCUTTING_MODIFICATION) / 2);
75 } else {
76 getMob().inventory.add(tree.item, 1);
77 }
78
79 } else {
80 getMob().inventory.add(tree.item, 1);
81 }
82
84 getMob().forClan(channel -> channel.activateTask(ClanTaskKey.CHOP_WILLOW_LOG, getMob().getName()));
85 } else if (tree == TreeData.YEW_TREE) {
86 getMob().forClan(channel -> channel.activateTask(ClanTaskKey.YEW_LOG, getMob().getName()));
87 } else if (tree == TreeData.MAGIC_TREE) {
88 getMob().forClan(channel -> channel.activateTask(ClanTaskKey.MAGIC_LOG, getMob().getName()));
89 }
90 if (object.active() && (tree.logs == 1 || tree.logs != 1 && Utility.random(8) <= 0) && !Area.inSuperDonatorZone(object) && !Area.inRegularDonatorZone(object)) {
91 this.cancel();
92 getMob().resetAnimation();
93 object.getGenericAttributes().set("logs", -1);
94 World.schedule(new ObjectReplacementEvent(object, tree.replacement, tree.respawn, () -> {
95 object.getGenericAttributes().set("logs", tree.logs);
96 }));
97 }
98 }
99 return true;
100 }
101
102 @Override
103 protected boolean canSchedule() {
104 return !getMob().skills.get(Skill.WOODCUTTING).isDoingSkill();
105 }
106
107 @Override
108 protected void onSchedule() {
109 if (!object.getGenericAttributes().has("logs")) {
110 object.getGenericAttributes().set("logs", tree.logs);
111 }
112
113 getMob().animate(axe.animation);
114 }
115
116 @Override
117 public void execute() {
118 if (!getMob().skills.get(Skill.WOODCUTTING).isDoingSkill()) {
119 cancel();
120 return;
121 }
122 if (object == null || !object.active() || object.getGenericAttributes() == null) {
123 cancel();
124 return;
125 }
126
127 if (!chop()) {
128 cancel();
129 }
130 }
131
132 @Override
133 protected void onCancel(boolean logout) {
134 getMob().resetFace();
135 getMob().skills.get(Skill.WOODCUTTING).setDoingSkill(false);
136 }
137
138 @Override
142
143 @Override
144 public String getName() {
145 return "woodcutting-action";
146 }
147}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double WOODCUTTING_MODIFICATION
The experience modification for woodcutting.
Definition Config.java:283
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
Handles spawning, rewarding and picking up of pets.
Definition Pets.java:27
static void onReward(Player player, int item, int chance)
Handles calculating the chance of a player receiving a skilling pet.
Definition Pets.java:33
Handles dropping & searching birds nest which are obtained from woodcutting.
static void drop(Player player)
Handles dropping the birds nest.
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
boolean canSchedule()
A function executed on registration.
void execute()
A function representing the unit of work that will be carried out.
void onCancel(boolean logout)
A function executed on cancellation.
WoodcuttingAction(Player mob, GameObject object, TreeData tree, AxeData axe)
static boolean success(Player player, TreeData tree, AxeData axe)
T getMob()
Gets the player.
Definition Action.java:44
final T mob
The Mob associated with this ActionEvent.
Definition Action.java:15
Action(T mob, int delay, boolean instant)
Creates a new Action randomevent.
Definition Action.java:24
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
An randomevent which replaces an object with another object.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
static final int WOODCUTTING
The woodcutting skill id.
Definition Skill.java:45
static final int FIREMAKING
The firemaking skill id.
Definition Skill.java:54
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
The container class that represents an item that can be interacted with.
Definition Item.java:21
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inRegularDonatorZone(Interactable entity)
Definition Area.java:151
static boolean inSuperDonatorZone(Interactable entity)
Definition Area.java:148
The OutgoingPacket that sends a message to a Players chatbox in the client.
A static-util class that provides additional functionality for generating pseudo-random numbers.
static boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
Holds the data for pets.
Definition PetData.java:14
Handles the perk rewards from prestiging.
static Optional< FiremakingData > forId(int id)
static boolean isEquipped(Player player, SkillCape cape)
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.