public static void setAmountToZero(Player p) { if (p.getTemporaryAttribute("smeltingBar") != null) { BarToSmelt bar = (BarToSmelt)p.getTemporaryAttribute("smeltingBar"); bar.setAmount(0); } }
private static bool canSmelt(Player p, BarToSmelt bar) { if (bar == null || bar.getAmount() <= 0) { return(false); } if (p.getSkills().getGreaterLevel(Skills.SKILL.SMITHING) < bar.getLevel()) { p.getPackets().sendMessage("You need a Smithing level of " + bar.getLevel() + " to make that bar."); return(false); } for (int i = 0; i < bar.getOre().Length; i++) { if (bar.getOreAmount()[i] != 0) { if (!p.getInventory().hasItemAmount(bar.getOre()[i], bar.getOreAmount()[i])) { p.getPackets().sendMessage("You don't have enough ore to make that bar."); return(false); } } } return(true); }
private static bool canSmelt(Player p, BarToSmelt bar) { if (bar == null || bar.getAmount() <= 0) { return false; } if (p.getSkills().getGreaterLevel(Skills.SKILL.SMITHING) < bar.getLevel()) { p.getPackets().sendMessage("You need a Smithing level of " + bar.getLevel() + " to make that bar."); return false; } for (int i = 0; i < bar.getOre().Length; i++) { if (bar.getOreAmount()[i] != 0) { if (!p.getInventory().hasItemAmount(bar.getOre()[i], bar.getOreAmount()[i])) { p.getPackets().sendMessage("You don't have enough ore to make that bar."); return false; } } } return true; }
public static void smeltOre(Player p, int buttonId, bool newSmelt, int amount) { p.getPackets().closeInterfaces(); int index = -1; if (!newSmelt && p.getTemporaryAttribute("smeltingBar") == null) { return; } if (newSmelt) { resetSmelting(p); index = getBarToMake(buttonId); if (index == -1) { return; } if (amount == -1) { amount = getAmount(buttonId); } if (amount == -2) { p.getPackets().displayEnterAmount(); p.setTemporaryAttribute("interfaceVariable", new EnterVariable(311, buttonId)); return; } p.setTemporaryAttribute("smeltingBar", new BarToSmelt(index, BARS[index], SMELT_LEVELS[index], SMELT_XP[index], amount, SMELT_ORES[index], SMELT_ORE_AMT[index], BAR_NAMES[index])); } BarToSmelt bar = (BarToSmelt)p.getTemporaryAttribute("smeltingBar"); if (!canSmelt(p, bar)) { resetSmelting(p); return; } for (int i = 0; i < bar.getOre().Length; i++) { if (bar.getOreAmount()[i] != 0) { for (int j = 0; j < bar.getOreAmount()[i]; j++) { if (!p.getInventory().deleteItem(bar.getOre()[i], 1)) { resetSmelting(p); return; } } } } string s = bar.getOre()[1] == 0 ? "ore" : "ore and coal"; p.getPackets().sendMessage("You place the " + bar.getName().ToLower() + " " + s + " into the furnace.."); p.setLastAnimation(new Animation(3243)); Event SmeltBarEvent = new Event(1800); SmeltBarEvent.setAction(() => { SmeltBarEvent.stop(); if (p.getTemporaryAttribute("smeltingBar") == null) { resetSmelting(p); return; } BarToSmelt myBar = (BarToSmelt)p.getTemporaryAttribute("smeltingBar"); if (!bar.Equals(myBar)) { resetSmelting(p); return; } bool dropIron = false; if (bar.getIndex() == 2) { if (!wearingForgingRing(p)) { if (Misc.random(1) == 0) { p.getPackets().sendMessage("You accidentally drop the iron ore deep into the furnace.."); dropIron = true; } } else { lowerForgingRing(p); } } if (!dropIron) { string s1 = bar.getIndex() == 2 || bar.getIndex() == 8 ? "an" : "a"; p.getPackets().sendMessage("You retrieve " + s1 + " " + bar.getName().ToLower() + " bar from the furnace.."); p.getInventory().addItem(bar.getBarId()); p.getSkills().addXp(Skills.SKILL.SMITHING, bar.getXp()); } bar.decreaseAmount(); if (bar.getAmount() >= 1) { smeltOre(p, -1, false, 1); } if (bar.getAmount() <= 0) { resetSmelting(p); } }); Server.registerEvent(SmeltBarEvent); }