RuneHive-Game
Loading...
Searching...
No Matches
Spinning.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.content.dialogue.ChatBoxItemDialogue;
11import com.runehive.content.dialogue.DialogueFactory;
12import com.runehive.game.world.entity.skill.Skill;
13import com.runehive.game.world.items.Item;
14import com.runehive.util.Utility;
15
16/**
17 * Handles spinning items on the spinning wheel.
18 *
19 * @author Daniel
20 */
21public class Spinning {
22 /**
23 * The spinnable data.
24 */
25 public enum Spinnable {
26 BOWSTRING(new Item(1779), new Item(1777), 15.0D, 10),
27 WOOL(new Item(1737), new Item(1759), 2.5D, 1),
28 ROPE(new Item(10814), new Item(954), 25.0D, 30),
29 MAGIC_STRING(new Item(6051), new Item(6038), 30.0D, 19),
30 YEW_STRING(new Item(6049), new Item(9438), 15.0D, 10),
31 SINEW_STRING(new Item(9436), new Item(9438), 15.0D, 10);
32
33 /**
34 * The spinnable item.
35 */
36 public Item item;
37
38 /**
39 * The spinnable outcome item.
40 */
41 public Item outcome;
42
43 /**
44 * The spinnable experience.
45 */
46 public double experience;
47
48 /**
49 * The level required to spin.
50 */
51 public int requiredLevel;
52
53 /**
54 * Constructs a new <code>Spinnable</code>.
55 *
56 * @param item The item required.
57 * @param outcome The outcome item.
58 * @param experience The experience rewarded.
59 * @param requiredLevel The level required.
60 */
62 this.item = item;
63 this.outcome = outcome;
64 this.experience = experience;
65 this.requiredLevel = requiredLevel;
66 }
67 }
68
69 /**
70 * Handles opening the spinning dialogue.
71 *
72 * @param player The player instance.
73 */
74 public static void open(Player player) {
75 DialogueFactory factory = player.dialogueFactory;
76 factory.sendOption("Ball of wool (wool)", () -> {
77 factory.onAction(() -> {
78 click(player, Spinnable.WOOL);
79 });
80 }, "Bow string (flax)", () -> {
81 factory.onAction(() -> {
82 click(player, Spinnable.BOWSTRING);
83 });
84 }, "Rope (yak hair)", () -> {
85 factory.onAction(() -> {
86 click(player, Spinnable.ROPE);
87 });
88 }, "Nevermind", () -> {
89 player.interfaceManager.close();
90 }).execute();
91 }
92
93 /**
94 * Opens the spinnable dialogue.
95 *
96 * @param player The player instance.
97 * @param spinnable The spinnable data.
98 */
99 public static void click(Player player, Spinnable spinnable) {
100 player.dialogueFactory.clear();
101
102 if (player.skills.getMaxLevel(Skill.CRAFTING) < spinnable.requiredLevel) {
103 player.dialogueFactory.sendStatement("You need a crafting level of " + spinnable.requiredLevel + " to spin this!").execute();
104 return;
105 }
106
107 if (!player.inventory.contains(spinnable.item)) {
108 player.dialogueFactory.sendStatement("You do not have the required items to do this!").execute();
109 return;
110 }
111
112 ChatBoxItemDialogue.sendInterface(player, 1746, spinnable.item, 170);
113 player.chatBoxItemDialogue = new ChatBoxItemDialogue(player) {
114 @Override
115 public void firstOption(Player player) {
116 player.action.execute(spin(player, spinnable, 1), true);
117 }
118
119 @Override
120 public void secondOption(Player player) {
121 player.action.execute(spin(player, spinnable, 5), true);
122 }
123
124 @Override
125 public void thirdOption(Player player) {
126 player.send(new SendInputAmount("Enter amount", 2, input -> player.action.execute(spin(player, spinnable, Integer.parseInt(input)), true)));
127 }
128
129 @Override
130 public void fourthOption(Player player) {
131 player.action.execute(spin(player, spinnable, 28), true);
132 }
133 };
134 }
135
136 /**
137 * The spinnable action.
138 *
139 * @param player The player instance.
140 * @param spinnable The spinnable data.
141 * @param amount The amount beeing spun.
142 * @return The spinnable action.
143 */
144 private static Action<Player> spin(Player player, Spinnable spinnable, int amount) {
145 return new Action<Player>(player, 2, true) {
146
147 int ticks = 0;
148
149 @Override
150 public void execute() {
151 if (!player.inventory.contains(spinnable.item)) {
152 cancel();
153 player.send(new SendMessage("<col=369>You have run out of materials."));
154 return;
155 }
156
157 player.animate(new Animation(896));
158 player.inventory.remove(spinnable.item);
159 player.inventory.add(spinnable.outcome);
161 player.send(new SendMessage("You spin the " + spinnable.item.getName() + " into " + Utility.getAOrAn(spinnable.outcome.getName()) + " " + spinnable.outcome.getName() + "."));
162
163 if (++ticks == amount) {
164 cancel();
165 return;
166 }
167 }
168
169 @Override
170 public String getName() {
171 return "Spinning";
172 }
173
174 @Override
175 public WalkablePolicy getWalkablePolicy() {
177 }
178 };
179 }
180}
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 void sendInterface(Player player, int interfaceId, Item item, int zoom)
Represents a factory class that contains important functions for building dialogues.
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
void clear()
Clears the current dialogue chain.
final DialogueFactory onAction(Runnable action)
Sets an action so this action can be executed after dialogues are done.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
Handles spinning items on the spinning wheel.
Definition Spinning.java:21
static Action< Player > spin(Player player, Spinnable spinnable, int amount)
The spinnable action.
static void open(Player player)
Handles opening the spinning dialogue.
Definition Spinning.java:74
static void click(Player player, Spinnable spinnable)
Opens the spinnable dialogue.
Definition Spinning.java:99
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)
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.
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.
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
Spinnable(Item item, Item outcome, double experience, int requiredLevel)
Constructs a new Spinnable.
Definition Spinning.java:61
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.