RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
WoodcuttingAction.java
1package com.osroyale.content.skill.impl.woodcutting;
2
3import com.osroyale.Config;
4import com.osroyale.content.achievement.AchievementHandler;
5import com.osroyale.content.achievement.AchievementKey;
6import com.osroyale.content.activity.randomevent.RandomEventHandler;
7import com.osroyale.content.clanchannel.content.ClanTaskKey;
8import com.osroyale.content.pet.PetData;
9import com.osroyale.content.pet.Pets;
10import com.osroyale.content.prestige.PrestigePerk;
11import com.osroyale.content.skill.impl.firemaking.FiremakingData;
12import com.osroyale.content.skillcape.SkillCape;
13import com.osroyale.game.action.Action;
14import com.osroyale.game.action.policy.WalkablePolicy;
15import com.osroyale.game.task.impl.ObjectReplacementEvent;
16import com.osroyale.game.world.World;
17import com.osroyale.game.world.entity.mob.player.Player;
18import com.osroyale.game.world.entity.skill.Skill;
19import com.osroyale.game.world.items.Item;
20import com.osroyale.game.world.items.ItemDefinition;
21import com.osroyale.game.world.object.GameObject;
22import com.osroyale.game.world.position.Area;
23import com.osroyale.net.packet.out.SendMessage;
24import com.osroyale.util.RandomUtils;
25import com.osroyale.util.Utility;
26
27import java.util.Optional;
28
34public class WoodcuttingAction extends Action<Player> {
35 private final GameObject object;
36 private final TreeData tree;
37 private final AxeData axe;
38
39 WoodcuttingAction(Player mob, GameObject object, TreeData tree, AxeData axe) {
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
54 if (Woodcutting.success(getMob(), tree, axe)) {
55 if (object == null || !object.active()) {
56 return false;
57 }
58
60 RandomEventHandler.trigger(getMob());
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
67 if ((SkillCape.isEquipped(getMob(), SkillCape.WOODCUTTING) || getMob().prestige.hasPerk(PrestigePerk.DOUBLE_WOOD)) && RandomUtils.success(.15)) {
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
83 if (tree == TreeData.WILLOW_TREE || tree == TreeData.WILLOW_TREE1) {
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}
static final double WOODCUTTING_MODIFICATION
Definition Config.java:325
static void activate(Player player, AchievementKey achievement)
static void onReward(Player player, int item, int chance)
Definition Pets.java:70
Action(T mob, int delay, boolean instant)
Definition Action.java:24
synchronized final void cancel()
Definition Task.java:147
static void schedule(Task task)
Definition World.java:284