Phần thưởng và ví
Phần thưởng hằng ngày, hằng tuần hoặc một lần do máy chủ quyết định và được cộng vào ví của từng người chơi.
Chú thích trong mã và tên API được giữ nguyên tiếng Anh để khớp với SDK.
Định nghĩa phần thưởng#
Tạo phần thưởng trên trang Phần thưởng:
| Trường | Ý nghĩa |
|---|---|
| Khóa phần thưởng | Định danh dùng trong mã, ví dụ daily_coins. |
| Số lượng và loại tiền | Số lượng được cộng và cộng vào loại tiền nào (ví dụ coins). |
| Thời gian chờ | daily, weekly hoặc once. |
| Đang hoạt động | Phần thưởng không hoạt động sẽ bị ẩn và không thể nhận. |
Liệt kê phần thưởng#
Khi có người chơi đã đăng nhập, mỗi phần thưởng kèm claimable và 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"Nhận thưởng#
Máy chủ quyết định có cho phép nhận hay không và cộng vào ví một cách nguyên tử (atomic). Lần nhận thứ hai trong cùng kỳ sẽ thất bại với conflict và 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"}'Ví#
Đọc số dư của người chơi theo từng loại tiền:
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"Khi nào phần thưởng được đặt lại#
Phần thưởng hằng ngày có thể nhận lại từ 00:00 UTC, hằng tuần từ 00:00 UTC thứ Hai, còn phần thưởng một lần thì không bao giờ nhận lại được.