# Attribute

## 📊 Attribute class

An attribute can be used as type for a stat, ability, character, etc. This class is used by the [stat](https://stylishesper.gitbook.io/inventool/scripting/api/stats/stat "mention") class to help define a its strengths and weaknesses.

> **Namespace:** `Esper.Inventool.Stats`\
> **Access:** `public`\
> **Type:** `class`\
> **Inherits:** `InventoolObject`

***

### 📦 Fields

| Access   | Field                     | Type                  | Description                                   |
| -------- | ------------------------- | --------------------- | --------------------------------------------- |
| `public` | `displayName`             | `string`              | The display name of the attribute.            |
| `public` | `localizedDisplayNameKey` | `string`              | The key of the localized display name string. |
| `public` | `icon`                    | `Sprite`              | An icon that represents the attribute.        |
| `public` | `effectivenesses`         | `List<Effectiveness>` | Effectivenesses against attributes.           |

***

### 🔍 Properties

| Access          | Property                        | Type     | Description                  |
| --------------- | ------------------------------- | -------- | ---------------------------- |
| `public static` | `DirectoryPath` *(Editor only)* | `string` | The directory of attributes. |

***

### 🧰 Methods

| Access          | Method                                                    | Returns           | Description                                                   |
| --------------- | --------------------------------------------------------- | ----------------- | ------------------------------------------------------------- |
| `public`        | `GetLocalizedDisplayName()`                               | `string`          | Gets the localized display name string.                       |
| `public`        | `GetAttackWeaknesses()`                                   | `List<Attribute>` | Gets attributes this attribute deals decreased damage to.     |
| `public`        | `GetAttackStrengths()`                                    | `List<Attribute>` | Gets attributes this attribute deals increased damage to.     |
| `public`        | `GetDefenseWeaknesses()`                                  | `List<Attribute>` | Gets attributes that deal increased damage to this attribute. |
| `public`        | `GetDefenseStrengths()`                                   | `List<Attribute>` | Gets attributes that deal decreased damage to this attribute. |
| `public`        | `HasEffectiveness(Attribute attribute)`                   | `bool`            | Checks if an attribute is in the effectiveness list.          |
| `public`        | `AddEffectiveness(Attribute attribute, float multiplier)` | `void`            | Adds an effectiveness entry.                                  |
| `public`        | `RemoveEffectiveness(Attribute attribute)`                | `void`            | Removes an effectiveness entry.                               |
| `public`        | `IsWeakAgainst(Attribute attribute)`                      | `bool`            | Checks if this attribute is weak against another.             |
| `public`        | `IsStrongAgainst(Attribute attribute)`                    | `bool`            | Checks if this attribute is strong against another.           |
| `public`        | `GetEffectiveness(Attribute attribute)`                   | `float`           | Gets the effectiveness multiplier against another attribute.  |
| `public`        | `SetData(Attribute attribute)`                            | `void`            | Sets the data of this attribute from another.                 |
| `public static` | `Create()` *(Editor only)*                                | `Attribute`       | Creates a new instance of an attribute.                       |
| `public`        | `UpdateAssetName()` *(Editor only)*                       | `void`            | Updates the name of the asset.                                |
| `public static` | `GetFullPath(Attribute attribute)` *(Editor only)*        | `string`          | Gets the full path of an attribute asset.                     |
| `public static` | `CreateCopy(Attribute original)`                          | `Attribute`       | Creates a copy of another attribute.                          |

***

### ➗ Operator overloads

* **Implicit from int:** Returns `Inventool.GetAttribute(id)`.
* **Implicit from string:** Returns `Inventool.GetAttribute(name)`.

***

## Creating Attributes

It's not at all recommended to create attributes at runtime, but it is possible. `Attribute`'s are scriptable objects which cannot be created as assets at runtime for later use.

```csharp
Attribute attribute = ScriptableObject.CreateInstance<Attribute>();
```

The attribute IDs must be unique. When creating them from the [attributes](https://stylishesper.gitbook.io/inventool/editors/inventool/stats/attributes "mention") tab, unique IDs are set automatically. However, this is not done when creating them at runtime. You'd need to create your own method of ensuring IDs of generated attributes are unique.

## Getting Attributes

Attributes created through the [attributes](https://stylishesper.gitbook.io/inventool/editors/inventool/stats/attributes "mention") tab can be retrieved at runtime.

### Get a Single Attribute

You can get an attribute by its ID, or name with the `Inventool.GetAttribute` method.

```csharp
Attribute myAttribute = Inventool.GetAttribute("Fire");
```

### Get All Attributes

```csharp
var attributes = Inventool.GetAllAttributes();
```

## Effectiveness

### Add Effectiveness

Adding an effectiveness requires a reference to an attribute.

```csharp
// x2 effectiveness
myAttribute.AddEffectiveness(otherAttribute, 2f);
```

### Remove Effectiveness

Removing an effectiveness requires a reference to an attribute.

```csharp
myAttribute.AddEffectiveness(otherAttribute);
```

### Check If An Effectiveness Exists

```csharp
bool exists = myAttribute.HasEffectiveness(otherAttribute);
```

### Get Effectiveness

You can get the effectiveness multiplier value with the `GetEffectiveness` method.

```csharp
float multiplier = myAttribute.GetEffectiveness(otherAttribute);
```

### Strengths/Weaknesses

There are multiple methods available to get both the attack and defense weaknesses of an attribute.

#### Attack Strengths

The `GetAttackStrengths` method returns a list of attributes that an attribute is more than 1x effective against.

```csharp
var attributes = myAttribute.GetAttackStrengths();
```

#### Attack Weaknesses

The `GetAttackWeaknessess` method returns a list of attributes that an attribute is less than 1x effective against.

```csharp
var attributes = myAttribute.GetAttackWeaknesses();
```

#### Defense Strengths

The `GetDefenseStrengths` method returns a list of attributes that are more less 1x effective against an attribute.

```csharp
var attributes = myAttribute.GetDefenseStrengths();
```

#### Defense Weaknesses

The `GetDefenseWeaknesses` method returns a list of attributes that are more than 1x effective against an attribute.

```csharp
var attributes = myAttribute.GetDefenseWeaknesses();
```
