> For the complete documentation index, see [llms.txt](https://digital-dungeon-assets.gitbook.io/digital-dungeon-assets-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://digital-dungeon-assets.gitbook.io/digital-dungeon-assets-docs/spell-system/markdown.md).

# Spell Component Overview

This component provides a lot of functions that enables a spell to be cast correctly and&#x20;

## Event Graph

The only thing there is a reference to the player, this is done with  an interface&#x20;

the only components we are getting from the player are the mesh movement component and other spell components, if you want to use it on other characters as well you technically can also just use "Get Owner -> Cast to Character"

<figure><img src="https://603854490-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYpx8GDKCTy6DRbPD4HF%2Fuploads%2FIsPDjQ8sBHLN1DMiUC5x%2F12.png?alt=media&amp;token=41d6b40c-5b3b-4bd9-b5d7-11bbeb76d707" alt=""><figcaption></figcaption></figure>

## Player Input

Listens for player input, then calls these Macros and Functions

<figure><img src="https://603854490-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYpx8GDKCTy6DRbPD4HF%2Fuploads%2FTCfMlwmGePLtp3V5PWlU%2FScreenshot%202024-08-29%20151222.png?alt=media&amp;token=2d211c5f-8bd2-4021-960a-6888b918f91a" alt=""><figcaption></figcaption></figure>

When adding a spell you assign it to a certain index in a Map, when pressing a button 1-4 we set it in  the spell system then it can read the correct data.

## RPC's

A collection of RPC's to make sure all clients are in sync and see the same result<br>

<figure><img src="https://603854490-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYpx8GDKCTy6DRbPD4HF%2Fuploads%2FHleNoTXpiI8GvXpZqrJZ%2FScreenshot%202024-08-29%20153144.png?alt=media&amp;token=58cf56de-f3c9-443d-a362-8e6fe13db94c" alt=""><figcaption></figcaption></figure>

## Functions

[<mark style="color:purple;">**Change Combat State**</mark>](#user-content-fn-1)[^1]\
Changes the combat state and notifies animation blueprint to switch animations, it also takes care of rotating the controlled character towards the camera, it also rotates the Character towards any locked in target from the "Targeting Component"

[<mark style="color:purple;">Cast Spell</mark>](#user-content-fn-1)[^1]

The main function of this component. It reads the data from the data table and saves it, afterwards spawning and attaching is being done with optional offsets. The call for casting a spell comes from the matching animation notifier <mark style="color:orange;">"Cast Spell"</mark>.

<mark style="color:purple;">Add Spell</mark>

Adds a spell to the specified index, after that it checks for the UI component and displays the spell to the correct key

<mark style="color:purple;">Remove Spell</mark>

Removes a spell from a specified slot, signals the UI components if available to remove it from the HUD

<mark style="color:purple;">Initiate Spell</mark>

Pre-checks if even able to cast spells, also cancels active animations to prepare for the next spell casting animation which triggers <mark style="color:orange;">"Cast Spell"</mark>

<mark style="color:purple;">Cancel Montages</mark>

Looks for active montages and stops them

<mark style="color:purple;">Set Widget Spell Index</mark>

Fires event dispatcher to notify subscribed components that the index has changed

<mark style="color:purple;">Get Fire Direction</mark>

Either provide the camera direction or the player facing direction or none if wished

<mark style="color:purple;">Clean Up Spell</mark>

Triggers the self-destruction of the spell with a given delay, then invalidates the reference to it in the Spell component

<mark style="color:purple;">Check If has enough mana</mark>

If available, gets data from stats component and checks if we are allowed to cast the spell

<mark style="color:purple;">Check If can init spell</mark>

Does several checks if the spell can be cast

<mark style="color:purple;">Set Spell Location Camera Auto Aim</mark>

Traces from the camera and check for valid surfaces, it has several fail saves if no surface is available. Afterwards it snaps the spell to the closest target near the casting location

<mark style="color:purple;">Set Spell Location Camera</mark>

The same as above but without the snapping. Checks for valid surfaces and cast the spell there

## Macros

<mark style="color:blue;">Switch On Spell Type</mark>

Set in the Data Table, it defines how the button press casts the spell, Either Instantly which just requires a single button press or Hold and release which requires holding the button and on release it stops casting

<mark style="color:blue;">End Current Montage</mark>

Checks if the spell is a Hold and release button type and stops it then if the button is released

<mark style="color:blue;">Allow Spell Casting</mark>

This is set by an animation notifier which blocks the input for casting a spell to make sure there are no interruptions while casting the spell

[^1]:
