# Stat Scaling Source

## 📈 StatScalingSource Struct

The `StatScalingSource` struct is used by a [stat](https://stylishesper.gitbook.io/inventool/scripting/api/stats/stat "mention") as the source to scale itself. It essentially works as the scaling settings.

> **Namespace:** `Esper.Inventool.Stats`\
> **Access:** `public`\
> **Type:** `struct`\
> **Attributes:** `[Serializable]`

***

### 📦 Fields

| Access   | Field          | Type                        | Description                                        |
| -------- | -------------- | --------------------------- | -------------------------------------------------- |
| `public` | `scalingType`  | `ScalingSource.ScalingType` | The scaling mode used (`None`, `Linear`, `Curve`). |
| `public` | `initialValue` | `StatValue`                 | The starting value.                                |
| `public` | `increment`    | `StatValue`                 | The scaling amount used for linear scaling.        |
| `public` | `min`          | `StatValue`                 | The minimum value used for curve scaling.          |
| `public` | `max`          | `StatValue`                 | The maximum value used for curve scaling.          |
| `public` | `curve`        | `AnimationCurve`            | The curve used when scaling type is `Curve`.       |

***

### 🧰 Constructors

| Access   | Constructor                                                                                     | Description                                   |
| -------- | ----------------------------------------------------------------------------------------------- | --------------------------------------------- |
| `public` | `StatScalingSource(StatValue initialValue)`                                                     | Creates a scaling source with no scaling.     |
| `public` | `StatScalingSource(StatValue initialValue, StatValue increment)`                                | Creates a scaling source with linear scaling. |
| `public` | `StatScalingSource(StatValue initialValue, StatValue min, StatValue max, AnimationCurve curve)` | Creates a scaling source with curve scaling.  |

***

### 🧰 Methods

| Access   | Method                                    | Returns     | Description                                                                   |
| -------- | ----------------------------------------- | ----------- | ----------------------------------------------------------------------------- |
| `public` | `SetIdentity(StatIdentity identity)`      | `void`      | Sets the identity for all values (`initialValue`, `increment`, `min`, `max`). |
| `public` | `GetScaledValue(int level, int maxLevel)` | `StatValue` | Gets the scaled value at a specific level.                                    |

## Create a Scaling Source

```csharp
// Linear scaling source
StatScalingSource myStatScalingSource = new StatScalingSource()
{
    scalingType = ScalingSource.ScalingType.Linear, // Linear scaling
    initialValue = new StatValue(myIdentity, 10), // Set the initial stat value to 10 
    increment = new StatValue(myIdentity, 10), // Scale by 10 per level
};
```

## Set Identity

The `SetIdentity` method can be used to set the [stat-identity](https://stylishesper.gitbook.io/inventool/scripting/api/stats/stat-identity "mention") of the stat values.

```csharp
myStatScalingSource.SetIdentity(myIdentity);
```

## Get Scaled Value

You can get the scaled value at a certain level with the `GetScaledValue` method. This requires 2 integers: the current level and the max level.

```csharp
// Current level: 1, Max level: 100
var scaledValue = myStatScalingSource.GetScaledValue(1, 100);
```
