GS2-Deploy/CDK Reference of GS2-Inventory

The template format used when creating stacks with GS2-Deploy, and implementation examples of template output in various languages using CDK

Entity

Resources operated in Deploy process

Namespace

Namespace

A namespace is a mechanism that allows multiple uses of the same service for different purposes within a single project. Each GS2 service is managed on a per namespace basis. Even when using the same service, if the namespace differs, the data is treated as a completely independent data space.

Therefore, you must create a namespace before you can start using each service.

TypeConditionRequiredDefaultValue LimitsDescription
namespaceIdstring
~ 1024 charsNamespace GRN
namestring
~ 128 charsNamespace name
descriptionstring~ 1024 charsDescription
transactionSettingTransactionSettingTransaction settings
acquireScriptScriptSettingScript to be executed when an item is obtained
overflowScriptScriptSettingScript to execute when unable to obtain due to reaching the acquisition limit
consumeScriptScriptSettingScript to run when consuming items
simpleItemAcquireScriptScriptSettingScript to be executed when acquiring simple items
simpleItemConsumeScriptScriptSettingScript to run when consuming simple items
bigItemAcquireScriptScriptSettingScript to be executed when acquiring big items
bigItemConsumeScriptScriptSettingScript to run when consuming big items
logSettingLogSettingLog output settings
createdAtlong
NowDatetime of creation
Unix time, milliseconds
Automatically configured on the server
updatedAtlong
NowDatetime of last update
Unix time, milliseconds
Automatically configured on the server
revisionlong00 ~ 9223372036854775805Revision

GetAttr

Generation results of resources that can be obtained with the !GetAttr tag

TypeDescription
ItemNamespaceNamespace created

Implementation Example

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-0001
import (
    "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 Template
public 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 Template
import 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 Template

TransactionSetting

Transaction settings

Transaction settings control how transactions are executed, their consistency, asynchronous processing, and conflict avoidance mechanisms. Combining features like AutoRun, AtomicCommit, Distributor, batch application of script results, and asynchronous acquisition actions via JobQueue enables robust transaction management tailored to game logic.

TypeConditionRequiredDefaultValue LimitsDescription
enableAutoRunbool
falseWhether to automatically execute issued transactions on the server side
enableAtomicCommitbool{enableAutoRun} == true
✓*
falseWhether to commit the execution of transactions atomically
* Required if enableAutoRun is true
transactionUseDistributorbool{enableAtomicCommit} == true
✓*
falseWhether to execute transactions asynchronously
* Required if enableAtomicCommit is true
commitScriptResultInUseDistributorbool{transactionUseDistributor} == true
✓*
falseWhether to execute the commit processing of the script result asynchronously
* Required if transactionUseDistributor is true
acquireActionUseJobQueuebool{enableAtomicCommit} == true
✓*
falseWhether to use GS2-JobQueue to execute the acquire action
* Required if enableAtomicCommit is true
distributorNamespaceIdstring
“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024 charsGS2-Distributor namespace used for transaction execution
queueNamespaceIdstring
“grn:gs2:{region}:{ownerId}:queue:default”~ 1024 charsNamespace in GS2-JobQueue used to run the transaction

ScriptSetting

Script settings

In GS2, you can associate custom scripts with microservice events and execute them. This model holds the settings for triggering script execution.

There are two main ways to execute a script: synchronous execution and asynchronous execution. Synchronous execution blocks processing until the script has finished executing. Instead, you can use the script execution result to stop the execution of the API or to tamper with the result of the API.

In contrast, asynchronous execution does not block processing until the script has finished executing. Since the script result cannot be used to stop the API execution or modify the API response, asynchronous execution does not affect the API’s response flow. For this reason, asynchronous execution is generally recommended.

There are two types of asynchronous execution methods: GS2-Script and Amazon EventBridge. By using Amazon EventBridge, you can write processing in languages other than Lua.

TypeConditionRequiredDefaultValue LimitsDescription
triggerScriptIdstring~ 1024 charsScript GRN of synchronous execution script
Must be specified in GRN format starting with “grn:gs2:”.
doneTriggerTargetTypeString Enum
enum {
  “none”,
  “gs2_script”,
  “aws”
}
“none”How to execute asynchronous scripts
Specifies the type of script to use for asynchronous execution.
You can choose from “Do not use asynchronous execution scripts (none)”, “Use GS2-Script (gs2_script)”, and “Use Amazon EventBridge (aws)”.
Enumerator String DefinitionDescription
“none”None
“gs2_script”GS2-Script
“aws”Amazon EventBridge
doneTriggerScriptIdstring{doneTriggerTargetType} == “gs2_script”~ 1024 charsScript GRN of asynchronous execution script
Must be specified in GRN format starting with “grn:gs2:”.

* Enabled if doneTriggerTargetType is “gs2_script”
doneTriggerQueueNamespaceIdstring{doneTriggerTargetType} == “gs2_script”~ 1024 charsGS2-JobQueue namespace GRN to execute asynchronous execution scripts
If you want to execute asynchronous execution scripts via GS2-JobQueue instead of executing them directly, specify the GS2-JobQueue namespace GRN.
There is little reason to use GS2-JobQueue, so you don’t need to specify it unless you have a specific reason.

* Enabled if doneTriggerTargetType is “gs2_script”

LogSetting

Log Export Settings

Manages log data export settings. This type holds the GS2-Log namespace identifier (Namespace ID) used to export log data. Specify the GS2-Log namespace where log data is collected and stored in the GRN format for the Log Namespace ID (loggingNamespaceId). Configuring this setting ensures that log data for API requests and responses occurring within the specified namespace is output to the target GS2-Log namespace. GS2-Log provides real-time logs that can be used for system monitoring, analysis, and debugging.

TypeConditionRequiredDefaultValue LimitsDescription
loggingNamespaceIdstring
~ 1024 charsGS2-Log namespace GRN to output logs

CurrentItemModelMaster

Currently Available Master Data

GS2 uses JSON format files for managing master data. By uploading these files, the master data settings are updated on the server.

To create JSON files, GS2 provides a master data editor within the management console. Additionally, you can create tools better suited for operating your game and export JSON files in the appropriate format.

TypeConditionRequiredDefaultValue LimitsDescription
namespaceIdstring
~ 1024 charsNamespace GRN
settingsstring
~ 5242880 bytes (5MB)Master Data

GetAttr

Generation results of resources that can be obtained with the !GetAttr tag

TypeDescription
ItemCurrentItemModelMasterUpdated and currently available possession master

Implementation Example

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: null
import (
    "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 Template
public 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 Template
import 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 Template

InventoryModel

Inventory Model

Inventory is like a bag that stores items owned by game players. Inventory can have a set capacity and cannot be owned beyond its capacity.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
~ 1024 charsInventory model GRN
namestring
~ 128 charsInventory Model Name
metadatastring~ 2048 charsMetadata
initialCapacityint
0 ~ 2147483646Initial Capacity
maxCapacityint
0 ~ 2147483646Maximum Capacity
protectReferencedItembool?falseItem Sets with registered references cannot be deleted
itemModelsList<ItemModel>
[]1 ~ 1000 itemsList of item models that can be stored in inventory

ItemModel

Item Model

Items can be held in groups within a single inventory slot, such as Potion ×99. This grouping of multiple items into one slot is called “stacking,” and a maximum stack size can be set for each item.

The behavior when the stack limit is reached can also be set for each item. Specifically, you can choose one of the following:

  • Add a new inventory slot to allow further acquisition
  • Prevent further acquisition once the limit is reached
TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
~ 1024 charsItem Model GRN
namestring
~ 128 charsItem Model Name
metadatastring~ 2048 charsMetadata
GS2-Enhance features a mechanism that works in conjunction with GS2-Inventory to perform enhancements. It sets the experience value when used as enhancement material in JSON format within the ItemModel metadata.
Details are explained in the Microservices Introduction / GS2-Enhance section.
stackingLimitlong
1 ~ 9223372036854775805Maximum stackable quantity
allowMultipleStacksbool
Whether to allow items to be stored in multiple slots when the maximum stackable quantity is exceeded
sortValueint
0 ~ 2147483646Display order

ItemModel

Item Model

Items can be held in groups within a single inventory slot, such as Potion ×99. This grouping of multiple items into one slot is called “stacking,” and a maximum stack size can be set for each item.

The behavior when the stack limit is reached can also be set for each item. Specifically, you can choose one of the following:

  • Add a new inventory slot to allow further acquisition
  • Prevent further acquisition once the limit is reached
TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
~ 1024 charsItem Model GRN
namestring
~ 128 charsItem Model Name
metadatastring~ 2048 charsMetadata
GS2-Enhance features a mechanism that works in conjunction with GS2-Inventory to perform enhancements. It sets the experience value when used as enhancement material in JSON format within the ItemModel metadata.
Details are explained in the Microservices Introduction / GS2-Enhance section.
stackingLimitlong
1 ~ 9223372036854775805Maximum stackable quantity
allowMultipleStacksbool
Whether to allow items to be stored in multiple slots when the maximum stackable quantity is exceeded
sortValueint
0 ~ 2147483646Display order

SimpleInventoryModel

Simple Inventory Model

In a normal InventoryModel, you could limit the amount of items that could be stored in your inventory. Simple Inventory, however, has no such functionality and simply stores the number of items in the inventory.

However, the Simple Inventory provides an API that can increase or decrease the number of items in a single process.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
~ 1024 charsInventory model GRN
namestring
~ 128 charsSimple Inventory Model Name
metadatastring~ 2048 charsMetadata
simpleItemModelsList<SimpleItemModel>
[]1 ~ 1000 itemsList of simple item models that can be stored in inventory

SimpleItemModel

Simple ItemModel

ItemModel allowed setting a maximum stackable quantity, enabling implementation where items exceeding a certain number could be split into multiple stacks. SimpleItem does not have such a function and simply stores the number of items in the possession of the item.

TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
~ 1024 charsSimple Item Model GRN
namestring
~ 128 charsSimple Item Model Name
metadatastring~ 2048 charsMetadata

SimpleItemModel

Simple ItemModel

ItemModel allowed setting a maximum stackable quantity, enabling implementation where items exceeding a certain number could be split into multiple stacks. SimpleItem does not have such a function and simply stores the number of items in the possession of the item.

TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
~ 1024 charsSimple Item Model GRN
namestring
~ 128 charsSimple Item Model Name
metadatastring~ 2048 charsMetadata

BigInventoryModel

Big Inventory model

In the normal InventoryModel and SimpleInventoryModel, the number of items that can be stored in the inventory is limited to the range of 64bit integer values. In inflationary games, you may need a wider range of values.

In the Big Inventory Model, the number of items that can be stored in the inventory can have an integer value of 1024 digits.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
~ 1024 charsInventory model GRN
namestring
~ 128 charsBig Inventory Model Name
metadatastring~ 2048 charsMetadata
bigItemModelsList<BigItemModel>
[]1 ~ 1000 itemsList of big item models that can be stored in inventory

BigItemModel

Big ItemModel

ItemModel allowed setting a maximum stackable quantity, enabling implementation where items exceeding a certain number could be split into multiple stacks. SimpleItem does not have such a function and simply stores the number of items in the possession of the item.

TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
~ 1024 charsBig Item Model GRN
namestring
~ 128 charsBig Item Model Name
metadatastring~ 2048 charsMetadata

BigItemModel

Big ItemModel

ItemModel allowed setting a maximum stackable quantity, enabling implementation where items exceeding a certain number could be split into multiple stacks. SimpleItem does not have such a function and simply stores the number of items in the possession of the item.

TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
~ 1024 charsBig Item Model GRN
namestring
~ 128 charsBig Item Model Name
metadatastring~ 2048 charsMetadata