GS2-Inventory SDK for Game Engine API リファレンス

モデル

EzInventoryModel

インベントリモデル

インベントリはゲームプレイヤーが所有しているアイテムを格納する鞄のようなものです。 インベントリには容量が設定でき、容量を超えては所有できません。

インベントリの容量は拡張することができます。 スタンプシートの報酬に設定ができますので、スタンプシートを使用して報酬を付与できる手段であれば、拡張の方法は問いません。

必須デフォルト値の制限説明
namestring~ 128文字インベントリモデル名
metadatastring~ 128文字メタデータ
initialCapacityint~ 2147483646初期サイズ
maxCapacityint~ 2147483646最大サイズ

EzItemModel

アイテムモデル

アイテムは ポーション×99 のようにインベントリの1容量に対して複数所有できます。 1容量で複数所有している状態を アイテムをスタック する。と呼び、アイテムごとにスタックできる最大数量を指定できます。

スタックできる最大数量に達したとき、新しくインベントリの容量を確保して所有することができるか、入手することが出来なくなるかをアイテムごとに設定できます。

必須デフォルト値の制限説明
namestring~ 128文字アイテムモデル名
metadatastring~ 128文字メタデータ
stackingLimitlong1 ~ 9223372036854775806スタック可能な最大数量
allowMultipleStacksboolスタック可能な最大数量を超えた時複数枠にアイテムを保管することを許すか
sortValueint~ 2147483646表示順番

EzInventory

インベントリ

インベントリはゲームプレイヤーが所有しているアイテムを格納する鞄のようなものです。 カバンには容量があり、プレイヤーごとに容量を拡張することができます。

必須デフォルト値の制限説明
inventoryIdstring~ 1024文字インベントリGRN
inventoryNamestring~ 128文字インベントリモデル名
currentInventoryCapacityUsageint0~ 2147483646キャパシティ使用量
currentInventoryMaxCapacityint1 ~ 2147483646最大キャパシティ

EzItemSet

アイテムはゲームプレイヤーの所有物です。

必須デフォルト値の制限説明
itemSetIdstring~ 1024文字有効期限ごとのアイテム所持数量GRN
namestringUUID~ 36文字アイテムセットを識別する名前
inventoryNamestring~ 128文字インベントリモデルの名前
itemNamestring~ 128文字アイテムモデルの名前
countlong1 ~ 9223372036854775806所持数量
sortValueint~ 2147483646表示順番
expiresAtlong0有効期限

メソッド

getInventoryModel

インベントリ名を指定してインベントリモデルを取得

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
inventoryNamestring~ 128文字インベントリモデル名

Result

説明
itemEzInventoryModelインベントリモデル

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).InventoryModel(
        inventoryName: "item"
    );
    var item = await domain.ModelAsync();
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).InventoryModel(
        inventoryName: "item"
    );
    var future = domain.Model();
    yield return future;
    var item = future.Result;
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->InventoryModel(
        "item" // inventoryName
    );
    const auto item = Domain.Model();

listInventoryModels

インベントリモデルの一覧を取得

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名

Result

説明
itemsList<EzInventoryModel>インベントリモデルのリスト

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    );
    var items = await domain.InventoryModelsAsync(
    ).ToListAsync();
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    );
    var it = domain.InventoryModels(
    );
    List<EzInventoryModel> items = new List<EzInventoryModel>();
    while (it.HasNext())
    {
        yield return it.Next();
        if (it.Error != null)
        {
            onError.Invoke(it.Error, null);
            break;
        }
        if (it.Current != null)
        {
            items.Add(it.Current);
        }
        else
        {
            break;
        }
    }
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    );
    const auto It = Domain->InventoryModels(
    );
    for (auto Item : *It)
    {

    }

getItemModel

インベントリ名とアイテム名を指定してアイテムモデルを取得

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
inventoryNamestring~ 128文字インベントリモデル名
itemNamestring~ 128文字アイテムモデル名

Result

説明
itemEzItemModel

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).InventoryModel(
        inventoryName: "item"
    ).ItemModel(
        itemName: "item-master-0001"
    );
    var item = await domain.ModelAsync();
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).InventoryModel(
        inventoryName: "item"
    ).ItemModel(
        itemName: "item-master-0001"
    );
    var future = domain.Model();
    yield return future;
    var item = future.Result;
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->InventoryModel(
        "item" // inventoryName
    )->ItemModel(
        "item-master-0001" // itemName
    );
    const auto item = Domain.Model();

listItemModels

インベントリ名を指定してアイテムモデルの一覧を取得

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
inventoryNamestring~ 128文字インベントリモデル名

Result

説明
itemsList<EzItemModel>アイテムモデルのリスト

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).InventoryModel(
        inventoryName: "item"
    );
    var items = await domain.ItemModelsAsync(
    ).ToListAsync();
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).InventoryModel(
        inventoryName: "item"
    );
    var it = domain.ItemModels(
    );
    List<EzItemModel> items = new List<EzItemModel>();
    while (it.HasNext())
    {
        yield return it.Next();
        if (it.Error != null)
        {
            onError.Invoke(it.Error, null);
            break;
        }
        if (it.Current != null)
        {
            items.Add(it.Current);
        }
        else
        {
            break;
        }
    }
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->InventoryModel(
        "item" // inventoryName
    );
    const auto It = Domain->ItemModels(
    );
    for (auto Item : *It)
    {

    }

getInventory

インベントリ名を指定してインベントリの情報を取得

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
inventoryNamestring~ 128文字インベントリモデル名
accessTokenstring~ 128文字ユーザーID

Result

説明
itemEzInventoryインベントリ

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "inventory-0001"
    );
    var item = await domain.ModelAsync();
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "inventory-0001"
    );
    var future = domain.Model();
    yield return future;
    var item = future.Result;
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Inventory(
        "inventory-0001" // inventoryName
    );
    const auto item = Domain.Model();

listInventories

インベントリの一覧を取得

ゲームプレイヤーに紐付いたインベントリの一覧を取得します。

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
accessTokenstring~ 128文字ユーザーID
pageTokenstring~ 1024文字データの取得を開始する位置を指定するトークン
limitint301 ~ 1000データの取得件数

Result

説明
itemsList<EzInventory>インベントリのリスト
nextPageTokenstringリストの続きを取得するためのページトークン

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    );
    var items = await domain.InventoriesAsync(
    ).ToListAsync();
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    );
    var it = domain.Inventories(
    );
    List<EzInventory> items = new List<EzInventory>();
    while (it.HasNext())
    {
        yield return it.Next();
        if (it.Error != null)
        {
            onError.Invoke(it.Error, null);
            break;
        }
        if (it.Current != null)
        {
            items.Add(it.Current);
        }
        else
        {
            break;
        }
    }
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    );
    const auto It = Domain->Inventories(
    );
    for (auto Item : *It)
    {

    }

consume

アイテムを消費

ゲーム内からアイテムを消費したい場合に使用します。

GS2のシステムと連携してアイテムの増減を行う場合はこのAPIを使用することはありません。 なぜなら、商品を購入するためや、クエストに参加するために必要な対価の場合は GS2-Showcase や GS2-Quest 上で対価を設定し、 商品の購入時やクエスト参加時に自動的に対価としてアイテムやその他のリソースが消費されるためです。

そのため、このAPIはGS2を介さない要素のためにアイテムを消費する場合に使用してください。

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
inventoryNamestring~ 128文字インベントリモデルの名前
itemNamestring~ 128文字アイテムモデルの名前
accessTokenstring~ 128文字ユーザーID
consumeCountlong1 ~ 9223372036854775806消費する量
itemSetNamestring~ 36文字アイテムセットを識別する名前

Result

説明
itemsList<EzItemSet>消費後の有効期限ごとのアイテム所持数量のリスト
itemModelEzItemModelアイテムモデル
inventoryEzInventoryインベントリ

Error

このAPIには特別な例外が定義されています。 GS2-SDK for GameEngine ではゲーム内でハンドリングが必要そうなエラーは一般的な例外から派生した特殊化した例外を用意することでハンドリングしやすくしています。 一般的なエラーの種類や、ハンドリング方法は こちら のドキュメントを参考にしてください。

基底クラス説明
ConflictExceptionConflictExceptionアイテムの操作処理が衝突しました。リトライが必要です
InsufficientExceptionBadRequestExceptionアイテムの所持数量が不足しています

実装例

try {
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "inventory-0001"
    ).ItemSet(
        itemName: "item-0001",
        itemSetName: null
    );
    var result = await domain.ConsumeAsync(
        consumeCount: 1L
    );
    var item = await result.ModelAsync();
} catch(Gs2.Gs2Inventory.Exception.Conflict e) {
    // Item manipulation process conflicted. Retry required.
} catch(Gs2.Gs2Inventory.Exception.Insufficient e) {
    // Insufficient quantity of items in your possession.
}
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "inventory-0001"
    ).ItemSet(
        itemName: "item-0001",
        itemSetName: null
    );
    var future = domain.Consume(
        consumeCount: 1L
    );
    yield return future;
    if (future.Error != null)
    {
        if (future.Error is Gs2.Gs2Inventory.Exception.ConflictException)
        {
            // Item manipulation process conflicted. Retry required.
        }
        if (future.Error is Gs2.Gs2Inventory.Exception.InsufficientException)
        {
            // Insufficient quantity of items in your possession.
        }
        onError.Invoke(future.Error, null);
        yield break;
    }
    var future2 = future.Result.Model();
    yield return future2;
    if (future2.Error != null)
    {
        onError.Invoke(future2.Error, null);
        yield break;
    }
    var result = future2.Result;
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Inventory(
        "inventory-0001" // inventoryName
    )->ItemSet(
        "item-0001", // itemName
        nullptr // itemSetName
    );
    const auto Future = Domain->Consume(
        1L
    );
    Future->StartSynchronousTask();
    if (Future->GetTask().IsError())
    {
        if (Gs2::Inventory::Error::FConflictError::TypeString == Task->GetTask().Error()->Type())
        {
            // Item manipulation process conflicted. Retry required.
        }
        if (Gs2::Inventory::Error::FInsufficientError::TypeString == Task->GetTask().Error()->Type())
        {
            // Insufficient quantity of items in your possession.
        }
        return false;
    }

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
    const auto Result = Future2->GetTask().Result();

getItem

インベントリ名とアイテム名を指定してアイテムを取得

アイテムは複数のスタックに分割されて応答されることがあります。 また、有効期限の異なるアイテムは、必ず別のスタックになります。

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
inventoryNamestring~ 128文字インベントリモデルの名前
itemNamestring~ 128文字アイテムモデルの名前
accessTokenstring~ 128文字ユーザーID

Result

説明
itemsList<EzItemSet>有効期限毎のアイテム所持数量リスト
itemModelEzItemModelアイテムモデル
inventoryEzInventoryインベントリ

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "item"
    ).ItemSet(
        itemName: "item-0001",
        itemSetName: "itemSet-0001"
    );
    var item = await domain.ModelAsync();
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "item"
    ).ItemSet(
        itemName: "item-0001",
        itemSetName: "itemSet-0001"
    );
    var future = domain.Model();
    yield return future;
    var item = future.Result;
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Inventory(
        "item" // inventoryName
    )->ItemSet(
        "item-0001", // itemName
        "itemSet-0001" // itemSetName
    );
    const auto item = Domain.Model();

getItemWithSignature

インベントリ名とアイテム名を指定して署名付きアイテムを取得

このAPIによって、APIを呼び出した瞬間に該当アイテムを所有していることを証明することができる

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
inventoryNamestring~ 128文字インベントリモデルの名前
itemNamestring~ 128文字アイテムモデルの名前
accessTokenstring~ 128文字ユーザーID
itemSetNamestring~ 36文字アイテムセットを識別する名前
keyIdstring~ 1024文字暗号鍵GRN

Result

説明
itemsList<EzItemSet>有効期限毎のアイテム所持数量リスト
itemModelEzItemModelアイテムモデル
inventoryEzInventoryインベントリ
bodystring署名対象のアイテムセット情報
signaturestring署名

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "inventory-0001"
    ).ItemSet(
        itemName: "item-0001",
        itemSetName: null
    );
    var result = await domain.GetItemWithSignatureAsync(
        keyId: "key-0001"
    );
    var item = await result.ModelAsync();
    var body = result.Body;
    var signature = result.Signature;
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "inventory-0001"
    ).ItemSet(
        itemName: "item-0001",
        itemSetName: null
    );
    var future = domain.GetItemWithSignature(
        keyId: "key-0001"
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
    var future2 = future.Result.Model();
    yield return future2;
    if (future2.Error != null)
    {
        onError.Invoke(future2.Error, null);
        yield break;
    }
    var result = future2.Result;
    var body = future.Result.Body;
    var signature = future.Result.Signature;
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Inventory(
        "inventory-0001" // inventoryName
    )->ItemSet(
        "item-0001", // itemName
        nullptr // itemSetName
    );
    const auto Future = Domain->GetItemWithSignature(
        "key-0001"
    );
    Future->StartSynchronousTask();
    if (Future->GetTask().IsError())
    {
        return false;
    }

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
    const auto Result = Future2->GetTask().Result();
    const auto Body = Result->Body;
    const auto Signature = Result->Signature;

listItems

指定したインベントリ内の所有しているアイテム一覧を取得

Request

必須デフォルト値の制限説明
namespaceNamestring~ 32文字ネームスペース名
inventoryNamestring~ 128文字インベントリの名前
accessTokenstring~ 128文字ユーザーID
pageTokenstring~ 1024文字データの取得を開始する位置を指定するトークン
limitint301 ~ 1000データの取得件数

Result

説明
itemsList<EzItemSet>有効期限ごとのアイテム所持数量のリスト
nextPageTokenstringリストの続きを取得するためのページトークン

実装例

    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "item"
    );
    var items = await domain.ItemSetsAsync(
    ).ToListAsync();
    var domain = gs2.Inventory.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Inventory(
        inventoryName: "item"
    );
    var it = domain.ItemSets(
    );
    List<EzItemSet> items = new List<EzItemSet>();
    while (it.HasNext())
    {
        yield return it.Next();
        if (it.Error != null)
        {
            onError.Invoke(it.Error, null);
            break;
        }
        if (it.Current != null)
        {
            items.Add(it.Current);
        }
        else
        {
            break;
        }
    }
    const auto Domain = Gs2->Inventory->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Inventory(
        "item" // inventoryName
    );
    const auto It = Domain->ItemSets(
    );
    for (auto Item : *It)
    {

    }