RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Glass.java
1package com.osroyale.content.skill.impl.crafting.impl;
2
3import com.osroyale.Config;
4import com.osroyale.net.packet.out.SendInputAmount;
5import com.osroyale.net.packet.out.SendMessage;
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.items.Item;
12import com.osroyale.game.world.items.ItemDefinition;
13import com.osroyale.util.Utility;
14
15import java.util.Arrays;
16import java.util.Optional;
17
59
60public class Glass {
61
63public enum GlassData {
64 VIAL(229, 33, 35.0D, 1775),
65 LIGHT_ORB(10973, 87, 70.0D, 1775),
66 BEER_GLASS(1919, 1, 17.5D, 1775),
67 CANDLE_LANTERN(4527, 4, 19.0D, 1775),
68 OIL_LAMP(4522, 12, 25.0D, 1775),
69 FISHBOWL(6667, 42, 42.5D, 1775),
70 LANTERN_LENS(4542, 49, 55.0D, 1775),
71 MOLTEN_GLASS(1775, 1, 20.0D, 1781),
72 UNPOWDERED_ORD(567, 46, 52.5D, 1775);
73
75 private final int product;
76
78 private final int level;
79
81 private final double experience;
82
84 private final int material;
85
87 GlassData(int product, int level, double experience, int material) {
88 this.product = product;
89 this.level = level;
90 this.experience = experience;
91 this.material = material;
92 }
93
95 public static Optional<GlassData> forGlass(int item) {
96 return Arrays.stream(values()).filter(g -> g.material == item).findFirst();
97 }
98 }
99
101 public static void open(Player player) {
102 player.interfaceManager.open(11462);
103 }
104
106 public static boolean click(Player player, int button) {
107 switch (button) {
109 case 11474: craft(player, GlassData.VIAL, 1); return true;
110 case 11473: craft(player, GlassData.VIAL, 5); return true;
111 case 11472: craft(player, GlassData.VIAL, 10); return true;
112 case 11471:
113 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
114 craft(player, GlassData.VIAL, Integer.parseInt(input))
115 ));
116 return true;
118 case 12396: craft(player, GlassData.UNPOWDERED_ORD, 1); return true;
119 case 12395: craft(player, GlassData.UNPOWDERED_ORD, 5); return true;
120 case 12394: craft(player, GlassData.UNPOWDERED_ORD, 10); return true;
121 case 11475:
122 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
123 craft(player, GlassData.UNPOWDERED_ORD, Integer.parseInt(input))
124 ));
125 return true;
127 case 12400: craft(player, GlassData.BEER_GLASS, 1); return true;
128 case 12399: craft(player, GlassData.BEER_GLASS, 5); return true;
129 case 12398: craft(player, GlassData.BEER_GLASS, 10); return true;
130 case 12397:
131 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
132 craft(player, GlassData.BEER_GLASS, Integer.parseInt(input))
133 ));
134 return true;
136 case 12404: craft(player, GlassData.CANDLE_LANTERN, 1); return true;
137 case 12403: craft(player, GlassData.CANDLE_LANTERN, 5); return true;
138 case 12402: craft(player, GlassData.CANDLE_LANTERN, 10); return true;
139 case 12401:
140 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
141 craft(player, GlassData.CANDLE_LANTERN, Integer.parseInt(input))
142 ));
143 return true;
145 case 12408: craft(player, GlassData.OIL_LAMP, 1); return true;
146 case 12407: craft(player, GlassData.OIL_LAMP, 5); return true;
147 case 12406: craft(player, GlassData.OIL_LAMP, 10); return true;
148 case 12405:
149 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
150 craft(player, GlassData.OIL_LAMP, Integer.parseInt(input))
151 ));
152 return true;
154 case 6203: craft(player, GlassData.FISHBOWL, 1); return true;
155 case 6202: craft(player, GlassData.FISHBOWL, 5); return true;
156 case 6201: craft(player, GlassData.FISHBOWL, 10); return true;
157 case 6200:
158 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
159 craft(player, GlassData.FISHBOWL, Integer.parseInt(input))
160 ));
161 return true;
163 case 12412: craft(player, GlassData.LANTERN_LENS, 1); return true;
164 case 12411: craft(player, GlassData.LANTERN_LENS, 5); return true;
165 case 12410: craft(player, GlassData.LANTERN_LENS, 10); return true;
166 case 12409:
167 player.send(new SendInputAmount("Enter the amount you would like to craft", 2, input ->
168 craft(player, GlassData.LANTERN_LENS, Integer.parseInt(input))
169 ));
170 return true;
171 }
172 return false;
173 }
174
176 public static void craft(Player player, GlassData glass, int amount) {
177 if (player.skills.getMaxLevel(Skill.CRAFTING) < glass.level) {
178 player.send(new SendMessage("You need a crafting level of " + glass.level + " to craft this!"));
179 return;
180 }
181
182 if (!player.inventory.contains(1785) && glass != GlassData.MOLTEN_GLASS) {
183 player.send(new SendMessage("You need a glassblowing pipe to do this!"));
184 return;
185 }
186
187 if (!player.inventory.contains(glass.material)) {
188 String name = ItemDefinition.get(glass.material).getName();
189 player.send(new SendMessage("You need " + Utility.getAOrAn(name) + " " + name + " to do this!"));
190 return;
191 }
192
193 player.interfaceManager.close();
194 player.action.execute(blow(player, glass, amount), true);
195 }
196
198 private static Action<Player> blow(Player player, GlassData glass, int amount) {
199 return new Action<Player>(player, 3, true) {
200 int ticks = 0;
201
202 @Override
203 public void execute() {
204 boolean moltenGlass = glass == GlassData.MOLTEN_GLASS;
205
206 if (moltenGlass && (!player.inventory.contains(1783) || !player.inventory.contains(1781))) {
207 player.send(new SendMessage("You need a bucket of sand and soda ash to make molten glass!"));
208 cancel();
209 return;
210 }
211
212 if (!player.inventory.contains(1785) && !moltenGlass) {
213 player.send(new SendMessage("You need a glassblowing pipe to do this!"));
214 cancel();
215 return;
216 }
217
218 if (!player.inventory.contains(glass.material)) {
219 String name = ItemDefinition.get(glass.material).getName();
220 player.send(new SendMessage("You need " + Utility.getAOrAn(name) + " " + name + " to do this!"));
221 cancel();
222 return;
223 }
224
225 player.inventory.remove(glass.material, 1);
226
227 if (moltenGlass) {
228 player.inventory.replace(1783, 1925, true);
229 }
230
231 String name = ItemDefinition.get(glass.product).getName();
232 player.animate(new Animation(moltenGlass ? 899 : 884));
233 player.inventory.add(new Item(glass.product));
234 player.skills.addExperience(Skill.CRAFTING, glass.experience * Config.CRAFTING_MODIFICATION);
235 player.send(new SendMessage("You make " + Utility.getAOrAn(name) + " " + name + "."));
236
237 if (++ticks == amount) {
238 cancel();
239 return;
240 }
241 }
242
243 @Override
244 public String getName() {
245 return "Glass";
246 }
247
248 @Override
249 public boolean prioritized() {
250 return false;
251 }
252
253 @Override
254 public WalkablePolicy getWalkablePolicy() {
255 return WalkablePolicy.NON_WALKABLE;
256 }
257 };
258 }
259}
static final double CRAFTING_MODIFICATION
Definition Config.java:295
static boolean click(Player player, int button)
Definition Glass.java:106
static void craft(Player player, GlassData glass, int amount)
Definition Glass.java:176
void addExperience(int id, double experience)
final boolean replace(int oldId, int newId, int index, boolean refresh)
static String getAOrAn(String nextWord)
Definition Utility.java:153
static Optional< GlassData > forGlass(int item)
Definition Glass.java:95
GlassData(int product, int level, double experience, int material)
Definition Glass.java:87