GameStat.cs

v4.0

GameStat is the in-game, runtime object to use, representing a Stat made with the Stat module.

GameStat.cs
// View GameStat.cs for all the methods (There are more!!)

// Get the parent Stat (Scriptable Object)
Stat parentOfThisGameStat = gameStat.Parent;

// Get the GameStatList that is holding this Stat
GameStatList parentList = gameStat.ParentList;

// Get the IHaveStats owner who owns the ParentList
IHaveStats thisStatsOwner = gameStat.Owner;

// Access the Dictionaries on this GameStat
// This is useful when you want to access the values that may change at runtime
Dictionaries gameStatDictionaries = gameStat.dictionaries;

// Access the Dictionaries on the Stat (Scriptable Object) of this GameStat
// This is useful when you want to access the fixed values
Dictionaries statDictionaries = gameStat.Parent.dictionaries;

// Get the name of this GameStat & type of this GameStat
var name = gameStat.objectName;
var type = gameStat.objectType;

// Get the values from this GameStat
var points = gameStat.Points;
var finalValue = gameStat.FinalValue;
var finalProficiency = gameStat.FinalProficiency;
var finalStat = gameStat.FinalStat

// Get the current Mastery Level
var masteryLevel = gameStat.MasteryLevel
var masteryLevelName = gameStat.MasteryLevelName

Creating a GameStat

Generally a GameStat will live inside a GameStatList. Objects can have multiple lists, such as an Actor which has "Stats" and "Skills". However, they can live outside of a list as well.

All Game Module "Lists" have multiple Add() and two "Transfer" methods: TransferTo() and ReceiveTransfer().

See the Game Modules "Lists" page details on how to create a GameStat.

Automation

The GameStat will be automated if the autoCompute value is true, which it is by default. When SetDirty() is called, the GameStat is added to the "recompute queue" on the Stats Repository in your scene.

If you do not want this to occur, code the value of autoCompute to false at Start() or Awake() or the creation of the GameStat.

To manually recompute the GameStat value, call gameStat.Recompute().

Get the Final Stat

The final stat is the computed float value that this GameStat provides given all the modifications from other Stats, ItemObject , Conditions, ItemAttribute and other Game Module objects.

Remember the GetOtherLevels() method on the IHaveStats owner needs to pass in the modification levels from the other Game Module objects which affect Stats.

I stronly suggest your Actors inherit from GameModulesActor. If so, all of this is already coded for you. Check the Game Modules Actor page for more details.

// Just get the float value of the final stat as it is right now
float finalStat = gameStat.FinalStat();

// Recompute the final stat first, along with all the stats which feed into this stat
float finalStat = gameStat.FinalStat(true, true);

Modifying Points (Stat as a Counter)

Points are intended to be modified only by the player or other factors in the game, but not by other Stats or ItemObjects etc. Consider these similar to "Skill Points", or "Gold", or "Hit Points" etc.

If you have set another Stat to modify this Stats point value by, that is true by default. Set the second parameter false if you'd like to not include this when adding the value.

// Add points (or add a negative value to subtract)
float newPoints = GameStat.AddPoints(pointsToAdd);

// Set the points value to a specific number
gameStat.SetPoints(newPointValue, false); // Will not modify the final value of the points

Last updated