Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

bevy-ability-system

БесплатноБез исполняемых скриптовНе проверен

Bevy ECS skill for abilities. Keywords: Bevy, ability, cooldown, ECS, gameplay.

thedivergentaiот thedivergentai★ 1 019 звёзд на GitHub

Об этом скилле

Bevy ability system

When to use

Load this when an actor grants, cools down, or spends an ability. Combat resolution stays on bevy-combat-system.

ECS shape

  • Components: ability id, charges, and cooldown remaining on the caster.
  • Resources: run-wide tables live in a resource (bevy-data-resources).
  • Systems: mutate those components on Update or the fixed timestep. Use .chain() when damage must land before death.
  • Messages: one-shot facts (hit, pickup, quest advance) go through bevy-events-messaging. This file does not add a new event type name.

Ability choices

Need Bevy idiom
Ability definition A Resource catalog plus a component row on the caster.
Cooldown remaining stepped with Time<Fixed>::delta_secs in FixedUpdate.
Cast MessageWriter<CastAccepted> after the cooldown and charge gates pass.

Scope

  • Cooldowns, charges, and catalogs are components and resources. Combat damage stays on bevy-combat-system.
  • Stacking status effects is a component list you tick on FixedUpdate.

Examples

[package]
name = "abilities"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.20"

Cooldown and charges share the caster. Tick, then accept the cast, on FixedUpdate.

#[derive(Component)]
struct Cooldown {
    remaining: f32,
    duration: f32,
}

#[derive(Component)]
struct Charges {
    current: u32,
    max: u32,
}

#[derive(Message)]
struct CastAccepted {
    caster: Entity,
}

fn tick_cooldowns(time: Res<Time<Fixed>>, mut query: Query<&mut Cooldown>) {
    let dt = time.delta_secs();
    for mut cooldown in &mut query {
        cooldown.remaining = (cooldown.remaining - dt).max(0.0);
    }
}

fn try_cast(
    mut casters: Query<(Entity, &mut Cooldown, &mut Charges)>,
    mut casts: MessageWriter<CastAccepted>,
) {
    for (entity, mut cooldown, mut charges) in &mut casters {
        if cooldown.remaining > 0.0 || charges.current == 0 {
            continue;
        }
        charges.current -= 1;
        cooldown.remaining = cooldown.duration;
        casts.write(CastAccepted { caster: entity });
    }
}

fn recharge(time: Res<Time<Fixed>>, mut casters: Query<(&Cooldown, &mut Charges)>) {
    let dt = time.delta_secs();
    for (cooldown, mut charges) in &mut casters {
        if cooldown.remaining <= 0.0 && charges.current < charges.max && dt > 0.0 {
            charges.current += 1;
        }
    }
}

pub struct AbilityPlugin;

impl Plugin for AbilityPlugin {
    fn build(&self, app: &mut App) {
        app.add_message::<CastAccepted>()
            .add_systems(FixedUpdate, (tick_cooldowns, try_cast, recharge).chain());
    }
}

The catalog is one resource. Live cooldown stays on the entity.

#[derive(Clone, Copy)]
struct AbilityDef {
    id: u32,
    cooldown: f32,
    cost: u32,
}

#[derive(Resource)]
struct AbilityCatalog {
    rows: Vec<AbilityDef>,
}

fn lookup(catalog: &AbilityCatalog, id: u32) -> Option<&AbilityDef> {
    catalog.rows.iter().find(|row| row.id == id)
}

#[derive(Component)]
struct Cooldown {
    remaining: f32,
    duration: f32,
}

#[derive(Component)]
struct Charges {
    current: u32,
    max: u32,
}

fn spawn_caster(mut commands: Commands, catalog: Res<AbilityCatalog>) {
    let def = lookup(&catalog, 1);
    let duration = def.map(|row| row.cooldown).unwrap_or(0.5);
    commands.spawn((
        Cooldown {
            remaining: 0.0,
            duration,
        },
        Charges { current: 2, max: 2 },
    ));
}

A shared lock sits in a resource so one system owns it.

#[derive(Message)]
struct CastAccepted {
    caster: Entity,
}

#[derive(Resource)]
struct GlobalCooldown {
    remaining: f32,
}

fn tick_gcd(time: Res<Time<Fixed>>, mut gcd: ResMut<GlobalCooldown>) {
    gcd.remaining = (gcd.remaining - time.delta_secs()).max(0.0);
}

fn arm_gcd(mut gcd: ResMut<GlobalCooldown>, mut casts: MessageReader<CastAccepted>) {
    for _cast in casts.read() {
        gcd.remaining = gcd.remaining.max(0.4);
    }
}

Register CastAccepted with add_message in the same plugin that adds tick_gcd and arm_gcd.

Expert Knowledge Delta

Target: Bevy 0.20+.

Core ECS types: Component, Resource, Query, Commands, Startup, Update, Fixed / FixedMain (bevy::time), .chain(), Plugin, DefaultPlugins, MinimalPlugins. Messages and observers are an ownership slot. See bevy-events-messaging for their APIs. Systems run in parallel unless .chain() orders the ones that conflict.

Who owns state

Piece Owner Who may mutate Schedule
Data on one entity Component One system via Query Update or FixedMain
One value for the whole app Resource One system Startup to insert, then the schedule that reads it
Spawn Commands The spawning system Startup for the initial world; later schedules for runtime spawn
Order that must not race .chain() The
Полный SKILL.md на GitHub

Установить bevy-ability-system в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/ecs-ownership.md

FAQ

Что делает скилл bevy-ability-system?

Bevy ECS skill for abilities. Keywords: Bevy, ability, cooldown, ECS, gameplay.

Как установить скилл bevy-ability-system?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл bevy-ability-system запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить bevy-ability-system с