Skip to main content

HungerStat

A class in Root.Township, Alta.StatSystem.

Stat definition asset for Hunger, a ThresholdStat. The value drops each stat update, regenerates health when well fed and deals starve damage when low, all scaled by server config settings.

Constructors​

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

Fields​

8 private and internal fields
MemberWhat it is
private StatDefinition fullnessStatDefinitionThe Fullness stat; starve damage only applies while it is below 1.
private AnimationCurve fullStateRegenCurve from hunger value (0 hungry, 1 full) to health regained per tick.
private StatDefinition healthDefinitionThe Health stat that regen and starve damage change.
private static DamageData hungerDamageDamage data with the Hunger source. Not used in this build.
private float hungerStarveDamageHealth removed per tick while starving.
private float hungerTickHunger drop per tick in the asset. Not used; the server config's HungerTick is used instead.
private StatDefinition recentDamageDefinitionStat for recent damage; more of it means less regen.
private float starveDamageHealthCutoffStarving stops dealing damage once health base is below this.

Methods​

MemberWhat it is
override void Applied(StatManager manager, Stat stat)Hooks the stat manager's update to drop hunger by the server config's HungerTick each tick, then sets up the threshold levels.
protected override ModifierSet[] GetSets(StatManager manager, Stat stat)Adds health regen to the top two threshold levels and starve damage to the lowest level.
2 private and internal methods
MemberWhat it is
private void ProcessHealthRegen(Stat stat, Stat health, Stat recentDamage)Adds health from fullStateRegen by hunger value, reduced by recent damage and scaled by the server's health regen multiplier.
private void ProcessStarveDamage(Stat stat, Stat fullnessStat, Stat health)Server config permitting, removes hungerStarveDamage health per tick while Fullness is below 1 and health is above the cutoff.

Used in​

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