Documentation index for AI agents

GS2-Exchange Deploy/CDK 레퍼런스

GS2-Deploy의 스택을 생성할 때 사용하는 템플릿 포맷과, CDK를 이용한 각종 언어의 템플릿 출력 구현 예제

엔티티

Deploy 처리에서 조작 대상이 되는 리소스

Namespace

네임스페이스

네임스페이스는 하나의 프로젝트 내에서 동일한 서비스를 서로 다른 용도로 여러 개 이용하기 위한 엔티티입니다.
GS2의 각 서비스는 네임스페이스 단위로 관리됩니다. 네임스페이스가 다르면 동일한 서비스라도 완전히 독립된 데이터 공간으로 취급됩니다.

따라서 각 서비스의 이용을 시작하려면 먼저 네임스페이스를 생성해야 합니다.

Request

리소스 생성·갱신 요청

타입활성화 조건필수기본값값 제한설명
namestring
~ 128자네임스페이스 이름
네임스페이스 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다.
descriptionstring~ 1024자설명문
enableAwaitExchangeboolfalse교환 결과 수령에 대기 시간이 발생하는 교환 기능을 사용할지 여부
활성화하면 await 타이밍 타입의 교환 레이트 모델을 사용할 수 있습니다. 이러한 교환은 보상을 받기 전에 실시간 경과가 필요하며, 플레이어가 결과를 기다려야 하는 제작이나 생산 계열의 메커니즘을 구현할 수 있습니다.
enableDirectExchangebooltrue직접 교환 API 호출 허용
활성화하면 클라이언트가 교환 API를 직접 호출하여 리소스 교환을 실행할 수 있습니다. 비활성화하면 트랜잭션 액션을 통해서만 교환이 트리거되어, 교환 발생에 대한 서버 측 제어가 더욱 엄격해집니다.
transactionSettingTransactionSetting
트랜잭션 설정
교환 조작 시 분산 트랜잭션의 실행 방식을 제어하는 설정입니다. 자동 실행, 원자적 커밋, 비동기 처리 등의 옵션을 지원합니다.
exchangeScriptScriptSetting교환을 실행하려고 할 때 실행할 스크립트 설정
Script 트리거 레퍼런스 - exchange
incrementalExchangeScriptScriptSetting코스트 상승형 교환을 실행하려고 할 때 실행할 스크립트 설정
Script 트리거 레퍼런스 - incrementalExchange
acquireAwaitScriptScriptSetting대기 방식 교환 처리에서 대기가 완료되어 보상을 받으려고 할 때 실행할 스크립트 설정
Script 트리거 레퍼런스 - acquireAwait
logSettingLogSetting로그 출력 설정
교환 조작의 로그 데이터를 GS2-Log에 출력하기 위한 설정입니다. GS2-Log의 네임스페이스를 지정함으로써 교환, 코스트 상승형 교환, 대기 조작의 API 요청·응답 로그를 수집할 수 있습니다.

GetAttr

!GetAttr 태그로 취득 가능한 리소스 생성 결과

타입설명
ItemNamespace생성한 네임스페이스

구현 예제

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
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
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
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
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
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
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

트랜잭션 설정

트랜잭션 설정은 트랜잭션의 실행 방법·정합성·비동기 처리·충돌 회피 메커니즘을 제어하는 설정입니다.
자동 실행(AutoRun), 원자적 실행(AtomicCommit), GS2-Distributor를 이용한 비동기 실행, 스크립트 결과의 일괄 적용, GS2-JobQueue를 통한 입수 액션의 비동기화 등을 조합하여 게임 로직에 맞는 견고한 트랜잭션 관리를 가능하게 합니다.

타입활성화 조건필수기본값값 제한설명
enableAutoRunboolfalse발행한 트랜잭션을 서버 사이드에서 자동으로 실행할지 여부
enableAtomicCommitbool{enableAutoRun} == truefalse트랜잭션의 실행을 원자적으로 커밋할지 여부
※ enableAutoRun이(가) true 이면 활성화
transactionUseDistributorbool{enableAtomicCommit} == truefalse트랜잭션을 비동기 처리로 실행할지 여부
※ enableAtomicCommit이(가) true 이면 활성화
commitScriptResultInUseDistributorbool{transactionUseDistributor} == truefalse스크립트의 결과 커밋 처리를 비동기 처리로 실행할지 여부
※ transactionUseDistributor이(가) true 이면 활성화
acquireActionUseJobQueuebool{enableAtomicCommit} == truefalse입수 액션을 실행할 때 GS2-JobQueue를 사용할지 여부
※ enableAtomicCommit이(가) true 이면 활성화
distributorNamespaceIdstring“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024자트랜잭션 실행에 사용하는 GS2-Distributor 네임스페이스 GRN
queueNamespaceIdstring“grn:gs2:{region}:{ownerId}:queue:default”~ 1024자트랜잭션 실행에 사용하는 GS2-JobQueue의 네임스페이스 GRN

ScriptSetting

스크립트 설정

GS2에서는 마이크로서비스의 이벤트에 연결하여 커스텀 스크립트를 실행할 수 있습니다.
이 모델은 스크립트 실행을 트리거하기 위한 설정을 보유합니다.

스크립트 실행 방식은 크게 두 가지로, 바로 “동기 실행"과 “비동기 실행"입니다.
동기 실행은 스크립트 실행이 완료될 때까지 처리가 블록됩니다.
대신 스크립트 실행 결과를 이용하여 API 실행을 중단시키거나 API 응답 내용을 제어할 수 있습니다.

한편, 비동기 실행에서는 스크립트 완료를 기다리기 위해 처리가 블록되는 일이 없습니다.
다만 스크립트 실행 결과를 이용하여 API 실행을 중단하거나 API 응답 내용을 변경할 수는 없습니다.
비동기 실행은 API의 응답 흐름에 영향을 주지 않으므로 원칙적으로 비동기 실행을 권장합니다.

비동기 실행에는 실행 방식이 두 가지 있으며, GS2-Script와 Amazon EventBridge가 있습니다.
Amazon EventBridge를 사용함으로써 Lua 이외의 언어로 처리를 작성할 수 있습니다.

타입활성화 조건필수기본값값 제한설명
triggerScriptIdstring~ 1024자API 실행 시 동기적으로 실행되는 GS2-Script의 스크립트 GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다.
doneTriggerTargetType문자열 열거형
enum {
  “none”,
  “gs2_script”,
  “aws”
}
“none”비동기 스크립트의 실행 방법
비동기 실행에서 사용할 스크립트의 종류를 지정합니다.
“비동기 실행의 스크립트를 사용하지 않음(none)”, “GS2-Script를 사용함(gs2_script)”, “Amazon EventBridge를 사용함(aws)” 중에서 선택할 수 있습니다.
정의설명
none없음
gs2_scriptGS2-Script
awsAmazon EventBridge
doneTriggerScriptIdstring{doneTriggerTargetType} == “gs2_script”~ 1024자비동기 실행할 GS2-Script 스크립트 GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다.
※ doneTriggerTargetType이(가) “gs2_script” 이면 활성화
doneTriggerQueueNamespaceIdstring{doneTriggerTargetType} == “gs2_script”~ 1024자비동기 실행 스크립트를 실행하는 GS2-JobQueue 네임스페이스 GRN
비동기 실행 스크립트를 직접 실행하지 않고 GS2-JobQueue를 경유하는 경우 GS2-JobQueue의 네임스페이스GRN을 지정합니다.
GS2-JobQueue를 이용해야 할 이유는 많지 않으므로, 특별한 이유가 없다면 지정할 필요는 없습니다.
※ doneTriggerTargetType이(가) “gs2_script” 이면 활성화

LogSetting

로그 출력 설정

로그 데이터의 출력 설정을 관리합니다. 이 타입은 로그 데이터를 기록하는 데 사용되는 GS2-Log 네임스페이스의 식별자(Namespace ID)를 보유합니다.
로그 네임스페이스ID(loggingNamespaceId)에는 로그 데이터를 수집하여 저장하는 GS2-Log의 네임스페이스를 GRN 형식으로 지정합니다.
이 설정을 하면 설정된 네임스페이스 내에서 발생한 API 요청·응답의 로그 데이터가 대상 GS2-Log 네임스페이스 쪽으로 출력됩니다.
GS2-Log에서는 실시간으로 로그가 제공되어 시스템 모니터링, 분석, 디버깅 등에 이용할 수 있습니다.

타입활성화 조건필수기본값값 제한설명
loggingNamespaceIdstring
~ 1024자로그를 출력할 GS2-Log의 네임스페이스 GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다.

CurrentRateMaster

현재 활성화된 레이트 모델의 마스터 데이터

이 마스터 데이터는 현재 네임스페이스 내에서 유효한 레이트 모델의 정의를 기술한 것입니다.
GS2에서는 마스터 데이터의 관리에 JSON 형식의 파일을 사용합니다.
파일을 업로드함으로써 실제로 서버에 설정을 반영할 수 있습니다.

JSON 파일을 작성하는 방법으로, 매니지먼트 콘솔 내에 마스터 데이터 에디터를 제공하고 있습니다.
또한 게임 운영에 더 적합한 도구를 직접 만들어 적절한 포맷의 JSON 파일을 출력하는 방식으로도 서비스를 이용할 수 있습니다.

Request

리소스 생성·갱신 요청

타입활성화 조건필수기본값값 제한설명
namespaceNamestring
~ 128자네임스페이스 이름
네임스페이스 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다.
mode문자열 열거형
enum {
  “direct”,
  “preUpload”
}
“direct”업데이트 모드
정의설명
direct마스터 데이터를 직접 업데이트
preUpload마스터 데이터를 업로드한 후 업데이트
settingsstring{mode} == “direct”
✓※
~ 5242880 바이트 (5MB)마스터 데이터
※ mode이(가) “direct” 이면 필수
uploadTokenstring{mode} == “preUpload”
✓※
~ 1024자사전 업로드로 획득한 토큰
업로드한 마스터 데이터를 적용하기 위해 사용됩니다.
※ mode이(가) “preUpload” 이면 필수

GetAttr

!GetAttr 태그로 취득 가능한 리소스 생성 결과

타입설명
ItemCurrentRateMaster갱신된 현재 활성화된 레이트 모델의 마스터 데이터

구현 예제

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
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
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
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
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
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
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

교환 레이트 모델

교환 레이트 모델은 리소스와 리소스를 교환할 때 사용하는 레이트를 정의하는 엔티티입니다.

즉시 교환할 수 있는 레이트뿐만 아니라, 현실 시간으로 일정 시간이 경과한 후에 교환할 수 있는 레이트도 설정할 수 있습니다.
현실 시간의 경과가 필요한 교환 레이트에는 즉시 교환을 실행하는 데 필요한 리소스를 추가로 정의할 수 있습니다.

타입활성화 조건필수기본값값 제한설명
rateModelIdstring
~ 1024자교환 레이트 모델 GRN
※ 서버가 자동으로 설정
namestring
~ 128자교환 레이트 모델 이름
교환 레이트 모델 종류 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다.
metadatastring~ 2048자메타데이터
메타데이터에는 임의의 값을 설정할 수 있습니다.
이 값들은 GS2의 동작에는 영향을 주지 않으므로, 게임 내에서 사용하는 정보를 저장하는 용도로 사용할 수 있습니다.
verifyActionsList<VerifyAction>[]0 ~ 10 items검증 액션 리스트
교환이 실행되기 전에 모두 통과해야 하는 사전 조건 체크입니다. 검증 액션 중 하나라도 실패하면, 리소스를 소비하지 않고 교환이 중단됩니다. 레벨 요건이나 인벤토리 용량 등의 조건을 강제하기 위해 사용됩니다.
consumeActionsList<ConsumeAction>[]0 ~ 10 items소비 액션 리스트
이 교환을 실행하기 위해 플레이어가 지불해야 하는 리소스(코스트)를 정의합니다. 여러 개의 소비 액션을 지정할 수 있어, 골드와 아이템을 모두 필요로 하는 것과 같은 복잡한 교환 코스트를 구현할 수 있습니다. 이러한 액션은 분산 트랜잭션 내의 소비 액션으로 실행됩니다.
timingType문자열 열거형
enum {
  “immediate”,
  “await”
}
“immediate”교환 종류
교환 실행 후 보상이 언제 전달되는지를 결정합니다. immediate는 교환 실행 시 즉시 보상을 전달합니다. await는 보상을 받기 전에 실시간의 경과가 필요하며, 대기 기간(예: 제작 시간)을 둡니다.
정의설명
immediate즉시
await현실 시간의 경과 대기
lockTimeint{timingType} == “await”
✓※
0 ~ 538214400교환 실행부터 실제로 보상을 받을 수 있게 될 때까지의 대기 시간(분)
timingType이 await인 경우에만 적용됩니다. 교환이 시작된 후 플레이어가 보상을 받을 수 있게 되기까지 경과해야 하는 실시간 분수를 지정합니다. 대기 시간은 스킵 기능을 사용하여 단축할 수 있습니다.
※ timingType이(가) “await” 이면 필수
acquireActionsList<AcquireAction>[]0 ~ 100 items획득 액션 리스트
교환 완료 시 플레이어가 받는 리소스(보상)를 정의합니다. 여러 개의 획득 액션을 지정하여 다양한 리소스 타입을 동시에 지급할 수 있습니다. 이러한 액션은 분산 트랜잭션 내의 획득 액션으로 실행됩니다.

AcquireAction

입수 액션

타입활성화 조건필수기본값값 제한설명
action문자열 열거형
enum {
"Gs2AdReward:AcquirePointByUserId",
"Gs2Dictionary:AddEntriesByUserId",
"Gs2Enchant:ReDrawBalanceParameterStatusByUserId",
"Gs2Enchant:SetBalanceParameterStatusByUserId",
"Gs2Enchant:ReDrawRarityParameterStatusByUserId",
"Gs2Enchant:AddRarityParameterStatusByUserId",
"Gs2Enchant:SetRarityParameterStatusByUserId",
"Gs2Enhance:DirectEnhanceByUserId",
"Gs2Enhance:UnleashByUserId",
"Gs2Enhance:CreateProgressByUserId",
"Gs2Exchange:ExchangeByUserId",
"Gs2Exchange:IncrementalExchangeByUserId",
"Gs2Exchange:CreateAwaitByUserId",
"Gs2Exchange:AcquireForceByUserId",
"Gs2Exchange:SkipByUserId",
"Gs2Experience:AddExperienceByUserId",
"Gs2Experience:SetExperienceByUserId",
"Gs2Experience:AddRankCapByUserId",
"Gs2Experience:SetRankCapByUserId",
"Gs2Experience:MultiplyAcquireActionsByUserId",
"Gs2Formation:AddMoldCapacityByUserId",
"Gs2Formation:SetMoldCapacityByUserId",
"Gs2Formation:AcquireActionsToFormProperties",
"Gs2Formation:SetFormByUserId",
"Gs2Formation:AcquireActionsToPropertyFormProperties",
"Gs2Friend:UpdateProfileByUserId",
"Gs2Grade:AddGradeByUserId",
"Gs2Grade:ApplyRankCapByUserId",
"Gs2Grade:MultiplyAcquireActionsByUserId",
"Gs2Guild:IncreaseMaximumCurrentMaximumMemberCountByGuildName",
"Gs2Guild:SetMaximumCurrentMaximumMemberCountByGuildName",
"Gs2Idle:IncreaseMaximumIdleMinutesByUserId",
"Gs2Idle:SetMaximumIdleMinutesByUserId",
"Gs2Idle:ReceiveByUserId",
"Gs2Inbox:SendMessageByUserId",
"Gs2Inventory:AddCapacityByUserId",
"Gs2Inventory:SetCapacityByUserId",
"Gs2Inventory:AcquireItemSetByUserId",
"Gs2Inventory:AcquireItemSetWithGradeByUserId",
"Gs2Inventory:AddReferenceOfByUserId",
"Gs2Inventory:DeleteReferenceOfByUserId",
"Gs2Inventory:AcquireSimpleItemsByUserId",
"Gs2Inventory:SetSimpleItemsByUserId",
"Gs2Inventory:AcquireBigItemByUserId",
"Gs2Inventory:SetBigItemByUserId",
"Gs2JobQueue:PushByUserId",
"Gs2Limit:CountDownByUserId",
"Gs2Limit:DeleteCounterByUserId",
"Gs2LoginReward:DeleteReceiveStatusByUserId",
"Gs2LoginReward:UnmarkReceivedByUserId",
"Gs2Lottery:DrawByUserId",
"Gs2Lottery:ResetBoxByUserId",
"Gs2Mission:RevertReceiveByUserId",
"Gs2Mission:IncreaseCounterByUserId",
"Gs2Mission:SetCounterByUserId",
"Gs2Money:DepositByUserId",
"Gs2Money:RevertRecordReceipt",
"Gs2Money2:DepositByUserId",
"Gs2Quest:CreateProgressByUserId",
"Gs2Schedule:TriggerByUserId",
"Gs2Schedule:ExtendTriggerByUserId",
"Gs2Script:InvokeScript",
"Gs2SerialKey:RevertUseByUserId",
"Gs2SerialKey:IssueOnce",
"Gs2Showcase:DecrementPurchaseCountByUserId",
"Gs2Showcase:ForceReDrawByUserId",
"Gs2SkillTree:MarkReleaseByUserId",
"Gs2Stamina:RecoverStaminaByUserId",
"Gs2Stamina:RaiseMaxValueByUserId",
"Gs2Stamina:SetMaxValueByUserId",
"Gs2Stamina:SetRecoverIntervalByUserId",
"Gs2Stamina:SetRecoverValueByUserId",
"Gs2StateMachine:StartStateMachineByUserId",
}
입수 액션에서 실행할 액션의 종류
requeststring
~ 524288자액션 실행 시 사용되는 요청의 JSON 문자열

ConsumeAction

소비 액션

타입활성화 조건필수기본값값 제한설명
action문자열 열거형
enum {
"Gs2AdReward:ConsumePointByUserId",
"Gs2Dictionary:DeleteEntriesByUserId",
"Gs2Enhance:DeleteProgressByUserId",
"Gs2Exchange:DeleteAwaitByUserId",
"Gs2Experience:SubExperienceByUserId",
"Gs2Experience:SubRankCapByUserId",
"Gs2Formation:SubMoldCapacityByUserId",
"Gs2Grade:SubGradeByUserId",
"Gs2Guild:DecreaseMaximumCurrentMaximumMemberCountByGuildName",
"Gs2Idle:DecreaseMaximumIdleMinutesByUserId",
"Gs2Inbox:OpenMessageByUserId",
"Gs2Inbox:DeleteMessageByUserId",
"Gs2Inventory:ConsumeItemSetByUserId",
"Gs2Inventory:ConsumeSimpleItemsByUserId",
"Gs2Inventory:ConsumeBigItemByUserId",
"Gs2JobQueue:DeleteJobByUserId",
"Gs2Limit:CountUpByUserId",
"Gs2LoginReward:MarkReceivedByUserId",
"Gs2Mission:ReceiveByUserId",
"Gs2Mission:BatchReceiveByUserId",
"Gs2Mission:DecreaseCounterByUserId",
"Gs2Mission:ResetCounterByUserId",
"Gs2Money:WithdrawByUserId",
"Gs2Money:RecordReceipt",
"Gs2Money2:WithdrawByUserId",
"Gs2Money2:VerifyReceiptByUserId",
"Gs2Quest:DeleteProgressByUserId",
"Gs2Ranking2:CreateGlobalRankingReceivedRewardByUserId",
"Gs2Ranking2:CreateClusterRankingReceivedRewardByUserId",
"Gs2Schedule:DeleteTriggerByUserId",
"Gs2SerialKey:UseByUserId",
"Gs2Showcase:IncrementPurchaseCountByUserId",
"Gs2SkillTree:MarkRestrainByUserId",
"Gs2Stamina:DecreaseMaxValueByUserId",
"Gs2Stamina:ConsumeStaminaByUserId",
}
소비 액션에서 실행할 액션의 종류
requeststring
~ 524288자액션 실행 시 사용되는 요청의 JSON 문자열

VerifyAction

검증 액션

타입활성화 조건필수기본값값 제한설명
action문자열 열거형
enum {
"Gs2Dictionary:VerifyEntryByUserId",
"Gs2Distributor:IfExpressionByUserId",
"Gs2Distributor:AndExpressionByUserId",
"Gs2Distributor:OrExpressionByUserId",
"Gs2Enchant:VerifyRarityParameterStatusByUserId",
"Gs2Experience:VerifyRankByUserId",
"Gs2Experience:VerifyRankCapByUserId",
"Gs2Grade:VerifyGradeByUserId",
"Gs2Grade:VerifyGradeUpMaterialByUserId",
"Gs2Guild:VerifyCurrentMaximumMemberCountByGuildName",
"Gs2Guild:VerifyIncludeMemberByUserId",
"Gs2Inventory:VerifyInventoryCurrentMaxCapacityByUserId",
"Gs2Inventory:VerifyItemSetByUserId",
"Gs2Inventory:VerifyReferenceOfByUserId",
"Gs2Inventory:VerifySimpleItemByUserId",
"Gs2Inventory:VerifyBigItemByUserId",
"Gs2Limit:VerifyCounterByUserId",
"Gs2Matchmaking:VerifyIncludeParticipantByUserId",
"Gs2Mission:VerifyCompleteByUserId",
"Gs2Mission:VerifyCounterValueByUserId",
"Gs2Ranking2:VerifyGlobalRankingScoreByUserId",
"Gs2Ranking2:VerifyClusterRankingScoreByUserId",
"Gs2Ranking2:VerifySubscribeRankingScoreByUserId",
"Gs2Schedule:VerifyTriggerByUserId",
"Gs2Schedule:VerifyEventByUserId",
"Gs2SerialKey:VerifyCodeByUserId",
"Gs2Stamina:VerifyStaminaValueByUserId",
"Gs2Stamina:VerifyStaminaMaxValueByUserId",
"Gs2Stamina:VerifyStaminaRecoverIntervalMinutesByUserId",
"Gs2Stamina:VerifyStaminaRecoverValueByUserId",
"Gs2Stamina:VerifyStaminaOverflowValueByUserId",
}
검증 액션에서 실행할 액션의 종류
requeststring
~ 524288자액션 실행 시 사용되는 요청의 JSON 문자열

IncrementalRateModel

코스트 상승형 교환 레이트 모델

일반적인 교환 레이트는 항상 일정한 레이트로 교환을 제공합니다.
상승형 교환 레이트에서는 교환 횟수에 따라 코스트가 상승하는 레이트를 정의할 수 있습니다.
예를 들어, 첫 번째 교환에서는 1:1로 교환할 수 있지만, 두 번째 교환에서는 2:1로 교환하게 되는 것과 같은 레이트를 정의할 수 있습니다.
이러한 레이트를 정의함으로써 플레이어가 게임을 진행함에 따라 얻을 수 있는 리소스의 가치를 높일 수 있습니다.

교환 횟수는 현실 시간의 경과에 따라 리셋할 수 있습니다.
이 기능을 이용하면 매일 또는 매주 교환에 필요한 코스트를 리셋할 수 있습니다.

타입활성화 조건필수기본값값 제한설명
incrementalRateModelIdstring
~ 1024자코스트 상승형 교환 레이트 모델 GRN
※ 서버가 자동으로 설정
namestring
~ 128자코스트 상승형 교환 레이트 모델의 이름
코스트 상승형 교환 레이트 모델 종류 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다.
metadatastring~ 2048자메타데이터
메타데이터에는 임의의 값을 설정할 수 있습니다.
이 값들은 GS2의 동작에는 영향을 주지 않으므로, 게임 내에서 사용하는 정보를 저장하는 용도로 사용할 수 있습니다.
consumeActionConsumeAction
소비 액션 (수량/값은 자동으로 덮어써집니다)
교환 비용으로 소비되는 리소스의 종류를 정의합니다. 실제 수량은 교환 횟수와 계산 방식(선형, 거듭제곱, 스크립트)에 기반하여 동적으로 계산됩니다. 액션 종류와 대상 리소스만 지정하면 되며, 수량 필드는 자동으로 덮어써집니다.
calculateType문자열 열거형
enum {
  “linear”,
  “power”,
  “gs2_script”
}
코스트 상승량 계산 방식
교환 횟수에 따라 코스트가 어떻게 상승하는지를 결정합니다. linear는 코스트를 baseValue +(coefficientValue × 교환 횟수)로 계산합니다. power는 코스트를 coefficientValue ×(교환 횟수 + 1)^2로 계산합니다. gs2_script는 임의의 로직을 위해 커스텀 GS2-Script에 계산을 위임합니다.
정의설명
linear베이스 값 + (계수 * 교환 횟수)
power계수 * (교환 횟수 + 1) ^ 2
gs2_scriptGS2-Script에 의한 임의의 로직
baseValuelong{calculateType} == “linear”
✓※
0 ~ 9223372036854775805베이스 값
linear 계산 방식을 사용하는 경우 첫 교환 시의 기본 코스트입니다. 합계 코스트는 baseValue +(coefficientValue × 교환 횟수)로 계산됩니다.
※ calculateType이(가) “linear” 이면 필수
coefficientValuelong{calculateType} in [“linear”, “power”]
✓※
0 ~ 9223372036854775805계수
교환 횟수에 따라 코스트가 얼마나 빠르게 상승하는지를 제어하는 승수입니다. linear 모드에서는 각 교환마다 이 값이 코스트에 더해집니다. power 모드에서는 코스트가 coefficientValue ×(교환 횟수 + 1)^2로 계산됩니다.
※ calculateType이(가) “linear”,“power"이면 필수
calculateScriptIdstring{calculateType} == “gs2_script”
✓※
~ 1024자코스트 계산 스크립트의 GRN
Script 트리거 레퍼런스 - calculateCost
※ calculateType이(가) “gs2_script” 이면 필수
exchangeCountIdstring
~ 1024자교환 실행 횟수를 관리하는 GS2-Limit의 횟수 제한 모델 GRN
각 사용자가 이 코스트 상승형 교환을 몇 번 실행했는지 추적하는 GS2-Limit의 횟수 제한 모델을 참조합니다. 카운트는 상승하는 코스트 계산에 사용되며, GS2-Limit의 리셋 타이밍을 사용하여 정기적으로(예: 매일 또는 매주) 리셋할 수 있습니다.
maximumExchangeCountint21474836460 ~ 2147483646교환 횟수 상한
사용자가 이 코스트 상승형 교환을 실행할 수 있는 최대 횟수입니다. 교환 횟수가 이 상한에 도달하면, GS2-Limit에 의한 카운트 리셋까지 이후의 교환이 거부됩니다.
acquireActionsList<AcquireAction>[]0 ~ 100 items획득 액션 리스트
코스트 상승형 교환 완료 시 플레이어가 받는 리소스(보상)를 정의합니다. 보상은 교환 횟수와 관계없이 일정하며, 코스트만 교환마다 증가합니다.