RuneHive-Game
Loading...
Searching...
No Matches
Stringing.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.action.Action;
7import com.runehive.game.action.policy.WalkablePolicy;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.content.dialogue.ChatBoxItemDialogue;
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/**
20 * Handles stringing amulets.
21 *
22 * @author Daniel
23 */
24public class Stringing {
25
26 /**
27 * The amulet data.
28 */
29 public enum AmuletData {
30 GOLD(1673, 1692, 8),
31 SAPPHIRE(1675, 1694, 24),
32 EMERALD(1677, 1696, 31),
33 RUBY(1679, 1698, 50),
34 DIAMOND(1681, 1700, 70),
35 DRAGONSTONE(1683, 1702, 80),
36 ONYX(6579, 6581, 90),
37 ZENYTE(19501, 19541, 98);
38
39 /**
40 * The amulet item.
41 */
42 private final int ingredient;
43
44 /**
45 * The product item.
46 */
47 private final int product;
48
49 /**
50 * The level required.
51 */
52 private final int level;
53
54 /**
55 * Constructs a new <code>AmuletData</code>.
56 *
57 * @param ingredient The amulet item.
58 * @param product The product item.
59 * @param level The level required.
60 */
62 this.ingredient = ingredient;
63 this.product = product;
64 this.level = level;
65 }
66
67 /**
68 * Grabs the amulet data.
69 *
70 * @param ingredient The amulet ingredient.
71 * @return The amulet data.
72 */
73 public static Optional<AmuletData> forAmulet(int ingredient) {
74 return Arrays.stream(values()).filter(a -> a.ingredient == ingredient).findAny();
75 }
76 }
77
78 /**
79 * Handles using item.
80 *
81 * @param player The player instance.
82 * @param used The item being used.
83 * @param with The item being used with.
84 */
85 public static boolean useItem(Player player, Item used, Item with) {
86 if (used.getId() != 1759 && with.getId() != 1759) {
87 return false;
88 }
89
90 Item wool = used.getId() == 1759 ? used : with;
91 Item amulet = wool.getId() == used.getId() ? with : used;
92
93 if (!AmuletData.forAmulet(amulet.getId()).isPresent()) {
94 return false;
95 }
96
97 AmuletData data = AmuletData.forAmulet(amulet.getId()).get();
98 craft(player, data);
99 return false;
100 }
101
102 /**
103 * Handles crafting the amulet.
104 *
105 * @param player The player instance.
106 * @param amulet The amulet data.
107 */
108 public static void craft(Player player, AmuletData amulet) {
109 player.dialogueFactory.clear();
110
111 if (player.skills.getMaxLevel(Skill.CRAFTING) < amulet.level) {
112 player.dialogueFactory.sendStatement("You need a crafting level of " + amulet.level + " to string this!").execute();
113 return;
114 }
115
116 if (!player.inventory.contains(amulet.ingredient) || !player.inventory.contains(1759)) {
117 player.dialogueFactory.sendStatement("You do not have the required items to do this!").execute();
118 return;
119 }
120
121 ChatBoxItemDialogue.sendInterface(player, 1746, amulet.ingredient, 170);
122 player.chatBoxItemDialogue = new ChatBoxItemDialogue(player) {
123 @Override
124 public void firstOption(Player player) {
125 player.action.execute(string(player, amulet, 1), false);
126 }
127
128 @Override
129 public void secondOption(Player player) {
130 player.action.execute(string(player, amulet, 5), true);
131 }
132
133 @Override
134 public void thirdOption(Player player) {
135 player.send(new SendInputAmount("Enter amount", 2, input -> player.action.execute(string(player, amulet, Integer.parseInt(input)), true)));
136 }
137
138 @Override
139 public void fourthOption(Player player) {
140 player.action.execute(string(player, amulet, 14), true);
141 }
142 };
143 }
144
145 /**
146 * The amulet stringing action.
147 *
148 * @param player The player instance.
149 * @param amulet The amulet data.
150 * @param amount The amount beeing spun.
151 * @return The spinnable action.
152 */
153 private static Action<Player> string(Player player, AmuletData amulet, int amount) {
154 return new Action<Player>(player, 2, true) {
155 int ticks = 0;
156
157 @Override
158 public void execute() {
159 if (!player.inventory.contains(amulet.ingredient) || !player.inventory.contains(1759)) {
160 cancel();
161
162 return;
163 }
164
165 player.inventory.remove(amulet.ingredient, 1);
166 player.inventory.remove(1759, 1);
167 player.inventory.add(amulet.product, 1);
169 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() + "."));
170
171 if (++ticks == amount) {
172 cancel();
173 return;
174 }
175 }
176
177 @Override
178 public String getName() {
179 return "Stringing";
180 }
181
182 @Override
183 public boolean prioritized() {
184 return false;
185 }
186
187 @Override
188 public WalkablePolicy getWalkablePolicy() {
190 }
191 };
192 }
193}
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)
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
void clear()
Clears the current dialogue chain.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
static void craft(Player player, AmuletData amulet)
Handles crafting the amulet.
static Action< Player > string(Player player, AmuletData amulet, int amount)
The amulet stringing action.
static boolean useItem(Player player, Item used, Item with)
Handles using item.
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.
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
final int getId()
Gets the identification of this item.
Definition Item.java:324
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
static Optional< AmuletData > forAmulet(int ingredient)
Grabs the amulet data.
AmuletData(int ingredient, int product, int level)
Constructs a new AmuletData.
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.