Skip to main content

Stat

A class in Root.Township, Alta.StatSystem.

One stat's live value on a StatManager. The value is (base plus extras, clamped to min and max) times the multipliers. Changes raise Changed and, past the definition's threshold, NetworkChanged.

Constructors​

MemberWhat it is
Stat(float value, float minimum, float maximum)Creates a Stat from application.
Stat(StatDefinitionApplication application)Creates a Stat from application.

Fields​

9 private and internal fields
MemberWhat it is
private float baseFlatBacking field for Base: the stat's own value, kept within minimum and maximum and saved. Synced in the range 0 to 127.
private float buffMultiplierBacking field for BuffMultiplier (default 1).
private float extraFlatFlat bonus set through Extra; Extra returns it plus nonBuffExtra.
private bool isEnabledBacking field for IsEnabled. It doesn't change Value; stats like hunger check it themselves.
private float lastNetworkedValueValue when the stat was last serialized; compared with the new value to decide whether a change needs syncing.
private float maximumBacking field for Maximum. The base is capped to it and the value is clamped to it before the multiplier.
private float minimumBacking field for Minimum. The base is raised to it and the value is clamped to it before the multiplier.
private float nonBuffExtraBacking field for NonBuffExtra, a flat bonus that isn't from a buff.
private float nonBuffMultiplierBacking field for NonBuffMultiplier (default 1); multiplied with buffMultiplier to give Multiplier.

Properties​

MemberWhat it is
StatDefinitionApplication Application { get; private set; }The StatDefinitionApplication this stat came from, holding its defaults.
float Base { get; set; }The stat's own value. Setting it clamps to Minimum and Maximum. This is the part that is saved.
float BuffMultiplier { get; set; }Multiplier from buffs. Part of Multiplier.
object ChangeData { get; set; }Context for the change that is about to happen (for example the damage), read by Changed handlers. Cleared after each change.
StatDefinition Definition { get; private set; }The StatDefinition this stat is for.
float Extra { get; set; }Flat bonus added to Base. Reading gives the buff extra plus NonBuffExtra; setting sets only the buff extra.
bool IsChanged { get; private set; }True after a change until the next OnChangedExternal.
bool IsEnabled { get; set; }Whether the stat is enabled. Setting it forces a network update.
float LastValue { get; private set; }The value at the previous change.
float Maximum { get; set; }Upper limit for Base plus extras. Lowering it pulls Base down.
float Minimum { get; set; }Lower limit for Base plus extras. Raising it pushes Base up.
float Multiplier { get; }Total multiplier, BuffMultiplier times NonBuffMultiplier.
float NonBuffExtra { get; set; }Flat bonus that does not come from buffs.
float NonBuffMultiplier { get; set; }Multiplier that does not come from buffs.
float Value { get; private set; }The final calculated value.

Events​

MemberWhat it is
event StatHandler ChangedRaised whenever Value changes.
event StatHandler ChangedExternalRaised on the stat manager's tick for stats that changed since the last tick.
event StatHandler DefinitionEventRaised by RunEvent; burn uses it to signal stat-specific events.
event StatHandler NetworkChangedRaised when a change passes the definition's sync threshold. The server's stat manager sends the stat to clients on it.

Methods​

MemberWhat it is
void Bind(StatHandler handler)Calls the handler once now, then on every Changed.
void ForceServerUpdate()Recalculates and raises both Changed and NetworkChanged even if nothing changed.
void Load(StatManagerSaveDataStat data)Restores Base from save data, rounded to 2 decimals.
void OnChangedExternal()Clears IsChanged and raises ChangedExternal. The stat manager calls it on its tick.
void Reset()Sets min, max and base back to the defaults from Application.
void RunEvent()Raises DefinitionEvent.
StatManagerSaveDataStat Save()Returns save data holding the definition and Base only.
void Serialize(Stream stream, bool isWritingFull)Reads or writes the stat. Full writes include range, extras and multipliers. Values are packed to fixed ranges (base and range 0 to 127) and rounded to 0.01.
void SetRange(float minimum, float maximum)Sets Minimum and Maximum together and forces a network update.
override string ToString()The value with at most one decimal.
1 private and internal method
MemberWhat it is
private void OnChanged(bool forceNetwork = false, bool forceEvent = false)Recalculates Value as (base plus extra, clamped to the range) times the multiplier. Raises Changed, and NetworkChanged when the change is big enough to sync.

Used in​

Members of other types that take, return or hold a Stat:

BurnEffect.burningManager, StatChangeEffect.ModifyStat, StatEffect.ModifyStat, StatSetEffect.ModifyStat, FixedImpactor.damageStat, Phantom.SpeedStat, Phantom.visibilityStat, ProgressStatChangeHook.TopicProgress.affectedStat, StatChangeHook.affectedStats, HealthBar.HealthBar, HealthBar.healthStat, HealthBar.UpdateHealthBar, ToggleEnemyHealthBars.CheckEnemyNeedsHealthBar, BurnStat.Applied, ControlledStat.Applied, DiscreteStatBar.OnStatChanged, FullEmptyStatTrigger.OnStatChanged, FullEmptyUpdateModifier.affectedStat, FullEmptyUpdateModifier.CheckApply, FullEmptyUpdateModifier.FullEmptyUpdateModifier, FullEmptyUpdateModifier.trackedStat, FullnessStat.Applied, HungerStat.Applied, HungerStat.GetSets, HungerStat.ProcessHealthRegen, HungerStat.ProcessStarveDamage, IncrementingStat.Applied, IndirectStatModifier.IndirectStatModifier, IndirectStatModifier.targetStat, LevelStatModifier.affectingStat, MaxStatDefinition.Applied, MaxStatDefinition.endOfFrameBuffer, MaxStatDefinition.UpdateManager, OnFullAffectTargetStatDefinition.Applied, PlayerWeightStat.Applied, PoisonStat.Applied, StaminaBarVisibility.HandStaminaView.handStaminaStat, StatAffectingArea.affectedStats, StatAppliedHandler.BeginInvoke, StatAppliedHandler.Invoke, StatBar.OnStatChanged, StatBar.SetupNotches, StatBarBase.OnStatChanged, StatBarBase.Stat, StatBarBase.trackedStat, StatBarSimple.OnStatChanged, StatBarSimple.UpdateValue, StatConverter.Last, StatDefinition.Applied, StatDefinition.GetStatOnPlayer, StatHandler.BeginInvoke, StatHandler.Invoke, StatListConverter.LastList, StatManager.ApplyIndirectModifier, StatManager.GetStat, StatManager.indirectModifiers, StatManager.Stats, StatManager.SyncStat, StatModifier.Stat, StatModifier.StatModifier and 38 more.