# Skill Nodes

A skill node is a skill's representation in a skill graph.  '`mySkillNode`' in the code examples below is an instance of a `SkillNode`.

## Getting a Skill Node

The recommended method of getting a skill node is through a [skill graph](https://stylishesper.gitbook.io/skill-tree/systems/skill-tree/skill-graphs#nodes). Alternatively, you can get a skill node with it's key.

```csharp
SkillNode mySkillNode = SkillTree.GetSkill("MySkillKey");
```

## Working with Skill Nodes

All of the data you can set for a skill node from the [editor-window](https://stylishesper.gitbook.io/skill-tree/systems/skill-tree/editor-window "mention") are public fields.

### Stats

You can use the `stats` field the access the full list of stats.

#### Getting a Stat

```
Stat stat = mySkillNode.GetStat("my stat name");
```

### States

There are 4 possible skill states:

| Name     | Description                    |
| -------- | ------------------------------ |
| Locked   | If the skill is locked.        |
| Unlocked | If the skill is unlocked.      |
| Obtained | If the skill is obtained.      |
| Maxed    | If the skill's level is maxed. |

Skills start out locked. Skill states can be managed with the methods below.

You can check the current state of a skill by comparing the state field or you may use the Boolean properties listed below.

| Name       | Description                    |
| ---------- | ------------------------------ |
| IsLocked   | If the skill is locked.        |
| IsUnlocked | If the skill is unlocked.      |
| IsObtained | If the skill is obtained.      |
| IsMaxed    | If the skill's level is maxed. |

#### Unlocking

Skills must be unlocked to be obtainable (or upgradable).

**TryUnlock**

This method attempts to unlock a skill if possible. Skills cannot be unlocked if the player doesn't meet the level requirement, no obtained skill leads to this skill through a connection, or if enough required skill points haven't been spent on skills in a specific skill tree.

```csharp
mySkillNode.TryUnlock();
```

**TryUnlockAllThroughConnections**

This method tries to unlock all skills that the skill has a connection with. This is useful when you need to unlock skills connected to another. For example, if skill B, C,  and D have a connection with skill A, this will unlock skills B, C, and D if skill A is obtained.

```csharp
mySkillNode.TryUnlockAllThroughConnections();
```

#### Obtaining

Once a skill is upgraded at least once, it's state changes to `Obtained`.

**TryUpgrade**

This method will upgrade a skill if possible. If a skill is not obtained or maxed, nothing will happen. This accepts a skill points parameter (`int`), which will decrease the player's skill points by the amount provided (it will decrease the `SkillTree.playerSkillPoints` field).

<pre class="language-csharp"><code class="lang-csharp"><strong>mySkillNode.TryUpgrade();
</strong></code></pre>

#### Maxing

The skill state will change to `Maxed` if it cannot be upgraded anymore.

#### Downgrading

Skills can be downgraded with `TryDowngrade`. Skill states will change accordingly. Downgrading may fail if the skill is at the lowest level (0). Downgrading may also be prevented from Skill Tree's settings.

```csharp
mySkillNode.TryDowngrade();
```

Optionally, you can use `Deplete` to completely downgrade a skill.

```csharp
mySkillNode.Deplete();
```

### Text Interpolation

Skills support text interpolation with the usage of text tags. You can learn more about this [here](https://stylishesper.gitbook.io/skill-tree/systems/skill-tree/editor-window/skills-skill-nodes/text-tags). Essentially, you can use text tags in a string, run the string through the skill's `GetInterpolatedText` method, and it will return the same string except with the tags replaced by the skill's details.

```csharp
// stat0_value refers to the current value of the first stat
string myString = "The skill deals {stat0_value} damage!"
string result = mySkillNode.GetInterpolatedText(myString);
```

Assuming `mySkillNode`'s first stat's current value is 100, `result` will equal:

```csharp
"The skill deals 100 damage!"
```

### Level Display String

You can get a string that represents the skill's current level out of the max level.

```csharp
// Example: "0/1"
string level = mySkillNode.levelDisplayString;
```

### Getting the Sprite

You can access the sprites with `mySkillNode.lockedSprite`, `mySkillNode.unlockedSprite`, and `mySkillNode.obtainedSprite`.

To get the relevant sprite based on the current state of the skill, use the `GetSprite` method.

```csharp
Sprite skillSprite = mySkillNode.GetSprite();
```

### Getting the Skill Graph

Skill nodes store a reference to the skill graph they are a part of.

```csharp
SkillGraph mySkillGraph = mySkillNode.graphReference;
```

### Getting the Skill Type

```csharp
string mySkillType = mySkillNode.GetSkillType();
```
