GS2-Inventory GS2-Deploy/CDK リファレンス
エンティティ
Deploy処理で操作する対象リソース
Namespace
ネームスペース
ネームスペースは一つのプロジェクトで同じサービスを異なる用途で複数利用できるようにするための仕組みです。
GS2 の各サービスはネームスペース単位で管理されます。ネームスペースが異なれば、同じサービスでも完全に独立したデータ空間として扱われます。
そのため、各サービスの利用を開始するにあたってネームスペースを作成する必要があります。
Request
リソースの生成リクエスト
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |
|---|---|---|---|---|---|---|
| namespaceName | string | ✓ | ~ 128文字 | ネームスペース名 | ||
| description | string | ~ 1024文字 | 説明文 | |||
| transactionSetting | TransactionSetting | トランザクション設定 | ||||
| acquireScript | ScriptSetting | アイテムを入手したときに実行するスクリプト | ||||
| overflowScript | ScriptSetting | 入手上限に当たって入手できなかったときに実行するスクリプト | ||||
| consumeScript | ScriptSetting | アイテムを消費するときに実行するスクリプト | ||||
| simpleItemAcquireScript | ScriptSetting | シンプルアイテムを入手したときに実行するスクリプト | ||||
| simpleItemConsumeScript | ScriptSetting | シンプルアイテムを消費するときに実行するスクリプト | ||||
| bigItemAcquireScript | ScriptSetting | 巨大アイテムを入手したときに実行するスクリプト | ||||
| bigItemConsumeScript | ScriptSetting | 巨大アイテムを消費するときに実行するスクリプト | ||||
| logSetting | LogSetting | ログの出力設定 |
GetAttr
!GetAttrタグで取得可能なリソースの生成結果
| 型 | 説明 | |
|---|---|---|
| Item | Namespace | 作成したネームスペース |
実装例
Type: GS2::Inventory::Namespace
Properties:
Name: namespace-0001
Description: null
TransactionSetting: null
AcquireScript: null
OverflowScript: null
ConsumeScript: null
SimpleItemAcquireScript: null
SimpleItemConsumeScript: null
BigItemAcquireScript: null
BigItemConsumeScript: 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/inventory"
"github.com/openlyinc/pointy"
)
SampleStack := core.NewStack()
inventory.NewNamespace(
&SampleStack,
"namespace-0001",
inventory.NamespaceOptions{
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\Inventory\Model\Namespace_(
stack: $this,
name: "namespace-0001",
options: new \Gs2Cdk\Inventory\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
class SampleStack extends io.gs2.cdk.core.model.Stack
{
public SampleStack() {
super();
new io.gs2.cdk.inventory.model.Namespace(
this,
"namespace-0001",
new io.gs2.cdk.inventory.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 Templatepublic class SampleStack : Gs2Cdk.Core.Model.Stack
{
public SampleStack() {
new Gs2Cdk.Gs2Inventory.Model.Namespace(
stack: this,
name: "namespace-0001",
options: new Gs2Cdk.Gs2Inventory.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 Templateimport core from "@/gs2cdk/core";
import inventory from "@/gs2cdk/inventory";
class SampleStack extends core.Stack
{
public constructor() {
super();
new inventory.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
from gs2_cdk import Stack, core, inventory
class SampleStack(Stack):
def __init__(self):
super().__init__()
inventory.Namespace(
stack=self,
name='namespace-0001',
options=inventory.NamespaceOptions(
log_setting=core.LogSetting(
logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001',
),
),
)
print(SampleStack().yaml()) # Generate TemplateTransactionSetting
トランザクション設定
トランザクション設定は、トランザクションの実行方法・整合性・非同期処理・競合回避の仕組みを制御する設定です。
自動実行(AutoRun)、アトミック実行(AtomicCommit)、非同期実行(Distributor)、スクリプト結果の一括適用、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 ではマイクロサービスのイベントに関連づけて、カスタムスクリプトを実行することができます。
このモデルは、スクリプトの実行をトリガーするための設定を保持します。
スクリプトの実行方式は大きく2種類あり、それは「同期実行」と「非同期実行」です。
同期実行は、スクリプトの実行が完了するまで処理がブロックされます。
代わりに、スクリプトの実行結果を使ってAPIの実行を止めたり、APIの結果を改ざんすることができます。
一方、非同期実行ではスクリプトの完了を待つために処理がブロックされることはありません。
ただし、スクリプトの実行結果を利用して API の実行を停止したり、API の応答内容を変更することはできません。
非同期実行は API の応答フローに影響を与えないため、原則として非同期実行を推奨します。
非同期実行には実行方式が2種類あり、GS2-Script と Amazon EventBridge があります。
Amazon EventBridge を使用することで、Lua 以外の言語で処理を記述することができます。
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| triggerScriptId | string | ~ 1024文字 | 同期実行スクリプトの 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で指定する必要があります。 |
CurrentItemModelMaster
現在アクティブなマスターデータ
現在ネームスペース内で有効な、アイテムモデルの定義を記述したマスターデータです。
GS2ではマスターデータの管理にJSON形式のファイルを使用します。
ファイルをアップロードすることで、実際にサーバーに設定を反映することができます。
JSONファイルを作成する方法として、マネージメントコンソール内にマスターデータエディタを提供しています。
また、よりゲームの運営に相応しいツールを作成し、適切なフォーマットのJSONファイルを書き出すことでもサービスを利用可能です。
Note
JSONファイルの形式については GS2-Inventory マスターデータリファレンス をご参照ください。Request
リソースの生成リクエスト
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| namespaceName | string | ✓ | ~ 128文字 | ネームスペース名 | ||||||||
| mode | 文字列列挙型 enum { “direct”, “preUpload” } | ✓ | “direct” | 更新モード
| ||||||||
| settings | string | {mode} == “direct” | ✓* | ~ 5242880文字 | マスターデータ ※ mode が “direct” であれば必須 | |||||||
| uploadToken | string | {mode} == “preUpload” | ✓* | ~ 1024文字 | プレアップロードで取得したトークン ※ mode が “preUpload” であれば必須 |
GetAttr
!GetAttrタグで取得可能なリソースの生成結果
| 型 | 説明 | |
|---|---|---|
| Item | CurrentItemModelMaster | 更新した現在アクティブなアイテムモデルのマスターデータ |
実装例
Type: GS2::Inventory::CurrentItemModelMaster
Properties:
NamespaceName: namespace-0001
Mode: direct
Settings: {
"version": "2019-02-05",
"inventoryModels": [
{
"name": "item",
"initialCapacity": 100,
"maxCapacity": 999,
"itemModels": [
{
"name": "item-0001",
"metadata": "ITEM_0001",
"stackingLimit": 99,
"allowMultipleStacks": false,
"sortValue": 1
},
{
"name": "item-0002",
"metadata": "ITEM_0002",
"stackingLimit": 49,
"allowMultipleStacks": true,
"sortValue": 2
},
{
"name": "item-0003",
"metadata": "ITEM_0003",
"stackingLimit": 9,
"allowMultipleStacks": false,
"sortValue": 3
}
],
"metadata": "INVENTORY_ITEM"
},
{
"name": "character",
"initialCapacity": 50,
"maxCapacity": 99,
"itemModels": [
{
"name": "character-0001",
"metadata": "CHARACTER_0001",
"stackingLimit": 99,
"allowMultipleStacks": false,
"sortValue": 1
},
{
"name": "character-0002",
"metadata": "CHARACTER_0002",
"stackingLimit": 49,
"allowMultipleStacks": true,
"sortValue": 2
},
{
"name": "character-0003",
"metadata": "CHARACTER_0003",
"stackingLimit": 9,
"allowMultipleStacks": false,
"sortValue": 3
}
],
"metadata": "INVENTORY_CHARACTER"
}
],
"simpleInventoryModels": [
{
"name": "item",
"simpleItemModels": [
{
"name": "item-0001",
"metadata": "ITEM_0001"
},
{
"name": "item-0002",
"metadata": "ITEM_0002"
},
{
"name": "item-0003",
"metadata": "ITEM_0003"
}
],
"metadata": "INVENTORY_ITEM"
}
],
"bigInventoryModels": [
{
"name": "item",
"bigItemModels": [
{
"name": "item-0001",
"metadata": "ITEM_0001"
},
{
"name": "item-0002",
"metadata": "ITEM_0002"
},
{
"name": "item-0003",
"metadata": "ITEM_0003"
}
],
"metadata": "INVENTORY_ITEM"
}
]
}
UploadToken: nullimport (
"github.com/gs2io/gs2-golang-cdk/core"
"github.com/gs2io/gs2-golang-cdk/inventory"
"github.com/openlyinc/pointy"
)
SampleStack := core.NewStack()
inventory.NewNamespace(
&SampleStack,
"namespace-0001",
inventory.NamespaceOptions{},
).MasterData(
[]inventory.InventoryModel{
inventory.NewInventoryModel(
"item",
100,
999,
[]inventory.ItemModel{
inventory.NewItemModel(
"item-0001",
99,
false,
1,
inventory.ItemModelOptions{
Metadata: pointy.String("ITEM_0001"),
},
),
inventory.NewItemModel(
"item-0002",
49,
true,
2,
inventory.ItemModelOptions{
Metadata: pointy.String("ITEM_0002"),
},
),
inventory.NewItemModel(
"item-0003",
9,
false,
3,
inventory.ItemModelOptions{
Metadata: pointy.String("ITEM_0003"),
},
),
},
inventory.InventoryModelOptions{
Metadata: pointy.String("INVENTORY_ITEM"),
},
),
inventory.NewInventoryModel(
"character",
50,
99,
[]inventory.ItemModel{
inventory.NewItemModel(
"character-0001",
99,
false,
1,
inventory.ItemModelOptions{
Metadata: pointy.String("CHARACTER_0001"),
},
),
inventory.NewItemModel(
"character-0002",
49,
true,
2,
inventory.ItemModelOptions{
Metadata: pointy.String("CHARACTER_0002"),
},
),
inventory.NewItemModel(
"character-0003",
9,
false,
3,
inventory.ItemModelOptions{
Metadata: pointy.String("CHARACTER_0003"),
},
),
},
inventory.InventoryModelOptions{
Metadata: pointy.String("INVENTORY_CHARACTER"),
},
),
},
[]inventory.SimpleInventoryModel{
inventory.NewSimpleInventoryModel(
"item",
[]inventory.SimpleItemModel{
inventory.NewSimpleItemModel(
"item-0001",
inventory.SimpleItemModelOptions{
Metadata: pointy.String("ITEM_0001"),
},
),
inventory.NewSimpleItemModel(
"item-0002",
inventory.SimpleItemModelOptions{
Metadata: pointy.String("ITEM_0002"),
},
),
inventory.NewSimpleItemModel(
"item-0003",
inventory.SimpleItemModelOptions{
Metadata: pointy.String("ITEM_0003"),
},
),
},
inventory.SimpleInventoryModelOptions{
Metadata: pointy.String("INVENTORY_ITEM"),
},
),
},
[]inventory.BigInventoryModel{
inventory.NewBigInventoryModel(
"item",
[]inventory.BigItemModel{
inventory.NewBigItemModel(
"item-0001",
inventory.BigItemModelOptions{
Metadata: pointy.String("ITEM_0001"),
},
),
inventory.NewBigItemModel(
"item-0002",
inventory.BigItemModelOptions{
Metadata: pointy.String("ITEM_0002"),
},
),
inventory.NewBigItemModel(
"item-0003",
inventory.BigItemModelOptions{
Metadata: pointy.String("ITEM_0003"),
},
),
},
inventory.BigInventoryModelOptions{
Metadata: pointy.String("INVENTORY_ITEM"),
},
),
},
)
println(SampleStack.Yaml()) // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
function __construct() {
parent::__construct();
(new \Gs2Cdk\Inventory\Model\Namespace_(
stack: $this,
name: "namespace-0001"
))->masterData(
[
new \Gs2Cdk\Inventory\Model\InventoryModel(
name:"item",
initialCapacity:100,
maxCapacity:999,
itemModels:[
new \Gs2Cdk\Inventory\Model\ItemModel(
name: "item-0001",
stackingLimit: 99,
allowMultipleStacks: False,
sortValue: 1,
options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
metadata: "ITEM_0001",
)
),
new \Gs2Cdk\Inventory\Model\ItemModel(
name: "item-0002",
stackingLimit: 49,
allowMultipleStacks: True,
sortValue: 2,
options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
metadata: "ITEM_0002",
)
),
new \Gs2Cdk\Inventory\Model\ItemModel(
name: "item-0003",
stackingLimit: 9,
allowMultipleStacks: False,
sortValue: 3,
options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
metadata: "ITEM_0003",
)
),
],
options: new \Gs2Cdk\Inventory\Model\Options\InventoryModelOptions(
metadata:"INVENTORY_ITEM"
)
),
new \Gs2Cdk\Inventory\Model\InventoryModel(
name:"character",
initialCapacity:50,
maxCapacity:99,
itemModels:[
new \Gs2Cdk\Inventory\Model\ItemModel(
name: "character-0001",
stackingLimit: 99,
allowMultipleStacks: False,
sortValue: 1,
options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
metadata: "CHARACTER_0001",
)
),
new \Gs2Cdk\Inventory\Model\ItemModel(
name: "character-0002",
stackingLimit: 49,
allowMultipleStacks: True,
sortValue: 2,
options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
metadata: "CHARACTER_0002",
)
),
new \Gs2Cdk\Inventory\Model\ItemModel(
name: "character-0003",
stackingLimit: 9,
allowMultipleStacks: False,
sortValue: 3,
options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
metadata: "CHARACTER_0003",
)
),
],
options: new \Gs2Cdk\Inventory\Model\Options\InventoryModelOptions(
metadata:"INVENTORY_CHARACTER"
)
)
],
[
new \Gs2Cdk\Inventory\Model\SimpleInventoryModel(
name:"item",
simpleItemModels:[
new \Gs2Cdk\Inventory\Model\SimpleItemModel(
name: "item-0001",
options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
metadata: "ITEM_0001",
)
),
new \Gs2Cdk\Inventory\Model\SimpleItemModel(
name: "item-0002",
options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
metadata: "ITEM_0002",
)
),
new \Gs2Cdk\Inventory\Model\SimpleItemModel(
name: "item-0003",
options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
metadata: "ITEM_0003",
)
),
],
options: new \Gs2Cdk\Inventory\Model\Options\SimpleInventoryModelOptions(
metadata:"INVENTORY_ITEM"
)
)
],
[
new \Gs2Cdk\Inventory\Model\BigInventoryModel(
name:"item",
bigItemModels:[
new \Gs2Cdk\Inventory\Model\BigItemModel(
name: "item-0001",
options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
metadata: "ITEM_0001",
)
),
new \Gs2Cdk\Inventory\Model\BigItemModel(
name: "item-0002",
options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
metadata: "ITEM_0002",
)
),
new \Gs2Cdk\Inventory\Model\BigItemModel(
name: "item-0003",
options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
metadata: "ITEM_0003",
)
),
],
options: new \Gs2Cdk\Inventory\Model\Options\BigInventoryModelOptions(
metadata:"INVENTORY_ITEM"
)
)
]
);
}
}
print((new SampleStack())->yaml()); // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
public SampleStack() {
super();
new io.gs2.cdk.inventory.model.Namespace(
this,
"namespace-0001"
).masterData(
Arrays.asList(
new io.gs2.cdk.inventory.model.InventoryModel(
"item",
100,
999,
Arrays.asList(
new io.gs2.cdk.inventory.model.ItemModel(
"item-0001",
99L,
false,
1,
new io.gs2.cdk.inventory.model.options.ItemModelOptions()
.withMetadata("ITEM_0001")
),
new io.gs2.cdk.inventory.model.ItemModel(
"item-0002",
49L,
true,
2,
new io.gs2.cdk.inventory.model.options.ItemModelOptions()
.withMetadata("ITEM_0002")
),
new io.gs2.cdk.inventory.model.ItemModel(
"item-0003",
9L,
false,
3,
new io.gs2.cdk.inventory.model.options.ItemModelOptions()
.withMetadata("ITEM_0003")
)
),
new io.gs2.cdk.inventory.model.options.InventoryModelOptions()
.withMetadata("INVENTORY_ITEM")
),
new io.gs2.cdk.inventory.model.InventoryModel(
"character",
50,
99,
Arrays.asList(
new io.gs2.cdk.inventory.model.ItemModel(
"character-0001",
99L,
false,
1,
new io.gs2.cdk.inventory.model.options.ItemModelOptions()
.withMetadata("CHARACTER_0001")
),
new io.gs2.cdk.inventory.model.ItemModel(
"character-0002",
49L,
true,
2,
new io.gs2.cdk.inventory.model.options.ItemModelOptions()
.withMetadata("CHARACTER_0002")
),
new io.gs2.cdk.inventory.model.ItemModel(
"character-0003",
9L,
false,
3,
new io.gs2.cdk.inventory.model.options.ItemModelOptions()
.withMetadata("CHARACTER_0003")
)
),
new io.gs2.cdk.inventory.model.options.InventoryModelOptions()
.withMetadata("INVENTORY_CHARACTER")
)
),
Arrays.asList(
new io.gs2.cdk.inventory.model.SimpleInventoryModel(
"item",
Arrays.asList(
new io.gs2.cdk.inventory.model.SimpleItemModel(
"item-0001",
new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
.withMetadata("ITEM_0001")
),
new io.gs2.cdk.inventory.model.SimpleItemModel(
"item-0002",
new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
.withMetadata("ITEM_0002")
),
new io.gs2.cdk.inventory.model.SimpleItemModel(
"item-0003",
new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
.withMetadata("ITEM_0003")
)
),
new io.gs2.cdk.inventory.model.options.SimpleInventoryModelOptions()
.withMetadata("INVENTORY_ITEM")
)
),
Arrays.asList(
new io.gs2.cdk.inventory.model.BigInventoryModel(
"item",
Arrays.asList(
new io.gs2.cdk.inventory.model.BigItemModel(
"item-0001",
new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
.withMetadata("ITEM_0001")
),
new io.gs2.cdk.inventory.model.BigItemModel(
"item-0002",
new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
.withMetadata("ITEM_0002")
),
new io.gs2.cdk.inventory.model.BigItemModel(
"item-0003",
new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
.withMetadata("ITEM_0003")
)
),
new io.gs2.cdk.inventory.model.options.BigInventoryModelOptions()
.withMetadata("INVENTORY_ITEM")
)
)
);
}
}
System.out.println(new SampleStack().yaml()); // Generate Templatepublic class SampleStack : Gs2Cdk.Core.Model.Stack
{
public SampleStack() {
new Gs2Cdk.Gs2Inventory.Model.Namespace(
stack: this,
name: "namespace-0001"
).MasterData(
new Gs2Cdk.Gs2Inventory.Model.InventoryModel[] {
new Gs2Cdk.Gs2Inventory.Model.InventoryModel(
name: "item",
initialCapacity: 100,
maxCapacity: 999,
itemModels: new Gs2Cdk.Gs2Inventory.Model.ItemModel[]
{
new Gs2Cdk.Gs2Inventory.Model.ItemModel(
name: "item-0001",
stackingLimit: 99L,
allowMultipleStacks: false,
sortValue: 1,
options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
{
metadata = "ITEM_0001"
}
),
new Gs2Cdk.Gs2Inventory.Model.ItemModel(
name: "item-0002",
stackingLimit: 49L,
allowMultipleStacks: true,
sortValue: 2,
options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
{
metadata = "ITEM_0002"
}
),
new Gs2Cdk.Gs2Inventory.Model.ItemModel(
name: "item-0003",
stackingLimit: 9L,
allowMultipleStacks: false,
sortValue: 3,
options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
{
metadata = "ITEM_0003"
}
)
},
options: new Gs2Cdk.Gs2Inventory.Model.Options.InventoryModelOptions
{
metadata = "INVENTORY_ITEM"
}
),
new Gs2Cdk.Gs2Inventory.Model.InventoryModel(
name: "character",
initialCapacity: 50,
maxCapacity: 99,
itemModels: new Gs2Cdk.Gs2Inventory.Model.ItemModel[]
{
new Gs2Cdk.Gs2Inventory.Model.ItemModel(
name: "character-0001",
stackingLimit: 99L,
allowMultipleStacks: false,
sortValue: 1,
options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
{
metadata = "CHARACTER_0001"
}
),
new Gs2Cdk.Gs2Inventory.Model.ItemModel(
name: "character-0002",
stackingLimit: 49L,
allowMultipleStacks: true,
sortValue: 2,
options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
{
metadata = "CHARACTER_0002"
}
),
new Gs2Cdk.Gs2Inventory.Model.ItemModel(
name: "character-0003",
stackingLimit: 9L,
allowMultipleStacks: false,
sortValue: 3,
options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
{
metadata = "CHARACTER_0003"
}
)
},
options: new Gs2Cdk.Gs2Inventory.Model.Options.InventoryModelOptions
{
metadata = "INVENTORY_CHARACTER"
}
)
},
new Gs2Cdk.Gs2Inventory.Model.SimpleInventoryModel[] {
new Gs2Cdk.Gs2Inventory.Model.SimpleInventoryModel(
name: "item",
simpleItemModels: new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel[]
{
new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
name: "item-0001",
options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
{
metadata = "ITEM_0001"
}
),
new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
name: "item-0002",
options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
{
metadata = "ITEM_0002"
}
),
new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
name: "item-0003",
options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
{
metadata = "ITEM_0003"
}
)
},
options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleInventoryModelOptions
{
metadata = "INVENTORY_ITEM"
}
)
},
new Gs2Cdk.Gs2Inventory.Model.BigInventoryModel[] {
new Gs2Cdk.Gs2Inventory.Model.BigInventoryModel(
name: "item",
bigItemModels: new Gs2Cdk.Gs2Inventory.Model.BigItemModel[]
{
new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
name: "item-0001",
options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
{
metadata = "ITEM_0001"
}
),
new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
name: "item-0002",
options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
{
metadata = "ITEM_0002"
}
),
new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
name: "item-0003",
options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
{
metadata = "ITEM_0003"
}
)
},
options: new Gs2Cdk.Gs2Inventory.Model.Options.BigInventoryModelOptions
{
metadata = "INVENTORY_ITEM"
}
)
}
);
}
}
Debug.Log(new SampleStack().Yaml()); // Generate Templateimport core from "@/gs2cdk/core";
import inventory from "@/gs2cdk/inventory";
class SampleStack extends core.Stack
{
public constructor() {
super();
new inventory.model.Namespace(
this,
"namespace-0001",
).masterData(
[
new inventory.model.InventoryModel(
"item",
100,
999,
[
new inventory.model.ItemModel(
"item-0001",
99,
false,
1,
{
metadata: "ITEM_0001"
}
),
new inventory.model.ItemModel(
"item-0002",
49,
true,
2,
{
metadata: "ITEM_0002"
}
),
new inventory.model.ItemModel(
"item-0003",
9,
false,
3,
{
metadata: "ITEM_0003"
}
),
],
{
metadata: "INVENTORY_ITEM"
}
),
new inventory.model.InventoryModel(
"character",
50,
99,
[
new inventory.model.ItemModel(
"character-0001",
99,
false,
1,
{
metadata: "CHARACTER_0001"
}
),
new inventory.model.ItemModel(
"character-0002",
49,
true,
2,
{
metadata: "CHARACTER_0002"
}
),
new inventory.model.ItemModel(
"character-0003",
9,
false,
3,
{
metadata: "CHARACTER_0003"
}
),
],
{
metadata: "INVENTORY_CHARACTER"
}
)
],
[
new inventory.model.SimpleInventoryModel(
"item",
[
new inventory.model.SimpleItemModel(
"item-0001",
{
metadata: "ITEM_0001"
}
),
new inventory.model.SimpleItemModel(
"item-0002",
{
metadata: "ITEM_0002"
}
),
new inventory.model.SimpleItemModel(
"item-0003",
{
metadata: "ITEM_0003"
}
),
],
{
metadata: "INVENTORY_ITEM"
}
)
],
[
new inventory.model.BigInventoryModel(
"item",
[
new inventory.model.BigItemModel(
"item-0001",
{
metadata: "ITEM_0001"
}
),
new inventory.model.BigItemModel(
"item-0002",
{
metadata: "ITEM_0002"
}
),
new inventory.model.BigItemModel(
"item-0003",
{
metadata: "ITEM_0003"
}
),
],
{
metadata: "INVENTORY_ITEM"
}
)
]
);
}
}
console.log(new SampleStack().yaml()); // Generate Template
from gs2_cdk import Stack, core, inventory
class SampleStack(Stack):
def __init__(self):
super().__init__()
inventory.Namespace(
stack=self,
name="namespace-0001",
).master_data(
inventory_models=[
inventory.InventoryModel(
name='item',
initial_capacity=100,
max_capacity=999,
item_models=[
inventory.ItemModel(
name='item-0001',
stacking_limit=99,
allow_multiple_stacks=False,
sort_value=1,
options=inventory.ItemModelOptions(
metadata='ITEM_0001',
),
),
inventory.ItemModel(
name='item-0002',
stacking_limit=49,
allow_multiple_stacks=True,
sort_value=2,
options=inventory.ItemModelOptions(
metadata='ITEM_0002',
),
),
inventory.ItemModel(
name='item-0003',
stacking_limit=9,
allow_multiple_stacks=False,
sort_value=3,
options=inventory.ItemModelOptions(
metadata='ITEM_0003',
),
),
],
options=inventory.InventoryModelOptions(
metadata = 'INVENTORY_ITEM'
),
),
inventory.InventoryModel(
name='character',
initial_capacity=50,
max_capacity=99,
item_models=[
inventory.ItemModel(
name='character-0001',
stacking_limit=99,
allow_multiple_stacks=False,
sort_value=1,
options=inventory.ItemModelOptions(
metadata='CHARACTER_0001',
),
),
inventory.ItemModel(
name='character-0002',
stacking_limit=49,
allow_multiple_stacks=True,
sort_value=2,
options=inventory.ItemModelOptions(
metadata='CHARACTER_0002',
),
),
inventory.ItemModel(
name='character-0003',
stacking_limit=9,
allow_multiple_stacks=False,
sort_value=3,
options=inventory.ItemModelOptions(
metadata='CHARACTER_0003',
),
),
],
options=inventory.InventoryModelOptions(
metadata = 'INVENTORY_CHARACTER'
),
),
],
simple_inventory_models=[
inventory.SimpleInventoryModel(
name='item',
simple_item_models=[
inventory.SimpleItemModel(
name='item-0001',
options=inventory.SimpleItemModelOptions(
metadata='ITEM_0001',
),
),
inventory.SimpleItemModel(
name='item-0002',
options=inventory.SimpleItemModelOptions(
metadata='ITEM_0002',
),
),
inventory.SimpleItemModel(
name='item-0003',
options=inventory.SimpleItemModelOptions(
metadata='ITEM_0003',
),
),
],
options=inventory.SimpleInventoryModelOptions(
metadata = 'INVENTORY_ITEM'
),
),
],
big_inventory_models=[
inventory.BigInventoryModel(
name='item',
big_item_models=[
inventory.BigItemModel(
name='item-0001',
options=inventory.BigItemModelOptions(
metadata='ITEM_0001',
),
),
inventory.BigItemModel(
name='item-0002',
options=inventory.BigItemModelOptions(
metadata='ITEM_0002',
),
),
inventory.BigItemModel(
name='item-0003',
options=inventory.BigItemModelOptions(
metadata='ITEM_0003',
),
),
],
options=inventory.BigInventoryModelOptions(
metadata = 'INVENTORY_ITEM'
),
),
],
)
print(SampleStack().yaml()) # Generate TemplateInventoryModel
インベントリモデル
インベントリはゲームプレイヤーが所有しているアイテムを格納するカバンのようなものです。
インベントリには容量が設定でき、容量を超えては所有できません。
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |
|---|---|---|---|---|---|---|
| inventoryModelId | string | ✓* | ~ 1024文字 | インベントリモデル
GRN ※ サーバー側で自動的に設定 | ||
| name | string | ✓ | ~ 128文字 | インベントリモデル名 | ||
| metadata | string | ~ 2048文字 | メタデータ | |||
| initialCapacity | int | ✓ | 0 ~ 2147483646 | 初期サイズ | ||
| maxCapacity | int | ✓ | 0 ~ 2147483646 | 最大サイズ | ||
| protectReferencedItem | bool? | false | 参照元が登録されているアイテムセットは削除できなくする | |||
| itemModels | List<ItemModel> | ✓ | [] | 1 ~ 1000 items | インベントリに格納可能なアイテムモデル一覧 |
ItemModel
アイテムモデル
アイテムは、ポーション ×99 のように、1つのインベントリ枠に複数個まとめて所持できます。
このように 1枠に複数個まとめることを「スタック」 と呼び、アイテムごとに スタックできる上限数 を設定できます。
スタック上限に達した場合の挙動もアイテムごとに設定できます。
具体的には、以下のどちらかを選べます:
- 新しいインベントリ枠を追加して、さらに所持できるようにする
- 上限に達したため、これ以上入手できないようにする
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |
|---|---|---|---|---|---|---|
| itemModelId | string | ✓* | ~ 1024文字 | アイテムモデル
GRN ※ サーバー側で自動的に設定 | ||
| name | string | ✓ | ~ 128文字 | アイテムモデル名 | ||
| metadata | string | ~ 2048文字 | メタデータ GS2-EnhanceにはGS2-Inventoryと連携して強化を行う仕組みがあり、ItemModelのメタデータにJSON形式で、強化素材として使用した場合の経験値量を設定します。 詳細は マイクロサービス紹介 / GS2-Enhance の項で解説しています。 | |||
| stackingLimit | long | ✓ | 1 ~ 9223372036854775805 | スタック可能な最大数量 | ||
| allowMultipleStacks | bool | ✓ | スタック可能な最大数量を超えた時複数枠にアイテムを保管することを許すか | |||
| sortValue | int | ✓ | 0 ~ 2147483646 | 表示順番 |
SimpleInventoryModel
シンプルインベントリモデル
通常の InventoryModel では、インベントリ内に格納できるアイテムの容量制限ができました。
しかし、シンプルインベントリ ではそのような機能はなく、単純にアイテムの所持数量を保持するのみとなります。
ただし、シンプルインベントリでは、複数のアイテムの増減処理を1回の処理で実行可能なAPIが利用できます。
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |
|---|---|---|---|---|---|---|
| inventoryModelId | string | ✓* | ~ 1024文字 | シンプルインベントリモデル
GRN ※ サーバー側で自動的に設定 | ||
| name | string | ✓ | ~ 128文字 | シンプルインベントリモデル名 | ||
| metadata | string | ~ 2048文字 | メタデータ | |||
| simpleItemModels | List<SimpleItemModel> | ✓ | [] | 1 ~ 1000 items | インベントリに格納可能なシンプルアイテムモデル一覧 |
SimpleItemModel
シンプルアイテムモデル
ItemModel では、スタックできる数量の最大値を設定でき、一定数を超える場合は複数のスタックに分けるような実装が可能でした。
シンプルアイテム にはそのような機能はなく、単純にアイテムの所持数量を保持するのみとなります。
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |
|---|---|---|---|---|---|---|
| itemModelId | string | ✓* | ~ 1024文字 | シンプルアイテムモデル
GRN ※ サーバー側で自動的に設定 | ||
| name | string | ✓ | ~ 128文字 | シンプルアイテムモデル名 | ||
| metadata | string | ~ 2048文字 | メタデータ |
BigInventoryModel
巨大インベントリモデル
通常の InventoryModel や SimpleInventoryModel では、インベントリに格納できるアイテムの数は 64bit 整数値の範囲に限られました。
インフレ系ゲームでは、もっと広い値の範囲を必要とする場合があります。
巨大インベントリモデルでは、インベントリに格納できるアイテムの数には1024桁の整数値を持たせることができます。
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |
|---|---|---|---|---|---|---|
| inventoryModelId | string | ✓* | ~ 1024文字 | 巨大インベントリモデル
GRN ※ サーバー側で自動的に設定 | ||
| name | string | ✓ | ~ 128文字 | 巨大インベントリモデル名 | ||
| metadata | string | ~ 2048文字 | メタデータ | |||
| bigItemModels | List<BigItemModel> | ✓ | [] | 1 ~ 1000 items | インベントリに格納可能な巨大アイテムモデル一覧 |
BigItemModel
巨大アイテムモデル
ItemModel では、スタックできる数量の最大値を設定でき、一定数を超える場合は複数のスタックに分けるような実装が可能でした。
巨大アイテム にはそのような機能はなく、単純にアイテムの所持数量を保持するのみとなります。
| 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 | |
|---|---|---|---|---|---|---|
| itemModelId | string | ✓* | ~ 1024文字 | 巨大アイテムモデル
GRN ※ サーバー側で自動的に設定 | ||
| name | string | ✓ | ~ 128文字 | 巨大アイテムモデル名 | ||
| metadata | string | ~ 2048文字 | メタデータ |