Economy #

Read more about the Economy system in Hiro here.

Donation claim #

Claim one or more rewards which are partially or full donated by other players.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEconomyDonationClaim(const Hiro::EconomyDonationClaimRewards& economyDonationClaimRewards)
{
    std::cout << "Successfully claimed donations!\n";
}

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

Hiro::EconomyDonationClaimRequest request;
request.donationIds = {"donation_1", "donation_2"};

hiroClient->economyDonationClaim(session, request, onEconomyDonationClaim, onError);

Donate some resource (currencies, items, etc.) to a user by donation ID.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
void onEconomyDonationGive(const Hiro::EconomyUpdateAck& economyUpdateAck)
{
    std::cout << "Successfully donated resources!\n";
}

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

Hiro::EconomyDonationGiveRequest request;
request.userId = "userId_1";
request.donationId = "donation_1";

hiroClient->economyDonationGive(session, request, onEconomyDonationGive, onError);

Get donation progress #

Get progress on one or more donations for a set of players by their IDs.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEconomyDonationGet(const Hiro::EconomyDonationsByUserList& economyDonationsByUserList)
{
    std::cout << "Successfully got donations!\n";
}

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

Hiro::EconomyDonationGetRequest request;
request.ids = {"userId_1", "userId_2"};

hiroClient->economyDonationGet(session, request, onEconomyDonationGet, onError);

Request a donation #

Request a donation which other players can contribute into.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEconomyDonationRequest(const Hiro::EconomyDonationAck& economyDonationAck)
{
    std::cout << "Successfully requested donation: " << economyDonationAck.donation.name << '\n';
}

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

Hiro::EconomyDonationRequest request;
request.donationId = "donation_1";

hiroClient->economyDonationRequest(session, request, onEconomyDonationRequest, onError);

Get store items #

Get all store items defined in the Virtual Store.

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

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

Hiro::EconomyListRequest request;
request.storeType = Hiro::EconomyStoreType::ECONOMY_STORE_TYPE_APPLE_APPSTORE;

hiroClient->economyStoreGet(session, request, onEconomyStoreGet, onError);

Grant currencies or reward modifiers #

Grant one or more currencies or reward modifiers to the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEconomyGrant(const Hiro::EconomyUpdateAck& economyUpdateAck)
{
    std::cout << "Successfully granted currency/rewards to player!\n";
}

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

Hiro::EconomyGrantRequest request;
request.currencies.insert(std::make_pair<std::string, std::string>("coins", "100"));

hiroClient->economyGrant(session, request, onEconomyGrant, onError);

Send a purchase intent #

Send a marker of intent to purchase by the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
void onPurchaseIntentSuccess()
{
    std::cout << "Successfully sent purchase intent!\n";
}

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

Hiro::EconomyPurchaseIntentRequest request;
request.itemId = "item_1";
request.storeType = Hiro::EconomyStoreType::ECONOMY_STORE_TYPE_APPLE_APPSTORE;
request.sku = "sku_1";

hiroClient->economyPurchaseIntent(session, request, onPurchaseIntentSuccess, onError);

Purchase a store item #

Purchase a store item by the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
void onEconomyPurchaseItem(const Hiro::EconomyPurchaseAck& economyPurchaseAck)
{
    std::cout << "Successfully purchased item!\n";
}

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

Hiro::EconomyPurchaseRequest request;
request.itemId = "item_1";
request.storeType = Hiro::EconomyStoreType::ECONOMY_STORE_TYPE_APPLE_APPSTORE;
request.receipt = "<receipt>";

hiroClient->economyPurchaseItem(session, request, onEconomyPurchaseItem, onError);

Get ad placement status #

Get the current status on an Ad placement which may have been rewarded.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
void onEconomyPlacementStatus(const Hiro::EconomyPlacementStatus& economyPlacementStatus)
{
    std::cout << "Found status for placement: " << economyPlacementStatus.placementId << "\n";
}

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

Hiro::EconomyPlacementStatusRequest request;
request.rewardId = "reward_1";
request.placementId = "placement_1";
request.count = 0;

hiroClient->economyPlacementStatus(session, request, onEconomyPlacementStatus, onError);

Start a new ad placement #

Start a new Ad placement by placement ID.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEconomyPlacementStart(const Hiro::EconomyPlacementStatus& economyPlacementStatus)
{
    std::cout << "Started placement: " << economyPlacementStatus.placementId << "\n";
}

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

Hiro::EconomyPlacementStartRequest request;
request.placementId = "placement_1";

hiroClient->economyPlacementStart(session, request, onEconomyPlacementStart, onError);

Placement success #

Webhook RPC to handle Rewarded Video Ad placement success callbacks.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
void onEconomyPlacementSuccess()
{
    std::cout << "Ad placement was successful!\n";
}

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

hiroClient->economyPlacementSuccess(session, onEconomyPlacementSuccess, onError);

Placement fail #

Webhook RPC to handle Rewarded Video Ad placement failure callbacks.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
void onEconomyPlacementFail()
{
    std::cout << "Ad placement failed!\n";
}

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

hiroClient->economyPlacementFail(session, onEconomyPlacementFail, onError);