> For the complete documentation index, see [llms.txt](https://docs.sparkframework.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sparkframework.dev/documentation/developer-guide/plugins/spellbooks/api.md).

# API

**Assembly:** `Spark.Spellbooks` **Interface:** `ISpellbooksPlugin` **Implementation:** `SpellbooksPlugin`

## Interface

```csharp
public interface ISpellbooksPlugin
{
    List<SpellbookEntry> GetAllSpellbooks();
    SpellbookEntry GetSpellbook(string spellbookId);
}
```

## Methods

### GetAllSpellbooks

```csharp
List<SpellbookEntry> GetAllSpellbooks()
```

Returns all spellbook entries in the database.

### GetSpellbook

```csharp
SpellbookEntry GetSpellbook(string spellbookId)
```

Returns the spellbook with the given ID, or `null` if not found.

## SpellbookEntry

Extends `SparkDatabaseEntry`. Defines a collection of abilities.

| Field       | Type                        | Description                 |
| ----------- | --------------------------- | --------------------------- |
| `abilities` | List\<SpellbookAbilityData> | Abilities in this spellbook |

**Methods:**

```csharp
List<AbilityEntry> GetAbilities()
bool HasAbility(AbilityEntry ability)
bool HasAbility(string abilityId)
List<SpellbookAbilityData> GetAbilitiesData()
```

### SpellbookAbilityData

| Field          | Type         | Description                                   |
| -------------- | ------------ | --------------------------------------------- |
| `ability`      | AbilityEntry | The ability                                   |
| `autoAddToBar` | bool         | Auto-add to ability bar when requirements met |

## Components

### SpellbookAutoAddHandler

MonoBehaviour that handles one-time auto-addition of abilities to the ability bar.

| Field             | Type   | Description                 |
| ----------------- | ------ | --------------------------- |
| `barIdentifier`   | string | Target ability bar          |
| `numberOfSlots`   | int    | Slots to fill               |
| `processOnEnable` | bool   | Process on component enable |

**Methods:**

```csharp
void ProcessAutoAddAbilities()
```

Checks ability requirements using `IRequirementsPlugin` and adds qualifying abilities to `AbilityBarEntity`. Tracks which abilities have been auto-added to avoid duplicates.

## Trigger Types

| Trigger                   | Description                   |
| ------------------------- | ----------------------------- |
| `AddSpellbookTriggerType` | Grants or removes a spellbook |

### AddSpellbookTriggerDataAsset

| Field             | Type           | Description             |
| ----------------- | -------------- | ----------------------- |
| `spellbookEntry`  | SpellbookEntry | Spellbook to add/remove |
| `removeSpellbook` | bool           | Remove instead of add   |
| `delay`           | float          | Execution delay         |

## Save Data

### SpellbookSaveData

Extends `SaveDataEntry`.

**Methods:**

```csharp
void AddSpellbook(string spellbookId)
void RemoveSpellbook(string spellbookId)
List<string> GetSpellbooks()
bool HasSpellbook(string spellbookId)

void MarkAbilityAsAutoAdded(string abilityId)
bool WasAbilityAutoAdded(string abilityId)

bool HasProcessedInitialSpellbooks()
void SetProcessedInitialSpellbooks()
```

Tracks spellbook ownership and which abilities have been auto-added to bars to prevent re-adding.

## Usage

```csharp
var spellbooks = Spark.GetPlugin<ISpellbooksPlugin>();
if (spellbooks != null)
{
    // Get all spellbooks
    var allBooks = spellbooks.GetAllSpellbooks();

    // Get a specific spellbook
    SpellbookEntry fireBook = spellbooks.GetSpellbook("fire_spellbook");

    // List abilities in a spellbook
    var abilities = fireBook.GetAbilities();
    foreach (var ability in abilities)
    {
        Debug.Log(ability.DisplayName);
    }

    // Check if spellbook contains an ability
    bool hasFireball = fireBook.HasAbility("fireball");
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sparkframework.dev/documentation/developer-guide/plugins/spellbooks/api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
