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

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

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




## エンティティ

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

### Namespace

ネームスペース<br>

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

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

#### Request

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

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| name | string |  | ✓|  |  ~ 128文字 | ネームスペース名<br>ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| description | string |  | |  |  ~ 1024文字 | 説明文 |
| transactionSetting | [TransactionSetting](#transactionsetting) |  | |  |  | トランザクション設定<br>バフの適用結果に基づいて実行される分散トランザクションの実行方法を制御する設定です。自動実行、アトミックコミット、非同期処理などのオプションが含まれます。 |
| applyBuffScript | [ScriptSetting](#scriptsetting) |  | |  |  | バフを適用する際に実行するスクリプトの設定<br>Script トリガーリファレンス - [`apply`](../script/#apply) |
| logSetting | [LogSetting](#logsetting) |  | |  |  | ログの出力設定<br>バフ操作のログデータを GS2-Log に出力するための設定です。APIリクエスト・レスポンスのログを収集する GS2-Log のネームスペースを指定します。 |

#### GetAttr

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

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

#### 実装例




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

Type: GS2::Buff::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSetting: null
  ApplyBuffScript: 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/buff"
)


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

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new buff.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, buff

class SampleStack(Stack):

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

---

### CurrentBuffMaster

現在アクティブなバフエントリーモデルのマスターデータ<br>

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

JSONファイルを作成する方法として、マネージメントコンソール内にマスターデータエディタを提供しています。<br>
また、よりゲームの運営に相応しいツールを作成し、適切なフォーマットのJSONファイルを書き出すことでもサービスを利用可能です。
{{% alert title="Note" color="info" %}}
JSONファイルの形式については [GS2-Buff マスターデータリファレンス](api_reference/buff/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 | [CurrentBuffMaster](../sdk#currentbuffmaster) | 更新された現在アクティブなバフエントリーモデルのマスターデータ

#### 実装例




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

Type: GS2::Buff::CurrentBuffMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2024-04-15",
    "buffEntryModels": [
      {
        "name": "buff-0001",
        "expression": "rate_add",
        "targetType": "model",
        "priority": 1,
        "metadata": "BUFF_0001",
        "targetModel":
          {
            "targetModelName": "Gs2Experience:Status",
            "targetFieldName": "rankCapValue",
            "conditionGrns": [
              {
                "targetModelName": "Gs2Experience:ExperienceModel",
                "targetGrn": "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
              },
              {
                "targetModelName": "Gs2Experience:ExperienceModel",
                "targetGrn": "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0002"
              }
            ],
            "rate": 1.0
          }
      },
      {
        "name": "buff-0002",
        "expression": "mul",
        "targetType": "action",
        "priority": 2,
        "metadata": "BUFF_0002",
        "targetAction":
          {
            "targetActionName": "Gs2Experience:AddExperienceByUserId",
            "targetFieldName": "experienceValue",
            "conditionGrns": [
              {
                "targetModelName": "Gs2Experience:ExperienceModel",
                "targetGrn": "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
              }
            ],
            "rate": 2.0
          }
      },
      {
        "name": "buff-0003",
        "expression": "mul",
        "targetType": "model",
        "priority": 3,
        "metadata": "BUFF_0003",
        "targetModel":
          {
            "targetModelName": "Gs2Experience:Status",
            "targetFieldName": "rankCapValue",
            "conditionGrns": [
              {
                "targetModelName": "Gs2Experience:ExperienceModel",
                "targetGrn": "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
              }
            ],
            "rate": 3.0
          }
      }
    ]
  }
  UploadToken: null

```

**Go**
```go

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


SampleStack := core.NewStack()
buff.NewNamespace(
    &SampleStack,
    "namespace-0001",
    buff.NamespaceOptions{},
).MasterData(
    []buff.BuffEntryModel{
        buff.NewBuffEntryModel(
            "buff-0001",
            buff.BuffEntryModelExpressionRateAdd,
            buff.BuffEntryModelTargetTypeModel,
            1,
            buff.BuffEntryModelOptions{
                Metadata: pointy.String("BUFF_0001"),
                TargetModel: &buff.BuffTargetModel{
                    TargetModelName: buff.BuffTargetModelTargetModelNameGs2ExperienceStatus,
                    TargetFieldName: "rankCapValue",
                    ConditionGrns: []buff.BuffTargetGrn{
                        buff.NewBuffTargetGrn(
                            "Gs2Experience:ExperienceModel",
                            "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001",
                            buff.BuffTargetGrnOptions{},
                        ),
                        buff.NewBuffTargetGrn(
                            "Gs2Experience:ExperienceModel",
                            "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0002",
                            buff.BuffTargetGrnOptions{},
                        ),
                    },
                    Rate: 1.0,
                },
            },
        ),
        buff.NewBuffEntryModel(
            "buff-0002",
            buff.BuffEntryModelExpressionMul,
            buff.BuffEntryModelTargetTypeAction,
            2,
            buff.BuffEntryModelOptions{
                Metadata: pointy.String("BUFF_0002"),
                TargetAction: &buff.BuffTargetAction{
                    TargetActionName: buff.BuffTargetActionTargetActionNameGs2ExperienceAddExperienceByUserId,
                    TargetFieldName: "experienceValue",
                    ConditionGrns: []buff.BuffTargetGrn{
                        buff.NewBuffTargetGrn(
                            "Gs2Experience:ExperienceModel",
                            "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001",
                            buff.BuffTargetGrnOptions{},
                        ),
                    },
                    Rate: 2.0,
                },
            },
        ),
        buff.NewBuffEntryModel(
            "buff-0003",
            buff.BuffEntryModelExpressionMul,
            buff.BuffEntryModelTargetTypeModel,
            3,
            buff.BuffEntryModelOptions{
                Metadata: pointy.String("BUFF_0003"),
                TargetModel: &buff.BuffTargetModel{
                    TargetModelName: buff.BuffTargetModelTargetModelNameGs2ExperienceStatus,
                    TargetFieldName: "rankCapValue",
                    ConditionGrns: []buff.BuffTargetGrn{
                        buff.NewBuffTargetGrn(
                            "Gs2Experience:ExperienceModel",
                            "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001",
                            buff.BuffTargetGrnOptions{},
                        ),
                    },
                    Rate: 3.0,
                },
            },
        ),
    },
)

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

```

**PHP**
```php

class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Buff\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Buff\Model\BuffEntryModel(
                    name:"buff-0001",
                    expression: \Gs2Cdk\Buff\Model\Enums\BuffEntryModelExpression::RATE_ADD,
                    targetType: \Gs2Cdk\Buff\Model\Enums\BuffEntryModelTargetType::MODEL,
                    priority:1,
                    options: new \Gs2Cdk\Buff\Model\Options\BuffEntryModelOptions(
                        metadata:"BUFF_0001",
                        targetModel:new \Gs2Cdk\Buff\Model\BuffTargetModel(
                            targetModelName: \Gs2Cdk\Buff\Model\Enums\BuffTargetModelTargetModelName::GS2_EXPERIENCE_STATUS,
                            targetFieldName: "rankCapValue",
                            conditionGrns: [
                                new \Gs2Cdk\Buff\Model\BuffTargetGrn(
                                    targetModelName: "Gs2Experience:ExperienceModel",
                                    targetGrn: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001",
                                ),
                                new \Gs2Cdk\Buff\Model\BuffTargetGrn(
                                    targetModelName: "Gs2Experience:ExperienceModel",
                                    targetGrn: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0002",
                                ),
                            ],
                            rate: 1.0,
                        )
                    )
                ),
                new \Gs2Cdk\Buff\Model\BuffEntryModel(
                    name:"buff-0002",
                    expression: \Gs2Cdk\Buff\Model\Enums\BuffEntryModelExpression::MUL,
                    targetType: \Gs2Cdk\Buff\Model\Enums\BuffEntryModelTargetType::ACTION,
                    priority:2,
                    options: new \Gs2Cdk\Buff\Model\Options\BuffEntryModelOptions(
                        metadata:"BUFF_0002",
                        targetAction:new \Gs2Cdk\Buff\Model\BuffTargetAction(
                            targetActionName: \Gs2Cdk\Buff\Model\Enums\BuffTargetActionTargetActionName::GS2_EXPERIENCE_ADD_EXPERIENCE_BY_USER_ID,
                            targetFieldName: "experienceValue",
                            conditionGrns: [
                                new \Gs2Cdk\Buff\Model\BuffTargetGrn(
                                    targetModelName: "Gs2Experience:ExperienceModel",
                                    targetGrn: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001",
                                ),
                            ],
                            rate: 2.0,
                        )
                    )
                ),
                new \Gs2Cdk\Buff\Model\BuffEntryModel(
                    name:"buff-0003",
                    expression: \Gs2Cdk\Buff\Model\Enums\BuffEntryModelExpression::MUL,
                    targetType: \Gs2Cdk\Buff\Model\Enums\BuffEntryModelTargetType::MODEL,
                    priority:3,
                    options: new \Gs2Cdk\Buff\Model\Options\BuffEntryModelOptions(
                        metadata:"BUFF_0003",
                        targetModel:new \Gs2Cdk\Buff\Model\BuffTargetModel(
                            targetModelName: \Gs2Cdk\Buff\Model\Enums\BuffTargetModelTargetModelName::GS2_EXPERIENCE_STATUS,
                            targetFieldName: "rankCapValue",
                            conditionGrns: [
                                new \Gs2Cdk\Buff\Model\BuffTargetGrn(
                                    targetModelName: "Gs2Experience:ExperienceModel",
                                    targetGrn: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001",
                                ),
                            ],
                            rate: 3.0,
                        )
                    )
                )
            ]
        );
    }
}

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

```

**Java**
```java

class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.buff.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.buff.model.BuffEntryModel(
                    "buff-0001",
                    io.gs2.cdk.buff.model.enums.BuffEntryModelExpression.RATE_ADD,
                    io.gs2.cdk.buff.model.enums.BuffEntryModelTargetType.MODEL,
                    1,
                    new io.gs2.cdk.buff.model.options.BuffEntryModelOptions()
                        .withMetadata("BUFF_0001")
                        .withTargetModel(new io.gs2.cdk.buff.model.BuffTargetModel(
                            io.gs2.cdk.buff.model.enums.BuffTargetModelTargetModelName.GS2_EXPERIENCE_STATUS,
                            "rankCapValue",
                            Arrays.asList(
                                new io.gs2.cdk.buff.model.BuffTargetGrn(
                                    "Gs2Experience:ExperienceModel",
                                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                ),
                                new io.gs2.cdk.buff.model.BuffTargetGrn(
                                    "Gs2Experience:ExperienceModel",
                                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0002"
                                )
                            ),
                            1.0f
                        ))
                ),
                new io.gs2.cdk.buff.model.BuffEntryModel(
                    "buff-0002",
                    io.gs2.cdk.buff.model.enums.BuffEntryModelExpression.MUL,
                    io.gs2.cdk.buff.model.enums.BuffEntryModelTargetType.ACTION,
                    2,
                    new io.gs2.cdk.buff.model.options.BuffEntryModelOptions()
                        .withMetadata("BUFF_0002")
                        .withTargetAction(new io.gs2.cdk.buff.model.BuffTargetAction(
                            io.gs2.cdk.buff.model.enums.BuffTargetActionTargetActionName.GS2_EXPERIENCE_ADD_EXPERIENCE_BY_USER_ID,
                            "experienceValue",
                            Arrays.asList(
                                new io.gs2.cdk.buff.model.BuffTargetGrn(
                                    "Gs2Experience:ExperienceModel",
                                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                )
                            ),
                            2.0f
                        ))
                ),
                new io.gs2.cdk.buff.model.BuffEntryModel(
                    "buff-0003",
                    io.gs2.cdk.buff.model.enums.BuffEntryModelExpression.MUL,
                    io.gs2.cdk.buff.model.enums.BuffEntryModelTargetType.MODEL,
                    3,
                    new io.gs2.cdk.buff.model.options.BuffEntryModelOptions()
                        .withMetadata("BUFF_0003")
                        .withTargetModel(new io.gs2.cdk.buff.model.BuffTargetModel(
                            io.gs2.cdk.buff.model.enums.BuffTargetModelTargetModelName.GS2_EXPERIENCE_STATUS,
                            "rankCapValue",
                            Arrays.asList(
                                new io.gs2.cdk.buff.model.BuffTargetGrn(
                                    "Gs2Experience:ExperienceModel",
                                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                )
                            ),
                            3.0f
                        ))
                )
            )
        );
    }
}

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

```

**C#**
```csharp

public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Buff.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Buff.Model.BuffEntryModel[] {
                new Gs2Cdk.Gs2Buff.Model.BuffEntryModel(
                    name: "buff-0001",
                    expression: Gs2Cdk.Gs2Buff.Model.Enums.BuffEntryModelExpression.RateAdd,
                    targetType: Gs2Cdk.Gs2Buff.Model.Enums.BuffEntryModelTargetType.Model,
                    priority: 1,
                    options: new Gs2Cdk.Gs2Buff.Model.Options.BuffEntryModelOptions
                    {
                        metadata = "BUFF_0001",
                        targetModel = new Gs2Cdk.Gs2Buff.Model.BuffTargetModel(
                            targetModelName: Gs2Cdk.Gs2Buff.Model.Enums.BuffTargetModelTargetModelName.Gs2ExperienceStatus,
                            targetFieldName: "rankCapValue",
                            conditionGrns: new Gs2Cdk.Gs2Buff.Model.BuffTargetGrn[]
                            {
                                new Gs2Cdk.Gs2Buff.Model.BuffTargetGrn(
                                    targetModelName: "Gs2Experience:ExperienceModel",
                                    targetGrn: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                ),
                                new Gs2Cdk.Gs2Buff.Model.BuffTargetGrn(
                                    targetModelName: "Gs2Experience:ExperienceModel",
                                    targetGrn: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0002"
                                )
                            },
                            rate: 1.0f
                        )
                    }
                ),
                new Gs2Cdk.Gs2Buff.Model.BuffEntryModel(
                    name: "buff-0002",
                    expression: Gs2Cdk.Gs2Buff.Model.Enums.BuffEntryModelExpression.Mul,
                    targetType: Gs2Cdk.Gs2Buff.Model.Enums.BuffEntryModelTargetType.Action,
                    priority: 2,
                    options: new Gs2Cdk.Gs2Buff.Model.Options.BuffEntryModelOptions
                    {
                        metadata = "BUFF_0002",
                        targetAction = new Gs2Cdk.Gs2Buff.Model.BuffTargetAction(
                            targetActionName: Gs2Cdk.Gs2Buff.Model.Enums.BuffTargetActionTargetActionName.Gs2ExperienceAddExperienceByUserId,
                            targetFieldName: "experienceValue",
                            conditionGrns: new Gs2Cdk.Gs2Buff.Model.BuffTargetGrn[]
                            {
                                new Gs2Cdk.Gs2Buff.Model.BuffTargetGrn(
                                    targetModelName: "Gs2Experience:ExperienceModel",
                                    targetGrn: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                )
                            },
                            rate: 2.0f
                        )
                    }
                ),
                new Gs2Cdk.Gs2Buff.Model.BuffEntryModel(
                    name: "buff-0003",
                    expression: Gs2Cdk.Gs2Buff.Model.Enums.BuffEntryModelExpression.Mul,
                    targetType: Gs2Cdk.Gs2Buff.Model.Enums.BuffEntryModelTargetType.Model,
                    priority: 3,
                    options: new Gs2Cdk.Gs2Buff.Model.Options.BuffEntryModelOptions
                    {
                        metadata = "BUFF_0003",
                        targetModel = new Gs2Cdk.Gs2Buff.Model.BuffTargetModel(
                            targetModelName: Gs2Cdk.Gs2Buff.Model.Enums.BuffTargetModelTargetModelName.Gs2ExperienceStatus,
                            targetFieldName: "rankCapValue",
                            conditionGrns: new Gs2Cdk.Gs2Buff.Model.BuffTargetGrn[]
                            {
                                new Gs2Cdk.Gs2Buff.Model.BuffTargetGrn(
                                    targetModelName: "Gs2Experience:ExperienceModel",
                                    targetGrn: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                )
                            },
                            rate: 3.0f
                        )
                    }
                )
            }
        );
    }
}

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

```

**TypeScript**
```typescript

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

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new buff.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new buff.model.BuffEntryModel(
                    "buff-0001",
                    buff.model.BuffEntryModelExpression.RATE_ADD,
                    buff.model.BuffEntryModelTargetType.MODEL,
                    1,
                    {
                        metadata: "BUFF_0001",
                        targetModel: new buff.model.BuffTargetModel(
                            buff.model.BuffTargetModelTargetModelName.GS2_EXPERIENCE_STATUS,
                            "rankCapValue",
                            [
                                new buff.model.BuffTargetGrn(
                                    "Gs2Experience:ExperienceModel",
                                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                ),
                                new buff.model.BuffTargetGrn(
                                    "Gs2Experience:ExperienceModel",
                                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0002"
                                ),
                            ],
                            1.0
                        )
                    }
                ),
                new buff.model.BuffEntryModel(
                    "buff-0002",
                    buff.model.BuffEntryModelExpression.MUL,
                    buff.model.BuffEntryModelTargetType.ACTION,
                    2,
                    {
                        metadata: "BUFF_0002",
                        targetAction: new buff.model.BuffTargetAction(
                            buff.model.BuffTargetActionTargetActionName.GS2_EXPERIENCE_ADD_EXPERIENCE_BY_USER_ID,
                            "experienceValue",
                            [
                                new buff.model.BuffTargetGrn(
                                    "Gs2Experience:ExperienceModel",
                                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                ),
                            ],
                            2.0
                        )
                    }
                ),
                new buff.model.BuffEntryModel(
                    "buff-0003",
                    buff.model.BuffEntryModelExpression.MUL,
                    buff.model.BuffEntryModelTargetType.MODEL,
                    3,
                    {
                        metadata: "BUFF_0003",
                        targetModel: new buff.model.BuffTargetModel(
                            buff.model.BuffTargetModelTargetModelName.GS2_EXPERIENCE_STATUS,
                            "rankCapValue",
                            [
                                new buff.model.BuffTargetGrn(
                                    "Gs2Experience:ExperienceModel",
                                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001"
                                ),
                            ],
                            3.0
                        )
                    }
                )
            ]
        );
    }
}

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

```

**Python**
```python

from gs2_cdk import Stack, core, buff

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        buff.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            buff_entry_models=[
                buff.BuffEntryModel(
                    name='buff-0001',
                    expression=buff.BuffEntryModelExpression.RATE_ADD,
                    target_type=buff.BuffEntryModelTargetType.MODEL,
                    priority=1,
                    options=buff.BuffEntryModelOptions(
                        metadata = 'BUFF_0001',
                        target_model = buff.BuffTargetModel(
                            target_model_name=buff.BuffTargetModelTargetModelName.GS2_EXPERIENCE_STATUS,
                            target_field_name='rankCapValue',
                            condition_grns=[
                                buff.BuffTargetGrn(
                                    target_model_name='Gs2Experience:ExperienceModel',
                                    target_grn='grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001',        
                                ),
                                buff.BuffTargetGrn(
                                    target_model_name='Gs2Experience:ExperienceModel',
                                    target_grn='grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0002',        
                                ),
                            ],
                            rate=1.0,        
                        )
                    ),
                ),
                buff.BuffEntryModel(
                    name='buff-0002',
                    expression=buff.BuffEntryModelExpression.MUL,
                    target_type=buff.BuffEntryModelTargetType.ACTION,
                    priority=2,
                    options=buff.BuffEntryModelOptions(
                        metadata = 'BUFF_0002',
                        target_action = buff.BuffTargetAction(
                            target_action_name=buff.BuffTargetActionTargetActionName.GS2_EXPERIENCE_ADD_EXPERIENCE_BY_USER_ID,
                            target_field_name='experienceValue',
                            condition_grns=[
                                buff.BuffTargetGrn(
                                    target_model_name='Gs2Experience:ExperienceModel',
                                    target_grn='grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001',        
                                ),
                            ],
                            rate=2.0,        
                        )
                    ),
                ),
                buff.BuffEntryModel(
                    name='buff-0003',
                    expression=buff.BuffEntryModelExpression.MUL,
                    target_type=buff.BuffEntryModelTargetType.MODEL,
                    priority=3,
                    options=buff.BuffEntryModelOptions(
                        metadata = 'BUFF_0003',
                        target_model = buff.BuffTargetModel(
                            target_model_name=buff.BuffTargetModelTargetModelName.GS2_EXPERIENCE_STATUS,
                            target_field_name='rankCapValue',
                            condition_grns=[
                                buff.BuffTargetGrn(
                                    target_model_name='Gs2Experience:ExperienceModel',
                                    target_grn='grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:experience-0001',        
                                ),
                            ],
                            rate=3.0,        
                        )
                    ),
                ),
            ],
        )

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

```


#### BuffEntryModel

バフエントリーモデル<br>

バフの適用量はバフエントリーモデルで管理し、同一の対象に対して複数のバフエントリーモデルを関連づけることが可能です。<br>
バフエントリーモデルの適用順番はバフエントリーモデルの `priority` で管理し、`priority` の値が小さいほど優先度が高くなります。<br>

バフの適用方式は3種類存在し「Rate Add」、「Mul」と「Value Add」があります。<br>
Rate Add はバフの適用レートに加算する命令、Mul はバフの適用レートに乗算する命令です。<br>
Value Add はバフの補正計算後の値に加算を行う命令です。<br>
たとえば、デフォルトのレートが 1.0 で、Rate Add 0.2 と設定するとバフの適用レートは 1.2 になります。<br>
Mul 0.5 と設定するとバフの適用レートは 0.5 倍になります。<br>

バフエントリーモデルには GS2-Schedule のイベントを関連づけることができ、イベントの開催期間中のみバフを適用するような設定も可能です。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| buffEntryModelId | string |  | ※ |  |  ~ 1024文字 | バフエントリーモデルGRN<br>※ サーバーが自動で設定 |
| name | string |  | ✓ |  |  ~ 128文字 | バフエントリーモデル名<br>バフエントリーモデル固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| metadata | string |  |  |  |  ~ 2048文字 | メタデータ<br>メタデータには任意の値を設定できます。<br>これらの値は GS2 の動作には影響しないため、ゲーム内で利用する情報の保存先として使用できます。 |
| expression | 文字列列挙型<br>enum {<br>&nbsp;&nbsp;"rate_add",<br>&nbsp;&nbsp;"mul",<br>&nbsp;&nbsp;"value_add"<br>}<br> |  | ✓ |  |  | バフの適用タイプ<br>バフ値を対象にどのように適用するかを指定します。「Rate Add」は補正レートに加算（例: 1.0 + 0.2 = 1.2）、「Mul」は補正レートに乗算（例: レート * 0.5）、「Value Add」はレートベースの補正計算後の値に直接加算します。"rate_add": 補正レートに加算 / "mul": 補正レートに乗算 / "value_add": 値を直接加算（モデルやアクションの数値のみ） /  |
| targetType | 文字列列挙型<br>enum {<br>&nbsp;&nbsp;"model",<br>&nbsp;&nbsp;"action"<br>}<br> |  | ✓ |  |  | バフを適用する対象の種類<br>バフをモデルのフィールド値に適用するか、アクションのパラメータに適用するかを指定します。「Model」は GS2 リソースモデルのフィールドを対象とし、「Action」は GS2 アクション（例：入手量や消費量）のパラメータを対象とします。"model": モデル / "action": アクション /  |
| targetModel | [BuffTargetModel](#bufftargetmodel) | {targetType} == "model" | ✓※ |  |  | バフを適用する対象のモデル<br>バフを適用する GS2 リソースモデルとフィールドを指定します。モデル名、フィールド名、対象リソースを特定する条件GRN、およびレート値が含まれます。<br>※ targetType が "model" であれば 必須 |
| targetAction | [BuffTargetAction](#bufftargetaction) | {targetType} == "action" | ✓※ |  |  | バフを適用する対象のアクション<br>バフを適用する GS2 アクションとパラメータを指定します。アクション名、フィールド名、対象リソースを特定する条件GRN、およびレート値が含まれます。<br>※ targetType が "action" であれば 必須 |
| priority | int |  | ✓ |  | 0 ~ 2147483646 | バフの適用優先度<br>バフエントリーモデルが評価される順序を決定します。値が小さいほど先に評価されます。同じフィールドを対象とする複数のバフがある場合、Rate Add と Mul 演算の相互作用により、適用順序が最終結果に影響します。 |
| applyPeriodScheduleEventId | string |  |  |  |  ~ 1024文字 | バフを適用するイベントの開催期間GRN<br>このバフの有効期間を制御する GS2-Schedule イベントの GRN です。指定した場合、イベントの開催期間中のみバフが適用されます。未指定の場合、バフは常に有効です。 |

#### BuffTargetModel

バフを適用する対象のモデル<br>

バフ適用の対象となる GS2 リソースモデルとフィールドを定義します。どのモデルのどのフィールド値をバフで変更するかを指定し、対象リソースインスタンスを特定する条件GRNと適用するレート値を含みます。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| targetModelName | 文字列列挙型<br>enum {<br>}<br> |  | ✓ |  |  | バフを適用するモデルの種類 |
| targetFieldName | string |  | ✓ |  |  ~ 64文字 | バフの適用対象フィールド名<br>バフによって値が変更される対象モデル上の数値フィールド名です。例えば、経験値や攻撃力などの数値属性を表すフィールドが対象となります。 |
| conditionGrns | [List&lt;BuffTargetGrn&gt;](#bufftargetgrn) |  | ✓ |  | 1 ~ 10 items | バフの適用条件GRNのリスト<br>バフ適用の対象リソースインスタンスを特定する GRN パターンのリストです。複数の GRN を組み合わせて、リソースを正確に特定する複合条件を形成します。 |
| rate | float |  | ✓ |  | 0 ~ 1000000 | 補正レート<br>適用されるバフ値です。適用タイプにより意味が異なります。「Rate Add」の場合は基本レートに加算、「Mul」の場合は現在のレートに乗算、「Value Add」の場合はレート計算後のフィールド値に直接加算されます。 |

#### BuffTargetAction

バフを適用する対象のアクション<br>

バフ適用の対象となる GS2 アクションとパラメータを定義します。どのアクションのどのパラメータをバフで変更するかを指定し、対象リソースインスタンスを特定する条件GRNと適用するレート値を含みます。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| targetActionName | 文字列列挙型<br>enum {<br>}<br> |  | ✓ |  |  | バフを適用するアクションの種類 |
| targetFieldName | string |  | ✓ |  |  ~ 64文字 | バフの適用対象フィールド名<br>バフによって値が変更される対象アクション上の数値パラメータ名です。例えば、入手数、消費量、報酬数量などを表すパラメータが対象となります。 |
| conditionGrns | [List&lt;BuffTargetGrn&gt;](#bufftargetgrn) |  | ✓ |  | 1 ~ 10 items | バフの適用条件GRNのリスト<br>バフ適用の対象リソースインスタンスを特定する GRN パターンのリストです。複数の GRN を組み合わせて、リソースを正確に特定する複合条件を形成します。 |
| rate | float |  | ✓ |  | 0 ~ 1000000 | 補正レート<br>適用されるバフ値です。適用タイプにより意味が異なります。「Rate Add」の場合は基本レートに加算、「Mul」の場合は現在のレートに乗算、「Value Add」の場合はレート計算後のパラメータ値に直接加算されます。 |

#### BuffTargetGrn

バフ適用条件となるリソースのGRNパターン<br>

バフが有効となるリソースインスタンスを絞り込むための条件 GRN パターンです。<br>
targetModelName で GS2サービスモデルの種別を特定し、targetGrn にはランタイムで解決されるコンテキスト変数（{region}、{ownerId}）を含めることができます。

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| targetModelName | string |  | ✓ |  |  ~ 64文字 | バフの適用条件のモデル名<br>条件GRNを解決するために使用される GS2 サービスモデルの名前です。GRN パターンがどのサービスのリソースモデルを参照するかを特定します。 |
| targetGrn | string |  | ✓ |  |  ~ 1024文字 | バフの適用条件GRN<br>ランタイムで解決されるコンテキストプレースホルダー（例：{region}、{ownerId}）を含む GRN テンプレートです。バフの対象となる特定のリソースインスタンスを特定するために使用されます。 |

---



