Ability skill system

From nlelouche/Unity-SkillForge · View interactive version

Ability skill system is an AI agent skill from the GitHub repository nlelouche/Unity-SkillForge. Data-driven ability system with ScriptableObject definitions, cooldowns, resource costs, targeting, and cast times.

How to use this skill

Skill file

Ability Skill System

Overview

Complete data-driven ability system using ScriptableObjects. Supports cooldowns, multiple resource types, targeting modes, cast times, and VFX/SFX integration.

When to Use

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    AbilityDataSO                            │
│              (ScriptableObject Asset)                       │
├─────────────────────────────────────────────────────────────┤
│  Identity: ID, Name, Description, Icon                      │
│  Cooldown: Duration, Shared Group                           │
│  Costs: [{Type: Mana, Amount: 30}, ...]                     │
│  Targeting: Self, Enemy, AOE, Direction                     │
│  Execution: CastTime, Duration, CanCancel                   │
└─────────────────────────────────────────────────────────────┘
                              ↓
┌─────────────────────────────────────────────────────────────┐
│                    AbilityManager                           │
│              (On Player/NPC)                                │
├─────────────────────────────────────────────────────────────┤
│  TryUseAbility(slotIndex, context)                          │
│  Cooldown Tracking, Resource Management                     │
│  Events: OnCooldownStarted, OnResourceChanged               │
└─────────────────────────────────────────────────────────────┘
                              ↓
┌─────────────────────────────────────────────────────────────┐
│                    AbilityExecutor                          │
│              (Handles Cast + Effect)                        │
├─────────────────────────────────────────────────────────────┤
│  StartCast(context), Execute(context)                       │
│  Spawn VFX, Play SFX, Apply Effects                         │
└─────────────────────────────────────────────────────────────┘

Components

| Component | Purpose |

|-----------|---------|

| AbilityDataSO | ScriptableObject with ability definition |

| AbilityManager | Main controller with cooldowns/resources |

| AbilityExecutor | Handles casting and effect execution |

| AbilitySlot | Binds ability to hotkey |

| IResourceProvider | Interface for resource systems |

Resource Types

Best Practices

Few-Shot Examples

Example 1: Create Fireball Ability

User: "Create a fireball ability with 5s cooldown, 30 mana cost."

Agent:

// 1. Create AbilityDataSO asset: Assets/Abilities/Fireball.asset
// 2. Set: CooldownDuration = 5, Costs = [{Mana, 30}]
// 3. Set: TargetType = PointOnGround, Range = 10
// 4. Assign VFX prefab and SFX clip

Example 2: Cooldown UI

User: "Show ability cooldown on button."

Agent:

abilityManager.OnCooldownStarted += (ability, duration) =>
{
    if (ability == myAbility)
        StartCooldownDisplay(duration);
};

Example 3: Resource Cost Check

User: "Gray out button if not enough mana."

Agent:

bool canUse = abilityManager.HasResource(ResourceType.Mana, ability.Costs[0].Amount) 
           && !abilityManager.IsOnCooldown(ability);
button.interactable = canUse;

TDD Contract

⚠️ Legacy Skill — Refactor Pending

Este skill NO tiene tests automatizados aún. El siguiente boilerplate es un punto de partida.

// Escribe estos tests ANTES de implementar:

// Test 1: should [expected behavior] when [condition]
[Test]
public void AbilitySkillSystem_Should{ExpectedBehavior}_When{Condition}()
{{
    // Arrange
    // TODO: Setup test fixtures
    
    // Act
    // TODO: Execute system under test
    
    // Assert
    Assert.Fail("Not implemented — write test first");
}}

// Test 2: should handle [edge case]
[Test]
public void AbilitySkillSystem_ShouldHandle{EdgeCase}()
{{
    // Arrange
    // TODO: Setup edge case scenario
    
    // Act
    // TODO: Execute
    
    // Assert
    Assert.Fail("Not implemented");
}}

// Test 3: should throw when [invalid input]
[Test]
public void AbilitySkillSystem_ShouldThrow_When{InvalidInput}()
{{
    // Arrange
    var invalidInput = default;
    
    // Act & Assert
    Assert.Throws<Exception>(() => {{ /* execute */ }});
}}

Pasos para completar el TDD:

  1. Descomenta los tests above
  2. Implementa la funcionalidad mínima para que compile
  3. Ejecuta los tests — deben fallar (RED)
  4. Implementa la funcionalidad real
  5. Verifica que los tests pasen (GREEN)
  6. Refactorea manteniendo los tests verdes

Nota: Este skill fue marcado como tdd_first: false durante la auditoría v2.0.1. La sección TDD fue agregada automáticamente pero requiere customización manual para reflejar el comportamiento real del skill.

Related Skills

Template Files

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.