> 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/items/gameitemattribute.cs.md).

# GameItemAttribute.cs

v4.0

The `ItemAttribute` Scriptable Object will not be serialized at runtime, and is intended to store permenent data, rather than mutable data that may change during the game. The `GameItemAttribute` is used for runtime use instead. It implements `IHaveStats`.

{% code title="GameItemAttribute.cs" %}

```csharp
// Owner will be the owner of the GameItemObject this is attached to. If it is not, 
// then owner will be the GameItemAttributeList this is in. If it is not in a
// List, then it will be the value of _owner. The Owner is the IHaveStats objects
// which is affected by the stat effects on these objects.
public IHaveStats Owner => ParentList == null ? _owner : ParentList.Owner;
public ItemAttribute Parent() // Get the ItemAttribute scriptable object
public GameItemObject ParentItemObject // The GameItemObject this is attached to
public GameItemAttributeList ParentList // the List this is in
public string Uid() // Uid of the parent
public virtual string GameId(bool forceNew = false) // In game unique ID of this GameItemObject

public int NameOrder // Name order for this attribute
public string HumanName // Human name
```

{% endcode %}

## Constructor

Pass in the `ItemAttribute` and the `owner`. The `owner` can be `null`, but is required if this `ItemAttribute` is meant to affect the `stats` of the `owner`. `ItemAttribute` can be `null` as well, if you are creating a container for a future `ItemAttribute`. Generally that is unlikely I think.

<pre class="language-csharp"><code class="lang-csharp">public GameItemAttribute(ItemAttribute parent, IHaveStats newOwner = null)
{
<strong>    _parent = parent; // v3.6
</strong>    SetUid(parent.Uid()); // v3.6 -- set the uid with this method now
    objectName = parent.objectName;
    objectType = parent.objectType;
    dictionaries = parent.dictionaries.Clone(); // Clone the dictionaries object, so we don't overwrite our Scriptable Object data!

    GameId();
    SetOwner(newOwner); // Will set null if value is default. Owner is first taken from Parents before reverting to _owner
}
</code></pre>

## Methods

```csharp
// Returns true if it is compatible with the provided uid or ItemAttribute
public bool CompatibleWith(string itemAttributeUid)
public bool CompatibleWith(ItemAttribute itemAttribute)
public bool CompatibleWith(GameItemAttribute gameItemAttribute)

// Returns true if it is not compatible with the provided uid or ItemAttribute
public bool IncompatibleWith(string itemAttributeUid)
public bool IncompatibleWith(ItemAttribute itemAttribute)
public bool IncompatibleWith(GameItemAttribute gameItemAttribute) 

// Returns true if the comparison is correct
public bool IsHigherLevelThan(GameItemAttribute other) => Level > other.Level;
public bool IsLowerLevelThan(GameItemAttribute other) => Level < other.Level;
public bool IsSameLevelAs(GameItemAttribute other) => Level == other.Level;

public bool IsHigherLevelThan(ItemAttribute other) => Level > other.level;
public bool IsLowerLevelThan(ItemAttribute other) => Level < other.level;
public bool IsSameLevelAs(ItemAttribute other) => Level == other.level;
```

#### Additional Methods

```csharp
// Sets the Owners stats dirty, any stat that the Owner has which are affected by this
// GameItemAttribute.
public void SetDirty(bool dirtyValue = true)
```

## Properties

```csharp
public int Level => Parent().level;
public bool Distinct => Parent().distinct;
public bool ReplaceOthers => Parent().replaceOthers;
public bool AffectsActor => Parent().affectsActor;
```
