RuneHive-Game
Loading...
Searching...
No Matches
Jewellery.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.crafting.impl;
2
3import com.runehive.Config;
4import com.runehive.game.Animation;
5import com.runehive.game.action.Action;
6import com.runehive.game.action.policy.WalkablePolicy;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.entity.skill.Skill;
9import com.runehive.game.world.items.Item;
10import com.runehive.game.world.items.ItemDefinition;
11import com.runehive.net.packet.out.SendInterfaceConfig;
12import com.runehive.net.packet.out.SendItemOnInterfaceSlot;
13import com.runehive.net.packet.out.SendMessage;
14import com.runehive.util.Utility;
15
16import java.util.Arrays;
17import java.util.Optional;
18
19/**
20 * Handles crafting jewellery.
21 *
22 * @author Daniel
23 */
24public final class Jewellery {
25
26 /**
27 * The jewellery type.
28 */
29 public enum JewelleryType {
30 RING(4233),
31 NECKLACE(4239),
32 AMULET(4245);
33
34 /**
35 * The itemcontainer identification.
36 */
37 public final int identification;
38
39 /**
40 * Constructs a new <code>JewelleryType</code>.
41 *
42 * @param identification The itemcontainer identification.
43 */
45 this.identification = identification;
46 }
47 }
48
49 /**
50 * The jewellery data.
51 */
52 /**
53 * Need to add furnace at home.
54 */
55 public enum JewelleryData {
56 GOLD_RING(1635, 5, 15, JewelleryType.RING, new Item(1592), new Item(2357)),
57 SAPPHIRE_RING(1637, 20, 40, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1607)),
58 EMERALD_RING(1639, 27, 55, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1605)),
59 RUBY_RING(1641, 34, 70, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1603)),
60 DIAMOND_RING(1643, 43, 85, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1601)),
61 DRAGONSTONE_RING(1645, 55, 100, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1615)),
62 ONYX_RING(6575, 67, 85, JewelleryType.RING, new Item(1592), new Item(2357), new Item(6573)),
63
64 GOLD_NECKLACE(1654, 6, 20, JewelleryType.NECKLACE, new Item(1597), new Item(2357)),
65 SAPPHIRE_NECKLACE(1656, 22, 55, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1607)),
66 EMERALD_NECKLACE(1658, 29, 60, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1605)),
67 RUBY_NECKLACE(1660, 40, 75, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1603)),
68 DIAMOND_NECKLACE(1662, 56, 90, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1601)),
69 DRAGONSTONE_NECKLACE(1664, 72, 105, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1615)),
70 ONYX_NECKLACE(6577, 82, 120, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(6573)),
71
72 GOLD_AMULET(1673, 8, 30, JewelleryType.AMULET, new Item(1595), new Item(2357)),
73 SAPPHIRE_AMULET(1675, 24, 65, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1607)),
74 EMERALD_AMULET(1677, 31, 61, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1605)),
75 RUBY_AMULET(1679, 50, 85, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1603)),
76 DIAMOND_AMULET(1681, 70, 100, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1601)),
77 DRAGONSTONE_AMULET(1683, 80, 125, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1615)),
78 ONYX_AMULET(6579, 90, 150, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(6573));
79
80 /**
81 * The production item.
82 */
83 public int product;
84
85 /**
86 * The level required.
87 */
88 public int level;
89
90 /**
91 * The experience rewarded.
92 */
93 public double experience;
94
95 /**
96 * The jewellery type.
97 */
99
100 /**
101 * The materials required.
102 */
103 public Item[] materials;
104
105 /**
106 * Constructs a new <code>JewelleryData</code>.
107 *
108 * @param product The production item.
109 * @param level The level required.
110 * @param experience The experience rewarded.
111 * @param type The jewellery type.
112 * @param materials The materials required.
113 */
115 this.product = product;
116 this.level = level;
117 this.experience = experience;
118 this.type = type;
119 this.materials = materials;
120 }
121
122 /**
123 * Gets the size of all the jewellery types.
124 *
125 * @param type The jewellery type.
126 * @return The jewellery size.
127 */
128 public static int getSize(JewelleryType type) {
129 int count = 0;
130 for (JewelleryData data : values()) {
131 if (data.type == type) {
132 count++;
133 }
134 }
135 return count;
136 }
137
138 /**
139 * Gets the product items based on the jewellery type.
140 *
141 * @param type The jewellery type.
142 * @return The jewellery type production items.
143 */
144 public static int[] getItems(JewelleryType type) {
145 int[] items = new int[getSize(type)];
146 int count = 0;
147 for (JewelleryData data : values()) {
148 if (data.type == type) {
149 items[count] = data.product;
150 count++;
151 }
152 }
153 return items;
154 }
155
156 /**
157 * Gets the jewellery data based on the product item.
158 *
159 * @param item The item being searched.
160 * @return The jewellery data.
161 */
162 public static Optional<JewelleryData> forItem(int item) {
163 return Arrays.stream(values()).filter(i -> i.product == item).findAny();
164 }
165 }
166
167 /**
168 * Opens the jewellery creation itemcontainer.
169 *
170 * @param player The player instance.
171 */
172 public static void open(Player player) {
174 for (int i = 0; i < items.length; i++) {
175 player.send(new SendItemOnInterfaceSlot(JewelleryType.RING.identification, items[i], 1, i));
176 }
177
179 for (int i = 0; i < items.length; i++) {
180 player.send(new SendItemOnInterfaceSlot(JewelleryType.NECKLACE.identification, items[i], 1, i));
181 }
182
184 for (int i = 0; i < items.length; i++) {
185 player.send(new SendItemOnInterfaceSlot(JewelleryType.AMULET.identification, items[i], 1, i));
186 }
187
188 player.send(new SendInterfaceConfig(4229, 0, -1));
189 player.send(new SendInterfaceConfig(4235, 0, -1));
190 player.send(new SendInterfaceConfig(4241, 0, -1));
191 player.interfaceManager.open(4161);
192 }
193
194 /**
195 * Handles clicking on the itemcontainer.
196 *
197 * @param player The player instance.
198 * @param item The item being crafted.
199 * @param amount The amount being crafted.
200 */
201 public static void click(Player player, int item, int amount) {
202 if (!JewelleryData.forItem(item).isPresent()) {
203 return;
204 }
205
206 JewelleryData jewellery = JewelleryData.forItem(item).get();
207
208 if (player.skills.getMaxLevel(Skill.CRAFTING) < jewellery.level) {
209 String name = ItemDefinition.get(jewellery.product).getName();
210 player.send(new SendMessage("You need a crafting level of " + jewellery.level + " to craft " + Utility.getAOrAn(name) + " " + name + "."));
211 return;
212 }
213
214 boolean contains = true;
215 for (Item i : jewellery.materials) {
216 if (!player.inventory.contains(i)) {
217 String req = i.getName();
218 player.send(new SendMessage("You need " + Utility.getAOrAn(req) + " " + req + " to make this!"));
219 contains = false;
220 }
221 }
222
223 if (!contains)
224 return;
225
226 player.interfaceManager.close();
227 player.action.execute(craft(player, jewellery, amount), true);
228 }
229
230 /**
231 * The jewellery crafting animation.
232 *
233 * @param player The player instance.
234 * @param jewellery The jewellery data being crafted.
235 * @param amount The amount of jewellery being crafter.
236 * @return The jewellery crafting action.
237 */
238 private static Action<Player> craft(Player player, JewelleryData jewellery, int amount) {
239 return new Action<Player>(player, 4, true) {
240 int ticks = 0;
241
242 @Override
243 public void execute() {
244 if (!player.inventory.containsAll(jewellery.materials)) {
245 player.send(new SendMessage("You do not have the required items to craft this!"));
246 cancel();
247 return;
248 }
249
250 player.animate(new Animation(899));
251
252 for (int index = 0; index < jewellery.materials.length; index++) {
253 if (index != 0) {
254 player.inventory.remove(jewellery.materials[index], -1, false);
255 }
256 }
257
258 player.inventory.add(new Item(jewellery.product), -1, true);
260 player.send(new SendMessage("You have crafted " + Utility.getAOrAn(new Item(jewellery.product).getName()) + " " + new Item(jewellery.product).getName() + "."));
261
262 if (++ticks == amount) {
263 cancel();
264 return;
265 }
266 }
267
268 @Override
269 public String getName() {
270 return "Jewellery crafting";
271 }
272
273 @Override
274 public boolean prioritized() {
275 return false;
276 }
277
278 @Override
279 public WalkablePolicy getWalkablePolicy() {
281 }
282 };
283 }
284}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double CRAFTING_MODIFICATION
The experience modification for crafting.
Definition Config.java:253
static Action< Player > craft(Player player, JewelleryData jewellery, int amount)
The jewellery crafting animation.
static void open(Player player)
Opens the jewellery creation itemcontainer.
static void click(Player player, int item, int amount)
Handles clicking on the itemcontainer.
Class that models a single animation used by an entity.
Represents an action an entity can execute.
Definition Action.java:12
public< A extends Action<?> > void execute(A action)
void open(int identification)
Opens an interface for the player.
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 CRAFTING
The crafting skill id.
Definition Skill.java:57
void addExperience(int id, double experience)
Adds experience to a given skill.
int getMaxLevel(int id)
Gets the highest possible level of a skill.
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
boolean remove(Item item)
Attempts to withdraw item from this container.
boolean add(Item item)
Attempts to deposit item into this container.
boolean contains(int id)
Determines if this container contains id.
final boolean containsAll(int... identifiers)
Determines if this container contains all identifiers.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String getAOrAn(String nextWord)
A or an.
Definition Utility.java:116
static int[] getItems(JewelleryType type)
Gets the product items based on the jewellery type.
JewelleryData(int product, int level, double experience, JewelleryType type, Item... materials)
Constructs a new JewelleryData.
static int getSize(JewelleryType type)
Gets the size of all the jewellery types.
static Optional< JewelleryData > forItem(int item)
Gets the jewellery data based on the product item.
JewelleryType(int identification)
Constructs a new JewelleryType.
final int identification
The itemcontainer identification.
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.