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

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

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




## エンティティ

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

### Namespace

ネームスペース<br>

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

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

#### Request

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

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| name | string |  | ✓|  |  ~ 128文字 | ネームスペース名<br>ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| description | string |  | |  |  ~ 1024文字 | 説明文 |
| transactionSetting | [TransactionSetting](#transactionsetting) |  | |  |  | トランザクション設定<br>経験値操作時の分散トランザクションの実行方法を制御する設定です。自動実行、アトミックコミット、非同期処理などのオプションをサポートします。 |
| rankCapScriptId | string |  | |  |  ~ 1024文字 | ランクキャップを動的に決定するスクリプトGRN<br>Script トリガーリファレンス - [`rankCapScript`](../script/#rankcapscript) |
| changeExperienceScript | [ScriptSetting](#scriptsetting) |  | |  |  | 経験値変化したときに実行するスクリプトの設定<br>Script トリガーリファレンス - [`changeExperience`](../script/#changeexperience) |
| changeRankScript | [ScriptSetting](#scriptsetting) |  | |  |  | ランク変化したときに実行するスクリプトの設定<br>Script トリガーリファレンス - [`changeRank`](../script/#changerank) |
| changeRankCapScript | [ScriptSetting](#scriptsetting) |  | |  |  | ランクキャップ変化したときに実行するスクリプトの設定<br>Script トリガーリファレンス - [`changeRankCap`](../script/#changerankcap) |
| overflowExperienceScript | string |  | |  |  ~ 1024文字 | 経験値あふれ時に実行するスクリプトの GRN<br>Script トリガーリファレンス - [`overflowExperience`](../script/#overflowexperience) |
| 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::Experience::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSetting: null
  RankCapScriptId: null
  ChangeExperienceScript: null
  ChangeRankScript: null
  ChangeRankCapScript: null
  OverflowExperienceScript: 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/experience"
)


SampleStack := core.NewStack()
experience.NewNamespace(
    &SampleStack,
    "namespace-0001",
    experience.NamespaceOptions{
        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\Experience\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Experience\Model\Options\NamespaceOptions(
                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.experience.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.experience.model.options.NamespaceOptions()
                        .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.Gs2Experience.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Experience.Model.Options.NamespaceOptions
            {
                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 experience from "@/gs2cdk/experience";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new experience.model.Namespace(
            this,
            "namespace-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, experience

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        experience.Namespace(
            stack=self,
            name='namespace-0001',
            options=experience.NamespaceOptions(
                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>"none",<br>"gs2_script",<br>"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で指定する必要があります。 |

---

### CurrentExperienceMaster

現在アクティブな経験値モデルのマスターデータ<br>

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

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

#### Request

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

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| namespaceName | string |  | ✓|  |  ~ 128文字 | ネームスペース名<br>ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| mode | 文字列列挙型<br>enum {<br>"direct",<br>"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 | [CurrentExperienceMaster](../sdk#currentexperiencemaster) | 更新された現在アクティブな経験値モデルのマスターデータ

#### 実装例




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

Type: GS2::Experience::CurrentExperienceMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2019-01-11",
    "experienceModels": [
      {
        "name": "character_ssr",
        "defaultExperience": 0,
        "defaultRankCap": 50,
        "maxRankCap": 80,
        "rankThreshold":
          {
            "metadata": "CHARACTER",
            "values": [
              100,
              200,
              300,
              400,
              500
            ]
          },
        "metadata": "SSR"
      },
      {
        "name": "character_sr",
        "defaultExperience": 0,
        "defaultRankCap": 40,
        "maxRankCap": 70,
        "rankThreshold":
          {
            "metadata": "CHARACTER",
            "values": [
              100,
              200,
              300,
              400,
              500
            ]
          },
        "metadata": "SR"
      },
      {
        "name": "character_r",
        "defaultExperience": 0,
        "defaultRankCap": 30,
        "maxRankCap": 60,
        "rankThreshold":
          {
            "metadata": "CHARACTER",
            "values": [
              100,
              200,
              300,
              400,
              500
            ]
          },
        "metadata": "R"
      },
      {
        "name": "equipment",
        "defaultExperience": 0,
        "defaultRankCap": 30,
        "maxRankCap": 50,
        "rankThreshold":
          {
            "metadata": "EQUIPMENT",
            "values": [
              200,
              400,
              600,
              800,
              1000
            ]
          },
        "metadata": "EQUIPMENT",
        "acquireActionRates": [
          {
            "name": "rate-0001",
            "mode": "big",
            "bigRates": [
              "1",
              "10",
              "100",
              "1000",
              "10000"
            ]
          }
        ]
      },
      {
        "name": "skill",
        "defaultExperience": 0,
        "defaultRankCap": 10,
        "maxRankCap": 20,
        "rankThreshold":
          {
            "metadata": "SKILL",
            "values": [
              300,
              600,
              900,
              1200,
              1500
            ]
          },
        "metadata": "SKILL"
      }
    ]
  }
  UploadToken: null

```

**Go**
```go

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


SampleStack := core.NewStack()
experience.NewNamespace(
    &SampleStack,
    "namespace-0001",
    experience.NamespaceOptions{},
).MasterData(
    []experience.ExperienceModel{
        experience.NewExperienceModel(
            "character_ssr",
            0,
            50,
            80,
            experience.NewThreshold(
                []int64{
                    100,
                    200,
                    300,
                    400,
                    500,
                },
                experience.ThresholdOptions{
                    Metadata: pointy.String("CHARACTER"),
                },
            ),
            experience.ExperienceModelOptions{
                Metadata: pointy.String("SSR"),
            },
        ),
        experience.NewExperienceModel(
            "character_sr",
            0,
            40,
            70,
            experience.NewThreshold(
                []int64{
                    100,
                    200,
                    300,
                    400,
                    500,
                },
                experience.ThresholdOptions{
                    Metadata: pointy.String("CHARACTER"),
                },
            ),
            experience.ExperienceModelOptions{
                Metadata: pointy.String("SR"),
            },
        ),
        experience.NewExperienceModel(
            "character_r",
            0,
            30,
            60,
            experience.NewThreshold(
                []int64{
                    100,
                    200,
                    300,
                    400,
                    500,
                },
                experience.ThresholdOptions{
                    Metadata: pointy.String("CHARACTER"),
                },
            ),
            experience.ExperienceModelOptions{
                Metadata: pointy.String("R"),
            },
        ),
        experience.NewExperienceModel(
            "equipment",
            0,
            30,
            50,
            experience.NewThreshold(
                []int64{
                    200,
                    400,
                    600,
                    800,
                    1000,
                },
                experience.ThresholdOptions{
                    Metadata: pointy.String("EQUIPMENT"),
                },
            ),
            experience.ExperienceModelOptions{
                Metadata: pointy.String("EQUIPMENT"),
                AcquireActionRates: []experience.AcquireActionRate{
                    experience.NewAcquireActionRate(
                        "rate-0001",
                        experience.AcquireActionRateModeBig,
                        experience.AcquireActionRateOptions{
                            BigRates: []string{
                                "1",
                                "10",
                                "100",
                                "1000",
                                "10000",
                            },
                        },
                    ),
                },
            },
        ),
        experience.NewExperienceModel(
            "skill",
            0,
            10,
            20,
            experience.NewThreshold(
                []int64{
                    300,
                    600,
                    900,
                    1200,
                    1500,
                },
                experience.ThresholdOptions{
                    Metadata: pointy.String("SKILL"),
                },
            ),
            experience.ExperienceModelOptions{
                Metadata: pointy.String("SKILL"),
            },
        ),
    },
)

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

```

**PHP**
```php

class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Experience\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Experience\Model\ExperienceModel(
                    name:"character_ssr",
                    defaultExperience:0,
                    defaultRankCap:50,
                    maxRankCap:80,
                    rankThreshold:new \Gs2Cdk\Experience\Model\Threshold(
                        values: [
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        options: new \Gs2Cdk\Experience\Model\Options\ThresholdOptions(
                            metadata: "CHARACTER",
                        ),
                    ),
                    options: new \Gs2Cdk\Experience\Model\Options\ExperienceModelOptions(
                        metadata:"SSR"
                    )
                ),
                new \Gs2Cdk\Experience\Model\ExperienceModel(
                    name:"character_sr",
                    defaultExperience:0,
                    defaultRankCap:40,
                    maxRankCap:70,
                    rankThreshold:new \Gs2Cdk\Experience\Model\Threshold(
                        values: [
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        options: new \Gs2Cdk\Experience\Model\Options\ThresholdOptions(
                            metadata: "CHARACTER",
                        ),
                    ),
                    options: new \Gs2Cdk\Experience\Model\Options\ExperienceModelOptions(
                        metadata:"SR"
                    )
                ),
                new \Gs2Cdk\Experience\Model\ExperienceModel(
                    name:"character_r",
                    defaultExperience:0,
                    defaultRankCap:30,
                    maxRankCap:60,
                    rankThreshold:new \Gs2Cdk\Experience\Model\Threshold(
                        values: [
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        options: new \Gs2Cdk\Experience\Model\Options\ThresholdOptions(
                            metadata: "CHARACTER",
                        ),
                    ),
                    options: new \Gs2Cdk\Experience\Model\Options\ExperienceModelOptions(
                        metadata:"R"
                    )
                ),
                new \Gs2Cdk\Experience\Model\ExperienceModel(
                    name:"equipment",
                    defaultExperience:0,
                    defaultRankCap:30,
                    maxRankCap:50,
                    rankThreshold:new \Gs2Cdk\Experience\Model\Threshold(
                        values: [
                            200,
                            400,
                            600,
                            800,
                            1000,
                        ],
                        options: new \Gs2Cdk\Experience\Model\Options\ThresholdOptions(
                            metadata: "EQUIPMENT",
                        ),
                    ),
                    options: new \Gs2Cdk\Experience\Model\Options\ExperienceModelOptions(
                        metadata:"EQUIPMENT",
                        acquireActionRates:[
                            new \Gs2Cdk\Experience\Model\AcquireActionRate(
                                name: "rate-0001",
                                mode: \Gs2Cdk\Experience\Model\Enums\AcquireActionRateMode::BIG,
                                options: new \Gs2Cdk\Experience\Model\Options\AcquireActionRateOptions(
                                    bigRates: [
                                        "1",
                                        "10",
                                        "100",
                                        "1000",
                                        "10000",
                                    ],
                                ),
                            ),
                        ]
                    )
                ),
                new \Gs2Cdk\Experience\Model\ExperienceModel(
                    name:"skill",
                    defaultExperience:0,
                    defaultRankCap:10,
                    maxRankCap:20,
                    rankThreshold:new \Gs2Cdk\Experience\Model\Threshold(
                        values: [
                            300,
                            600,
                            900,
                            1200,
                            1500,
                        ],
                        options: new \Gs2Cdk\Experience\Model\Options\ThresholdOptions(
                            metadata: "SKILL",
                        ),
                    ),
                    options: new \Gs2Cdk\Experience\Model\Options\ExperienceModelOptions(
                        metadata:"SKILL"
                    )
                )
            ]
        );
    }
}

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

```

**Java**
```java

class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.experience.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.experience.model.ExperienceModel(
                    "character_ssr",
                    0L,
                    50L,
                    80L,
                    new io.gs2.cdk.experience.model.Threshold(
                        Arrays.asList(
                            100L,
                            200L,
                            300L,
                            400L,
                            500L
                        ),
                        new io.gs2.cdk.experience.model.options.ThresholdOptions()
                            .withMetadata("CHARACTER")
                    ),
                    new io.gs2.cdk.experience.model.options.ExperienceModelOptions()
                        .withMetadata("SSR")
                ),
                new io.gs2.cdk.experience.model.ExperienceModel(
                    "character_sr",
                    0L,
                    40L,
                    70L,
                    new io.gs2.cdk.experience.model.Threshold(
                        Arrays.asList(
                            100L,
                            200L,
                            300L,
                            400L,
                            500L
                        ),
                        new io.gs2.cdk.experience.model.options.ThresholdOptions()
                            .withMetadata("CHARACTER")
                    ),
                    new io.gs2.cdk.experience.model.options.ExperienceModelOptions()
                        .withMetadata("SR")
                ),
                new io.gs2.cdk.experience.model.ExperienceModel(
                    "character_r",
                    0L,
                    30L,
                    60L,
                    new io.gs2.cdk.experience.model.Threshold(
                        Arrays.asList(
                            100L,
                            200L,
                            300L,
                            400L,
                            500L
                        ),
                        new io.gs2.cdk.experience.model.options.ThresholdOptions()
                            .withMetadata("CHARACTER")
                    ),
                    new io.gs2.cdk.experience.model.options.ExperienceModelOptions()
                        .withMetadata("R")
                ),
                new io.gs2.cdk.experience.model.ExperienceModel(
                    "equipment",
                    0L,
                    30L,
                    50L,
                    new io.gs2.cdk.experience.model.Threshold(
                        Arrays.asList(
                            200L,
                            400L,
                            600L,
                            800L,
                            1000L
                        ),
                        new io.gs2.cdk.experience.model.options.ThresholdOptions()
                            .withMetadata("EQUIPMENT")
                    ),
                    new io.gs2.cdk.experience.model.options.ExperienceModelOptions()
                        .withMetadata("EQUIPMENT")
                        .withAcquireActionRates(Arrays.asList(
                            new io.gs2.cdk.experience.model.AcquireActionRate(
                                "rate-0001",
                                io.gs2.cdk.experience.model.enums.AcquireActionRateMode.BIG,
                                new io.gs2.cdk.experience.model.options.AcquireActionRateOptions()
                                    .withBigRates(Arrays.asList(
                                        "1",
                                        "10",
                                        "100",
                                        "1000",
                                        "10000"
                                    ))
                            )
                        ))
                ),
                new io.gs2.cdk.experience.model.ExperienceModel(
                    "skill",
                    0L,
                    10L,
                    20L,
                    new io.gs2.cdk.experience.model.Threshold(
                        Arrays.asList(
                            300L,
                            600L,
                            900L,
                            1200L,
                            1500L
                        ),
                        new io.gs2.cdk.experience.model.options.ThresholdOptions()
                            .withMetadata("SKILL")
                    ),
                    new io.gs2.cdk.experience.model.options.ExperienceModelOptions()
                        .withMetadata("SKILL")
                )
            )
        );
    }
}

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

```

**C#**
```csharp

public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Experience.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Experience.Model.ExperienceModel[] {
                new Gs2Cdk.Gs2Experience.Model.ExperienceModel(
                    name: "character_ssr",
                    defaultExperience: 0L,
                    defaultRankCap: 50L,
                    maxRankCap: 80L,
                    rankThreshold: new Gs2Cdk.Gs2Experience.Model.Threshold(
                        values: new long[]
                        {
                            100L,
                            200L,
                            300L,
                            400L,
                            500L,
                        },
                        options: new Gs2Cdk.Gs2Experience.Model.Options.ThresholdOptions
                        {
                            metadata = "CHARACTER"
                        }
                    ),
                    options: new Gs2Cdk.Gs2Experience.Model.Options.ExperienceModelOptions
                    {
                        metadata = "SSR"
                    }
                ),
                new Gs2Cdk.Gs2Experience.Model.ExperienceModel(
                    name: "character_sr",
                    defaultExperience: 0L,
                    defaultRankCap: 40L,
                    maxRankCap: 70L,
                    rankThreshold: new Gs2Cdk.Gs2Experience.Model.Threshold(
                        values: new long[]
                        {
                            100L,
                            200L,
                            300L,
                            400L,
                            500L,
                        },
                        options: new Gs2Cdk.Gs2Experience.Model.Options.ThresholdOptions
                        {
                            metadata = "CHARACTER"
                        }
                    ),
                    options: new Gs2Cdk.Gs2Experience.Model.Options.ExperienceModelOptions
                    {
                        metadata = "SR"
                    }
                ),
                new Gs2Cdk.Gs2Experience.Model.ExperienceModel(
                    name: "character_r",
                    defaultExperience: 0L,
                    defaultRankCap: 30L,
                    maxRankCap: 60L,
                    rankThreshold: new Gs2Cdk.Gs2Experience.Model.Threshold(
                        values: new long[]
                        {
                            100L,
                            200L,
                            300L,
                            400L,
                            500L,
                        },
                        options: new Gs2Cdk.Gs2Experience.Model.Options.ThresholdOptions
                        {
                            metadata = "CHARACTER"
                        }
                    ),
                    options: new Gs2Cdk.Gs2Experience.Model.Options.ExperienceModelOptions
                    {
                        metadata = "R"
                    }
                ),
                new Gs2Cdk.Gs2Experience.Model.ExperienceModel(
                    name: "equipment",
                    defaultExperience: 0L,
                    defaultRankCap: 30L,
                    maxRankCap: 50L,
                    rankThreshold: new Gs2Cdk.Gs2Experience.Model.Threshold(
                        values: new long[]
                        {
                            200L,
                            400L,
                            600L,
                            800L,
                            1000L,
                        },
                        options: new Gs2Cdk.Gs2Experience.Model.Options.ThresholdOptions
                        {
                            metadata = "EQUIPMENT"
                        }
                    ),
                    options: new Gs2Cdk.Gs2Experience.Model.Options.ExperienceModelOptions
                    {
                        metadata = "EQUIPMENT",
                        acquireActionRates = new Gs2Cdk.Gs2Experience.Model.AcquireActionRate[]
                        {
                            new Gs2Cdk.Gs2Experience.Model.AcquireActionRate(
                                name: "rate-0001",
                                mode: Gs2Cdk.Gs2Experience.Model.Enums.AcquireActionRateMode.Big,
                                options: new Gs2Cdk.Gs2Experience.Model.Options.AcquireActionRateOptions
                                {
                                    bigRates = new string[]
                                    {
                                        "1",
                                        "10",
                                        "100",
                                        "1000",
                                        "10000",
                                    }
                                }
                            )
                        }
                    }
                ),
                new Gs2Cdk.Gs2Experience.Model.ExperienceModel(
                    name: "skill",
                    defaultExperience: 0L,
                    defaultRankCap: 10L,
                    maxRankCap: 20L,
                    rankThreshold: new Gs2Cdk.Gs2Experience.Model.Threshold(
                        values: new long[]
                        {
                            300L,
                            600L,
                            900L,
                            1200L,
                            1500L,
                        },
                        options: new Gs2Cdk.Gs2Experience.Model.Options.ThresholdOptions
                        {
                            metadata = "SKILL"
                        }
                    ),
                    options: new Gs2Cdk.Gs2Experience.Model.Options.ExperienceModelOptions
                    {
                        metadata = "SKILL"
                    }
                )
            }
        );
    }
}

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

```

**TypeScript**
```typescript

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

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new experience.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new experience.model.ExperienceModel(
                    "character_ssr",
                    0,
                    50,
                    80,
                    new experience.model.Threshold(
                        [
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        {
                            metadata: "CHARACTER"
                        }
                    ),
                    {
                        metadata: "SSR"
                    }
                ),
                new experience.model.ExperienceModel(
                    "character_sr",
                    0,
                    40,
                    70,
                    new experience.model.Threshold(
                        [
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        {
                            metadata: "CHARACTER"
                        }
                    ),
                    {
                        metadata: "SR"
                    }
                ),
                new experience.model.ExperienceModel(
                    "character_r",
                    0,
                    30,
                    60,
                    new experience.model.Threshold(
                        [
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        {
                            metadata: "CHARACTER"
                        }
                    ),
                    {
                        metadata: "R"
                    }
                ),
                new experience.model.ExperienceModel(
                    "equipment",
                    0,
                    30,
                    50,
                    new experience.model.Threshold(
                        [
                            200,
                            400,
                            600,
                            800,
                            1000,
                        ],
                        {
                            metadata: "EQUIPMENT"
                        }
                    ),
                    {
                        metadata: "EQUIPMENT",
                        acquireActionRates: [
                            new experience.model.AcquireActionRate(
                                "rate-0001",
                                experience.model.AcquireActionRateMode.BIG,
                                {
                                    bigRates: [
                                        "1",
                                        "10",
                                        "100",
                                        "1000",
                                        "10000",
                                    ]
                                }
                            ),
                        ]
                    }
                ),
                new experience.model.ExperienceModel(
                    "skill",
                    0,
                    10,
                    20,
                    new experience.model.Threshold(
                        [
                            300,
                            600,
                            900,
                            1200,
                            1500,
                        ],
                        {
                            metadata: "SKILL"
                        }
                    ),
                    {
                        metadata: "SKILL"
                    }
                )
            ]
        );
    }
}

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

```

**Python**
```python

from gs2_cdk import Stack, core, experience

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        experience.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            experience_models=[
                experience.ExperienceModel(
                    name='character_ssr',
                    default_experience=0,
                    default_rank_cap=50,
                    max_rank_cap=80,
                    rank_threshold=experience.Threshold(
                        values=[
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        options=experience.ThresholdOptions(
                            metadata='CHARACTER',
                        ),
                    ),
                    options=experience.ExperienceModelOptions(
                        metadata = 'SSR'
                    ),
                ),
                experience.ExperienceModel(
                    name='character_sr',
                    default_experience=0,
                    default_rank_cap=40,
                    max_rank_cap=70,
                    rank_threshold=experience.Threshold(
                        values=[
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        options=experience.ThresholdOptions(
                            metadata='CHARACTER',
                        ),
                    ),
                    options=experience.ExperienceModelOptions(
                        metadata = 'SR'
                    ),
                ),
                experience.ExperienceModel(
                    name='character_r',
                    default_experience=0,
                    default_rank_cap=30,
                    max_rank_cap=60,
                    rank_threshold=experience.Threshold(
                        values=[
                            100,
                            200,
                            300,
                            400,
                            500,
                        ],
                        options=experience.ThresholdOptions(
                            metadata='CHARACTER',
                        ),
                    ),
                    options=experience.ExperienceModelOptions(
                        metadata = 'R'
                    ),
                ),
                experience.ExperienceModel(
                    name='equipment',
                    default_experience=0,
                    default_rank_cap=30,
                    max_rank_cap=50,
                    rank_threshold=experience.Threshold(
                        values=[
                            200,
                            400,
                            600,
                            800,
                            1000,
                        ],
                        options=experience.ThresholdOptions(
                            metadata='EQUIPMENT',
                        ),
                    ),
                    options=experience.ExperienceModelOptions(
                        metadata = 'EQUIPMENT',
                        acquire_action_rates = [
                            experience.AcquireActionRate(
                                name='rate-0001',
                                mode=experience.AcquireActionRateMode.BIG,
                                options=experience.AcquireActionRateOptions(
                                    big_rates=[
                                        '1',
                                        '10',
                                        '100',
                                        '1000',
                                        '10000',
                                    ],
                                ),
                            ),
                        ]
                    ),
                ),
                experience.ExperienceModel(
                    name='skill',
                    default_experience=0,
                    default_rank_cap=10,
                    max_rank_cap=20,
                    rank_threshold=experience.Threshold(
                        values=[
                            300,
                            600,
                            900,
                            1200,
                            1500,
                        ],
                        options=experience.ThresholdOptions(
                            metadata='SKILL',
                        ),
                    ),
                    options=experience.ExperienceModelOptions(
                        metadata = 'SKILL'
                    ),
                ),
            ],
        )

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

```


#### ExperienceModel

経験値モデル<br>

経験値とランクシステムのルールを定義します。ランクアップに必要な経験値の閾値、デフォルトのランクキャップ、最大ランクキャップを設定します。ランクキャップはステータスが到達できる最大ランクを制限し、ステータスごとに最大ランクキャップまで引き上げることができます（例: 限界突破）。オプションで、現在のランクに基づいて報酬倍率を調整する入手アクションレートテーブルを含めることができます。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| experienceModelId | string |  | ※ |  |  ~ 1024文字 | 経験値モデルGRN<br>※ サーバーが自動で設定 |
| name | string |  | ✓ |  |  ~ 128文字 | 経験値モデル名<br>経験値モデル固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| metadata | string |  |  |  |  ~ 2048文字 | メタデータ<br>メタデータには任意の値を設定できます。<br>これらの値は GS2 の動作には影響しないため、ゲーム内で利用する情報の保存先として使用できます。 |
| defaultExperience | long |  |  | 0 | 0 ~ 9223372036854775805 | 経験値の初期値<br>新規作成されたステータスに割り当てられる経験値です。通常、プレイヤーが進行の最初から始めるように 0 に設定されます。初期ランクはこの値からランクアップ閾値テーブルを使用して決定されます。 |
| defaultRankCap | long |  | ✓ |  | 0 ~ 9223372036854775805 | ランクキャップの初期値<br>新規作成されたステータスが到達できるデフォルトの最大ランクです。このランクの閾値を超えた経験値は破棄されるかオーバーフロースクリプトがトリガーされます。ランクキャップは限界突破などの操作により、ステータスごとに maxRankCap まで引き上げることができます。 |
| maxRankCap | long |  | ✓ |  | 0 ~ 9223372036854775805 | ランクキャップの最大値<br>ランクキャップの絶対的な上限です。ランクキャップ増加操作（限界突破など）を行っても、ランクキャップはこの値を超えることはできません。defaultRankCap 以上の値である必要があります。 |
| rankThreshold | [Threshold](#threshold) |  | ✓ |  |  | ランクアップ閾値<br>各ランクに必要な累計経験値を定義する閾値テーブルを参照します。閾値のエントリ数が到達可能な最大ランクを決定し、各エントリの値は次のランクに到達するために必要な経験値を指定します。 |
| acquireActionRates | [List&lt;AcquireActionRate&gt;](#acquireactionrate) |  |  |  | 0 ~ 100 items | 報酬加算テーブルリスト<br>ステータスのランクを参照として使用する際に報酬量を調整するランクベースの倍率テーブルを定義します。各テーブルはランクと倍率をマッピングし、同じアクションからより高ランクのキャラクターがより多くの報酬を受け取るような仕組みを実現できます。 |

#### Threshold

ランクアップ閾値<br>

ランクアップ閾値は経験値からランク（レベル）を決定するために必要な数列です。<br>
[10, 20] という値を設定した場合、経験値の値が 0~9 の間はランク1、10~19 の間はランク2、経験値の値が 20 でランク3 となり、それ以上経験値を入手することが出来なくなります。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| metadata | string |  |  |  |  ~ 2048文字 | メタデータ<br>メタデータには任意の値を設定できます。<br>これらの値は GS2 の動作には影響しないため、ゲーム内で利用する情報の保存先として使用できます。 |
| values | List&lt;long&gt; |  | ✓ |  | 1 ~ 10000 items | ランクアップ経験値閾値リスト<br>ランク進行を定義する累計経験値の順序付き配列です。エントリ数が到達可能な最大ランクを決定します。例えば [10, 20] の場合、経験値 0〜9 でランク1、10〜19 でランク2、20 以上でランク3（それ以上の経験値獲得は不可）となります。 |

#### AcquireActionRate

報酬加算テーブル<br>

ステータスの現在のランクに基づいて報酬量を調整するランクベースの倍率テーブルを定義します。テーブルの各エントリはランクに対応し、入手量に適用される倍率を指定します。標準的な倍精度浮動小数点値と、大規模な計算用の大数値文字列表現の両方をサポートします。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| name | string |  | ✓ |  |  ~ 128文字 | 報酬加算テーブル名<br>この報酬加算テーブルの一意な識別子です。特定の入手アクションに適用する倍率テーブルを指定する際に参照されます。 |
| mode | 文字列列挙型<br>enum {<br>"double",<br>"big"<br>}<br> |  |  | "double" |  | 報酬加算テーブルの種類<br>倍率値の数値精度を選択します。標準的な浮動小数点数（2^48 まで）には "double" を、大規模な計算が必要な場合は 1024 桁までの文字列表現をサポートする "big" を使用します。"double": 2^48 未満の浮動小数点数 / "big": 文字列表記で1024桁未満の浮動小数点数 /  |
| rates | List&lt;double&gt; | {mode} == "double" | ✓※ |  | 1 ~ 10000 items | ランクごとの加算量(倍率)<br>ランクをインデックスとする倍率値の配列です。i 番目のエントリはステータスがランク i の時に適用される報酬倍率を定義します。mode が "double" に設定されている場合に使用されます。<br>※ mode が "double" であれば 必須 |
| bigRates | List&lt;string&gt; | {mode} == "big" | ✓※ |  | 1 ~ 10000 items | ランクごとの加算量(倍率)<br>ランクをインデックスとする文字列表現の倍率値の配列です。i 番目のエントリはステータスがランク i の時に適用される報酬倍率を定義します。大数値精度が必要な計算で mode が "big" に設定されている場合に使用されます。<br>※ mode が "big" であれば 必須 |

---



