Class LootItemConfig
java.lang.Object
com.csse3200.game.inventory.items.lootbox.configs.LootItemConfig
LootItemConfig is a configuration class representing a specific loot item, including its class type,
weight, constructor parameters, and how to instantiate it. This class is used in loot tables to
define items that can be generated from loot boxes with a specified probability.
-
Constructor Summary
ConstructorsConstructorDescriptionLootItemConfig
(Class<? extends AbstractItem> item, double weight, Class<?>[] parameterTypes, Object[] parameters) Constructs a LootItemConfig with the specified item class, weight, and constructor parameters. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new instance of the loot item using reflection, with the specified constructor parameters.double
Gets the weight of the loot item, used to determine its selection probability in a loot table.
-
Constructor Details
-
LootItemConfig
public LootItemConfig(Class<? extends AbstractItem> item, double weight, Class<?>[] parameterTypes, Object[] parameters) Constructs a LootItemConfig with the specified item class, weight, and constructor parameters.- Parameters:
item
- The class type of the loot item (must extend AbstractItem).weight
- The weight of the item, determining its probability of being selected.parameterTypes
- An array of Classes representing the types of parameters for the item's constructor.parameters
- An array of Objects representing the parameters to pass to the constructor when creating an item.
-
-
Method Details
-
getWeight
public double getWeight()Gets the weight of the loot item, used to determine its selection probability in a loot table.- Returns:
- The weight of the item as a double.
-
createNewItem
public AbstractItem createNewItem() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessExceptionCreates a new instance of the loot item using reflection, with the specified constructor parameters. This method finds the correct constructor based on the parameter types and instantiates the item.- Returns:
- A new instance of the specified AbstractItem.
- Throws:
NoSuchMethodException
- See belowInvocationTargetException
- See belowInstantiationException
- See belowIllegalAccessException
- If the item cannot be instantiated, including issues with constructor access or parameter mismatches.
-