java.lang.Object
com.csse3200.game.inventory.items.lootbox.configs.BaseLootTable

public class BaseLootTable extends Object
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 Details

  • 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

      public List<LootItemConfig> 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

      public AbstractItem 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

      public List<AbstractItem> getRandomItems(int rolls)
      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.