# AI Interaction Manager

<div align="left"><figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FOXndO6hKeLj0uEuE8Vaf%2FActorComponent_64x.png?alt=media&#x26;token=b00844b2-cbc3-4f89-9f4b-d2c8e193007c" alt=""><figcaption></figcaption></figure></div>

The **AI Interaction Manager (AC\_AI\_InteractionManager)** is responsible for handling NPC interactions, primarily focusing on **dialogue and vendor** logic. It determines **which dialogue should be displayed based on the player's progress** and displays the associated dialog entry upon interaction. Additionally, it allows NPCs to function as vendors, providing a seamless transition from dialogue into a shop or trade interface.

It is added to the **Soulslike NPC (B\_Soulslike\_NPC)** class by default.

### **How it Works**

* **Dialogue Handling**
  * Upon interaction with an NPC, the `BeginDialog` method is triggered. It ensures that a reference to the player's **Progress Manager** and the NPC’s **Dialog Asset** is valid before proceeding.
  * It fetches the appropriate **Dialog Table** based on the player’s progress and resets the **dialog index** to 0.
  * The dialog index is adjusted accordingly, either moving to the next line or exiting the conversation.
  * If the player **exits mid-dialog**, the system ensures that the dialog index is adjusted appropriately *(so that entries that execute gameplay events cannot be re-triggered).*
* **Executing Gameplay Events**
  * If the current dialog entry has an **event**, it triggers it via[ **AC\_ProgressManager**](https://soulslike-framework.isik.vip/components-managers/player-specific-components/progress-manager) **-> ExecuteGameplayEvent()**.
* **Vendor Handling**
  * Upon completing the **last dialog entry**, the system checks if the NPC has an associated **vendor asset**.
  * If a vendor asset is found, the **NPC Window** is set up, transitioning the player into the vendor/shop interface.
  * If no vendor asset is present, the conversation simply ends.

### Example Usage

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FWvDHO7aWa8XzESwOHRfr%2Fimage.png?alt=media&#x26;token=c48cdc45-a77c-4c5c-9b59-998dd7d8151b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FTKy5rDJ0rOrvOh3eIjxl%2Fimage.png?alt=media&#x26;token=e232b8b6-59ea-424b-a59d-36f21d281f7e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2Fl2ZeDmw6zUlswrdKgmc9%2Fimage.png?alt=media&#x26;token=30571764-6000-4bf9-bacb-3fb5b03f6f3c" alt=""><figcaption></figcaption></figure>
