WeightList
Class in ChivalrousGames.Common

Description

A list-like object that stores objects with an associated weight. Designed with random selection of items in mind.

Methods

Add
public void Add (T obj, int weight);
Parameters
objT (Generic)Object to add to the list
weightintWeight of the object in the list
Description
Adds an item to the list with a specified weight.
GetTotalWeight
public int GetTotalWeight();
Return
intThe total weight of the list
Description
Gets the total weight of all items in the list. If there is no item in the list, the total weight is zero.
GetObject
public T GetObject(int randomValue);
Parameters
randomValueintBetween 1 and GetTotalWeight() both inclusively
Return
T (Generic)An item from the list
Description
Selects an item from the list based on a specified pre-randomized value
GetObject
public T GetObject(ChivalrousGames.Common.Random random);
Parameters
randomChivalrousGames.Common.RandomThe random to use to select an item from the list
Return
T (Generic)An item from the list
Description
Selects an item from the list based on a specified random object