> For the complete documentation index, see [llms.txt](/llms.txt)

# GS2-Exchange Deploy/CDK リファレンス

GS2-Deployのスタックを作成する際に使用するテンプレートのフォーマットと、CDKによる各種言語のテンプレート出力の実装例




## エンティティ

Deploy処理で操作の対象となるリソース

### Namespace

ネームスペース<br>

ネームスペースは、一つのプロジェクト内で同じサービスを異なる用途で複数利用するためのエンティティです。<br>
GS2 の各サービスはネームスペース単位で管理されます。ネームスペースが異なれば、同じサービスでも完全に独立したデータ空間として扱われます。<br>

そのため、各サービスの利用を開始するにあたってネームスペースを作成する必要があります。

#### Request

リソースの生成・更新リクエスト

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| name | string |  | ✓|  |  ~ 128文字 | ネームスペース名<br>ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| description | string |  | |  |  ~ 1024文字 | 説明文 |
| enableAwaitExchange | bool |  | | false |  | 交換結果の受け取りに待ち時間の発生する交換機能を利用するか<br>有効にすると、`await` タイミングタイプの交換レートモデルが利用可能になります。これらの交換は報酬を受け取る前に実時間の経過が必要で、プレイヤーが結果を待つ必要のあるクラフトや生産系の仕組みを実現できます。 |
| enableDirectExchange | bool |  | | true |  | 直接交換 API の呼び出しを許可する<br>有効にすると、クライアントが交換 API を直接呼び出してリソース交換を実行できます。無効にすると、トランザクションアクション経由でのみ交換がトリガーされ、交換発生のサーバーサイド制御がより厳密になります。 |
| transactionSetting | [TransactionSetting](#transactionsetting) |  | ✓|  |  | トランザクション設定<br>交換操作時の分散トランザクションの実行方法を制御する設定です。自動実行、アトミックコミット、非同期処理などのオプションをサポートします。 |
| exchangeScript | [ScriptSetting](#scriptsetting) |  | |  |  | 交換を実行しようとしたときに実行するスクリプトの設定<br>Script トリガーリファレンス - [`exchange`](../script/#exchange) |
| incrementalExchangeScript | [ScriptSetting](#scriptsetting) |  | |  |  | コスト上昇型交換を実行しようとしたときに実行するスクリプトの設定<br>Script トリガーリファレンス - [`incrementalExchange`](../script/#incrementalexchange) |
| acquireAwaitScript | [ScriptSetting](#scriptsetting) |  | |  |  | 待機方式の交換処理で、待機が完了し報酬を受け取ろうとしたときに実行するスクリプトの設定<br>Script トリガーリファレンス - [`acquireAwait`](../script/#acquireawait) |
| logSetting | [LogSetting](#logsetting) |  | |  |  | ログの出力設定<br>交換操作のログデータを GS2-Log に出力するための設定です。GS2-Log のネームスペースを指定することで、交換、コスト上昇型交換、待機操作の API リクエスト・レスポンスログを収集できます。 |

#### GetAttr

[!GetAttr](/articles/tech/deploy/#getattr)タグで取得可能なリソースの生成結果

| | 型 | 説明 |
| --- | --- | --- |
| Item | [Namespace](../sdk#namespace) | 作成したネームスペース

#### 実装例




**GS2-Deploy(YAML)**
```yaml

Type: GS2::Exchange::Namespace
Properties:
  Name: namespace-0001
  Description: null
  EnableAwaitExchange: null
  EnableDirectExchange: null
  TransactionSetting: 
    EnableAutoRun: true
    QueueNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001
  ExchangeScript: null
  IncrementalExchangeScript: null
  AcquireAwaitScript: null
  LogSetting: 
    LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001

```

**Go**
```go

import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/exchange"
    "github.com/openlyinc/pointy"
)


SampleStack := core.NewStack()
exchange.NewNamespace(
    &SampleStack,
    "namespace-0001",
    exchange.NamespaceOptions{
        TransactionSetting: core.NewTransactionSetting(
            core.TransactionSettingOptions{
                QueueNamespaceId: pointy.String("grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001"),
            },
        ),
        LogSetting: &core.LogSetting{
            LoggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001",
        },
    },
)

println(SampleStack.Yaml())  // Generate Template

```

**PHP**
```php

class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Exchange\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Exchange\Model\Options\NamespaceOptions(
                transactionSetting: new \Gs2Cdk\Core\Model\TransactionSetting(
                    new \Gs2Cdk\Core\Model\TransactionSettingOptions(
                        queueNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001"
                    )
                ),
                logSetting: new \Gs2Cdk\Core\Model\LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            )
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template

```

**Java**
```java

class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.exchange.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.exchange.model.options.NamespaceOptions()
                        .withTransactionSetting(new io.gs2.cdk.core.model.TransactionSetting(
                            new io.gs2.cdk.core.model.options.TransactionSettingOptions()
                                .withQueueNamespaceId("grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001")
                        ))
                        .withLogSetting(new io.gs2.cdk.core.model.LogSetting(
                            "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                        ))
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template

```

**C#**
```csharp

public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Exchange.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Exchange.Model.Options.NamespaceOptions
            {
                transactionSetting = new Gs2Cdk.Core.Model.TransactionSetting(
                    options: new Gs2Cdk.Core.Model.TransactionSettingOptions
                    {
                        queueNamespaceId = "grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001"
                    }
                ),
                logSetting = new Gs2Cdk.Core.Model.LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

```

**TypeScript**
```typescript

import core from "@/gs2cdk/core";
import exchange from "@/gs2cdk/exchange";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new exchange.model.Namespace(
            this,
            "namespace-0001",
            {
                transactionSetting: new core.TransactionSetting(
                    {
                        queueNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001"
                    }
                ),
                logSetting: new core.LogSetting(
                    "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template

```

**Python**
```python

from gs2_cdk import Stack, core, exchange

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        exchange.Namespace(
            stack=self,
            name='namespace-0001',
            options=exchange.NamespaceOptions(
                transaction_setting=core.TransactionSetting(
                    options=core.TransactionSettingOptions(
                        queue_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001',
                    )
                ),
                log_setting=core.LogSetting(
                    logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001',
                ),
            ),
        )

print(SampleStack().yaml())  # Generate Template

```


#### TransactionSetting

トランザクション設定<br>

トランザクション設定は、トランザクションの実行方法・整合性・非同期処理・競合回避の仕組みを制御する設定です。<br>
自動実行（AutoRun）、アトミック実行（AtomicCommit）、GS2-Distributor を利用した非同期実行、スクリプト結果の一括適用、GS2-JobQueue による入手アクションの非同期化などを組み合わせ、ゲームロジックに応じた堅牢なトランザクション管理を可能にします。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| enableAutoRun | bool |  |  | false |  | 発行したトランザクションをサーバーサイドで自動的に実行するか |
| enableAtomicCommit | bool | {enableAutoRun} == true |  | false |  | トランザクションの実行をアトミックにコミットするか<br>※ enableAutoRun が true であれば 有効 |
| transactionUseDistributor | bool | {enableAtomicCommit} == true |  | false |  | トランザクションを非同期処理で実行する<br>※ enableAtomicCommit が true であれば 有効 |
| commitScriptResultInUseDistributor | bool | {transactionUseDistributor} == true |  | false |  | スクリプトの結果コミット処理を非同期処理で実行するか<br>※ transactionUseDistributor が true であれば 有効 |
| acquireActionUseJobQueue | bool | {enableAtomicCommit} == true |  | false |  | 入手アクションを実行する際に GS2-JobQueue を使用するか<br>※ enableAtomicCommit が true であれば 有効 |
| distributorNamespaceId | string |  |  | "grn:gs2:{region}:{ownerId}:distributor:default" |  ~ 1024文字 | トランザクションの実行に使用する GS2-Distributor ネームスペースGRN |
| queueNamespaceId | string |  |  | "grn:gs2:{region}:{ownerId}:queue:default" |  ~ 1024文字 | トランザクションの実行に使用する GS2-JobQueue のネームスペースGRN |

#### ScriptSetting

スクリプト設定<br>

GS2 ではマイクロサービスのイベントに関連づけて、カスタムスクリプトを実行することができます。<br>
このモデルは、スクリプトの実行をトリガーするための設定を保持します。<br>

スクリプトの実行方式は大きく2種類あり、それは「同期実行」と「非同期実行」です。<br>
同期実行は、スクリプトの実行が完了するまで処理がブロックされます。<br>
代わりに、スクリプトの実行結果を使って API の実行を止めたり、API のレスポンス内容を制御することができます。<br>

一方、非同期実行ではスクリプトの完了を待つために処理がブロックされることはありません。<br>
ただし、スクリプトの実行結果を利用して API の実行を停止したり、API の応答内容を変更することはできません。<br>
非同期実行は API の応答フローに影響を与えないため、原則として非同期実行を推奨します。<br>

非同期実行には実行方式が2種類あり、GS2-Script と Amazon EventBridge があります。<br>
Amazon EventBridge を使用することで、Lua 以外の言語で処理を記述することができます。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| triggerScriptId | string |  |  |  |  ~ 1024文字 | API 実行時に同期的に実行される GS2-Script のスクリプトGRN<br>「grn:gs2:」ではじまる GRN 形式のIDで指定する必要があります。 |
| doneTriggerTargetType | 文字列列挙型<br>enum {<br>&nbsp;&nbsp;"none",<br>&nbsp;&nbsp;"gs2_script",<br>&nbsp;&nbsp;"aws"<br>}<br> |  |  | "none" |  | 非同期スクリプトの実行方法<br>非同期実行で使用するスクリプトの種類を指定します。<br>「非同期実行のスクリプトを使用しない(none)」「GS2-Scriptを使用する(gs2_script)」「Amazon EventBridgeを使用する(aws)」が選択できます。"none": なし / "gs2_script": GS2-Script / "aws": Amazon EventBridge /  |
| doneTriggerScriptId | string | {doneTriggerTargetType} == "gs2_script" |  |  |  ~ 1024文字 | 非同期実行する GS2-Script スクリプトGRN<br>「grn:gs2:」ではじまる GRN 形式のIDで指定する必要があります。<br>※ doneTriggerTargetType が "gs2_script" であれば 有効 |
| doneTriggerQueueNamespaceId | string | {doneTriggerTargetType} == "gs2_script" |  |  |  ~ 1024文字 | 非同期実行スクリプトを実行する GS2-JobQueue ネームスペースGRN<br>非同期実行スクリプトを直接実行するのではなく、GS2-JobQueue を経由する場合は GS2-JobQueue のネームスペースGRN を指定します。<br>GS2-JobQueue を利用する理由は多くはありませんので、特に理由がなければ指定する必要はありません。<br>※ doneTriggerTargetType が "gs2_script" であれば 有効 |

#### LogSetting

ログの出力設定<br>

ログデータの出力設定を管理します。この型は、ログデータを書き出すために使用される GS2-Log ネームスペースの識別子（Namespace ID）を保持します。<br>
ログネームスペースID(loggingNamespaceId)には、ログデータを収集し保存する GS2-Log のネームスペースを、GRNの形式で指定します。<br>
この設定をすることで、設定されたネームスペース内で発生したAPIリクエスト・レスポンスのログデータが、対象の GS2-Log ネームスペース側へ出力されるようになります。<br>
GS2-Log ではリアルタイムでログが提供され、システムの監視や分析、デバッグなどに利用できます。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| loggingNamespaceId | string |  | ✓ |  |  ~ 1024文字 | ログを出力する GS2-Log のネームスペースGRN<br>「grn:gs2:」ではじまる GRN 形式のIDで指定する必要があります。 |

---

### CurrentRateMaster

現在アクティブなレートモデルのマスターデータ<br>

現在ネームスペース内で有効な、レートモデルの定義を記述したマスターデータです。<br>
GS2ではマスターデータの管理にJSON形式のファイルを使用します。<br>
ファイルをアップロードすることで、実際にサーバーに設定を反映することができます。<br>

JSONファイルを作成する方法として、マネージメントコンソール内にマスターデータエディタを提供しています。<br>
また、よりゲームの運営に相応しいツールを作成し、適切なフォーマットのJSONファイルを書き出すことでもサービスを利用可能です。
{{% alert title="Note" color="info" %}}
JSONファイルの形式については [GS2-Exchange マスターデータリファレンス](api_reference/exchange/master_data/) をご参照ください。
{{% /alert %}}

#### Request

リソースの生成・更新リクエスト

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| namespaceName | string |  | ✓|  |  ~ 128文字 | ネームスペース名<br>ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| mode | 文字列列挙型<br>enum {<br>&nbsp;&nbsp;"direct",<br>&nbsp;&nbsp;"preUpload"<br>}<br> |  | | "direct" |  | 更新モード"direct": マスターデータを直接更新 / "preUpload": マスターデータをアップロードしてから更新 /  |
| settings | string | {mode} == "direct" | ✓※|  |  ~ 5242880 バイト (5MB) | マスターデータ<br>※ mode が "direct" であれば必須 |
| uploadToken | string | {mode} == "preUpload" | ✓※|  |  ~ 1024文字 | 事前アップロードで取得したトークン<br>アップロードしたマスターデータを適用するために使用されます。<br>※ mode が "preUpload" であれば必須 |

#### GetAttr

[!GetAttr](/articles/tech/deploy/#getattr)タグで取得可能なリソースの生成結果

| | 型 | 説明 |
| --- | --- | --- |
| Item | [CurrentRateMaster](../sdk#currentratemaster) | 更新された現在アクティブなレートモデルのマスターデータ

#### 実装例




**GS2-Deploy(YAML)**
```yaml

Type: GS2::Exchange::CurrentRateMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2019-08-19",
    "rateModels": [
      {
        "name": "material_n_to_r",
        "timingType": "await",
        "metadata": "N2R",
        "consumeActions": [
          {
            "action": "Gs2Inventory:ConsumeItemSetByUserId",
            "request": {
              "namespaceName": "namespace-0001",
              "inventoryName": "inventory-0001",
              "itemName": "item-0001",
              "consumeCount": 1,
              "itemSetName": "#{itemSetName}",
              "userId": "#{userId}"
            }
          }
        ],
        "lockTime": 50,
        "acquireActions": [
          {
            "action": "Gs2Inventory:AcquireItemSetByUserId",
            "request": {
              "namespaceName": "namespace-0001",
              "inventoryName": "inventory-0001",
              "itemName": "item-0001",
              "acquireCount": 1,
              "expiresAt": 0,
              "createNewItemSet": false,
              "itemSetName": "",
              "userId": "#{userId}"
            }
          }
        ]
      },
      {
        "name": "material_r_to_n",
        "timingType": "await",
        "metadata": "N2R",
        "consumeActions": [
          {
            "action": "Gs2Inventory:ConsumeItemSetByUserId",
            "request": {
              "namespaceName": "namespace-0001",
              "inventoryName": "inventory-0001",
              "itemName": "item-0001",
              "consumeCount": 1,
              "itemSetName": "#{itemSetName}",
              "userId": "#{userId}"
            }
          }
        ],
        "lockTime": 50,
        "acquireActions": [
          {
            "action": "Gs2Inventory:AcquireItemSetByUserId",
            "request": {
              "namespaceName": "namespace-0001",
              "inventoryName": "inventory-0001",
              "itemName": "item-0001",
              "acquireCount": 1,
              "expiresAt": 0,
              "createNewItemSet": false,
              "itemSetName": "",
              "userId": "#{userId}"
            }
          }
        ]
      }
    ],
    "incrementalRateModels": []
    
  }
  UploadToken: null

```

**Go**
```go

import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/exchange"
    "github.com/gs2io/gs2-golang-cdk/inventory"
    "github.com/openlyinc/pointy"
)


SampleStack := core.NewStack()
exchange.NewNamespace(
    &SampleStack,
    "namespace-0001",
    exchange.NamespaceOptions{},
).MasterData(
    []exchange.RateModel{
        exchange.NewRateModel(
            "material_n_to_r",
            exchange.RateModelTimingTypeAwait,
            exchange.RateModelOptions{
                Metadata: pointy.String("N2R"),
                ConsumeActions: []core.ConsumeAction{
                    inventory.ConsumeItemSetByUserId(
                        "namespace-0001",
                        "inventory-0001",
                        "item-0001",
                        1,
                        pointy.String("#{itemSetName}"),
                    ),
                },
                LockTime: pointy.Int32(50),
                AcquireActions: []core.AcquireAction{
                    inventory.AcquireItemSetByUserId(
                        "namespace-0001",
                        "inventory-0001",
                        "item-0001",
                        1,
                        pointy.Int64(0),
                        pointy.Bool(false),
                        pointy.String(""),
                    ),
                },
            },
        ),
        exchange.NewRateModel(
            "material_r_to_n",
            exchange.RateModelTimingTypeAwait,
            exchange.RateModelOptions{
                Metadata: pointy.String("N2R"),
                ConsumeActions: []core.ConsumeAction{
                    inventory.ConsumeItemSetByUserId(
                        "namespace-0001",
                        "inventory-0001",
                        "item-0001",
                        1,
                        pointy.String("#{itemSetName}"),
                    ),
                },
                LockTime: pointy.Int32(50),
                AcquireActions: []core.AcquireAction{
                    inventory.AcquireItemSetByUserId(
                        "namespace-0001",
                        "inventory-0001",
                        "item-0001",
                        1,
                        pointy.Int64(0),
                        pointy.Bool(false),
                        pointy.String(""),
                    ),
                },
            },
        ),
    },
    []exchange.IncrementalRateModel{
    },
)

println(SampleStack.Yaml())  // Generate Template

```

**PHP**
```php

class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Exchange\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Exchange\Model\RateModel(
                    name:"material_n_to_r",
                    timingType: \Gs2Cdk\Exchange\Model\Enums\RateModelTimingType::AWAIT,
                    options: new \Gs2Cdk\Exchange\Model\Options\RateModelOptions(
                        metadata:"N2R",
                        consumeActions:[
                            new \Gs2Cdk\Inventory\StampSheet\ConsumeItemSetByUserId(
                                namespaceName: "namespace-0001",
                                inventoryName: "inventory-0001",
                                itemName: "item-0001",
                                consumeCount: 1,
                                itemSetName: "#{itemSetName}",
                                userId: "#{userId}"
                            ),
                        ],
                        lockTime:50,
                        acquireActions:[
                            new \Gs2Cdk\Inventory\StampSheet\AcquireItemSetByUserId(
                                namespaceName: "namespace-0001",
                                inventoryName: "inventory-0001",
                                itemName: "item-0001",
                                acquireCount: 1,
                                expiresAt: 0,
                                createNewItemSet: false,
                                itemSetName: "",
                                userId: "#{userId}"
                            ),
                        ]
                    )
                ),
                new \Gs2Cdk\Exchange\Model\RateModel(
                    name:"material_r_to_n",
                    timingType: \Gs2Cdk\Exchange\Model\Enums\RateModelTimingType::AWAIT,
                    options: new \Gs2Cdk\Exchange\Model\Options\RateModelOptions(
                        metadata:"N2R",
                        consumeActions:[
                            new \Gs2Cdk\Inventory\StampSheet\ConsumeItemSetByUserId(
                                namespaceName: "namespace-0001",
                                inventoryName: "inventory-0001",
                                itemName: "item-0001",
                                consumeCount: 1,
                                itemSetName: "#{itemSetName}",
                                userId: "#{userId}"
                            ),
                        ],
                        lockTime:50,
                        acquireActions:[
                            new \Gs2Cdk\Inventory\StampSheet\AcquireItemSetByUserId(
                                namespaceName: "namespace-0001",
                                inventoryName: "inventory-0001",
                                itemName: "item-0001",
                                acquireCount: 1,
                                expiresAt: 0,
                                createNewItemSet: false,
                                itemSetName: "",
                                userId: "#{userId}"
                            ),
                        ]
                    )
                )
            ],
            [
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template

```

**Java**
```java

class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.exchange.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.exchange.model.RateModel(
                    "material_n_to_r",
                    io.gs2.cdk.exchange.model.enums.RateModelTimingType.AWAIT,
                    new io.gs2.cdk.exchange.model.options.RateModelOptions()
                        .withMetadata("N2R")
                        .withConsumeActions(Arrays.asList(
                            new io.gs2.cdk.inventory.stampSheet.ConsumeItemSetByUserId(
                                "namespace-0001",
                                "inventory-0001",
                                "item-0001",
                                1L,
                                "#{itemSetName}",
                                "#{userId}"
                            )
                        ))
                        .withLockTime(50)
                        .withAcquireActions(Arrays.asList(
                            new io.gs2.cdk.inventory.stampSheet.AcquireItemSetByUserId(
                                "namespace-0001",
                                "inventory-0001",
                                "item-0001",
                                1L,
                                0L,
                                false,
                                "",
                                "#{userId}"
                            )
                        ))
                ),
                new io.gs2.cdk.exchange.model.RateModel(
                    "material_r_to_n",
                    io.gs2.cdk.exchange.model.enums.RateModelTimingType.AWAIT,
                    new io.gs2.cdk.exchange.model.options.RateModelOptions()
                        .withMetadata("N2R")
                        .withConsumeActions(Arrays.asList(
                            new io.gs2.cdk.inventory.stampSheet.ConsumeItemSetByUserId(
                                "namespace-0001",
                                "inventory-0001",
                                "item-0001",
                                1L,
                                "#{itemSetName}",
                                "#{userId}"
                            )
                        ))
                        .withLockTime(50)
                        .withAcquireActions(Arrays.asList(
                            new io.gs2.cdk.inventory.stampSheet.AcquireItemSetByUserId(
                                "namespace-0001",
                                "inventory-0001",
                                "item-0001",
                                1L,
                                0L,
                                false,
                                "",
                                "#{userId}"
                            )
                        ))
                )
            ),
            Arrays.asList(
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template

```

**C#**
```csharp

public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Exchange.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Exchange.Model.RateModel[] {
                new Gs2Cdk.Gs2Exchange.Model.RateModel(
                    name: "material_n_to_r",
                    timingType: Gs2Cdk.Gs2Exchange.Model.Enums.RateModelTimingType.Await,
                    options: new Gs2Cdk.Gs2Exchange.Model.Options.RateModelOptions
                    {
                        metadata = "N2R",
                        consumeActions = new Gs2Cdk.Core.Model.ConsumeAction[]
                        {
                            new Gs2Cdk.Gs2Inventory.StampSheet.ConsumeItemSetByUserId(
                                namespaceName: "namespace-0001",
                                inventoryName: "inventory-0001",
                                itemName: "item-0001",
                                consumeCount: 1,
                                itemSetName: "#{itemSetName}",
                                userId: "#{userId}"
                            )
                        },
                        lockTime = 50,
                        acquireActions = new Gs2Cdk.Core.Model.AcquireAction[]
                        {
                            new Gs2Cdk.Gs2Inventory.StampSheet.AcquireItemSetByUserId(
                                namespaceName: "namespace-0001",
                                inventoryName: "inventory-0001",
                                itemName: "item-0001",
                                acquireCount: 1,
                                expiresAt: 0,
                                createNewItemSet: false,
                                itemSetName: "",
                                userId: "#{userId}"
                            )
                        }
                    }
                ),
                new Gs2Cdk.Gs2Exchange.Model.RateModel(
                    name: "material_r_to_n",
                    timingType: Gs2Cdk.Gs2Exchange.Model.Enums.RateModelTimingType.Await,
                    options: new Gs2Cdk.Gs2Exchange.Model.Options.RateModelOptions
                    {
                        metadata = "N2R",
                        consumeActions = new Gs2Cdk.Core.Model.ConsumeAction[]
                        {
                            new Gs2Cdk.Gs2Inventory.StampSheet.ConsumeItemSetByUserId(
                                namespaceName: "namespace-0001",
                                inventoryName: "inventory-0001",
                                itemName: "item-0001",
                                consumeCount: 1,
                                itemSetName: "#{itemSetName}",
                                userId: "#{userId}"
                            )
                        },
                        lockTime = 50,
                        acquireActions = new Gs2Cdk.Core.Model.AcquireAction[]
                        {
                            new Gs2Cdk.Gs2Inventory.StampSheet.AcquireItemSetByUserId(
                                namespaceName: "namespace-0001",
                                inventoryName: "inventory-0001",
                                itemName: "item-0001",
                                acquireCount: 1,
                                expiresAt: 0,
                                createNewItemSet: false,
                                itemSetName: "",
                                userId: "#{userId}"
                            )
                        }
                    }
                )
            },
            new Gs2Cdk.Gs2Exchange.Model.IncrementalRateModel[] {
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

```

**TypeScript**
```typescript

import core from "@/gs2cdk/core";
import exchange from "@/gs2cdk/exchange";
import inventory from "@/gs2cdk/inventory";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new exchange.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new exchange.model.RateModel(
                    "material_n_to_r",
                    exchange.model.RateModelTimingType.AWAIT,
                    {
                        metadata: "N2R",
                        consumeActions: [
                            new inventory.stampSheet.ConsumeItemSetByUserId(
                                "namespace-0001",
                                "inventory-0001",
                                "item-0001",
                                1,
                                "#{itemSetName}",
                                null,
                                "#{userId}"
                            ),
                        ],
                        lockTime: 50,
                        acquireActions: [
                            new inventory.stampSheet.AcquireItemSetByUserId(
                                "namespace-0001",
                                "inventory-0001",
                                "item-0001",
                                1,
                                0,
                                false,
                                "",
                                null,
                                "#{userId}"
                            ),
                        ]
                    }
                ),
                new exchange.model.RateModel(
                    "material_r_to_n",
                    exchange.model.RateModelTimingType.AWAIT,
                    {
                        metadata: "N2R",
                        consumeActions: [
                            new inventory.stampSheet.ConsumeItemSetByUserId(
                                "namespace-0001",
                                "inventory-0001",
                                "item-0001",
                                1,
                                "#{itemSetName}",
                                null,
                                "#{userId}"
                            ),
                        ],
                        lockTime: 50,
                        acquireActions: [
                            new inventory.stampSheet.AcquireItemSetByUserId(
                                "namespace-0001",
                                "inventory-0001",
                                "item-0001",
                                1,
                                0,
                                false,
                                "",
                                null,
                                "#{userId}"
                            ),
                        ]
                    }
                )
            ],
            [
            ]
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template

```

**Python**
```python

from gs2_cdk import Stack, core, exchange, inventory

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        exchange.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            rate_models=[
                exchange.RateModel(
                    name='material_n_to_r',
                    timing_type=exchange.RateModelTimingType.AWAIT,
                    options=exchange.RateModelOptions(
                        metadata = 'N2R',
                        consume_actions = [
                            inventory.ConsumeItemSetByUserId(
                                namespace_name='namespace-0001',
                                inventory_name='inventory-0001',
                                item_name='item-0001',
                                consume_count=1,
                                item_set_name='#{itemSetName}',
                                user_id='#{userId}'
                            ),
                        ],
                        lock_time = 50,
                        acquire_actions = [
                            inventory.AcquireItemSetByUserId(
                                namespace_name='namespace-0001',
                                inventory_name='inventory-0001',
                                item_name='item-0001',
                                acquire_count=1,
                                expires_at=0,
                                create_new_item_set=False,
                                item_set_name="",
                                user_id='#{userId}'
                            ),
                        ]
                    ),
                ),
                exchange.RateModel(
                    name='material_r_to_n',
                    timing_type=exchange.RateModelTimingType.AWAIT,
                    options=exchange.RateModelOptions(
                        metadata = 'N2R',
                        consume_actions = [
                            inventory.ConsumeItemSetByUserId(
                                namespace_name='namespace-0001',
                                inventory_name='inventory-0001',
                                item_name='item-0001',
                                consume_count=1,
                                item_set_name='#{itemSetName}',
                                user_id='#{userId}'
                            ),
                        ],
                        lock_time = 50,
                        acquire_actions = [
                            inventory.AcquireItemSetByUserId(
                                namespace_name='namespace-0001',
                                inventory_name='inventory-0001',
                                item_name='item-0001',
                                acquire_count=1,
                                expires_at=0,
                                create_new_item_set=False,
                                item_set_name="",
                                user_id='#{userId}'
                            ),
                        ]
                    ),
                ),
            ],
            incremental_rate_models=[
            ],
        )

print(SampleStack().yaml())  # Generate Template

```


#### RateModel

交換レートモデル<br>

交換レートモデルはリソースとリソースを交換する際に使用するレートを定義するエンティティです。<br>

直ちに交換できるレートだけでなく、現実時間で一定時間経過したのちに交換できるレートを設定できます。<br>
現実時間での時間経過が必要な交換レートには、更に即時交換を実行するために必要なリソースを定義することが可能です。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| rateModelId | string |  | ※ |  |  ~ 1024文字 | 交換レートモデルGRN<br>※ サーバーが自動で設定 |
| name | string |  | ✓ |  |  ~ 128文字 | 交換レートモデル名<br>交換レートモデルの種類固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| metadata | string |  |  |  |  ~ 2048文字 | メタデータ<br>メタデータには任意の値を設定できます。<br>これらの値は GS2 の動作には影響しないため、ゲーム内で利用する情報の保存先として使用できます。 |
| verifyActions | [List&lt;VerifyAction&gt;](#verifyaction) |  |  | [] | 0 ~ 10 items | 検証アクションリスト<br>交換が実行される前にすべてパスする必要がある事前条件チェックです。いずれかの検証アクションが失敗すると、リソースを消費せずに交換が中止されます。レベル要件やインベントリ容量などの条件を強制するために使用されます。 |
| consumeActions | [List&lt;ConsumeAction&gt;](#consumeaction) |  |  | [] | 0 ~ 10 items | 消費アクションリスト<br>この交換を実行するためにプレイヤーが支払う必要があるリソース（コスト）を定義します。複数の消費アクションを指定でき、ゴールドとアイテムの両方を必要とするような複雑な交換コストを実現できます。これらのアクションは分散トランザクション内の消費アクションとして実行されます。 |
| timingType | 文字列列挙型<br>enum {<br>&nbsp;&nbsp;"immediate",<br>&nbsp;&nbsp;"await"<br>}<br> |  |  | "immediate" |  | 交換の種類<br>交換実行後に報酬がいつ配送されるかを決定します。`immediate` は交換実行時に即座に報酬を配送します。`await` は報酬を受け取る前に実時間の経過が必要で、待機期間（例: クラフト時間）を設けます。"immediate": 即時 / "await": 現実時間の経過待ち /  |
| lockTime | int | {timingType} == "await" | ✓※ |  | 0 ~ 538214400 | 交換実行から実際に報酬を受け取れるようになるまでの待ち時間（分）<br>timingType が `await` の場合にのみ適用されます。交換が開始されてからプレイヤーが報酬を受け取れるようになるまでに経過する必要がある実時間の分数を指定します。待ち時間はスキップ機能を使用して短縮できます。<br>※ timingType が "await" であれば 必須 |
| acquireActions | [List&lt;AcquireAction&gt;](#acquireaction) |  |  | [] | 0 ~ 100 items | 入手アクションリスト<br>交換完了時にプレイヤーが受け取るリソース（報酬）を定義します。複数の入手アクションを指定して、さまざまなリソースタイプを同時に付与できます。これらのアクションは分散トランザクション内の入手アクションとして実行されます。 |

#### AcquireAction

入手アクション

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| action | 文字列列挙型<br>enum {<br>}<br> |  | ✓ |  |  | 入手アクションで実行するアクションの種類 |
| request | string |  | ✓ |  |  ~ 524288文字 | アクション実行時に使用されるリクエストのJSON文字列 |

#### ConsumeAction

消費アクション

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| action | 文字列列挙型<br>enum {<br>}<br> |  | ✓ |  |  | 消費アクションで実行するアクションの種類 |
| request | string |  | ✓ |  |  ~ 524288文字 | アクション実行時に使用されるリクエストのJSON文字列 |

#### VerifyAction

検証アクション

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| action | 文字列列挙型<br>enum {<br>}<br> |  | ✓ |  |  | 検証アクションで実行するアクションの種類 |
| request | string |  | ✓ |  |  ~ 524288文字 | アクション実行時に使用されるリクエストのJSON文字列 |

#### IncrementalRateModel

コスト上昇型交換レートモデル<br>

通常の交換レートは常に一定のレートでの交換を提供します。<br>
上昇型交換レートでは、交換回数に応じてコストが上昇していくレートを定義することができます。<br>
例えば、1回目の交換では 1:1 で交換できるが、2回目の交換では 2:1 で交換できる、といったレートを定義することができます。<br>
このようなレートを定義することで、プレイヤーがゲームを進めることで得られるリソースの価値を上げることができます。<br>

交換回数は現実時間の経過でリセットすることができます。<br>
この機能を利用することで、毎日あるいは毎週交換に必要なコストをリセットすることができます。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| incrementalRateModelId | string |  | ※ |  |  ~ 1024文字 | コスト上昇型交換レートモデルGRN<br>※ サーバーが自動で設定 |
| name | string |  | ✓ |  |  ~ 128文字 | コスト上昇型交換レートモデルの名前<br>コスト上昇型交換レートモデルの種類固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| metadata | string |  |  |  |  ~ 2048文字 | メタデータ<br>メタデータには任意の値を設定できます。<br>これらの値は GS2 の動作には影響しないため、ゲーム内で利用する情報の保存先として使用できます。 |
| consumeAction | [ConsumeAction](#consumeaction) |  | ✓ |  |  | 消費アクション（数量/値は自動的に上書きされます）<br>交換のコストとして消費されるリソースの種類を定義します。実際の数量は交換回数と計算方式（線形、べき乗、スクリプト）に基づいて動的に計算されます。アクションの種類と対象リソースのみ指定すればよく、数量フィールドは自動的に上書きされます。 |
| calculateType | 文字列列挙型<br>enum {<br>&nbsp;&nbsp;"linear",<br>&nbsp;&nbsp;"power",<br>&nbsp;&nbsp;"gs2_script"<br>}<br> |  | ✓ |  |  | コスト上昇量の計算方式<br>交換回数に応じてコストがどのように上昇するかを決定します。`linear` はコストを baseValue +（coefficientValue × 交換回数）として計算します。`power` はコストを coefficientValue ×（交換回数 + 1）^2 として計算します。`gs2_script` は任意のロジックのためにカスタム GS2-Script に計算を委任します。"linear": ベース値 + (係数 * 交換回数) / "power": 係数 * (交換回数 + 1) ^ 2 / "gs2_script": GS2-Script による任意のロジック /  |
| baseValue | long | {calculateType} == "linear" | ✓※ |  | 0 ~ 9223372036854775805 | ベース値<br>`linear` 計算方式を使用する場合の初回交換時の基本コストです。合計コストは baseValue +（coefficientValue × 交換回数）として計算されます。<br>※ calculateType が "linear" であれば 必須 |
| coefficientValue | long | {calculateType} in ["linear", "power"] | ✓※ |  | 0 ~ 9223372036854775805 | 係数<br>交換回数に応じてコストがどれだけ速く上昇するかを制御する乗数です。`linear` モードでは、各交換でこの値がコストに加算されます。`power` モードでは、コストは coefficientValue ×（交換回数 + 1）^2 として計算されます。<br>※ calculateType が "linear","power"であれば 必須 |
| calculateScriptId | string | {calculateType} == "gs2_script" | ✓※ |  |  ~ 1024文字 | コスト計算スクリプトのGRN<br>Script トリガーリファレンス - [`calculateCost`](../script/#calculatecost)<br>※ calculateType が "gs2_script" であれば 必須 |
| exchangeCountId | string |  | ✓ |  |  ~ 1024文字 | 交換実行回数を管理する GS2-Limit の回数制限モデル GRN<br>各ユーザーがこのコスト上昇型交換を何回実行したかを追跡する GS2-Limit の回数制限モデルを参照します。カウントは上昇するコストの計算に使用され、GS2-Limit のリセットタイミングを使用して定期的（例: 毎日または毎週）にリセットできます。 |
| maximumExchangeCount | int |  |  | 2147483646 | 0 ~ 2147483646 | 交換回数の上限<br>ユーザーがこのコスト上昇型交換を実行できる最大回数です。交換回数がこの上限に達すると、GS2-Limit によるカウントリセットまでそれ以降の交換が拒否されます。 |
| acquireActions | [List&lt;AcquireAction&gt;](#acquireaction) |  |  | [] | 0 ~ 100 items | 入手アクションリスト<br>コスト上昇型交換の完了時にプレイヤーが受け取るリソース（報酬）を定義します。報酬は交換回数に関わらず一定で、コストのみが交換ごとに増加します。 |

---



