ChivalrousGames.com/Products/Common/Documentation/WeightList/

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
obj T (Generic) Object to add to the list
weight int Weight of the object in the list
Description

Adds an item to the list with a specified weight.

GetTotalWeight
public int GetTotalWeight();
Return
int The total weight of the list
Description

Gets the total weight of all items in the list

GetObject
public T GetObject(int randomValue);
Parameters
randomValue int Between 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
random ChivalrousGames.Common.Random The 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