71public class Fletching
extends Skill {
73 private static final Logger logger = LogManager.getLogger(Fletching.class);
75 private static final String FLETCHABLE_KEY =
"FLETCHABLE_KEY";
77 private final static HashMap<Integer, Fletchable> FLETCHABLES =
new HashMap<>();
79 public Fletching(
int level,
double experience) {
80 super(
Skill.FLETCHING, level, experience);
83 public static void addFletchable(Fletchable fletchable) {
84 if (FLETCHABLES.put(fletchable.getWith().getId(), fletchable) !=
null) {
85 System.out.println(
"[Fletching] Conflicting item values: " + fletchable.getWith().getId() +
" Type: " + fletchable.getClass().getSimpleName());
89 private Fletchable getFletchable(
int use,
int with) {
90 return FLETCHABLES.getOrDefault(use, FLETCHABLES.get(with));
94 protected double modifier() {
100 Item first =
event.getFirst();
101 Item second =
event.getSecond();
107 Fletchable fletchable = getFletchable(first.getId(), second.getId());
109 if (fletchable ==
null || first.getId() == 590 || second.getId() == 590 || first.getId() == 8792 || second.getId() == 8792) {
113 if (!fletchable.getUse().equalIds(first) && !fletchable.getUse().equalIds(second)) {
114 player.message(
"You need to use this with " +
Utility.
getAOrAn(fletchable.getUse().getName()) +
" " + fletchable.getUse().getName().toLowerCase() +
" to fletch this item.");
118 String prefix = fletchable.getWith().getName().split(
" ")[0];
120 switch (fletchable.getFletchableItems().length) {
123 player.attributes.set(FLETCHABLE_KEY, fletchable);
124 player.send(
new SendString(
"\\n \\n \\n \\n" + fletchable.getFletchableItems()[0].getProduct().getName(), 2799));
129 player.attributes.set(FLETCHABLE_KEY, fletchable);
132 player.send(
new SendString(
"\\n \\n \\n \\n".concat(prefix +
" Short Bow"), 8874));
133 player.send(
new SendString(
"\\n \\n \\n \\n".concat(prefix +
" Long Bow"), 8878));
137 player.attributes.set(FLETCHABLE_KEY, fletchable);
141 player.send(
new SendString(
"\\n \\n \\n \\n".concat(
"Arrow heads"), 8889));
142 player.send(
new SendString(
"\\n \\n \\n \\n".concat(prefix +
" Short Bow"), 8893));
143 player.send(
new SendString(
"\\n \\n \\n \\n".concat(prefix +
" Long Bow"), 8897));
147 player.attributes.set(FLETCHABLE_KEY, fletchable);
153 String[] productNames;
154 if (fletchable ==
Carvable.AMETHYST) {
155 productNames =
new String[]{
"Arrowtips",
"Bolt tips",
"Javelin heads",
"Dart tips"};
157 productNames =
new String[]{
"Arrow Shafts",
"Short Bow",
"Long Bow",
"Crossbow Stock"};
160 player.send(
new SendString(
"\\n \\n \\n \\n".concat(productNames[0]), 8909));
161 player.send(
new SendString(
"\\n \\n \\n \\n".concat(productNames[1]), 8913));
162 player.send(
new SendString(
"\\n \\n \\n \\n".concat(productNames[2]), 8917));
163 player.send(
new SendString(
"\\n \\n \\n \\n".concat(productNames[3]), 8921));
173 if (player.attributes.get(FLETCHABLE_KEY, Fletchable.class) ==
null) {
177 Fletchable fletchable = player.attributes.get(FLETCHABLE_KEY, Fletchable.class);
179 int button =
event.getButton();
185 start(player, fletchable, 0, 15);
193 start(player, fletchable, 0, 1);
201 start(player, fletchable, 0, 5);
208 start(player, fletchable, 0, 10);
220 start(player, fletchable, 0, Integer.parseInt(input))));
222 }
catch (Exception ex) {
223 logger.error(String.format(
"player=%s error fletching option1: make-x", player.
getName()), ex);
231 start(player, fletchable, 1, 1);
238 start(player, fletchable, 1, 5);
245 start(player, fletchable, 1, 10);
253 player.send(
new SendInputAmount(
"Enter amount", 2, input -> start(player, fletchable, 1, Integer.parseInt(input))));
254 }
catch (Exception ex) {
255 logger.error(String.format(
"player=%s error fletching option2: make-x", player.
getName()), ex);
262 start(player, fletchable, 2, 1);
268 start(player, fletchable, 2, 5);
274 start(player, fletchable, 2, 10);
281 player.send(
new SendInputAmount(
"Enter amount", 2, input -> start(player, fletchable, 2, Integer.parseInt(input))));
282 }
catch (Exception ex) {
283 logger.error(String.format(
"player=%s error fletching option3: make-x", player.
getName()), ex);
289 start(player, fletchable, 3, 1);
294 start(player, fletchable, 3, 5);
299 start(player, fletchable, 3, 10);
306 player.send(
new SendInputAmount(
"Enter amount", 2, input -> start(player, fletchable, 3, Integer.parseInt(input))));
307 }
catch (Exception ex) {
308 logger.error(String.format(
"player=%s error fletching option3: make-x", player.
getName()), ex);
317 public boolean fletch(
Player player,
int index,
int amount) {
318 Fletchable fletchable = player.attributes.get(FLETCHABLE_KEY);
320 if (fletchable ==
null) {
324 return start(player, fletchable, index, amount);
328 public boolean start(
Player player, Fletchable fletchable,
int index,
int amount) {
329 if (fletchable ==
null) {
333 player.attributes.remove(FLETCHABLE_KEY);
335 player.interfaceManager.close();
337 if (player.skills.
getLevel(
Skill.FLETCHING) < item.getLevel()) {
338 player.dialogueFactory.
sendStatement(
"<col=369>You need a Fletching level of " + item.getLevel() +
" to do that.").
execute();
342 if (!(player.inventory.
containsAll(fletchable.getIngredients()))) {
343 String firstName = fletchable.getUse().getName().toLowerCase();
344 String secondName = fletchable.getWith().getName().toLowerCase();
346 if (fletchable.getUse().getAmount() > 1 && !firstName.endsWith(
"s")) {
347 firstName = firstName.concat(
"s");
350 if (fletchable.getWith().getAmount() > 1 && !secondName.endsWith(
"s")) {
351 secondName = secondName.concat(
"s");
354 if (fletchable.getUse().getAmount() == 1 && firstName.endsWith(
"s")) {
355 firstName = firstName.substring(0, firstName.length() - 1);
358 if (fletchable.getWith().getAmount() == 1 && secondName.endsWith(
"s")) {
359 secondName = secondName.substring(0, secondName.length() - 1);
362 final String firstAmount;
364 if (fletchable.getUse().getAmount() == 1) {
367 firstAmount = String.valueOf(fletchable.getUse().getAmount());
370 final String secondAmount;
372 if (fletchable.getWith().getAmount() == 1) {
375 secondAmount = String.valueOf(fletchable.getWith().getAmount());
378 String firstRequirement = firstAmount +
" " + firstName;
379 String secondRequirement = secondAmount +
" " + secondName;
380 player.send(
new SendMessage(
"You need " + firstRequirement +
" and " + secondRequirement +
" to do that."));
384 player.action.execute(fletch(player, fletchable, item, amount),
true);
393 public void execute() {
395 player.animate(
new Animation(fletchable.getAnimation()));
396 player.graphic(
new Graphic(fletchable.getGraphics()));
399 if (fletchable ==
Carvable.AMETHYST) {
406 player.inventory.
removeAll(fletchable.getIngredients());
409 player.inventory.
addOrDrop(item.getProduct());
410 player.playerAssistant.activateSkilling(1);
413 if (fletchable.getProductionMessage() !=
null) {
414 player.send(
new SendMessage(fletchable.getProductionMessage()));
417 if (fletchable ==
Stringable.MAGIC_SHORTBOWS) {
418 getMob().forClan(channel -> channel.activateTask(
ClanTaskKey.MAGIC_SHORTBOW, getMob().
getName()));
419 }
else if (fletchable ==
Stringable.YEW_SHORTBOWS) {
420 getMob().forClan(channel -> channel.activateTask(
ClanTaskKey.YEW_SHORTBOW, getMob().
getName()));
421 }
else if (fletchable instanceof
Arrow) {
425 if (iterations == amount || iterations > 28 || !(player.inventory.
containsAll(fletchable.getIngredients()))) {
427 if (!(player.inventory.
containsAll(fletchable.getIngredients()))) {
428 player.send(
new SendMessage(
"<col=369>You have run out of materials."));
441 public boolean prioritized() {