RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Stringing.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.action.Action;
7import com.osroyale.game.action.policy.WalkablePolicy;
8import com.osroyale.game.world.entity.mob.player.Player;
9import com.osroyale.content.dialogue.ChatBoxItemDialogue;
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
18
59
60public class Stringing {
61
65public enum AmuletData {
66 GOLD(1673, 1692, 8),
67 SAPPHIRE(1675, 1694, 24),
68 EMERALD(1677, 1696, 31),
69 RUBY(1679, 1698, 50),
70 DIAMOND(1681, 1700, 70),
71 DRAGONSTONE(1683, 1702, 80),
72 ONYX(6579, 6581, 90),
73 ZENYTE(19501, 19541, 98);
74
78 private final int ingredient;
79
83 private final int product;
84
88 private final int level;
89
97 AmuletData(int ingredient, int product, int level) {
98 this.ingredient = ingredient;
99 this.product = product;
100 this.level = level;
101 }
102
109 public static Optional<AmuletData> forAmulet(int ingredient) {
110 return Arrays.stream(values()).filter(a -> a.ingredient == ingredient).findAny();
111 }
112 }
113
121 public static boolean useItem(Player player, Item used, Item with) {
122 if (used.getId() != 1759 && with.getId() != 1759) {
123 return false;
124 }
125
126 Item wool = used.getId() == 1759 ? used : with;
127 Item amulet = wool.getId() == used.getId() ? with : used;
128
129 if (!AmuletData.forAmulet(amulet.getId()).isPresent()) {
130 return false;
131 }
132
133 AmuletData data = AmuletData.forAmulet(amulet.getId()).get();
134 craft(player, data);
135 return false;
136 }
137
144 public static void craft(Player player, AmuletData amulet) {
145 player.dialogueFactory.clear();
146
147 if (player.skills.getMaxLevel(Skill.CRAFTING) < amulet.level) {
148 player.dialogueFactory.sendStatement("You need a crafting level of " + amulet.level + " to string this!").execute();
149 return;
150 }
151
152 if (!player.inventory.contains(amulet.ingredient) || !player.inventory.contains(1759)) {
153 player.dialogueFactory.sendStatement("You do not have the required items to do this!").execute();
154 return;
155 }
156
157 ChatBoxItemDialogue.sendInterface(player, 1746, amulet.ingredient, 170);
158 player.chatBoxItemDialogue = new ChatBoxItemDialogue(player) {
159 @Override
160 public void firstOption(Player player) {
161 player.action.execute(string(player, amulet, 1), false);
162 }
163
164 @Override
165 public void secondOption(Player player) {
166 player.action.execute(string(player, amulet, 5), true);
167 }
168
169 @Override
170 public void thirdOption(Player player) {
171 player.send(new SendInputAmount("Enter amount", 2, input -> player.action.execute(string(player, amulet, Integer.parseInt(input)), true)));
172 }
173
174 @Override
175 public void fourthOption(Player player) {
176 player.action.execute(string(player, amulet, 14), true);
177 }
178 };
179 }
180
189 private static Action<Player> string(Player player, AmuletData amulet, int amount) {
190 return new Action<Player>(player, 2, true) {
191 int ticks = 0;
192
193 @Override
194 public void execute() {
195 if (!player.inventory.contains(amulet.ingredient) || !player.inventory.contains(1759)) {
196 cancel();
197
198 return;
199 }
200
201 player.inventory.remove(amulet.ingredient, 1);
202 player.inventory.remove(1759, 1);
203 player.inventory.add(amulet.product, 1);
205 player.send(new SendMessage("You string the " + ItemDefinition.get(amulet.ingredient).getName() + " into " + Utility.getAOrAn(ItemDefinition.get(amulet.product).getName()) + " " + ItemDefinition.get(amulet.product).getName() + "."));
206
207 if (++ticks == amount) {
208 cancel();
209 return;
210 }
211 }
212
213 @Override
214 public String getName() {
215 return "Stringing";
216 }
217
218 @Override
219 public boolean prioritized() {
220 return false;
221 }
222
223 @Override
224 public WalkablePolicy getWalkablePolicy() {
225 return WalkablePolicy.NON_WALKABLE;
226 }
227 };
228 }
229}
static final double CRAFTING_MODIFICATION
Definition Config.java:295
final DialogueFactory sendStatement(String... lines)
static void craft(Player player, AmuletData amulet)
static boolean useItem(Player player, Item used, Item with)
void addExperience(int id, double experience)
static String getAOrAn(String nextWord)
Definition Utility.java:153
static Optional< AmuletData > forAmulet(int ingredient)