RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Spinning.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.content.dialogue.ChatBoxItemDialogue;
11import com.osroyale.content.dialogue.DialogueFactory;
12import com.osroyale.game.world.entity.skill.Skill;
13import com.osroyale.game.world.items.Item;
14import com.osroyale.util.Utility;
15
61
62public class Spinning {
66public enum Spinnable {
67 BOWSTRING(new Item(1779), new Item(1777), 15.0D, 10),
68 WOOL(new Item(1737), new Item(1759), 2.5D, 1),
69 ROPE(new Item(10814), new Item(954), 25.0D, 30),
70 MAGIC_STRING(new Item(6051), new Item(6038), 30.0D, 19),
71 YEW_STRING(new Item(6049), new Item(9438), 15.0D, 10),
72 SINEW_STRING(new Item(9436), new Item(9438), 15.0D, 10);
73
77 public Item item;
78
82 public Item outcome;
83
87 public double experience;
88
92 public int requiredLevel;
93
102 Spinnable(Item item, Item outcome, double experience, int requiredLevel) {
103 this.item = item;
104 this.outcome = outcome;
105 this.experience = experience;
106 this.requiredLevel = requiredLevel;
107 }
108 }
109
115 public static void open(Player player) {
116 DialogueFactory factory = player.dialogueFactory;
117 factory.sendOption("Ball of wool (wool)", () -> {
118 factory.onAction(() -> {
119 click(player, Spinnable.WOOL);
120 });
121 }, "Bow string (flax)", () -> {
122 factory.onAction(() -> {
123 click(player, Spinnable.BOWSTRING);
124 });
125 }, "Rope (yak hair)", () -> {
126 factory.onAction(() -> {
127 click(player, Spinnable.ROPE);
128 });
129 }, "Nevermind", () -> {
130 player.interfaceManager.close();
131 }).execute();
132 }
133
140 public static void click(Player player, Spinnable spinnable) {
141 player.dialogueFactory.clear();
142
143 if (player.skills.getMaxLevel(Skill.CRAFTING) < spinnable.requiredLevel) {
144 player.dialogueFactory.sendStatement("You need a crafting level of " + spinnable.requiredLevel + " to spin this!").execute();
145 return;
146 }
147
148 if (!player.inventory.contains(spinnable.item)) {
149 player.dialogueFactory.sendStatement("You do not have the required items to do this!").execute();
150 return;
151 }
152
153 ChatBoxItemDialogue.sendInterface(player, 1746, spinnable.item, 170);
154 player.chatBoxItemDialogue = new ChatBoxItemDialogue(player) {
155 @Override
156 public void firstOption(Player player) {
157 player.action.execute(spin(player, spinnable, 1), true);
158 }
159
160 @Override
161 public void secondOption(Player player) {
162 player.action.execute(spin(player, spinnable, 5), true);
163 }
164
165 @Override
166 public void thirdOption(Player player) {
167 player.send(new SendInputAmount("Enter amount", 2, input -> player.action.execute(spin(player, spinnable, Integer.parseInt(input)), true)));
168 }
169
170 @Override
171 public void fourthOption(Player player) {
172 player.action.execute(spin(player, spinnable, 28), true);
173 }
174 };
175 }
176
185 private static Action<Player> spin(Player player, Spinnable spinnable, int amount) {
186 return new Action<Player>(player, 2, true) {
187
188 int ticks = 0;
189
190 @Override
191 public void execute() {
192 if (!player.inventory.contains(spinnable.item)) {
193 cancel();
194 player.send(new SendMessage("<col=369>You have run out of materials."));
195 return;
196 }
197
198 player.animate(new Animation(896));
199 player.inventory.remove(spinnable.item);
200 player.inventory.add(spinnable.outcome);
201 player.skills.addExperience(Skill.CRAFTING, spinnable.experience * Config.CRAFTING_MODIFICATION);
202 player.send(new SendMessage("You spin the " + spinnable.item.getName() + " into " + Utility.getAOrAn(spinnable.outcome.getName()) + " " + spinnable.outcome.getName() + "."));
203
204 if (++ticks == amount) {
205 cancel();
206 return;
207 }
208 }
209
210 @Override
211 public String getName() {
212 return "Spinning";
213 }
214
215 @Override
216 public WalkablePolicy getWalkablePolicy() {
217 return WalkablePolicy.NON_WALKABLE;
218 }
219 };
220 }
221}
static final double CRAFTING_MODIFICATION
Definition Config.java:295
final DialogueFactory sendStatement(String... lines)
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
final DialogueFactory onAction(Runnable action)
static void click(Player player, Spinnable spinnable)
void addExperience(int id, double experience)
static String getAOrAn(String nextWord)
Definition Utility.java:153
Spinnable(Item item, Item outcome, double experience, int requiredLevel)