Class ProbabilityEntry<T>
A serializable entry that pairs an item of type T with a
probability weight and a set of optional control flags used by
ProbabilityList<T>.
Inherited Members
Namespace: Scylla.Core.Util.Random
Assembly: ScyllaCore.dll
Syntax
[Serializable]
public class ProbabilityEntry<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type of item this entry holds. |
Remarks
Each entry exposes four orthogonal feature sets:
- Core selection - Probability, Enabled, and Locked govern whether and how often the entry is chosen.
- Influence - InfluenceMin, InfluenceMax, and InfluenceInverted let an external IProbabilityInfluence provider dynamically push the effective probability toward a min or max bound.
- Depletion - IsDepletable, Units, and MaxUnits model consumable items that become unavailable once their unit count reaches zero.
- Reset - the internal Scylla.Core.Util.Random.ProbabilityEntry<T>.OriginalProbability field stores the probability assigned at construction so that ResetProbabilities() can restore the entry to its initial state.
Unity cannot serialize open generic types directly. For Unity Inspector support,
create a concrete closed subclass, for example:
public class StringProbabilityEntry : ProbabilityEntry<string> { }
This type MUST remain a reference type (class, not struct) because
ProbabilityList<T> mutates entries in-place through local variables
(e.g., decrementing Units during depletion). Changing it to a value
type would silently break those mutations.
Constructors
ProbabilityEntry(T, float)
Initializes a new ProbabilityEntry<T> with the given item and probability weight, and applies default values for all optional feature flags.
Declaration
public ProbabilityEntry(T item, float probability)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to associate with this entry. |
| float | probability | Initial probability weight. Must be non-negative. Stored in both Probability and Scylla.Core.Util.Random.ProbabilityEntry<T>.OriginalProbability. |
Remarks
Default state: entry is Enabled, not Locked, not
IsDepletable, influence range is [0, 1], and
InfluenceInverted is false.
Fields
Enabled
When true, this entry participates in selection. When false, the
entry is excluded entirely: its probability contributes neither to the alias table
nor to the CDF built by ProbabilityList<T>.
Declaration
public bool Enabled
Field Value
| Type | Description |
|---|---|
| bool |
InfluenceInverted
When true, the sign of the incoming influence value is flipped before it is
applied. This makes a positive influence push the probability toward
InfluenceMin instead of InfluenceMax, which is useful
for "rarity" entries that should become less likely when a buff is active.
Declaration
public bool InfluenceInverted
Field Value
| Type | Description |
|---|---|
| bool |
InfluenceMax
The effective probability ceiling when an IProbabilityInfluence provider
supplies an influence of +1.0. Defaults to 1.
At +1.0 influence the effective probability equals this value.
Declaration
public float InfluenceMax
Field Value
| Type | Description |
|---|---|
| float |
InfluenceMin
The effective probability floor when an IProbabilityInfluence provider
supplies an influence of -1.0. Defaults to 0.
At -1.0 influence the effective probability equals this value.
Declaration
public float InfluenceMin
Field Value
| Type | Description |
|---|---|
| float |
IsDepletable
When true and the owning IsDepletable master
switch is also true, this entry has a limited supply tracked via
Units. Once Units reaches zero the entry is excluded
from selection until RefillEntry(int) or
RefillAll() is called.
Declaration
public bool IsDepletable
Field Value
| Type | Description |
|---|---|
| bool |
Item
The item that is returned when this entry is selected by a ProbabilityList<T>.
Declaration
public T Item
Field Value
| Type | Description |
|---|---|
| T |
Locked
When true, ProbabilityNormalizer will not scale this entry's
Probability. The locked probability is subtracted from the
available remainder before unlocked entries are scaled.
Declaration
public bool Locked
Field Value
| Type | Description |
|---|---|
| bool |
MaxUnits
The maximum number of uses for this entry, restored by
RefillEntry(int) and
RefillAll().
Only meaningful when IsDepletable is true.
Declaration
public int MaxUnits
Field Value
| Type | Description |
|---|---|
| int |
Probability
The current probability weight for this entry, in the range [0, 1].
ProbabilityList<T> normalizes all enabled entry probabilities
at build time so they sum to 1. Direct assignment bypasses that normalization;
call Normalize() afterwards if needed.
Declaration
public float Probability
Field Value
| Type | Description |
|---|---|
| float |
Units
The number of remaining uses for this entry. Decremented by one on each successful
pick when IsDepletable is true and the list's
IsDepletable is also true.
Only meaningful when IsDepletable is true.
Declaration
public int Units
Field Value
| Type | Description |
|---|---|
| int |