> For the complete documentation index, see [llms.txt](https://infinitypbr.gitbook.io/magic-pig-games/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/stats-and-skills/ihavestats.md).

# IHaveStats

v4.0

Any object which has **Stats** should implement `IHaveStats`. Doing so will also implement [`IUseGameModules` and `IHaveGameId`](/magic-pig-games/game-modules-4/v4-migration-tips/interfaces.md).

{% hint style="success" %}
Actors which inherit [`GameModulesActor` or `GameModulesInventoryActor`](/magic-pig-games/game-modules-4/important-information/inherit-from-gamemodulesactor.md) have these methods already built in!
{% endhint %}

Below is some sample code for the required methods, which you may choose to use or modify for your purposes. Unless you are adding `Stats` that are not actors, you would not need to do any of the following, so long as you inherit `GameModulesActor` :)

<pre class="language-csharp"><code class="lang-csharp"><strong>// TryGetGameStat()
</strong><strong>public override bool TryGetGameStat(Stat stat, out GameStat gameStat) 
</strong>    => TryGetGameStat(stat.Uid(), out gameStat);
    
public override bool TryGetGameStat(string uid, out GameStat gameStat)
{
    gameStat = stats.Get(uid, false);
    return gameStat != null;
}

// GetOtherLevels()
public virtual List&#x3C;ModificationLevel> GetOtherLevels(bool cache = false)
{
    if (_modificationLevels != null &#x26;&#x26; !cache)
        return _modificationLevels;

    var otherModificationLevels = new List&#x3C;ModificationLevel>();
    
    // You would add the "Modification Levels" from other Game Module
    // objects used on this object or actor.
    otherModificationLevels.AddRange(conditions.ModificationLevels);
    otherModificationLevels.AddRange(quests.ModificationLevels);
    otherModificationLevels.AddRange(equippedItems.ModificationLevels);
    
    // This example is from DemoActor.cs in the Party Based RPG demo game
    if (!string.IsNullOrWhiteSpace(ActorRace.objectName)) 
        otherModificationLevels.Add(ActorRace.ModificationLevel);
    if (!string.IsNullOrWhiteSpace(ActorClass.objectName)) 
        otherModificationLevels.Add(ActorClass.ModificationLevel);

    _modificationLevels = otherModificationLevels;
    return otherModificationLevels;
}

// SetStatsDirty()
public virtual void SetStatsDirty(List&#x3C;Stat> statList)
{
    ResetOtherLevels(false); // Set this to cache next time it is required
    foreach (var stat in statList)
    {
        if (!TryGetGameStat(stat, out var gameStat)) continue;
        gameStat.SetDirty();
    }
}

// GetStat()
public virtual GameStat GetStat(Stat stat, bool addIfNull = true) 
    => GetStat(stat.Uid(), addIfNull);
public virtual GameStat GetStat(string uid, bool addIfNull = true) 
    => stats.Get(uid, addIfNull);
</code></pre>
