Code:
package server.model.players;
import server.model.players.Client;
import server.event.EventManager;
import server.event.Event;
import server.event.EventContainer;
import server.util.Misc;
import server.model.players.packets.ClickObject;
/*
* Author - Ferocious & Mod Loc ([email protected])
* http://www.rune-server.org/members/ags
* http://www.rune-server.org/members/Ferocious
*/
public class Chest {
public static boolean Canusebox = true;
public static int Common [] =
{1323, 1313, 1315, 1321, 1109, 1079, 1093, 1127, 10828, 3749, 1213, 1261,
1333, 2440, 2436, 2442, 1704, 1725 }; // Add more item Id's
public static int Uncommon [] =
{4151, 4587, 4586, 9185, 11732, 4716, 4718, 4720, 4722, 4753, 4755,
4757, 4759 }; // Add more item Id's
public static int Rare [] =
{11700, 11698, 773, 6585, 774, 11702, 11704,
11706, 11708, 11690, 11690 }; // Add more item Id's
public static int GenerateMysteryChest(final Client c) {
EventManager.getSingleton().addEvent(new Event() {
int BoxTimer = 2;
public void execute(EventContainer Box) {
Canusebox = false;
if (BoxTimer == 2) {
c.sendMessage("Opening the chest...");
}
if (BoxTimer == 0) {
int Random = Misc.random(100);
if (Random <= 71) {
c.getItems().addItem(Common[(int) (Math.random() * Common.length)], 1);
c.getItems().addItem(Common[(int) (Math.random() * Common.length)], 1);
c.getItems().addItem(Common[(int) (Math.random() * Common.length)], 1);
c.getItems().addItem(Common[(int) (Math.random() * Common.length)], 1);
c.sendMessage("You have recieved six @gre@common @bla@items.");
} else if (Random >= 72 && Random <= 92) {
c.getItems().addItem(Uncommon[(int) (Math.random() * Uncommon.length)], 1);
c.getItems().addItem(Uncommon[(int) (Math.random() * Uncommon.length)], 1);
c.getItems().addItem(Uncommon[(int) (Math.random() * Uncommon.length)], 1);
c.sendMessage("You have recieved three @yel@uncommon @bla@items.");
} else if (Random >= 93 && Random <= 100) {
c.getItems().addItem(Rare[(int) (Math.random() * Rare.length)], 1);
c.getItems().addItem(Rare[(int) (Math.random() * Rare.length)], 1);
c.sendMessage("You have recieved two @red@rare @bla@items.");
}
}
if (c == null || BoxTimer <= 0) {
Box.stop();
Canusebox = true;
return;
}
if (BoxTimer >= 0) {
BoxTimer--;
}
}
}, 1000);
return Common[(int) (Math.random() * Common.length)];
}
public static void Open(int itemID, Client c) {
if (c.objectId == 4126) {
if (c.getItems().freeSlots() > 1) {
if (Canusebox == true) {
c.chest = 1;
GenerateMysteryChest(c);
} else {
c.sendMessage("Please wait while your current process is finished.");
}
} else {
c.sendMessage("You need at least 2 slots to open this chest.");
}
}
}
}