GS2-Exchange Deploy/CDK 레퍼런스
엔티티
Deploy 처리에서 조작 대상이 되는 리소스
Namespace
네임스페이스
네임스페이스는 하나의 프로젝트 내에서 동일한 서비스를 서로 다른 용도로 여러 개 이용하기 위한 엔티티입니다.
GS2의 각 서비스는 네임스페이스 단위로 관리됩니다. 네임스페이스가 다르면 동일한 서비스라도 완전히 독립된 데이터 공간으로 취급됩니다.
따라서 각 서비스의 이용을 시작하려면 먼저 네임스페이스를 생성해야 합니다.
Request
리소스 생성·갱신 요청
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |
|---|---|---|---|---|---|---|
| name | string | ✓ | ~ 128자 | 네임스페이스 이름 네임스페이스 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다. | ||
| description | string | ~ 1024자 | 설명문 | |||
| enableAwaitExchange | bool | false | 교환 결과 수령에 대기 시간이 발생하는 교환 기능을 사용할지 여부 활성화하면 await 타이밍 타입의 교환 레이트 모델을 사용할 수 있습니다. 이러한 교환은 보상을 받기 전에 실시간 경과가 필요하며, 플레이어가 결과를 기다려야 하는 제작이나 생산 계열의 메커니즘을 구현할 수 있습니다. | |||
| enableDirectExchange | bool | true | 직접 교환 API 호출 허용 활성화하면 클라이언트가 교환 API를 직접 호출하여 리소스 교환을 실행할 수 있습니다. 비활성화하면 트랜잭션 액션을 통해서만 교환이 트리거되어, 교환 발생에 대한 서버 측 제어가 더욱 엄격해집니다. | |||
| transactionSetting | TransactionSetting | ✓ | 트랜잭션 설정 교환 조작 시 분산 트랜잭션의 실행 방식을 제어하는 설정입니다. 자동 실행, 원자적 커밋, 비동기 처리 등의 옵션을 지원합니다. | |||
| exchangeScript | ScriptSetting | 교환을 실행하려고 할 때 실행할 스크립트 설정 Script 트리거 레퍼런스 - exchange | ||||
| incrementalExchangeScript | ScriptSetting | 코스트 상승형 교환을 실행하려고 할 때 실행할 스크립트 설정 Script 트리거 레퍼런스 - incrementalExchange | ||||
| acquireAwaitScript | ScriptSetting | 대기 방식 교환 처리에서 대기가 완료되어 보상을 받으려고 할 때 실행할 스크립트 설정 Script 트리거 레퍼런스 - acquireAwait | ||||
| logSetting | LogSetting | 로그 출력 설정 교환 조작의 로그 데이터를 GS2-Log에 출력하기 위한 설정입니다. GS2-Log의 네임스페이스를 지정함으로써 교환, 코스트 상승형 교환, 대기 조작의 API 요청·응답 로그를 수집할 수 있습니다. |
GetAttr
!GetAttr 태그로 취득 가능한 리소스 생성 결과
| 타입 | 설명 | |
|---|---|---|
| Item | Namespace | 생성한 네임스페이스 |
구현 예제
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-0001import (
"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 Templateclass 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 Templatepublic 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 Templateimport 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 TemplateTransactionSetting
트랜잭션 설정
트랜잭션 설정은 트랜잭션의 실행 방법·정합성·비동기 처리·충돌 회피 메커니즘을 제어하는 설정입니다.
자동 실행(AutoRun), 원자적 실행(AtomicCommit), GS2-Distributor를 이용한 비동기 실행, 스크립트 결과의 일괄 적용, GS2-JobQueue를 통한 입수 액션의 비동기화 등을 조합하여 게임 로직에 맞는 견고한 트랜잭션 관리를 가능하게 합니다.
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |
|---|---|---|---|---|---|---|
| enableAutoRun | bool | false | 발행한 트랜잭션을 서버 사이드에서 자동으로 실행할지 여부 | |||
| enableAtomicCommit | bool | {enableAutoRun} == true | false | 트랜잭션의 실행을 원자적으로 커밋할지 여부 ※ enableAutoRun이(가) true 이면 활성화 | ||
| transactionUseDistributor | bool | {enableAtomicCommit} == true | false | 트랜잭션을 비동기 처리로 실행할지 여부 ※ enableAtomicCommit이(가) true 이면 활성화 | ||
| commitScriptResultInUseDistributor | bool | {transactionUseDistributor} == true | false | 스크립트의 결과 커밋 처리를 비동기 처리로 실행할지 여부 ※ transactionUseDistributor이(가) true 이면 활성화 | ||
| acquireActionUseJobQueue | bool | {enableAtomicCommit} == true | false | 입수 액션을 실행할 때 GS2-JobQueue를 사용할지 여부 ※ 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
스크립트 설정
GS2에서는 마이크로서비스의 이벤트에 연결하여 커스텀 스크립트를 실행할 수 있습니다.
이 모델은 스크립트 실행을 트리거하기 위한 설정을 보유합니다.
스크립트 실행 방식은 크게 두 가지로, 바로 “동기 실행"과 “비동기 실행"입니다.
동기 실행은 스크립트 실행이 완료될 때까지 처리가 블록됩니다.
대신 스크립트 실행 결과를 이용하여 API 실행을 중단시키거나 API 응답 내용을 제어할 수 있습니다.
한편, 비동기 실행에서는 스크립트 완료를 기다리기 위해 처리가 블록되는 일이 없습니다.
다만 스크립트 실행 결과를 이용하여 API 실행을 중단하거나 API 응답 내용을 변경할 수는 없습니다.
비동기 실행은 API의 응답 흐름에 영향을 주지 않으므로 원칙적으로 비동기 실행을 권장합니다.
비동기 실행에는 실행 방식이 두 가지 있으며, GS2-Script와 Amazon EventBridge가 있습니다.
Amazon EventBridge를 사용함으로써 Lua 이외의 언어로 처리를 작성할 수 있습니다.
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| triggerScriptId | string | ~ 1024자 | API 실행 시 동기적으로 실행되는 GS2-Script의 스크립트
GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다. | |||||||||||
| doneTriggerTargetType | 문자열 열거형 enum { “none”, “gs2_script”, “aws” } | “none” | 비동기 스크립트의 실행 방법 비동기 실행에서 사용할 스크립트의 종류를 지정합니다. “비동기 실행의 스크립트를 사용하지 않음(none)”, “GS2-Script를 사용함(gs2_script)”, “Amazon EventBridge를 사용함(aws)” 중에서 선택할 수 있습니다.
| |||||||||||
| doneTriggerScriptId | string | {doneTriggerTargetType} == “gs2_script” | ~ 1024자 | 비동기 실행할 GS2-Script 스크립트
GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다. ※ doneTriggerTargetType이(가) “gs2_script” 이면 활성화 | ||||||||||
| doneTriggerQueueNamespaceId | string | {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에서는 실시간으로 로그가 제공되어 시스템 모니터링, 분석, 디버깅 등에 이용할 수 있습니다.
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |
|---|---|---|---|---|---|---|
| loggingNamespaceId | string | ✓ | ~ 1024자 | 로그를 출력할 GS2-Log의 네임스페이스
GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다. |
CurrentRateMaster
현재 활성화된 레이트 모델의 마스터 데이터
이 마스터 데이터는 현재 네임스페이스 내에서 유효한 레이트 모델의 정의를 기술한 것입니다.
GS2에서는 마스터 데이터의 관리에 JSON 형식의 파일을 사용합니다.
파일을 업로드함으로써 실제로 서버에 설정을 반영할 수 있습니다.
JSON 파일을 작성하는 방법으로, 매니지먼트 콘솔 내에 마스터 데이터 에디터를 제공하고 있습니다.
또한 게임 운영에 더 적합한 도구를 직접 만들어 적절한 포맷의 JSON 파일을 출력하는 방식으로도 서비스를 이용할 수 있습니다.
JSON 파일 형식에 대해서는 GS2-Exchange 마스터 데이터 레퍼런스를 참조해 주세요.
Request
리소스 생성·갱신 요청
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| namespaceName | string | ✓ | ~ 128자 | 네임스페이스 이름 네임스페이스 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다. | ||||||||
| mode | 문자열 열거형 enum { “direct”, “preUpload” } | “direct” | 업데이트 모드
| |||||||||
| settings | string | {mode} == “direct” | ✓※ | ~ 5242880 바이트 (5MB) | 마스터 데이터 ※ mode이(가) “direct” 이면 필수 | |||||||
| uploadToken | string | {mode} == “preUpload” | ✓※ | ~ 1024자 | 사전 업로드로 획득한 토큰 업로드한 마스터 데이터를 적용하기 위해 사용됩니다. ※ mode이(가) “preUpload” 이면 필수 |
GetAttr
!GetAttr 태그로 취득 가능한 리소스 생성 결과
| 타입 | 설명 | |
|---|---|---|
| Item | CurrentRateMaster | 갱신된 현재 활성화된 레이트 모델의 마스터 데이터 |
구현 예제
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: nullimport (
"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 Templateclass 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 Templatepublic 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 Templateimport 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 TemplateRateModel
교환 레이트 모델
교환 레이트 모델은 리소스와 리소스를 교환할 때 사용하는 레이트를 정의하는 엔티티입니다.
즉시 교환할 수 있는 레이트뿐만 아니라, 현실 시간으로 일정 시간이 경과한 후에 교환할 수 있는 레이트도 설정할 수 있습니다.
현실 시간의 경과가 필요한 교환 레이트에는 즉시 교환을 실행하는 데 필요한 리소스를 추가로 정의할 수 있습니다.
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| rateModelId | string | ※ | ~ 1024자 | 교환 레이트 모델 GRN
※ 서버가 자동으로 설정 | ||||||||
| name | string | ✓ | ~ 128자 | 교환 레이트 모델 이름 교환 레이트 모델 종류 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다. | ||||||||
| metadata | string | ~ 2048자 | 메타데이터 메타데이터에는 임의의 값을 설정할 수 있습니다. 이 값들은 GS2의 동작에는 영향을 주지 않으므로, 게임 내에서 사용하는 정보를 저장하는 용도로 사용할 수 있습니다. | |||||||||
| verifyActions | List<VerifyAction> | [] | 0 ~ 10 items | 검증 액션 리스트 교환이 실행되기 전에 모두 통과해야 하는 사전 조건 체크입니다. 검증 액션 중 하나라도 실패하면, 리소스를 소비하지 않고 교환이 중단됩니다. 레벨 요건이나 인벤토리 용량 등의 조건을 강제하기 위해 사용됩니다. | ||||||||
| consumeActions | List<ConsumeAction> | [] | 0 ~ 10 items | 소비 액션 리스트 이 교환을 실행하기 위해 플레이어가 지불해야 하는 리소스(코스트)를 정의합니다. 여러 개의 소비 액션을 지정할 수 있어, 골드와 아이템을 모두 필요로 하는 것과 같은 복잡한 교환 코스트를 구현할 수 있습니다. 이러한 액션은 분산 트랜잭션 내의 소비 액션으로 실행됩니다. | ||||||||
| timingType | 문자열 열거형 enum { “immediate”, “await” } | “immediate” | 교환 종류 교환 실행 후 보상이 언제 전달되는지를 결정합니다. immediate는 교환 실행 시 즉시 보상을 전달합니다. await는 보상을 받기 전에 실시간의 경과가 필요하며, 대기 기간(예: 제작 시간)을 둡니다.
| |||||||||
| lockTime | int | {timingType} == “await” | ✓※ | 0 ~ 538214400 | 교환 실행부터 실제로 보상을 받을 수 있게 될 때까지의 대기 시간(분) timingType이 await인 경우에만 적용됩니다. 교환이 시작된 후 플레이어가 보상을 받을 수 있게 되기까지 경과해야 하는 실시간 분수를 지정합니다. 대기 시간은 스킵 기능을 사용하여 단축할 수 있습니다.※ timingType이(가) “await” 이면 필수 | |||||||
| acquireActions | List<AcquireAction> | [] | 0 ~ 100 items | 획득 액션 리스트 교환 완료 시 플레이어가 받는 리소스(보상)를 정의합니다. 여러 개의 획득 액션을 지정하여 다양한 리소스 타입을 동시에 지급할 수 있습니다. 이러한 액션은 분산 트랜잭션 내의 획득 액션으로 실행됩니다. |
AcquireAction
입수 액션
ConsumeAction
소비 액션
VerifyAction
검증 액션
IncrementalRateModel
코스트 상승형 교환 레이트 모델
일반적인 교환 레이트는 항상 일정한 레이트로 교환을 제공합니다.
상승형 교환 레이트에서는 교환 횟수에 따라 코스트가 상승하는 레이트를 정의할 수 있습니다.
예를 들어, 첫 번째 교환에서는 1:1로 교환할 수 있지만, 두 번째 교환에서는 2:1로 교환하게 되는 것과 같은 레이트를 정의할 수 있습니다.
이러한 레이트를 정의함으로써 플레이어가 게임을 진행함에 따라 얻을 수 있는 리소스의 가치를 높일 수 있습니다.
교환 횟수는 현실 시간의 경과에 따라 리셋할 수 있습니다.
이 기능을 이용하면 매일 또는 매주 교환에 필요한 코스트를 리셋할 수 있습니다.
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| incrementalRateModelId | string | ※ | ~ 1024자 | 코스트 상승형 교환 레이트 모델 GRN
※ 서버가 자동으로 설정 | ||||||||||
| name | string | ✓ | ~ 128자 | 코스트 상승형 교환 레이트 모델의 이름 코스트 상승형 교환 레이트 모델 종류 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다. | ||||||||||
| metadata | string | ~ 2048자 | 메타데이터 메타데이터에는 임의의 값을 설정할 수 있습니다. 이 값들은 GS2의 동작에는 영향을 주지 않으므로, 게임 내에서 사용하는 정보를 저장하는 용도로 사용할 수 있습니다. | |||||||||||
| consumeAction | ConsumeAction | ✓ | 소비 액션 (수량/값은 자동으로 덮어써집니다) 교환 비용으로 소비되는 리소스의 종류를 정의합니다. 실제 수량은 교환 횟수와 계산 방식(선형, 거듭제곱, 스크립트)에 기반하여 동적으로 계산됩니다. 액션 종류와 대상 리소스만 지정하면 되며, 수량 필드는 자동으로 덮어써집니다. | |||||||||||
| calculateType | 문자열 열거형 enum { “linear”, “power”, “gs2_script” } | ✓ | 코스트 상승량 계산 방식 교환 횟수에 따라 코스트가 어떻게 상승하는지를 결정합니다. linear는 코스트를 baseValue +(coefficientValue × 교환 횟수)로 계산합니다. power는 코스트를 coefficientValue ×(교환 횟수 + 1)^2로 계산합니다. gs2_script는 임의의 로직을 위해 커스텀 GS2-Script에 계산을 위임합니다.
| |||||||||||
| baseValue | long | {calculateType} == “linear” | ✓※ | 0 ~ 9223372036854775805 | 베이스 값linear 계산 방식을 사용하는 경우 첫 교환 시의 기본 코스트입니다. 합계 코스트는 baseValue +(coefficientValue × 교환 횟수)로 계산됩니다.※ calculateType이(가) “linear” 이면 필수 | |||||||||
| coefficientValue | long | {calculateType} in [“linear”, “power”] | ✓※ | 0 ~ 9223372036854775805 | 계수 교환 횟수에 따라 코스트가 얼마나 빠르게 상승하는지를 제어하는 승수입니다. linear 모드에서는 각 교환마다 이 값이 코스트에 더해집니다. power 모드에서는 코스트가 coefficientValue ×(교환 횟수 + 1)^2로 계산됩니다.※ calculateType이(가) “linear”,“power"이면 필수 | |||||||||
| calculateScriptId | string | {calculateType} == “gs2_script” | ✓※ | ~ 1024자 | 코스트 계산 스크립트의 GRN
Script 트리거 레퍼런스 - calculateCost※ calculateType이(가) “gs2_script” 이면 필수 | |||||||||
| exchangeCountId | string | ✓ | ~ 1024자 | 교환 실행 횟수를 관리하는 GS2-Limit의 횟수 제한 모델 GRN
각 사용자가 이 코스트 상승형 교환을 몇 번 실행했는지 추적하는 GS2-Limit의 횟수 제한 모델을 참조합니다. 카운트는 상승하는 코스트 계산에 사용되며, GS2-Limit의 리셋 타이밍을 사용하여 정기적으로(예: 매일 또는 매주) 리셋할 수 있습니다. | ||||||||||
| maximumExchangeCount | int | 2147483646 | 0 ~ 2147483646 | 교환 횟수 상한 사용자가 이 코스트 상승형 교환을 실행할 수 있는 최대 횟수입니다. 교환 횟수가 이 상한에 도달하면, GS2-Limit에 의한 카운트 리셋까지 이후의 교환이 거부됩니다. | ||||||||||
| acquireActions | List<AcquireAction> | [] | 0 ~ 100 items | 획득 액션 리스트 코스트 상승형 교환 완료 시 플레이어가 받는 리소스(보상)를 정의합니다. 보상은 교환 횟수와 관계없이 일정하며, 코스트만 교환마다 증가합니다. |