Skip to content

ProbabilityEnum<T>

Namespace: SideXP.Core | Inherits from: ProbabilityCollection, ISerializationCallbackReceiver

public class ProbabilityEnum<T> : ProbabilityCollection, ISerializationCallbackReceiver

Represents a list of enum values bound to a probabiility value, from which those items can be picked randomly by taking account of their probability.

Type parameters

  • T: The type of the enumerations of which values are bound to probability values.

Fields

MinProbability

public const float MinProbability = 0

MaxProbability

public const float MaxProbability = 100

Properties

Items

public override IProbabilityItem[] Items

The items in this collection.

this[int]

public override IProbabilityItem this[int index]

Base class for implementing lists with items bound to a probability value, and able to pick an item based on that probability value.

this[T]

public IProbabilityItem this[T enumValue]

Gets an item in this collection by its enum value.

Parameters

  • enumValue: The value of the item to get.

Methods

OnAfterDeserialize()

public void OnAfterDeserialize()

Inherited documentation.

OnBeforeSerialize()

public void OnBeforeSerialize()

Inherited documentation.

Get(T)

public bool Get(out T data)

Gets an object from this collection picked randomly based on the probability values.

Parameters

  • data: Outputs the picked object.

Returns

Returns true if a valid object has been picked from the list successfully.

Remarks

An item with a probability of zero or less is never picked. If the collection is empty or every item has a non-positive probability, this returns false.

GetProbabilityPercents(T)

public float GetProbabilityPercents(T data)

Gets the probability percentage for a given object in this collection to be picked.

Parameters

  • data: The object from this collection.

Returns

Returns the probability percentage for the given object to be picked.

Remarks

A probability of zero or less is reported as a 0% chance, consistently with Get.