# Adding a New Buff

## Add Buffs to Your Attack Skills

First, you need to find your skill prefab. You'll see that two new properties have been added to the skill script: the "Add Buff Event" where you can select a only event, and the second one where you can add your own or preset three buffs.

Assets/RGame/RoguelikeKit/Prefabs/Skill/BothSideSkill.prefab

![](https://2218703886-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4YPyrdOyfjDGtlxlvjSd%2Fuploads%2FlnYEgeuM1XHXXTxdZvDv%2Fimage.png?alt=media\&token=5407f105-b12b-48e1-98ff-69dd73cae1ab)

### Adding a New Buff

This guide walks you through creating and configuring a new buff in the RGame RoguelikeKit, using **BurnBuff** as an example.

#### 1. Inspect the Existing Buff Asset

1.  In Unity, navigate to:

    ```
    Assets/RGame/RoguelikeKit/ScriptableObjects/DataSO/Buff/BurnBuff.asset
    ```
2.

    <figure><img src="https://2218703886-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4YPyrdOyfjDGtlxlvjSd%2Fuploads%2FqNgom6N1LtRKM5IlMpeb%2Fimage.png?alt=media&#x26;token=4126611a-bad8-4005-ba0a-f3b7e83bd36f" alt=""><figcaption></figcaption></figure>
3. Select **BurnBuff.asset** to view its properties in the Inspector. You will see four key fields:
   * **Duration**: Total lifespan of the buff (in seconds).
   * **TickInterval**: How often **TickEffect()** is called. For **BurnBuff**, this is set to 1s (one damage tick per second).
   * **OnRemove:** choose a unique event.
   * **Damage**: Amount of damage dealt each tick.

<figure><img src="https://2218703886-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4YPyrdOyfjDGtlxlvjSd%2Fuploads%2FsFlf5LU7MM7Rfh6SRS26%2Fimage.png?alt=media&#x26;token=f7bb670d-2e69-4b9d-a7ff-a71e7a7033de" alt=""><figcaption></figcaption></figure>

> _The remaining two built‑in buff types (e.g. FreezeBuff, SlowBuff) use the same properties—just examine their asset files and you’ll see how Duration, Interval, and effect parameters differ._

#### 2. Create a New Buff Script

1. Right‑click in your project window and choose **Create → RGame → RoguelikeKit → Buff → BaseBuff** (or duplicate **BurnBuff** and rename).
2. Name your new script: **MyCustomBuff.cs**.

#### 3. Implement Core Methods

Each buff requires three overrides in your **BaseBuff** subclass:

* **Activate()**: Called when the buff is applied.
* **TickEffect()**: Called every **TickInterval** seconds while active.
* **DeActivate()**: Called when the buff expires or is removed.

Below is the full **BurnBuff** implementation for reference:

```csharp
using UnityEngine;

namespace RGame.RoguelikeKit
{
    [CreateAssetMenu(menuName = "RGame/RoguelikeKit/Buff/BurnBuff")]
    public class BurnBuff : BaseBuff
    {
        public int Damage;
        private EnemyHit _ownerHit;
        
        public override void Activate()
        {
            BuffName = "BurnBuff";
            
            // Visual: tint sprite red
            var mat = Owner.MySpriteRenderer.material;
            mat.SetColor("_FlameRedBlend", Color.red);

            // Cleanup on death
            Owner.OnDeath += OnOwnerDestroy;

            // Cache damage component
            _ownerHit = Owner.GetComponentInChildren<EnemyHit>();
        }

        public override void DeActivate()
        {
            // Reset visual
            var mat = Owner.MySpriteRenderer.material;
            mat.SetColor("_FlameRedBlend", Color.white);

            // Remove death listener
            Owner.OnDeath -= OnOwnerDestroy;
        }

        public override void TickEffect()
        {
            base.TickEffect();
            _ownerHit.Hit(Damage);
        }
        
        private void OnOwnerDestroy(Enemy owner)
        {
            // Raise event to clear buffs
            RemoveAllBuff.RaiseEvent(this);
        }
    }
}
```

#### 4. Configure Your New Buff Asset

1. In the Inspector, set **Duration**, **TickInterval**, and any custom parameters (e.g., damage, slow percentage).
2. Wire up **OnRemoveAllBuff** to the appropriate event channel.

#### 5. (Optional) Use Your AI Assistant

If you prefer, ask your AI assistant to scaffold a new buff class using this pattern:

```
Tell me to create a {BuffName} that {effect description} every {interval}s for {duration}s.
```

Your assistant can generate the C# boilerplate and even set up properties—no coding worries required.

You don't need to worry about the AI being unable to create the effect you want. As long as it's not particularly complex, the AI can handle it.

***

You’re all set! With this pattern, you can rapidly add new buff types—just follow the **Activate()**, **TickEffect()**, and **DeActivate()** lifecycle, then configure the asset parameters in the Inspector.



