RuneHive-Game
Loading...
Searching...
No Matches
Glass.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.crafting.impl;
2
3import com.runehive.Config;
4import com.runehive.net.packet.out.SendInputAmount;
5import com.runehive.net.packet.out.SendMessage;
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.items.Item;
12import com.runehive.game.world.items.ItemDefinition;
13import com.runehive.util.Utility;
14
15import java.util.Arrays;
16import java.util.Optional;
17
18/**
19 * Handles the glass crafting.
20 *
21 * @author Daniel
22 */
23public class Glass {
24
25 /** Holds all the glass data. */
26 public enum GlassData {
27 VIAL(229, 33, 35.0D, 1775),
28 LIGHT_ORB(10973, 87, 70.0D, 1775),
29 BEER_GLASS(1919, 1, 17.5D, 1775),
30 CANDLE_LANTERN(4527, 4, 19.0D, 1775),
31 OIL_LAMP(4522, 12, 25.0D, 1775),
32 FISHBOWL(6667, 42, 42.5D, 1775),
33 LANTERN_LENS(4542, 49, 55.0D, 1775),
34 MOLTEN_GLASS(1775, 1, 20.0D, 1781),
35 UNPOWDERED_ORD(567, 46, 52.5D, 1775);
36
37 /** The glass product. */
38 private final int product;
39
40 /** The level required. */
41 private final int level;
42
43 /** The experienced rewarded. */
44 private final double experience;
45
46 /** The material required. */
47 private final int material;
48
49 /** Constructs a new <code>GlassData</code>. */
50 GlassData(int product, int level, double experience, int material) {
51 this.product = product;
52 this.level = level;
53 this.experience = experience;
54 this.material = material;
55 }
56
57 /** Gets the glass data based on the material item. */
58 public static Optional<GlassData> forGlass(int item) {
59 return Arrays.stream(values()).filter(g -> g.material == item).findFirst();
60 }
61 }
62
63 /** Handles opening the glass crafting interface. */
64 public static void open(Player player) {
65 player.interfaceManager.open(11462);
66 }
67
68 /** Handles clicking on the interface. */
69 public static boolean click(Player player, int button) {
70 switch (button) {
71 /** Vial */
72 case 11474: craft(player, GlassData.VIAL, 1); return true;
73 case 11473: craft(player, GlassData.VIAL, 5); return true;
74 case 11472: craft(player, GlassData.VIAL, 10); return true;
75 case 11471:
76 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
77 craft(player, GlassData.VIAL, Integer.parseInt(input))
78 ));
79 return true;
80 /** Orb */
81 case 12396: craft(player, GlassData.UNPOWDERED_ORD, 1); return true;
82 case 12395: craft(player, GlassData.UNPOWDERED_ORD, 5); return true;
83 case 12394: craft(player, GlassData.UNPOWDERED_ORD, 10); return true;
84 case 11475:
85 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
86 craft(player, GlassData.UNPOWDERED_ORD, Integer.parseInt(input))
87 ));
88 return true;
89 /** Beer glass */
90 case 12400: craft(player, GlassData.BEER_GLASS, 1); return true;
91 case 12399: craft(player, GlassData.BEER_GLASS, 5); return true;
92 case 12398: craft(player, GlassData.BEER_GLASS, 10); return true;
93 case 12397:
94 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
95 craft(player, GlassData.BEER_GLASS, Integer.parseInt(input))
96 ));
97 return true;
98 /** Candle lantern */
99 case 12404: craft(player, GlassData.CANDLE_LANTERN, 1); return true;
100 case 12403: craft(player, GlassData.CANDLE_LANTERN, 5); return true;
101 case 12402: craft(player, GlassData.CANDLE_LANTERN, 10); return true;
102 case 12401:
103 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
104 craft(player, GlassData.CANDLE_LANTERN, Integer.parseInt(input))
105 ));
106 return true;
107 /** Oil lamp */
108 case 12408: craft(player, GlassData.OIL_LAMP, 1); return true;
109 case 12407: craft(player, GlassData.OIL_LAMP, 5); return true;
110 case 12406: craft(player, GlassData.OIL_LAMP, 10); return true;
111 case 12405:
112 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
113 craft(player, GlassData.OIL_LAMP, Integer.parseInt(input))
114 ));
115 return true;
116 /** Fishbowl */
117 case 6203: craft(player, GlassData.FISHBOWL, 1); return true;
118 case 6202: craft(player, GlassData.FISHBOWL, 5); return true;
119 case 6201: craft(player, GlassData.FISHBOWL, 10); return true;
120 case 6200:
121 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
122 craft(player, GlassData.FISHBOWL, Integer.parseInt(input))
123 ));
124 return true;
125 /** Lantern lens */
126 case 12412: craft(player, GlassData.LANTERN_LENS, 1); return true;
127 case 12411: craft(player, GlassData.LANTERN_LENS, 5); return true;
128 case 12410: craft(player, GlassData.LANTERN_LENS, 10); return true;
129 case 12409:
130 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
131 craft(player, GlassData.LANTERN_LENS, Integer.parseInt(input))
132 ));
133 return true;
134 }
135 return false;
136 }
137
138 /** Handles crafting the glass. */
139 public static void craft(Player player, GlassData glass, int amount) {
140 if (player.skills.getMaxLevel(Skill.CRAFTING) < glass.level) {
141 player.send(new SendMessage("You need a crafting level of " + glass.level + " to craft this!"));
142 return;
143 }
144
145 if (!player.inventory.contains(1785) && glass != GlassData.MOLTEN_GLASS) {
146 player.send(new SendMessage("You need a glassblowing pipe to do this!"));
147 return;
148 }
149
150 if (!player.inventory.contains(glass.material)) {
151 String name = ItemDefinition.get(glass.material).getName();
152 player.send(new SendMessage("You need " + Utility.getAOrAn(name) + " " + name + " to do this!"));
153 return;
154 }
155
156 player.interfaceManager.close();
157 player.action.execute(blow(player, glass, amount), true);
158 }
159
160 /** Handles blowing the glass data. */
161 private static Action<Player> blow(Player player, GlassData glass, int amount) {
162 return new Action<Player>(player, 3, true) {
163 int ticks = 0;
164
165 @Override
166 public void execute() {
167 boolean moltenGlass = glass == GlassData.MOLTEN_GLASS;
168
169 if (moltenGlass && (!player.inventory.contains(1783) || !player.inventory.contains(1781))) {
170 player.send(new SendMessage("You need a bucket of sand and soda ash to make molten glass!"));
171 cancel();
172 return;
173 }
174
175 if (!player.inventory.contains(1785) && !moltenGlass) {
176 player.send(new SendMessage("You need a glassblowing pipe to do this!"));
177 cancel();
178 return;
179 }
180
181 if (!player.inventory.contains(glass.material)) {
182 String name = ItemDefinition.get(glass.material).getName();
183 player.send(new SendMessage("You need " + Utility.getAOrAn(name) + " " + name + " to do this!"));
184 cancel();
185 return;
186 }
187
188 player.inventory.remove(glass.material, 1);
189
190 if (moltenGlass) {
191 player.inventory.replace(1783, 1925, true);
192 }
193
194 String name = ItemDefinition.get(glass.product).getName();
195 player.animate(new Animation(moltenGlass ? 899 : 884));
196 player.inventory.add(new Item(glass.product));
198 player.send(new SendMessage("You make " + Utility.getAOrAn(name) + " " + name + "."));
199
200 if (++ticks == amount) {
201 cancel();
202 return;
203 }
204 }
205
206 @Override
207 public String getName() {
208 return "Glass";
209 }
210
211 @Override
212 public boolean prioritized() {
213 return false;
214 }
215
216 @Override
217 public WalkablePolicy getWalkablePolicy() {
219 }
220 };
221 }
222}
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 boolean click(Player player, int button)
Handles clicking on the interface.
Definition Glass.java:69
static Action< Player > blow(Player player, GlassData glass, int amount)
Handles blowing the glass data.
Definition Glass.java:161
static void craft(Player player, GlassData glass, int amount)
Handles crafting the glass.
Definition Glass.java:139
static void open(Player player)
Handles opening the glass crafting interface.
Definition Glass.java:64
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.
final boolean replace(int oldId, int newId, int index, boolean refresh)
Replaces the first occurrence of the Item having the identifier oldId with newId.
boolean contains(int id)
Determines if this container contains id.
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 Optional< GlassData > forGlass(int item)
Gets the glass data based on the material item.
Definition Glass.java:58
final double experience
The experienced rewarded.
Definition Glass.java:44
GlassData(int product, int level, double experience, int material)
Constructs a new GlassData.
Definition Glass.java:50
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.