RuneHive-Game
Loading...
Searching...
No Matches
Tanning.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.SendItemOnInterfaceZoom;
6import com.runehive.net.packet.out.SendMessage;
7import com.runehive.net.packet.out.SendString;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.game.world.items.Item;
10import com.runehive.game.world.items.ItemDefinition;
11import com.runehive.util.Utility;
12
13/**
14 * Handles tanning leathers.
15 *
16 * @author Daniel
17 */
18public class Tanning {
19
20 /**
21 * The tan data.
22 */
23 public enum TanData {
24 LEATHER(1739, 1741, 1),
25 HARD_LEATHER(1739, 1743, 3),
26 SNAKE_HIDE(6287, 6287, 15),
27 SNAKESKIN(6287, 6289, 20),
28 GREEN_LEATHER(1753, 1745, 20),
29 BLUE_LEATHER(1751, 2505, 20),
30 RED_LEATHER(1749, 2507, 20),
31 BLACK_LEATHER(1747, 2509, 20);
32
33 /**
34 * The ingredient item.
35 */
36 public final int ingredient;
37
38 /**
39 * The product item
40 */
41 public final int product;
42
43 /**
44 * The tan cost.
45 */
46 public final int cost;
47
48 /**
49 * Constructs a new <code>TanData</code>.
50 *
51 * @param ingredient The ingredient item.
52 * @param product The product item.
53 * @param cost The tan cost.
54 */
55 TanData(int ingredient, int product, int cost) {
56 this.ingredient = ingredient;
57 this.product = product;
58 this.cost = cost;
59 }
60 }
61
62 /**
63 * Handles opening the tanning itemcontainer.
64 *
65 * @param player The player instance.
66 */
67 public static void open(Player player) {
68 int count = 0;
69 for (TanData data : TanData.values()) {
70 player.send(new SendItemOnInterfaceZoom(14769 + count, 250, data.ingredient));
71 player.send(new SendString((player.inventory.contains(data.ingredient) ? "<col=23db44>" : "<col=e0061c>") + Utility.formatEnum(data.name()), 14777 + count));
72 player.send(new SendString((player.inventory.contains(new Item(Config.CURRENCY, data.cost)) ? "<col=23db44>" : "<col=e0061c>") + data.cost + " coins", 14785 + count));
73 count++;
74 }
75
76 player.interfaceManager.open(14670);
77 }
78
79 /**
80 * Tans the leather.
81 *
82 * @param player The player instance.
83 * @param amount The amount being tanned.
84 * @param data The tan data.
85 */
86 public static void tan(Player player, int amount, TanData data) {
87 if (!player.inventory.contains(data.ingredient)) {
88 player.send(new SendMessage("You do not have any " + ItemDefinition.get(data.ingredient).getName() + " to do this."));
89 return;
90 }
91
92 int contain = player.inventory.computeAmountForId(data.ingredient);
93
94 if (amount > contain)
95 amount = contain;
96
97 int cost = data.cost * amount;
98
99 if (!player.inventory.contains(new Item(Config.CURRENCY, cost))) {
100 player.send(new SendMessage("You need " + cost + " coins to tan " + amount + " " + ItemDefinition.get(data.ingredient).getName() + "!"));
101 return;
102 }
103
104 player.inventory.remove(Config.CURRENCY, cost);
105 player.inventory.remove(data.ingredient, amount);
106 player.inventory.add(data.product, amount);
107 player.send(new SendMessage("You successfully tan all the " + ItemDefinition.get(data.ingredient).getName() + " for " + amount + " coins.", true));
108 }
109
110 /**
111 * Handles clicking the tan buttons on the itemcontainer.
112 *
113 * @param player The player instance.
114 * @param button The button identification.
115 * @return If a button was clicked.
116 */
117 public static boolean click(Player player, int button) {
118 switch (button) {
119 /** Leather */
120 case 14817:
121 tan(player, 1, TanData.LEATHER);
122 return true;
123 case 14809:
124 tan(player, 5, TanData.LEATHER);
125 return true;
126 case 14801:
127 player.send(new SendInputAmount("How many leathers would you like to tan?", 2, input -> {
128 tan(player, Integer.parseInt(input), TanData.LEATHER);
129 }));
130 return true;
131 case 14793:
132 tan(player, 28, TanData.LEATHER);
133 return true;
134
135 /** Hard leather */
136 case 14818:
137 tan(player, 1, TanData.HARD_LEATHER);
138 return true;
139 case 14810:
140 tan(player, 5, TanData.HARD_LEATHER);
141 return true;
142 case 14802:
143 player.send(new SendInputAmount("How many leathers would you like to tan?", 2, input -> {
144 tan(player, Integer.parseInt(input), TanData.HARD_LEATHER);
145 }));
146 return true;
147 case 14794:
148 tan(player, 28, TanData.HARD_LEATHER);
149 return true;
150
151 /** Snake hide */
152 case 14819:
153 tan(player, 1, TanData.SNAKE_HIDE);
154 return true;
155 case 14811:
156 tan(player, 5, TanData.SNAKE_HIDE);
157 return true;
158 case 14803:
159 player.send(new SendInputAmount("How many leathers would you like to tan?", 2, input -> {
160 tan(player, Integer.parseInt(input), TanData.SNAKE_HIDE);
161 }));
162 return true;
163 case 14795:
164 tan(player, 28, TanData.SNAKE_HIDE);
165 return true;
166
167 /** Snakeskin */
168 case 14820:
169 tan(player, 1, TanData.SNAKESKIN);
170 return true;
171 case 14812:
172 tan(player, 5, TanData.SNAKESKIN);
173 return true;
174 case 14804:
175 player.send(new SendInputAmount("How many leathers would you like to tan?", 2, input -> {
176 tan(player, Integer.parseInt(input), TanData.SNAKESKIN);
177 }));
178 return true;
179 case 14796:
180 tan(player, 28, TanData.SNAKESKIN);
181 return true;
182
183 /** Green leather */
184 case 14821:
185 tan(player, 1, TanData.GREEN_LEATHER);
186 return true;
187 case 14813:
188 tan(player, 5, TanData.GREEN_LEATHER);
189 return true;
190 case 14805:
191 player.send(new SendInputAmount("How many leathers would you like to tan?", 2, input -> {
192 tan(player, Integer.parseInt(input), TanData.GREEN_LEATHER);
193 }));
194 return true;
195 case 14797:
196 tan(player, 28, TanData.GREEN_LEATHER);
197 return true;
198
199 /** Blue leather */
200 case 14822:
201 tan(player, 1, TanData.BLUE_LEATHER);
202 return true;
203 case 14814:
204 tan(player, 5, TanData.BLUE_LEATHER);
205 return true;
206 case 14806:
207 player.send(new SendInputAmount("How many leathers would you like to tan?", 2, input -> {
208 tan(player, Integer.parseInt(input), TanData.BLUE_LEATHER);
209 }));
210 return true;
211 case 14798:
212 tan(player, 28, TanData.BLUE_LEATHER);
213 return true;
214
215 /** Red leather */
216 case 14823:
217 tan(player, 1, TanData.RED_LEATHER);
218 return true;
219 case 14815:
220 tan(player, 5, TanData.RED_LEATHER);
221 return true;
222 case 14807:
223 player.send(new SendInputAmount("How many leathers would you like to tan?", 2, input -> {
224 tan(player, Integer.parseInt(input), TanData.RED_LEATHER);
225 }));
226 return true;
227 case 14799:
228 tan(player, 28, TanData.RED_LEATHER);
229 return true;
230
231 /** Black leather */
232 case 14824:
233 tan(player, 1, TanData.BLACK_LEATHER);
234 return true;
235 case 14816:
236 tan(player, 5, TanData.BLACK_LEATHER);
237 return true;
238 case 14808:
239 player.send(new SendInputAmount("How many leathers would you like to tan?", 2, input -> {
240 tan(player, Integer.parseInt(input), TanData.BLACK_LEATHER);
241 }));
242 return true;
243 case 14800:
244 tan(player, 28, TanData.BLACK_LEATHER);
245 return true;
246 }
247 return false;
248 }
249}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final int CURRENCY
The currency identification of the server.
Definition Config.java:175
static void tan(Player player, int amount, TanData data)
Tans the leather.
Definition Tanning.java:86
static boolean click(Player player, int button)
Handles clicking the tan buttons on the itemcontainer.
Definition Tanning.java:117
static void open(Player player)
Handles opening the tanning itemcontainer.
Definition Tanning.java:67
void open(int identification)
Opens an interface for the player.
This class represents a character controlled by a player.
Definition Player.java:125
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 computeAmountForId(int id)
Computes the total quantity of the Items in this container with id.
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.
Handles sending the SendItemOnInterfaceZoom packet.
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatEnum(final String string)
Formats name of enum.
Definition Utility.java:89
TanData(int ingredient, int product, int cost)
Constructs a new TanData.
Definition Tanning.java:55