Rewards and wallet
Daily, weekly or one-time rewards decided by the server and credited to a per-player wallet.
Define rewards#
Create rewards on the Rewards page:
| Field | Meaning |
|---|---|
| Reward key | Identifier used in code, e.g. daily_coins. |
| Amount and currency | How much is credited, and to which currency (e.g. coins). |
| Cooldown | daily, weekly or once. |
| Active | Inactive rewards are hidden and cannot be claimed. |
List rewards#
With a signed-in player each reward includes claimable and next_claim_at:
var available = await Majacloud.Rewards.ListAsync();
foreach (var reward in available.Value)
Debug.Log(reward.RewardKey + " claimable: " + reward.Claimable + " next: " + reward.NextClaimAt);var available := await Majacloud.rewards.list()
for reward in available.value:
print(reward.reward_key, " claimable: ", reward.claimable, " next: ", reward.next_claim_at)const available = await mc.rewards.list();
for (const reward of available.value) console.log(reward.reward_key, reward.claimable, reward.next_claim_at);curl https://majacloud.majanite.com/v1/rewards -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"Claim#
The server decides whether the claim is allowed and credits the wallet atomically. A second claim in the same period fails with conflict and details.next_claim_at.
var claim = await Majacloud.Rewards.ClaimAsync("daily_coins");
if (claim.Ok)
{
Debug.Log($"+{claim.Value.Amount} {claim.Value.Currency}, balance {claim.Value.Balance}");
}
else if (claim.Error.Code == MajacloudErrorCode.Conflict)
{
DateTime? next = claim.Error.GetDetailDateTime("next_claim_at"); // UTC
}var claim := await Majacloud.rewards.claim("daily_coins")
if claim.ok:
print("+%s %s, balance %s" % [claim.value.amount, claim.value.currency, claim.value.balance])
elif claim.error == "conflict":
print("Come back at ", claim.details.next_claim_at) # UTCconst claim = await mc.rewards.claim('daily_coins');
if (claim.ok) {
console.log(`+${claim.value.amount} ${claim.value.currency}, balance ${claim.value.balance}`);
} else if (claim.error.code === 'conflict') {
console.log('Come back at ' + claim.error.details.next_claim_at); // UTC
}curl -X POST https://majacloud.majanite.com/v1/rewards/claim -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"reward_key": "daily_coins"}'Wallet#
Read the player's balances per currency:
var wallet = await Majacloud.Rewards.GetWalletAsync();
Debug.Log("Coins: " + wallet.Value.Coins + ", gems: " + wallet.Value.Get("gems"));var wallet := await Majacloud.rewards.get_wallet()
print("Coins: ", wallet.value.get("coins", 0))const wallet = await mc.rewards.getWallet();
console.log('Coins: ' + (wallet.value.balances.coins || 0));curl https://majacloud.majanite.com/v1/wallet -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"When rewards reset#
Daily rewards can be claimed again from 00:00 UTC, weekly rewards from Monday 00:00 UTC, and one-time rewards never again.