What I did once with a loot table was using a enum class of the items
And within that enum class I added an array of items
Like this example:
public enum Item {
// item name, item sprite, item option/tag
NULL("NULL",1,Assets.null(), "null"),
HEALTH_POT("Health Potion",2,Assets.getHealthPotion(), "use"),
STAMINA_POT("Stamina Potion",3,Assets.getStaminaPotion(), "use"),
HELM_RED("Red Helm",4,Assets.getHelm_red(), "wear"),
BODY_RED("Red Body",5,Assets.getBody_red(), "wear"),
LEGS_RED("Red Legs",6,Assets.getLegs_red(), "wear"),
BOOTS_RED("Red Boots",7,Assets.getBoots_red(), "wear");
private int itemID;
private BufferedImage itemImage;
private String itemName;
private String tag;
public Item[] itemPack_01 = {
Item.HEALTH_POT, Item.BODY_RED, Item.HELM_RED, Item.STAMINA_POT, Item.NULL, Item.NULL, Item.NULL, Item.NULL, Item.NULL, Item.NULL, Item.NULL
};
public Item[] itemPack_02 = {
Item.HEALTH_POT, Item.BOOTS_RED, Item.LEGS_RED, Item.STAMINA_POT, Item.NULL, Item.NULL, Item.NULL, Item.NULL, Item.NULL, Item.NULL, Item.NULL
};
private Item(String itemName,int itemID, BufferedImage itemImage, String tag) {
this.itemName = itemName;
this.itemID = itemID;
this.itemImage = itemImage;
this.tag = tag;
}
public int getItemID() {
return itemID;
}
public BufferedImage getItemImage() {
return itemImage;
}
public String getItemName() {
return itemName;
}
public String getTag() {
return tag;
}
}
When ever looting a chest killing an enemy, or anything that gives items, you can get a random item from the
length of the array you choosed. like this:
public Item getItem() {
Item dropItem;
int l = items.length;
int i = (int)(Math.random()*l);
if(i > l){ // just in case
dropItem = Item.NULL;
} else {
dropItem = items[i];
}
return dropItem;
}
I based this on a old Runescape private server loot system.
But I would recommend the post of roquen, because it is easier to make guides of how much % to get an item etc,
and to edit and difficulty’s rates.
But if your game is not that big, and you want a fast and easy way, I would recommend this.