Achievements

Integration Guide
The AchievementsModule allows to give the user different rewards for making progress. The first things you'll need to decide are when you want to reward the user and what should be given as a reward.
Currently, the achievements support 3 types of user rewards:
  1. 1.
    Virtual Items rewards - the virtual items are added to the user's inventory
  2. 2.
    Currency Coins rewards - the currency coins are added to the user's data. It is not possible to give the special "rgn-coin" as a currency reward here.
  3. 3.
    Progression rewards - If you want to track user progress. You can use custom progression data types and store those in the user's data. When the achievement is completed and the progression rewards are given, it will increment the user's progression values accordingly. The progression values should be numbers. To retrieve the progression data you need to use the GameProgressModule
You can create new achievements by using the developer dashboard or by reaching out to the Ready team.

Retrieve achievement list:

using System.Collections.Generic;
using RGN.Modules.Achievement;
namespace SomeNamespace
{
internal sealed class GetAchievements
{
public async void GetAchievementsAsync()
{
List<AchievementData> achievementsData =
await AchievementsModule.I.GetAsync();
for (int i = 0; i < achievementsData.Count; ++i)
{
var achievement = achievementsData[i];
UnityEngine.Debug.Log(achievement.name);
UnityEngine.Debug.Log(achievement.description);
}
}
}
}
The GetAsync() method supports pagination. You can provide limit and startAfter parameters to partially retrieve the achievements. The startAfter parameter is based on the AchievementData.updatedAt field.

Response:

Returns list of achievements created for the current application.
Details of AchievementData:
  • achievementId (string) - unique identifier of the achievement, is used to trigger
  • name (string) - the name of the achievement
  • description (string) - description of the achievement
  • virtualItemRewards (List<string>) - virtual item ids which will be added to user inventory after an achievement is triggered. Is ignored if empty or null.
  • currencyRewards (List<Currency>) - currencies which will be added to user data after an achievement is triggered. Is ignored if empty or null.
  • progressionRewards (List<PregressionReward>) - adds custom progression data to the user's data. You can retrieve the progression data by using the GameProgressModule. Is ignored if empty or null.
  • repeatable (bool) - indicates whether the achievement can be completed multiple times. It means if this value is true then the rewards are given to the user every time the achievement is triggered. In case it is false the rewards are given only the first time. All subsequent calls to the achievements trigger function will not give any user rewards
  • repeatNoMoreOftenThanCron (string) - This string specifies how often the achievement can repeat. This parameter is used only in case the achievement is repeatable. The parameter is a cron string. You can use this website to specify the string: https://crontab.guru/
  • allowClientTrigger (bool) - It is possible to trigger the achievement from the client side. If this parameter is false then the trigger will throw an exception when it is called from the SDK side. This parameter is useful in combination with the Matchmaking API. The matchmaking API is currently implemented only on the server side. It is used for giving rewards when a user wins a match.
  • createdAt (long) - timestamp in milliseconds since midnight, January 1, 1970 UTC when the item was created. You can use the RGN.Utility.DateTimeUtility class to convert the value to DateTime or string.
  • updatedAt (long) - timestamp in milliseconds since midnight, January 1, 1970 UTC when the item was last time updated. You can use the RGN.Utility.DateTimeUtility class to convert the value to DateTime or string.
  • createdBy (string) - creator user id.
  • updatedBy (string) - id of the user who last time updated the achievement data.

Trigger achievement:

In order to complete an achievement you can call the following function by passing the achievement's unique id (string) as a parameter:
using RGN.Modules.Achievement;
using UnityEngine;
namespace SomeNamespace
{
internal sealed class TriggerAchievement
{
public async void CompleteAchievementAsync(string achievementId)
{
string triggeredAchievementId =
await AchievementsModule.I.TriggerAsync(achievementId);
Debug.Log(triggeredAchievementId);
}
}
}
In case the achievement is not repeatable and was already triggered for the current user this call will succeed, but the rewards will not be given again. The same applies to repeatable achievements, but with the repeatNoMoreOftenThanCron setting.
You can for example create a daily reward achievement that will reward the user on every login, but no more often than once a day. In this case, you need to set repeatable flag to true and set the repeatNoMoreOftenThanCron string to "0 0 * * *".

Get users competed achievements:

When the user completes an achievement (the rewards are given to the user) the information is stored in the backend. You can get all completed achievements for the currently authorized user, or for other users in case you provide the userId parameter.
using System.Collections.Generic;
using RGN.Modules.Achievement;
using UnityEngine;
namespace SomeNamespace
{
internal sealed class GetUserCompletedAchievements
{
public async void GetUserCompletedAchievementsAsync()
{
List<CompletedAchievement> comptedAchievements =
await AchievementsModule.I.GetUserCompletedAchievements();
for (int i = 0; i < comptedAchievements.Count; ++i)
{
CompletedAchievement achievement = comptedAchievements[i];
Debug.Log(achievement.achievementId);
for (int j = 0; j < achievement.history.Count; ++j)
{
Debug.Log(JsonUtility.ToJson(achievement.history[j]));
}
}
}
}
}
Each completed achievement entry contains non-empty history list. This list stores all times the rewards were given to the user for this achievement. For example, if the user completed "achievement_a" 3 times, then the history list will contain 3 items.
You can provide the userId parameter to get the completed achievements for other users.
The GetUserCompletedAchievements() method also supports pagination. You can provide the limit and startAfter parameters to partially retrieve the completed user achievements. The startAfter parameter is based on the CompletedAchievement.lastCompleteTime field.