# Bevy Economy System

Bevy ECS economy: Wallet components, a PriceTable resource, Purchase and Transfer...

- Repository: https://github.com/thedivergentai/Game-Dev-Agentic-Skills (917 stars)
- Category: Engineering
- License: LGPL-3.0
- Last updated: 2026-10-16
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-economy-system -g -a claude-code -y`
Codex: `npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-economy-system -g -a codex -y`
Cursor: `npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-economy-system -g -a cursor -y`
Gemini CLI: `npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-economy-system -g -a gemini-cli -y`

## Description

Bevy ECS economy: Wallet components, a PriceTable resource, Purchase and Transfer messages, vendor stock. Use when a debit must see the price row and two wallets must not be written by unordered systems. Keywords: Bevy, economy, wallet, price, Purchase, get_many_mut.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Bevy economy system

## When to use

Load this when wallets, prices, or vendors change numbers. Item identity stays on bevy-inventory-system.

## ECS shape

- **Components:** wallet amounts you define.
- **Resources:** price rows live in one resource (bevy-data-resources).
- **Systems:** mutate wallets on `Update`. Use `.chain()` when stock must drop before the wallet debit.
- **Messages:** a purchase or transfer is a message. This file names `Purchase` and `Transfer`.

## Idioms

| Need | Bevy shape |
| --- | --- |
| Wallet | A component of currency amounts you define. |
| Price row | A resource table. |
| Transaction | A message. One system writes both wallets with `get_many_mut`. |

## Scope

- Coins live on a wallet component. Prices live in one resource. A purchase message is the only writer of the buyer wallet.
- Persistence of the wallet belongs on bevy-save-load.

## Examples

```toml
[package]
name = "economy"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.20"
```

Price lookup and the wallet write share one chain so the debit sees the row that was chosen.

```rust
#[derive(Component)]
struct Wallet {
    coins: u32,
}

#[derive(Clone, Copy)]
struct PriceRow {
    item: u32,
    cost: u32,
}

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

#[derive(Message)]
struct Purchase {
    buyer: Entity,
    item: u32,
}

fn buy(
    mut purchases: MessageReader<Purchase>,
    table: Res<PriceTable>,
    mut wallets: Query<&mut Wallet>,
) {
    for purchase in purchases.read() {
        let Some(row) = table.rows.iter().find(|row| row.item == purchase.item) else {
            continue;
        };
        let Ok(mut wallet) = wallets.get_mut(purchase.buyer) else {
            continue;
        };
        if wallet.coins < row.cost {
            continue;
        }
        wallet.coins -= row.cost;
    }
}

pub struct EconomyPlugin;

The rest: https://github.com/thedivergentai/Game-Dev-Agentic-Skills/blob/HEAD/skills/bevy-economy-system/SKILL.md
