> For AI agents: the complete documentation index is available at /cheat-terminal/ja/llms.txt, the full documentation bundle is available at /cheat-terminal/ja/llms-full.txt.

# コマンドを追加する

コマンドは `RegisterCommand(...)` で明示的に登録します。自動 scan はなく、実行経路も reflection 呼び出しではなく `CommandContext` delegate です。

> **usage 文字列のルール** — `usage` はチート HUD での実行方法を決めます。
> 引数が不要なら括弧なし（`god`）、必須引数は `<amount>`、任意引数は `[amount]` と書きます。
> HUD はパラメーター別の入力欄と Run ボタンを生成します。コマンド名の入力は不要です。 → [チート HUD](/cheat-terminal/ja/usage/cheat-hud.md)

## 基本登録

```csharp
using System.Globalization;
using Achieve.CheatTerminal;
using UnityEngine;

public class PlayerCheats : MonoBehaviour
{
    private int _gold;

    private void Start()
    {
        TerminalBehaviour.RegisterCommand(
            "gold",
            AddGold,
            "ゴールドを追加",
            "Cheats",
            "gold <amount>");

        TerminalBehaviour.RegisterCommand(
            "god",
            ctx => ctx.Output.WriteLine("god toggled", LogLevel.Success),
            "無敵を切り替え",
            "Cheats",
            "god");
    }

    private void AddGold(CommandContext ctx)
    {
        if (!ctx.Has(0) ||
            !int.TryParse(ctx.Args[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out int amount))
        {
            ctx.Output.WriteLine("Usage: gold <amount>", LogLevel.Error);
            return;
        }

        _gold += amount;
        ctx.Output.WriteLine($"Gold is now {_gold}", LogLevel.Success);
    }
}
```

コンソールで `gold 100000` や `god` を実行できます。`help Cheats` はカテゴリ内のコマンドを説明付きで表示します。

## static コマンド

static メソッドも自動収集しません。必要なタイミングで明示的に登録してください。

```csharp
public static class DebugCheats
{
    public static void Register(Terminal terminal)
    {
        terminal.RegisterCommand("ping", Ping, "Print pong", "Debug", "ping");
        terminal.RegisterCommand("timescale", SetTimeScale, "Set Time.timeScale", "Debug", "timescale <scale>");
    }

    private static void Ping(CommandContext ctx)
        => ctx.Output.WriteLine("pong", LogLevel.Success);

    private static void SetTimeScale(CommandContext ctx)
    {
        if (!ctx.Has(0) || !float.TryParse(ctx.Args[0], NumberStyles.Float,
                CultureInfo.InvariantCulture, out float scale))
        {
            ctx.Output.WriteLine("Usage: timescale <scale>", LogLevel.Error);
            return;
        }

        Time.timeScale = scale;
    }
}
```

登録:

```csharp
DebugCheats.Register(TerminalBehaviour.Current);
```

## 引数

`CommandContext` から引数を読みます。

- `ctx.Args`: 元の引数リスト
- `ctx.Has(index)`: 引数が存在するか
- `ctx.GetString/GetInt/GetFloat/GetBool`: fallback 付きの簡易 getter
- 厳密な検証が必要な場合は `TryParse(..., CultureInfo.InvariantCulture, ...)` を直接使ってください。

## 補完候補を追加する

登録時に command-specific suggestions を追加できます。

```csharp
TerminalBehaviour.RegisterCommand(
    "difficulty",
    ctx => SetDifficulty(ctx.GetString(0, "normal")),
    "Set difficulty",
    "Cheats",
    "difficulty <easy|normal|hard>",
    (ctx, results) =>
    {
        if (ctx.ArgumentIndex != 0) return;
        foreach (var value in new[] { "easy", "normal", "hard" })
        {
            if (value.StartsWith(ctx.CurrentToken, System.StringComparison.OrdinalIgnoreCase))
                results.Add(new CompletionItem(value, value, "difficulty value", "Cheats"));
        }
    });
```

`<easy|normal|hard>` のような usage token も 기본 keyword suggestions として cache されます。

## Data table 登録

登録した table は `data` command、input suggestions、`Data` tab に表示されます。

```csharp
TerminalBehaviour.RegisterDataTable("items", "Items", () => new[]
{
    new DataTableRow("sword_001", "Bronze Sword"),
    new DataTableRow("potion_hp", "Health Potion"),
});
```

## 出力

`CommandContext.Output` でレベル付きの出力ができます。

```csharp
TerminalBehaviour.RegisterCommand("save", ctx =>
{
    ctx.Output.WriteLine("Saved", LogLevel.Success); // Info/Success/Warning/Error/System
}, "Save game", "System", "save");
```

## 高度: ITerminalModule

:::info
**これは誰向けですか?**

関連コマンドを再利用可能なパッケージとして配布したい場合に使います。

ゲーム内のチートやデバッグコマンドなら `RegisterCommand(...)` で十分です。

:::

`ITerminalModule` を実装すると、`InstallModule()` でまとめて登録できます。

```csharp
using Achieve.CheatTerminal;

public class NetworkDebugModule : ITerminalModule
{
    public string Name => "NetworkDebug";

    public void Install(Terminal terminal)
    {
        terminal.RegisterCommand(
            "net",
            Run,
            "Network debug tools",
            "Network",
            "net <ping|status>");
    }

    private static void Run(CommandContext ctx)
    {
        string sub = ctx.GetString(0, "status");
        switch (sub)
        {
            case "ping":   ctx.Output.WriteLine("pong", LogLevel.Success); break;
            case "status": ctx.Output.WriteLine("connected", LogLevel.Info); break;
            default:       ctx.Output.WriteLine($"Unknown: {sub}", LogLevel.Error); break;
        }
    }
}
```

bootstrap 後に登録できます:

```csharp
TerminalBehaviour.Instance.InstallModule(new NetworkDebugModule());
```

次: [コマンドリファレンス](/cheat-terminal/ja/usage/commands.md)
