Code:
/*
* @author Codeusa
*/
public class CrystalChest {
private static final int[] CHEST_REWARDS = { 1079, 1093, 526, 1969, 371, 2363, 451 };
private static final int DRAGONSTONE = 1631;
private static final int OPEN_ANIMATION = 881;
public static final int[] KEY_HALVES = { 985, 987 };
public static final int KEY = 989;
public static void createKey(User u) {
if (u.getInventory().contains(toothHalf(), 1)
&& u.getInventory().contains(loopHalf(), 1)) {
u.getInventory().getContainer().remove(new Item(toothHalf(), 1));
u.getInventory().getContainer().remove(new Item(loopHalf(), 1));
u.getInventory().addItem(KEY, 1);
}
}
public static boolean canOpen(User u) {
if (u.getInventory().contains(KEY)) {
return true;
} else {
u.sendMessage("The chest is locked");
return false;
}
}
public static void searchChest(final User u) {
if (canOpen(p)) {
u.sendMessage("You unlock the chest with your key.");
u.getInventory().getContainer().remove(new Item(KEY, 1));
u.animate(OPEN_ANIMATION);
World.getWorld().submit(new Tick(2) {
public void execute() {
u.getInventory().addItem(DRAGONSTONE, 1);
u.getInventory().addItem(995, Misc.random(8230));
u.getInventory().addItem(CHEST_REWARDS[Misc.random(getLength() - 1)], 1);
u.sendMessage("You find some treasure in the chest.");
this.stop();
}
});
}
}
public static int getLength() {
return CHEST_REWARDS.length;
}
public static int toothHalf(){
return KEY_HALVES[0];
}
public static int loopHalf(){
return KEY_HALVES[1];
}
}
There you go, a proper chest. Woop dee doo.