RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Smelting.java
1package com.osroyale.content.skill.impl.smithing;
2
3import com.osroyale.Config;
4import com.osroyale.content.skillcape.SkillCape;
5import com.osroyale.content.activity.randomevent.RandomEventHandler;
6import com.osroyale.game.Animation;
7import com.osroyale.game.action.Action;
8import com.osroyale.game.action.policy.WalkablePolicy;
9import com.osroyale.game.world.entity.mob.player.Player;
10import com.osroyale.game.world.entity.skill.Skill;
11import com.osroyale.game.world.object.GameObject;
12import com.osroyale.net.packet.out.SendChatBoxInterface;
13import com.osroyale.net.packet.out.SendInputAmount;
14import com.osroyale.net.packet.out.SendItemModelOnInterface;
15
16import java.util.Optional;
17
18public final class Smelting extends Action<Player> {
20 private static final int[] FURNACE_IDS = {16469, 3994};
21
23 private static final int[] SMELT_FRAME = {2405, 2406, 2407, 2409, 2410, 2411, 2412, 2413};
24
26 public static final int[] SMELT_BARS = {2349, 2351, 2355, 2353, 2357, 2359, 2361, 2363};
27
29 private final SmeltingData definition;
30
32 private final boolean spell;
33
35 private int amount;
36
38 private Smelting(Player player, SmeltingData definition, int amount, boolean spell) {
39 super(player, SkillCape.isEquipped(player, SkillCape.SMITHING) ? 1 : 2, false);
40 this.definition = definition;
41 this.amount = amount;
42 this.spell = spell;
43 }
44
46 static boolean smelt(Player player, int buttonId) {
47 Optional<SmeltingData> data = SmeltingData.getDefinition(buttonId);
48
49 if (!data.isPresent()) {
50 return false;
51 }
52
53 if (data.get().amount == -1) {
54 player.send(new SendInputAmount("How many you would like to melt?", 2, s -> Smelting.smelt(player, data.get(), Integer.parseInt(s))));
55 return true;
56 }
57
58 smelt(player, data.get(), data.get().amount);
59 return true;
60 }
61
63 private static void smelt(Player player, SmeltingData data, int amount) {
64 player.interfaceManager.close();
65 player.action.execute(new Smelting(player, data, amount, false));
66 player.skills.get(Skill.SMITHING).setDoingSkill(true);
67 }
68
70 static boolean openInterface(Player player, GameObject object) {
71 boolean accessible = false;
72
73 for (int id : FURNACE_IDS) {
74 if (object.getId() == id) {
75 accessible = true;
76 break;
77 }
78 }
79
80 if (!accessible) {
81 return false;
82 }
83
84 player.send(new SendChatBoxInterface(2400));
85 return true;
86 }
87
89 public static void clearInterfaces(Player player) {
90 for (int j = 0; j < SMELT_FRAME.length; j++) {
91 player.send(new SendItemModelOnInterface(SMELT_FRAME[j], 150, SMELT_BARS[j]));
92 }
93 }
94
96 private boolean smelt() {
97 if (getMob().skills.get(Skill.SMITHING).getLevel() < definition.requirement) {
98 getMob().message("You need a smithing level of " + definition.requirement + " to smelt this bar.");
99 return false;
100 }
101
102 if (!getMob().inventory.containsAll(definition.required)) {
103 getMob().message("You don't have the required items to smelt this bar.");
104 return false;
105 }
106
107 if (!spell) {
108 getMob().animate(new Animation(899));
109 }
110 getMob().inventory.removeAll(definition.required);
111 getMob().inventory.addAll(definition.produced);
112 getMob().skills.addExperience(Skill.SMITHING, definition.experience * Config.SMITHING_MODIFICATION);
113 getMob().playerAssistant.activateSkilling(1);
114 RandomEventHandler.trigger(getMob());
115 amount--;
116
117 if (amount < 1) {
118 this.cancel();
119 }
120
121 return true;
122 }
123
124 @Override
125 protected boolean canSchedule() {
126 return !getMob().skills.get(Skill.SMITHING).isDoingSkill();
127 }
128
129 @Override
130 protected void onSchedule() {
131 }
132
133 @Override
134 public void execute() {
135 if (!getMob().skills.get(Skill.SMITHING).isDoingSkill()) {
136 cancel();
137 return;
138 }
139
140 if (!smelt()) {
141 cancel();
142 }
143 }
144
145 @Override
146 protected void onCancel(boolean logout) {
147 getMob().resetFace();
148 getMob().skills.get(Skill.SMITHING).setDoingSkill(false);
149 }
150
151 @Override
152 public boolean prioritized() {
153 return false;
154 }
155
156 @Override
157 public WalkablePolicy getWalkablePolicy() {
158 return WalkablePolicy.NON_WALKABLE;
159 }
160
161 @Override
162 public String getName() {
163 return "smelting-action";
164 }
165}
abstract WalkablePolicy getWalkablePolicy()
synchronized final void cancel()
Definition Task.java:147