RuneHive-Game
Loading...
Searching...
No Matches
SmithingArmour.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.smithing;
2
3import com.google.common.collect.ImmutableMap;
4import com.runehive.Config;
5import com.runehive.content.skill.impl.ProducingSkillAction;
6import com.runehive.content.skill.impl.slayer.SlayerUnlockable;
7import com.runehive.content.skillcape.SkillCape;
8import com.runehive.game.Animation;
9import com.runehive.game.action.policy.WalkablePolicy;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.entity.skill.Skill;
12import com.runehive.game.world.items.Item;
13import com.runehive.game.world.object.GameObject;
14import com.runehive.net.packet.out.SendItemOnInterfaceSlot;
15import com.runehive.net.packet.out.SendMessage;
16import com.runehive.net.packet.out.SendString;
17import com.runehive.util.StringUtils;
18
19import java.util.Optional;
20
21/**
22 * Holds functionality for creating items on an anvil.
23 *
24 * @author <a href="http://www.rune-server.org/members/stand+up/">Stand Up</a>
25 */
26public final class SmithingArmour extends ProducingSkillAction {
27
28 private static final ImmutableMap<Integer, SmithingTable[]> TABLE = ImmutableMap.<Integer, SmithingTable[]>builder().put(2349, SmithingTable.BronzeTable.values()).put(2351, SmithingTable.IronTable.values()).put(2353, SmithingTable.SteelTable.values()).put(2359, SmithingTable.MithrilTable.values()).put(2361, SmithingTable.AdamantTable.values()).put(2363, SmithingTable.RuniteTable.values()).build();
29 private static final int[][] FRAME_DATA = {{1125, 1094, 0, 1119}, {1126, 1091, 0, 1120}, {1109, 1098, 0, 1121}, {1127, 1102, 0, 1122}, {1128, 1107, 0, 1123}, {1124, 1085, 1, 1119}, {1129, 1093, 1, 1120}, {1110, 1099, 1, 1121}, {1113, 1103, 1, 1122}, {1130, 1108, 1, 1123}, {1116, 1087, 2, 1119}, {1118, 1083, 2, 1120}, {1111, 1100, 2, 1121}, {1114, 1104, 2, 1122}, {1131, 1106, 2, 1123}, {1089, 1086, 3, 1119}, {1095, 1092, 3, 1120}, {1112, 1101, 3, 1121}, {1115, 1105, 3, 1122}, {1132, 1096, 3, 1123}, {1090, 1088, 4, 1119}, {8428, 8429, 4, 1120}, {11459, 11461, 4, 1121}, {13357, 13358, 4, 1122}, {1135, 1134, 4, 1123},};
30
31 /** The definition for this table. */
33
34 /** The amount being created. */
35 private int amount;
36
37 /** Constructs a new {@link Smithing} skill. */
39 super(player, Optional.empty(), SkillCape.isEquipped(player, SkillCape.SMITHING) ? 2 : 4, true);
40 this.definition = definition;
41 this.amount = amount;
42 }
43
44 /** Attempts to forge the item clicked for the specified {@code player}. */
45 static boolean forge(Player player, int interfaceId, int slot, int amount) {
46 if (player.attributes.get("smithing_equipment") == null) {
47 return false;
48 }
49 SmithingTable[] values = TABLE.get(((Item) player.attributes.get("smithing_equipment")).getId());
50
51 if (values == null) {
52 return false;
53 }
54
55 SmithingTable table = null;
56
57 for (int i = 0; i < FRAME_DATA.length; i++) {
58 if (FRAME_DATA[i][3] == interfaceId && slot == FRAME_DATA[i][2]) {
59 if (i >= values.length)
60 break;
61 table = values[i];
62 break;
63 }
64 }
65
66 if (table == null) {
67 return false;
68 }
69
70 if(table.getProduced().getId() == 2 && !player.slayer.getUnlocked().contains(SlayerUnlockable.CANNON_BALLS)) {
71 player.message("You need to unlock the ability to make cannon balls first.");
72 return false;
73 }
74 if(table.getProduced().getId() == 2 && !player.inventory.contains(4)) {
75 player.message("You need a mould to make cannon balls.");
76 return false;
77 }
78
79 SmithingArmour smithing = new SmithingArmour(player, table, amount);
80 smithing.start();
81 return true;
82 }
83
84 /** Opens the smithing itemcontainer and sets all the values for the specified {code player}. */
85 static boolean openInterface(Player player, Item item, GameObject object) {
86 if (object.getDefinition().getId() != 2097 && object.getDefinition().getId() != 2672) {
87 return false;
88 }
89
90 if (!player.inventory.containsAny(2347, 2949)) {
91 player.send(new SendMessage("You need a hammer to forge items."));
92 return true;
93 }
94
95 if (item.getId() == 11286) {
96 if (!player.inventory.containsAll(11286, 1540)) {
97 player.send(new SendMessage("You need a dragonic visage and an anti-dragonfire shield."));
98 return true;
99 }
100 if (!player.skills.get(Skill.SMITHING).reqLevel(85)) {
101 player.send(new SendMessage("You need a level of 85 smithing to do this."));
102 return true;
103 }
104 player.animate(new Animation(898));
106 player.inventory.removeAll(new Item(11286), new Item(1540));
107 player.inventory.add(new Item(11283));
108 return true;
109 }
110
111 if (item.getId() == 22006) {
112 if (!player.inventory.containsAll(22006, 1540)) {
113 player.send(new SendMessage("You need a skeletal visage and an anti-dragonfire shield."));
114 return true;
115 }
116 if (!player.skills.get(Skill.SMITHING).reqLevel(90)) {
117 player.send(new SendMessage("You need a level of 90 smithing to do this."));
118 return true;
119 }
120 player.animate(new Animation(898));
122 player.inventory.removeAll(new Item(22006), new Item(1540));
123 player.inventory.add(new Item(22003));
124 return true;
125 }
126
127 //Godsword blade creation.
128 if (item.getId() == 11794 || item.getId() == 11796 || item.getId() == 11798) {
129 if (!player.inventory.containsAll(11794, 11796, 11798)) {
130 player.send(new SendMessage("You do not have all the godsword shards."));
131 return true;
132 }
133 if (!player.skills.get(Skill.SMITHING).reqLevel(80)) {
134 player.send(new SendMessage("You need a level of 80 smithing to do this."));
135 return true;
136 }
137 player.animate(new Animation(898));
138 player.skills.addExperience(Skill.SMITHING, 200);
139 player.inventory.removeAll(new Item(11794), new Item(11796), new Item(11798));
140 player.inventory.add(new Item(11798));
141 return true;
142 }
143
144 SmithingTable[] values = TABLE.get(item.getId());
145
146 if (values == null) {
147 return false;
148 }
149
150 SmithingTable table = null;
151
152 for (int i = 0; i < FRAME_DATA.length; i++) {
153 if (i >= values.length) {
154 player.send(new SendString("", FRAME_DATA[i][0]));
155 player.send(new SendString("", FRAME_DATA[i][1]));
156 player.send(new SendItemOnInterfaceSlot(FRAME_DATA[i][3], new Item(-1, 0), FRAME_DATA[i][2]));
157 continue;
158 }
159
160 table = values[i];
161
162 if (table == null || table.getBar() == null) {
163 return false;
164 }
165
166 final boolean has_bar = player.inventory.computeAmountForId(table.getBar().getId()) >= table.getBarsRequired();
167 final String bar_color = !has_bar ? "@red@" : "@gre@";
168 final String name_color = player.skills.get(Skill.SMITHING).getMaxLevel() >= table.getLevelRequirement() && has_bar ? "@whi@" : "@bla@";
169
170 player.send(new SendString(bar_color + table.getBarsRequired() + " Bar" + (table.getBarsRequired() != 1 ? "s" : ""), FRAME_DATA[i][0]));
171 player.send(new SendString(name_color + StringUtils.capitalize(table.getName().toLowerCase()), FRAME_DATA[i][1]));
172 player.send(new SendItemOnInterfaceSlot(FRAME_DATA[i][3], table.getProduced(), FRAME_DATA[i][2]));
173 }
174 if (table == null || table.getBar() == null) {
175 return false;
176 }
177 player.attributes.set("smithing_equipment", table.getBar());
178 player.interfaceManager.open(994);
179 return true;
180 }
181
182 @Override
183 public void onProduce(boolean success) {
184 if (success) {
185 getMob().getPlayer().animate(new Animation(898));
186 amount--;
187 if (amount < 1)
188 this.cancel();
189 }
190 }
191
192 @Override
193 public void onCancel(boolean logout) {
194 getMob().attributes.remove("smithing_equipment");
195 }
196
197 @Override
198 public Optional<Item[]> removeItem() {
199 return Optional.of(new Item[]{new Item(definition.getBar().getId(), definition.getBarsRequired())});
200 }
201
202 @Override
203 public Optional<Item[]> produceItem() {
204 return Optional.of(new Item[]{definition.getProduced()});
205 }
206
207 @Override
208 public boolean canInit() {
209 if (!getMob().skills.get(Skill.SMITHING).reqLevel(definition.getLevelRequirement())) {
210 getMob().getPlayer().send(new SendMessage("You need a smithing level of " + definition.getLevelRequirement() + " to smith " + StringUtils.appendIndefiniteArticle(definition.getName())));
211 return false;
212 }
213 return true;
214 }
215
216 @Override
217 public void init() {
218 getMob().getPlayer().interfaceManager.close();
219 }
220
221 @Override
222 public Optional<SkillAnimation> animation() {
223 return Optional.empty();
224 }
225
226 @Override
227 public double experience() {
228 return definition.getExperience() * Config.SMITHING_MODIFICATION;
229 }
230
231 @Override
232 public int skill() {
233 return Skill.SMITHING;
234 }
235
236 @Override
237 public boolean prioritized() {
238 return false;
239 }
240
241 @Override
245
246 @Override
247 public String getName() {
248 return "smithing_armour";
249 }
250}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double SMITHING_MODIFICATION
The experience modification for smithing.
Definition Config.java:289
ProducingSkillAction(Player player, Optional< Position > position, boolean instant)
Creates a new ProducingSkillAction.
Set< SlayerUnlockable > getUnlocked()
Definition Slayer.java:359
static boolean forge(Player player, int interfaceId, int slot, int amount)
Attempts to forge the item clicked for the specified player.
int skill()
The skill we should hand to experience to.
Optional< SkillAnimation > animation()
The skill animation to execute.
static boolean openInterface(Player player, Item item, GameObject object)
Opens the smithing itemcontainer and sets all the values for the specified {code player}...
double experience()
The experience given from this action.
SmithingArmour(Player player, SmithingTable definition, int amount)
Constructs a new Smithing skill.
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
Optional< Item[]> produceItem()
The item that will be added upon production.
boolean prioritized()
Determines if this action is prioritized.
static final ImmutableMap< Integer, SmithingTable[]> TABLE
void onProduce(boolean success)
The method executed upon production of an item.
void init()
Any functionality that should be handled when this action is submitted.
Optional< Item[]> removeItem()
The item that will be removed upon production.
void onCancel(boolean logout)
A function executed on cancellation.
final SmithingTable definition
The definition for this table.
boolean canInit()
Determines if this action can be initialized.
Class that models a single animation used by an entity.
T getMob()
Gets the player.
Definition Action.java:44
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
final GenericAttributes attributes
Definition Mob.java:95
void open(int identification)
Opens an interface for the player.
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 SMITHING
The smithing skill id.
Definition Skill.java:60
boolean reqLevel(int level)
Determines if your level is greater than or equal to level.
Definition Skill.java:270
int getMaxLevel()
Gets the maximum skill level.
Definition Skill.java:214
void addExperience(int id, double experience)
Adds experience to a given skill.
Skill get(int id)
Gets the skill for an id.
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
final int computeAmountForId(int id)
Computes the total quantity of the Items in this container with id.
boolean add(Item item)
Attempts to deposit item into this container.
boolean contains(int id)
Determines if this container contains id.
final boolean containsAny(int... identifiers)
Determines if this container contains any identifiers.
boolean removeAll(Collection<? extends Item > items)
Attempts to withdraw items in bulk from this container.
final boolean containsAll(int... identifiers)
Determines if this container contains all identifiers.
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.
static String capitalize(String string)
static String appendIndefiniteArticle(String thing)
Appends the determined indefinite article to thing.
public< K, E > E get(K key)
Gets a generic attribute.
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
Holds all the unlockable slayer rewards and tasks.
static boolean isEquipped(Player player, SkillCape cape)
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.
String getName()
The name of the producable item.
int getBarsRequired()
The bars required for smithing this bar.
Item getProduced()
The produced item for smithing this bar.
int getLevelRequirement()
The level requirement for smithing this bar.
Item getBar()
The item identification for the bar used to forge the table of items.