[go: up one dir, main page]

Inventory #

Read more about the Inventory system in Hiro here.

List items #

List all inventory items defined in the codex, optionally filtered by category.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
void onInventoryList(const Hiro::InventoryList& inventoryList)
{
    for (auto it = inventoryList.items.begin(); it != inventoryList.items.end(); it++)
    {
        std::cout << "Found codex item: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::InventoryListRequest request;
request.itemCategory = "weapons";

hiroClient->inventoryList(session, request, onInventoryList, onError);

List user inventory items #

List all inventory items owned by the player, optionally filtered by category.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
void onInventoryListInventory(const Hiro::InventoryList& inventoryList)
{
    for (auto it = inventoryList.items.begin(); it != inventoryList.items.end(); it++)
    {
        std::cout << "Found inventory item: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::InventoryListRequest request;
request.itemCategory = "weapons";

hiroClient->inventoryListInventory(session, request, onInventoryListInventory, onError);

Consume inventory items #

Consume one or more inventory items owned by the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onInventoryConsume(const Hiro::InventoryConsumeRewards& inventoryConsumeRewards)
{
    std::cout << "Successfully consumed inventory items!\n";
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::InventoryConsumeRequest request;
request.items.insert(std::make_pair<std::string, std::string>("health_potion", "1"));

hiroClient->inventoryConsume(session, request, onInventoryConsume, onError);

Grant inventory items #

Grant one or more inventory items to the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
void onInventoryGrant(const Hiro::InventoryUpdateAck& inventoryUpdateAck)
{
    for (auto it = inventoryUpdateAck.inventory.items.begin(); it != inventoryUpdateAck.inventory.items.end(); it++)
    {
        std::cout << "Found inventory item: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::InventoryGrantRequest request;
request.items.insert(std::make_pair<std::string, std::string>("bronze_sword", "1"));

hiroClient->inventoryGrant(session, request, onInventoryGrant, onError);

Update inventory items #

Update the properties on one or more inventory items owned by the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
void onInventoryUpdate(const Hiro::InventoryUpdateAck& inventoryUpdateAck)
{
    for (auto it = inventoryUpdateAck.inventory.items.begin(); it != inventoryUpdateAck.inventory.items.end(); it++)
    {
        std::cout << "Found inventory item: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::InventoryUpdateItemsRequest request;

Hiro::InventoryUpdateItemProperties itemProperties;
itemProperties.stringProperties.insert(std::make_pair<std::string, std::string>("example_property", "example_value"));
itemProperties.numericProperties.insert(std::make_pair<std::string, double>("numeric_property", 10));

request.itemUpdates.insert(std::make_pair("bronze_sword", itemProperties));

hiroClient->inventoryUpdate(session, request, onInventoryUpdate, onError);