Skip to main content

Distribution<TThis, T, TItem, TFestivityGroup>

A class in Root.Township, Alta.Caves.

A weighted random table of assets, used by world and cave generation. Weights can depend on location attributes, and festivity groups add items while their festivity is active.

Constructors​

MemberWhat it is
Distribution()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

MemberWhat it is
protected List<TFestivityGroup> festivitiesSerialized festivity groups.
protected List<TItem> itemsSerialized main items.
protected float nullChanceChance (0 to 1) of picking nothing, before attribute multipliers.
1 private and internal field
MemberWhat it is
private AttributeCurveRange[] globalMultipliersAttribute curves that scale the overall chance of picking anything, based on the given attribute set.

Properties​

MemberWhat it is
IReadOnlyCollection<TFestivityGroup> Festivities { get; }Groups of extra items that count only while their festivity is active.
IReadOnlyCollection<TItem> Items { get; }The main items and their weights.

Methods​

MemberWhat it is
float GetMultiplier(int itemIndex, AttributeSet attributes)The weight of a main item for the given attributes.
IEnumerable<IDistributionItem<T>> GetPossibleResults() (iterator)Every item that could come out right now, including active festivity items.
T GetRandom(AttributeSet attributes = null)Picks a weighted random item, or null by the null chance. Accepts your own random source.
T GetRandom(Func<double> randomValue, AttributeSet attributes = null)Picks a weighted random item, or null by the null chance. Accepts your own random source.
int GetRandomIndex(AttributeSet attributes, out TFestivityGroup festivity)Like GetRandom but returns the index, and the festivity group it came from if any. -1 for nothing.
int GetRandomIndex(Func<double> randomValue, AttributeSet attributes, out TFestivityGroup festivity)Like GetRandom but returns the index, and the festivity group it came from if any. -1 for nothing.
void Migrate<TThisOther, TOther, TItemOther, TFestivityGroupOther>(TThisOther other, Func<TOther, T> convert)Copies another distribution's settings and items, converting each item's asset.
static double Random()The default random source, Unity's Random.value.