RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
SmithingArmour.java
1package com.osroyale.content.skill.impl.smithing;
2
3import com.google.common.collect.ImmutableMap;
4import com.osroyale.Config;
5import com.osroyale.content.skill.impl.ProducingSkillAction;
6import com.osroyale.content.skill.impl.slayer.SlayerUnlockable;
7import com.osroyale.content.skillcape.SkillCape;
8import com.osroyale.game.Animation;
9import com.osroyale.game.action.policy.WalkablePolicy;
10import com.osroyale.game.world.entity.mob.player.Player;
11import com.osroyale.game.world.entity.skill.Skill;
12import com.osroyale.game.world.items.Item;
13import com.osroyale.game.world.object.GameObject;
14import com.osroyale.net.packet.out.SendItemOnInterfaceSlot;
15import com.osroyale.net.packet.out.SendMessage;
16import com.osroyale.net.packet.out.SendString;
17import com.osroyale.util.StringUtils;
18
19import java.util.Optional;
20
62
63public final class SmithingArmour extends ProducingSkillAction {
64
65 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();
66 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},};
67
69 private final SmithingTable definition;
70
72 private int amount;
73
75 private SmithingArmour(Player player, SmithingTable definition, int amount) {
76 super(player, Optional.empty(), SkillCape.isEquipped(player, SkillCape.SMITHING) ? 2 : 4, true);
77 this.definition = definition;
78 this.amount = amount;
79 }
80
82 static boolean forge(Player player, int interfaceId, int slot, int amount) {
83 if (player.attributes.get("smithing_equipment") == null) {
84 return false;
85 }
86 SmithingTable[] values = TABLE.get(((Item) player.attributes.get("smithing_equipment")).getId());
87
88 if (values == null) {
89 return false;
90 }
91
92 SmithingTable table = null;
93
94 for (int i = 0; i < FRAME_DATA.length; i++) {
95 if (FRAME_DATA[i][3] == interfaceId && slot == FRAME_DATA[i][2]) {
96 if (i >= values.length)
97 break;
98 table = values[i];
99 break;
100 }
101 }
102
103 if (table == null) {
104 return false;
105 }
106
107 if(table.getProduced().getId() == 2 && !player.slayer.getUnlocked().contains(SlayerUnlockable.CANNON_BALLS)) {
108 player.message("You need to unlock the ability to make cannon balls first.");
109 return false;
110 }
111 if(table.getProduced().getId() == 2 && !player.inventory.contains(4)) {
112 player.message("You need a mould to make cannon balls.");
113 return false;
114 }
115
116 SmithingArmour smithing = new SmithingArmour(player, table, amount);
117 smithing.start();
118 return true;
119 }
120
122 static boolean openInterface(Player player, Item item, GameObject object) {
123 if (object.getDefinition().getId() != 2097 && object.getDefinition().getId() != 2672) {
124 return false;
125 }
126
127 if (!player.inventory.containsAny(2347, 2949)) {
128 player.send(new SendMessage("You need a hammer to forge items."));
129 return true;
130 }
131
132 if (item.getId() == 11286) {
133 if (!player.inventory.containsAll(11286, 1540)) {
134 player.send(new SendMessage("You need a dragonic visage and an anti-dragonfire shield."));
135 return true;
136 }
137 if (!player.skills.get(Skill.SMITHING).reqLevel(85)) {
138 player.send(new SendMessage("You need a level of 85 smithing to do this."));
139 return true;
140 }
141 player.animate(new Animation(898));
143 player.inventory.removeAll(new Item(11286), new Item(1540));
144 player.inventory.add(new Item(11283));
145 return true;
146 }
147
148 if (item.getId() == 22006) {
149 if (!player.inventory.containsAll(22006, 1540)) {
150 player.send(new SendMessage("You need a skeletal visage and an anti-dragonfire shield."));
151 return true;
152 }
153 if (!player.skills.get(Skill.SMITHING).reqLevel(90)) {
154 player.send(new SendMessage("You need a level of 90 smithing to do this."));
155 return true;
156 }
157 player.animate(new Animation(898));
159 player.inventory.removeAll(new Item(22006), new Item(1540));
160 player.inventory.add(new Item(22003));
161 return true;
162 }
163
164 //Godsword blade creation.
165 if (item.getId() == 11794 || item.getId() == 11796 || item.getId() == 11798) {
166 if (!player.inventory.containsAll(11794, 11796, 11798)) {
167 player.send(new SendMessage("You do not have all the godsword shards."));
168 return true;
169 }
170 if (!player.skills.get(Skill.SMITHING).reqLevel(80)) {
171 player.send(new SendMessage("You need a level of 80 smithing to do this."));
172 return true;
173 }
174 player.animate(new Animation(898));
175 player.skills.addExperience(Skill.SMITHING, 200);
176 player.inventory.removeAll(new Item(11794), new Item(11796), new Item(11798));
177 player.inventory.add(new Item(11798));
178 return true;
179 }
180
181 SmithingTable[] values = TABLE.get(item.getId());
182
183 if (values == null) {
184 return false;
185 }
186
187 SmithingTable table = null;
188
189 for (int i = 0; i < FRAME_DATA.length; i++) {
190 if (i >= values.length) {
191 player.send(new SendString("", FRAME_DATA[i][0]));
192 player.send(new SendString("", FRAME_DATA[i][1]));
193 player.send(new SendItemOnInterfaceSlot(FRAME_DATA[i][3], new Item(-1, 0), FRAME_DATA[i][2]));
194 continue;
195 }
196
197 table = values[i];
198
199 if (table == null || table.getBar() == null) {
200 return false;
201 }
202
203 final boolean has_bar = player.inventory.computeAmountForId(table.getBar().getId()) >= table.getBarsRequired();
204 final String bar_color = !has_bar ? "@red@" : "@gre@";
205 final String name_color = player.skills.get(Skill.SMITHING).getMaxLevel() >= table.getLevelRequirement() && has_bar ? "@whi@" : "@bla@";
206
207 player.send(new SendString(bar_color + table.getBarsRequired() + " Bar" + (table.getBarsRequired() != 1 ? "s" : ""), FRAME_DATA[i][0]));
208 player.send(new SendString(name_color + StringUtils.capitalize(table.getName().toLowerCase()), FRAME_DATA[i][1]));
209 player.send(new SendItemOnInterfaceSlot(FRAME_DATA[i][3], table.getProduced(), FRAME_DATA[i][2]));
210 }
211 if (table == null || table.getBar() == null) {
212 return false;
213 }
214 player.attributes.set("smithing_equipment", table.getBar());
215 player.interfaceManager.open(994);
216 return true;
217 }
218
219 @Override
220 public void onProduce(boolean success) {
221 if (success) {
222 getMob().getPlayer().animate(new Animation(898));
223 amount--;
224 if (amount < 1)
225 this.cancel();
226 }
227 }
228
229 @Override
230 public void onCancel(boolean logout) {
231 getMob().attributes.remove("smithing_equipment");
232 }
233
234 @Override
235 public Optional<Item[]> removeItem() {
236 return Optional.of(new Item[]{new Item(definition.getBar().getId(), definition.getBarsRequired())});
237 }
238
239 @Override
240 public Optional<Item[]> produceItem() {
241 return Optional.of(new Item[]{definition.getProduced()});
242 }
243
244 @Override
245 public boolean canInit() {
246 if (!getMob().skills.get(Skill.SMITHING).reqLevel(definition.getLevelRequirement())) {
247 getMob().getPlayer().send(new SendMessage("You need a smithing level of " + definition.getLevelRequirement() + " to smith " + StringUtils.appendIndefiniteArticle(definition.getName())));
248 return false;
249 }
250 return true;
251 }
252
253 @Override
254 public void init() {
255 getMob().getPlayer().interfaceManager.close();
256 }
257
258 @Override
259 public Optional<SkillAnimation> animation() {
260 return Optional.empty();
261 }
262
263 @Override
264 public double experience() {
265 return definition.getExperience() * Config.SMITHING_MODIFICATION;
266 }
267
268 @Override
269 public int skill() {
270 return Skill.SMITHING;
271 }
272
273 @Override
274 public boolean prioritized() {
275 return false;
276 }
277
278 @Override
282
283 @Override
284 public String getName() {
285 return "smithing_armour";
286 }
287}
static final double SMITHING_MODIFICATION
Definition Config.java:331
ProducingSkillAction(Player player, Optional< Position > position, boolean instant)
synchronized final void cancel()
Definition Task.java:147
void addExperience(int id, double experience)
boolean removeAll(Collection<? extends Item > items)
static String appendIndefiniteArticle(String thing)