Skip to main content

LevelStatModifier

A class in Root.Township, Alta.StatSystem.

Networked component that holds a saved level from 0 to maxLevel and applies a flat modifier to a stat based on that level. The server changes the level and syncs it.

Constructors​

MemberWhat it is
LevelStatModifier()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

10 private and internal fields
MemberWhat it is
private Stat affectingStatServer: the stat being modified.
private int currentLevelThe current level. Saved.
private int maxLevelHighest level.
private StatModifier modifierServer: the flat stat modifier applied for the current level.
private int oldLevelUnused.
private IntEvent onCurrentLevelChangedEvent fired with the new level on both server and clients.
private MethodSync syncNetwork sync for the level.
private StatManager targetManagerThe stat manager holding the target stat.
private StatDefinition targetStatThe stat to modify.
private AnimationCurve valueAtLevelCurve giving the modifier value for each level.

Methods​

MemberWhat it is
void DecreaseLevel(int amount = 1)Server: lowers the level (not below 0), updates the modifier and syncs.
void Empty()Server: sets the level to 0, updates the modifier and syncs.
void IncreaseLevel(int amount = 1)Server: raises the level (capped at maxLevel), updates the modifier and syncs.
override void Initialize()Creates the level sync.
override void InitializeAsServer(SpawnData data)Finds the target stat and applies the saved level if above 0.
override void OnConnected(Player player)Sends the level to a joining player if above 0.
2 private and internal methods
MemberWhat it is
private void Sync(IPlayer player, Stream stream)Network handler for the level. Clients update to the received level.
private void UpdateLevel()Server applies or updates the modifier from valueAtLevel. Both sides fire onCurrentLevelChanged.