var category = InventorySystemManager.GetItemCategory("MyCategory");
// Get all ItemDefinition from the category. CAREFUL when using this solution the array size can be bigger than the numberOfItems!
var itemDefinitionsForCategory = new ItemDefinition[0];
var numberOfItems = category.GetAllChildrenElements(ref itemDefinitionsForCategory);
// Or you could get all item Definitions and filter by category.
var itemDefinitionsForCategory2 = new List<ItemDefinition>();
var allItemDefinitions = InventorySystemManager.ItemDefinitionRegister.GetAll();
foreach (var itemDefinition in allItemDefinitions) {
if (category.InherentlyContains(itemDefinition)) {
itemDefinitionsForCategory2.Add(itemDefinition);
}
}
//From the definition create a list of ItemInfo, where the amount of Item defines the probabily
var itemInfos = new List<ItemInfo>();
for (int i = 0; i < itemDefinitionsForCategory2.Count; i++) {
var probability = 1; // Choose the probability here. The higher the number the higher the probability to get it.
var itemInfo = (ItemInfo) (probability, itemDefinitionsForCategory2[i].DefaultItem);
itemInfos.Add( itemInfo );
}
//Create a probability table
var probabilityTable = new ItemInfoProbabilityTable(itemInfos);
//ALL the above should be done once in an intialization phase. Then you can call the function below whenever.
//Get a random item with probability
var minAmount = 1;
var maxAmount = 3;
var listOfRandomItems = probabilityTable.GetRandomItemInfos(minAmount, maxAmount);