Class BaseLootTable
java.lang.Object
com.csse3200.game.inventory.items.lootbox.configs.BaseLootTable
BaseLootTable is a concrete class representing a basic loot table used to manage and generate loot items.
It provides functionality to add items with specified weights, retrieve single or multiple random items,
and calculate their probabilities based on the assigned weights.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a BaseLootTable and initializes the list of items. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addItem
(Class<? extends AbstractItem> item, double weight, Class<?>[] parameterTypes, Object[] parameters) Adds a loot item to the loot table with the specified weight and constructor parameters.getItems()
Retrieves the list of loot items in this loot table.Selects a random item from the loot table based on the weights of each item.getRandomItems
(int rolls) Retrieves a list of multiple random items from the loot table, based on the specified number of rolls.
-
Field Details
-
items
-
-
Constructor Details
-
BaseLootTable
public BaseLootTable()Constructs a BaseLootTable and initializes the list of items.
-
-
Method Details
-
addItem
public void addItem(Class<? extends AbstractItem> item, double weight, Class<?>[] parameterTypes, Object[] parameters) Adds a loot item to the loot table with the specified weight and constructor parameters. The weight determines the probability of the item being selected when generating loot.- Parameters:
item
- The class type of the loot item (must extend AbstractItem).weight
- The weight of the loot item, influencing its selection probability.parameterTypes
- The types of parameters needed for the item's constructor.parameters
- The parameters to be passed when creating a new instance of the item.
-
getItems
Retrieves the list of loot items in this loot table.- Returns:
- List of LootItemConfig objects representing the items and their weights in the loot table.
-
getRandomItem
Selects a random item from the loot table based on the weights of each item. Items with higher weights have a greater probability of being selected.- Returns:
- A new instance of a randomly selected AbstractItem, or null if an error occurs during instantiation.
-
getRandomItems
Retrieves a list of multiple random items from the loot table, based on the specified number of rolls. Each roll independently selects an item, allowing for duplicates.- Parameters:
rolls
- The number of times to roll for items, determining how many items are returned.- Returns:
- A list of randomly selected AbstractItem objects.
-