}
private void handleRegularSmelting(int times1) {
final int times = --times1;
ItemSmeltingDef smeltingDef = ItemAttributes
.getSmeltingDef(item.id);
if (smeltingDef == null) {
owner.getActionSender().sendMessage(
"Nothing interesting happens.");
return;
}
for (ReqOreDef reqOre : smeltingDef.getReqOres()) {
if (owner.getInventory().countId(reqOre.getId()) < reqOre
.getAmount()) {
if (item.id == 151) {
smeltingDef = EntityHandler
.getItemSmeltingDef(9999);
break;
}
owner.getActionSender()
.sendMessage(
"You need "
+ reqOre.getAmount()
+ " "
+ EntityHandler
.getItemDef(
reqOre.getId())
.getName()
+ " to smelt a "
+ item.getDef()
.getName()
+ ".");
return;
}
}
if (owner.getCurStat(13) < smeltingDef.getReqLevel()) {
owner.getActionSender().sendMessage(
"You need a smithing level of "
+ smeltingDef.getReqLevel()
+ " to smelt this.");
return;
}
if (!owner.getInventory().contains(item.id)) {
return;
}
owner.setBusy(true);
showBubble();
owner.getActionSender().sendMessage(
"You smelt the " + item.getDef().getName()
+ " in the furnace.");
final ItemSmeltingDef def = smeltingDef;
Instance.getDelayedEventHandler().add(
new ShortEvent(owner) {
public void action() {
InvItem bar = new InvItem(def
.getBarId());
if (owner.getInventory().remove(
item.id, item.amount, false)) {
for (ReqOreDef reqOre : def
.getReqOres()) {
owner.getInventory().remove(
reqOre.getId(),
reqOre.amount, false);
}
if (item.id == 151
&& def.getReqOres().length == 0
&& DataConversions.random(
0, 1) == 1) {
owner.getActionSender()
.sendMessage(
"The ore is too impure and unable to be refined.");
} else {
owner.getInventory().add(
bar.id, bar.amount,
false);
owner.getActionSender()
.sendMessage(
"You retrieve a "
+ bar.getDef()
.getName()
+ ".");
owner.incExp(13, def.getExp(),
true);
owner.getActionSender()
.sendStat(13);
}
owner.getActionSender()
.sendInventory();
}
owner.setBusy(false);
if (times > 0)
handleRegularSmelting(times);
}
});
}
private void handleRefill() {
handleRefill((int) Math.ceil(owner.getMaxStat(15) / 10));
}
private void handleRefill(int times) {
if (!itemId(new int[] { 21, 140, 465 })
&& !itemId(Formulae.potionsUnfinished)
&& !itemId(Formulae.potions1Dose)
&& !itemId(Formulae.potions2Dose)
&& !itemId(Formulae.potions3Dose)) {
owner.getActionSender().sendMessage(
"Nothing interesting happens.");
return;
}
if (owner.getInventory().remove(item.id, item.amount,
false)) {
showBubble();
owner.getActionSender().sendSound("filljug");
switch (item.id) {
case 21:
owner.getInventory().add(50, 1, false);
break;
case 140:
owner.getInventory().add(141, 1, false);
break;
default:
owner.getInventory().add(464, 1, false);
break;
}
owner.getActionSender().sendInventory();
if (--times > 0) {
handleRefill(times);
}
}
}
private void handleCooking(int passedvalue) {
final int tries = --passedvalue;
if (item.id == 622) { // Seaweed (Glass)
if (!Server.isMembers()) {
owner.getActionSender().sendMessage(
GameServer.P2P_LIMIT_MESSAGE);
return;
}
owner.setBusy(true);
showBubble();
owner.getActionSender().sendSound("cooking");
owner.getActionSender().sendMessage(
"You put the seaweed on the "
+ object.getGameObjectDef()
.getName() + ".");
Instance.getDelayedEventHandler().add(
new ShortEvent(owner) {
public void action() {
if (owner.getInventory()
.remove(item.id,
item.amount, false)) {
owner.getActionSender()
.sendMessage(
"The seaweed burns to ashes");
owner.getInventory().add(624,
1, false);
owner.getActionSender()
.sendInventory();
}
owner.setBusy(false);
if (tries > 0) {
handleCooking(tries);
}
}
});
} else {
final ItemCookingDef cookingDef = ItemAttributes
.getCookingDef(item.id);
if (cookingDef == null) {
owner.getActionSender().sendMessage(
"Nothing interesting happens.");
return;
}
if (owner.getCurStat(7) < cookingDef.getReqLevel()) {
owner.getActionSender().sendMessage(
"You need a cooking level of "
+ cookingDef.getReqLevel()
+ " to cook this.");
return;
}
owner.setBusy(true);
showBubble();
owner.getActionSender().sendSound("cooking");
owner.getActionSender().sendMessage(
"You cook the "
+ item.getDef().getName()
+ " on the "
+ object.getGameObjectDef()
.getName() + ".");
Instance.getDelayedEventHandler().add(
new ShortEvent(owner) {
public void action() {
InvItem cookedFood = new InvItem(
cookingDef.getCookedId());
if (owner.getInventory()
.remove(item.id,
item.amount, false)) {
if (!Formulae.burnFood(item.id,
owner.getCurStat(7))) {
owner.getInventory().add(
cookedFood.id,
cookedFood.amount,
false);
owner.getActionSender()
.sendMessage(
"The "
+ item.getDef()
.getName()
+ " is now nicely cooked.");
owner.incExp(
7,
cookingDef.getExp(),
true);
owner.getActionSender()
.sendStat(7);
} else {
owner.getInventory()
.add(cookingDef
.getBurnedId(),
1, false);
owner.getActionSender()
.sendMessage(
"You accidently burn the "
+ item.getDef()
.getName()
+ ".");
}
owner.getActionSender()
.sendInventory();
}
owner.setBusy(false);
if (tries > 0
&& owner.getInventory()
.contains(item.id)) {
handleCooking(tries);
}
}
});
}
}
private void handleSmithing(int barID, int toMake) {
ItemSmithingDef def = EntityHandler
.getSmithingDef((Formulae.getBarType(barID) * 21)
+ toMake);
if (def == null) {
owner.getActionSender().sendMessage(
"Nothing interesting happens.");
return;
}
if (owner.getCurStat(13) < def.getRequiredLevel()) {
owner.getActionSender().sendMessage(
"You need at smithing level of "
+ def.getRequiredLevel()
+ " to make this");
return;
}
if (owner.getInventory().countId(barID) < def
.getRequiredBars()) {
owner.getActionSender().sendMessage(
"You don't have enough bars to make this.");
return;
}
owner.getActionSender().sendSound("anvil");
for (int x = 0; x < def.getRequiredBars(); x++) {
owner.getInventory().remove(barID, 1, false);
}
Bubble bubble = new Bubble(owner, item.id);
for (Player p : owner.getViewArea().getPlayersInView()) {
p.informOfBubble(bubble);
}
if (EntityHandler.getItemDef(def.getItemID())
.isStackable()) {
owner.getActionSender().sendMessage(
"You hammer the metal into some "
+ EntityHandler.getItemDef(
def.getItemID()).getName());
owner.getInventory().add(def.getItemID(),
def.getAmount(), false);
} else {
owner.getActionSender().sendMessage(
"You hammer the metal into a "
+ EntityHandler.getItemDef(
def.getItemID()).getName());
for (int x = 0; x < def.getAmount(); x++) {
owner.getInventory().add(def.getItemID(), 1,
false);
}
}
owner.incExp(
13,
Formulae.getSmithingExp(barID,
def.getRequiredBars()), true, true);
owner.getActionSender().sendStat(13);
owner.getActionSender().sendInventory();
}
private boolean itemId(int[] ids) {