RuneHive-Game
Loading...
Searching...
No Matches
Smelting.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.smithing;
2
3import com.runehive.Config;
4import com.runehive.content.skillcape.SkillCape;
5import com.runehive.content.activity.randomevent.RandomEventHandler;
6import com.runehive.game.Animation;
7import com.runehive.game.action.Action;
8import com.runehive.game.action.policy.WalkablePolicy;
9import com.runehive.game.world.entity.mob.player.Player;
10import com.runehive.game.world.entity.skill.Skill;
11import com.runehive.game.world.object.GameObject;
12import com.runehive.net.packet.out.SendChatBoxInterface;
13import com.runehive.net.packet.out.SendInputAmount;
14import com.runehive.net.packet.out.SendItemModelOnInterface;
15
16import java.util.Optional;
17
18public final class Smelting extends Action<Player> {
19 /** The array which holds all the possible furnace ids a player can smelt his bars in. */
20 private static final int[] FURNACE_IDS = {16469, 3994};
21
22 /** The array which holds all the frames you can draw an item on. */
23 private static final int[] SMELT_FRAME = {2405, 2406, 2407, 2409, 2410, 2411, 2412, 2413};
24
25 /** The bar identification to be drawn on each frame. */
26 public static final int[] SMELT_BARS = {2349, 2351, 2355, 2353, 2357, 2359, 2361, 2363};
27
28 /** The definition of the bar we're creating. */
29 private final SmeltingData definition;
30
31 /** Determines if we're smelting dependant on the superheat spell. */
32 private final boolean spell;
33
34 /** The amount we're producing. */
35 private int amount;
36
37 /** Constructs a new {@link Smelting}. */
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
45 /** Attempts to start smelting for the specified {@code player}. */
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
62 /** Smelts the {@code data} for the specified {@code player} and produces the exact amount the player inputed if he has the requirements. */
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));
67 }
68
69 /** Opens the smelting itemcontainer for the {@code player}. */
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
88 /** Sends the items on the smelting itemcontainer. */
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
95 /** Checks if the player has the requirements to smelt. */
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);
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
160
161 @Override
162 public String getName() {
163 return "smelting-action";
164 }
165}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double SMITHING_MODIFICATION
The experience modification for smithing.
Definition Config.java:289
static boolean smelt(Player player, int buttonId)
Attempts to start smelting for the specified player.
Definition Smelting.java:46
boolean canSchedule()
A function executed on registration.
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
void execute()
A function representing the unit of work that will be carried out.
void onCancel(boolean logout)
A function executed on cancellation.
static final int[] FURNACE_IDS
The array which holds all the possible furnace ids a player can smelt his bars in.
Definition Smelting.java:20
String getName()
Gets the name of this action.
static boolean openInterface(Player player, GameObject object)
Opens the smelting itemcontainer for the player.
Definition Smelting.java:70
static final int[] SMELT_BARS
The bar identification to be drawn on each frame.
Definition Smelting.java:26
final boolean spell
Determines if we're smelting dependant on the superheat spell.
Definition Smelting.java:32
static void clearInterfaces(Player player)
Sends the items on the smelting itemcontainer.
Definition Smelting.java:89
boolean prioritized()
Determines if this action is prioritized.
int amount
The amount we're producing.
Definition Smelting.java:35
void onSchedule()
A function executed on registration.
boolean smelt()
Checks if the player has the requirements to smelt.
Definition Smelting.java:96
Smelting(Player player, SmeltingData definition, int amount, boolean spell)
Constructs a new Smelting.
Definition Smelting.java:38
static void smelt(Player player, SmeltingData data, int amount)
Smelts the data for the specified player and produces the exact amount the player inputed if he has t...
Definition Smelting.java:63
static final int[] SMELT_FRAME
The array which holds all the frames you can draw an item on.
Definition Smelting.java:23
final SmeltingData definition
The definition of the bar we're creating.
Definition Smelting.java:29
Class that models a single animation used by an entity.
T getMob()
Gets the player.
Definition Action.java:44
Action(T mob, int delay, boolean instant)
Creates a new Action randomevent.
Definition Action.java:24
public< A extends Action<?> > void execute(A action)
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
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 SMITHING
The smithing skill id.
Definition Skill.java:60
void setDoingSkill(boolean doingSkill)
Definition Skill.java:489
Skill get(int id)
Gets the skill for an id.
The enumerated type whose elements represent definitions for each smeltable bar.
static Optional< SmeltingData > getDefinition(int buttonId)
Searches for a match for the internal button identification.
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.