# Interfaces

Objects which have stats should implement `IHaveStats`. This, and similar interfaces such as `IHaveConditions` and `IHaveQuests` each themselves implement `IUseGameModules` which in turn, implements `IHaveGameId`

### `IHaveGameId`

A `GameId` is a unique identifier for runtime objects. Objects like `Stat` and `Condition`, which are Game Module Scriptable Objects, have a unique `Uid()` value. However, a `GameConditionList` may have multiple instances of a `GameCondition`, all of which have the same `Uid()`. The `Uid()` on a "Game" version of a Game Module type is the same as the Scriptable Object version.

Each of these instances will have a unique `GameId()`, which enables specific objects to be handled in cases where there are multiple similar objects.

Here is some sample code you can use, which will create a random value when the `_gameId` is empty. Afterward, it will return the value that was created.

```csharp
[SerializeField] private string _gameId;

public virtual string GameId(bool forceNew = false) =>
    string.IsNullOrWhiteSpace(_gameId) || forceNew
        ? _gameId = Guid.NewGuid().ToString() 
        : _gameId;
```

Once a `GameID()` value is set, something that generally will happen at runtime, it should never change. The value will be saved along with the rest of the data.

Each `GameID()` must be unique. If you know you have only one instance of an object, and you will never have another, you can explictly set the value to something more human readable.

```csharp
[SerializeField] private string _gameId = "Human Readable Id";
public virtual string GameId(bool forceNew = false) => _gameId;
```

{% hint style="info" %}
The GameId() is used in the [**Blackboard**](/magic-pig-games/game-modules-4/module-documentation/blackboard.md) module for `BlackboardNote` and `BlackboardEvent` objects to identify the object mentioned in the note or event.

[**Stats**](/magic-pig-games/game-modules-4/module-documentation/stats-and-skills.md) can automatically post their values to the **Blackboard**, and they use the randomly generated `GameId()` string in that context. Other modules use the value simialrly.
{% endhint %}

### IUseGameModules

The various modules utlize an "Owner" concept to automatically operate. The "Owner Name" is a string, often something human readable, but may also be the `GameId()` value on the object. In some cases, this method may not be used at all.

```csharp
// Hard coded owner name
public string GetOwnerName() => "Game Data";

// GetOwnerName() used in debug logs
private void PlayerGotHit()
{
    var target = gameData.RandomPlayer;
    foreach (var condition in onHitConditions)
    {
        Debug.Log($"Will give condition {condition.objectName} to {target.GetOwnerName()}}");                        target.AddCondition(condition, this);
        gameData.PlayerGotHit(target);
    }
    PlayerObject.playerObject.GotHit();
}
```

The `SetOwner()` method is important, and is used to ensure that various [**Game Module Lists**](/magic-pig-games/game-modules-4/module-documentation/quests/gamequestlist.md) know who their owner is.

In the example below, from the **Party Based RPG demo game**, the `SetOwner()` method calls the same method on the two Game Module lists, a `GameStatList` and `GameQuestList`. The methods on those lists will ensure all items in the lists also have the `GameData` objet as their owner.

```csharp
// GameData.cs
public void SetOwner(object newOwner)
{
    partyStats.SetOwner((IHaveStats)newOwner);
    quests.SetOwner((IHaveQuests)newOwner);
}
```

{% hint style="success" %}
Calling `SetOwner()`, which then calls the same method on the various lists, should be one on during `StartActions()`, something to run after loading data. `GameData.cs` does this during `StartActions()`, which is called right after `LoadState()`.

```
SetOwner(this);
```

{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/v4-migration-tips/interfaces.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
