1package com.osroyale.content.skill.impl.smithing;
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;
16import java.util.Optional;
18public final class Smelting
extends Action<Player> {
20 private static final int[] FURNACE_IDS = {16469, 3994};
23 private static final int[] SMELT_FRAME = {2405, 2406, 2407, 2409, 2410, 2411, 2412, 2413};
26 public static final int[] SMELT_BARS = {2349, 2351, 2355, 2353, 2357, 2359, 2361, 2363};
29 private final SmeltingData definition;
32 private final boolean spell;
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;
46 static boolean smelt(Player player,
int buttonId) {
47 Optional<SmeltingData> data = SmeltingData.getDefinition(buttonId);
49 if (!data.isPresent()) {
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))));
58 smelt(player, data.get(), data.get().amount);
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);
70 static boolean openInterface(Player player, GameObject
object) {
71 boolean accessible =
false;
73 for (
int id : FURNACE_IDS) {
74 if (
object.getId() ==
id) {
84 player.send(
new SendChatBoxInterface(2400));
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]));
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.");
102 if (!
getMob().inventory.containsAll(definition.required)) {
103 getMob().message(
"You don't have the required items to smelt this bar.");
108 getMob().animate(
new Animation(899));
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());
126 return !
getMob().skills.get(Skill.SMITHING).isDoingSkill();
135 if (!
getMob().skills.get(Skill.SMITHING).isDoingSkill()) {
146 protected void onCancel(
boolean logout) {
148 getMob().skills.get(Skill.SMITHING).setDoingSkill(
false);
163 return "smelting-action";
abstract String getName()
abstract WalkablePolicy getWalkablePolicy()
synchronized final void cancel()