Stats
v4.0
Last updated
v4.0
Last updated
The Stats module allows you to easily set up and access "Stat" data for your project. Creatively used, this could easily even add more functionality if Stat
classes are used for other things, such as skills and counters (Gold, Experience, Health, Points).
A main concept of Stats is that each Stat
object could potentially affect or be affected by others Stat
objects, or other Game Module objects. These values can be set up in the Inspector, and then utilized in your project in whatever way makes sense.
The final value of Stat
objects can be affected by other Stats, Conditions, Item Objects, Item Attributes, and even Quests. All of this is handled automatically at runtime!
The system will automatically recalculate the final value of each Stat
when the underlying data changes, meaning once it is set up in your code, the values will always remain up to date.
Each GameStat (the in-game version of the Stat), will have three numbers:
Points: These provide a constant fixed amount. Generally this is used as a counter, with value being added or subtracted throughout the game.
Base Value: This is similar to Points, but will combined with "value" modifications from other objects.
Base Proficiency: This is a float
default to 0.0f
, meaning "no change". The final proficiency value may be modified by other objects.
The Final Stat is computed using Points, Value, and Proficiency. The Final Value is the sum of the Base Value and modifications from other objects which affect this stat -- Items, Quests, Conditions, other Stats, etc.
Final Proficiency is the sum of Base Proficiency and modifications from other objects. A value of 0f
would mean "no effect".
The sum of Points + Final Value is then multiplied by 1 + Final Proficiency to get the Final Stat.
Example: Lets say our "Strength" stat has these values: Points: 10 Base Value: 0 Base Proficiency: 0 Without anything affecting this stat, the Final Stat is: (10 + 0) * (1 + 0) = 10 Lets say the Actor has the following modifications: "Sword of Strength": +3 Value "Bodybuilding" Stat: +0.2 Proficiency
"Elf" Character Race: -0.1 Proficiency These modifications are then included when computing the final stat. Note the "Proficiency" modifications are summed, so the final Proficiency modification is: 0.2 + -0.1 = 0.1 The Final Stat is: (10 + 3) * (1 + 0.1) = 13 * 1.1 = 14.3
If your Actors inherit from GameModulesActor
, then all of this is handled automatically!!
As an example, you may set up a Stat
called Experience which may hold the experience points a player has collected. You may also set up another Stat
called Experience Mod which is modifyable, but not trainable.
Finally, you may set up a trainable Stat
called Learning, a skill which the player could learn, and then master / upgrade, throughout the game.
Learning could be set to modify Experience Mod per "skill point", a value which may be something players can advance throughout the game. Perhaps Learning provides 0.02 points per skill point to Experience Mod. (Thats 2% more)
In the Inspector for Experience, you may choose to modify any "points" added to the Stat
by the Experience Mod you set up.
So instead of simply adding "100" to the Experience Stat
, the following math is used automatically:
In this example, a player with 5 skill points on the Learning Stat
would have a total modification to the Experience Mod of 0.1, and the 100 experience points will be worth 110 for this player.
The goal of the Stats
module is to make all of this relatively complex connections more easy to set up and manage, with runtime operations as automatic as possible. Time setting it all up, and thinking about how various Stat
objects can work together, can enable a very smooth operation later on.